ICP  1
Classes | Macros | Functions | Variables
selogger.cpp File Reference
#include "stdafx.h"
#include "selogger.h"
#include "isisdb.h"
#include "epicsdb.h"
#include "icputils.h"

Go to the source code of this file.

Classes

struct  MyOverlapped
 
struct  my_overlap_t
 
struct  workpacket
 
struct  se_log_values_t
 
struct  se_clear_values2_t
 
struct  se_set_period_t
 
struct  se_set_run_state_t
 

Macros

#define SQLITE_CHECK_RC(__rc)
 
#define SQLITE_HANDLE_EXCEPTION(__func_name)
 
#define OPEN_DATABASE
 

Functions

static void my_overlap (void *arg)
 
static void my_io_complete (void *arg)
 
static HANDLE createAppendFile (const char *filename)
 
static void appendToFileAsync (HANDLE h, const char *message, bool close_after_write)
 
static void appendToFileAsync (const char *filename, const char *message)
 
BOOL APIENTRY DllMain (HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
 
static time_t unixTime (const char *isotime)
 
static int ISOtime (time_t time, char *buffer, int len)
 
static int __stdcall se_log_values_list (const std::list< se_log_values_t * > *tlist)
 
static void process_requests (void *arg)
 
static int general_init ()
 
static int __stdcall se_async (workpacket *work)
 
static int count_rows_callback (void *arg, int argc, char **argv, char **azColName)
 
const char *__stdcall se_version ()
 
static int my_sqlite3_exec (sqlite3 *db, const char *sql, int(*callback)(void *, int, char **, char **), void *arg, char **errmsg)
 
static int se_set_config_param (const char *name, const char *value)
 
static int se_get_config_param (const char *name, std::string &value)
 
static int se_set_config_param (const char *name, long value)
 
static long get_run_number ()
 
static long get_period ()
 
static int isReal (const char *value)
 
SELOGGER_API int __stdcall se_start_epics_thread (epics_thread_data_t *arg)
 
SELOGGER_API int __stdcall se_set_block_value (const char *block_name, const char *block_value)
 
SELOGGER_API int __stdcall se_set_block_values (const std::vector< std::string > &block_names, const std::vector< std::string > &block_values)
 
SELOGGER_API int __stdcall se_log_value (long run_number, const char *source, const char *iso_time, const char *block_name, const char *block_value)
 
SELOGGER_API int __stdcall se_wait_for_async ()
 
static int __stdcall se_async (se_log_values_t *work)
 
SELOGGER_API int __stdcall se_log_value_async (long run_number, const char *source, const char *iso_time, const char *block_name, const char *block_value)
 
SELOGGER_API int __stdcall se_log_values_async (long run_number, const char *source, const std::vector< std::string > &iso_times, const std::vector< std::string > &block_names, const std::vector< std::string > &block_values)
 
SELOGGER_API int __stdcall se_log_fvalues (long run_number, const char *source, const std::vector< std::string > &iso_times, const std::vector< std::string > &block_names, const std::vector< float > &block_values)
 
SELOGGER_API int __stdcall se_log_values (long run_number, const char *source, const std::vector< std::string > &iso_times, const std::vector< std::string > &block_names, const std::vector< std::string > &block_values)
 
SELOGGER_API int __stdcall se_close ()
 
SELOGGER_API const char *__stdcall se_get_errmsg ()
 
SELOGGER_API int __stdcall se_log_run (int run_number, const char *source, const char *iso_time, int period, int run_status, int is_running, int is_waiting, int good_frames, int raw_frames, float good_uamph, float raw_uamph, int64_t monitor_sum0, float dae_beam_current, int64_t total_counts, float count_rate, float npratio_current)
 
SELOGGER_API int __stdcall se_set_run_number (int run_number)
 
SELOGGER_API int __stdcall se_set_period (int period)
 
SELOGGER_API int __stdcall se_get_seci_config (std::string &seci_config)
 
SELOGGER_API int __stdcall se_set_run_state (int run_number, const char *state, int is_start)
 
SELOGGER_API int __stdcall se_new_seci_config (const char *config_name)
 
SELOGGER_API int __stdcall se_set_block_details (const char *block_name, const char *setpoint_value, const char *vi_name, const char *read_control_label, const char *set_control_label, const char *button_control_label, unsigned options, const char *nexus_name, float low_limit, float high_limit, const char *units, const char *current_value)
 
static int seblock_rows_callback (void *arg, int argc, char **argv, char **)
 
SELOGGER_API int __stdcall se_new_measurement (const char *label, std::string &res)
 
SELOGGER_API int __stdcall se_get_measurement_label (const char *measurement_id, std::string &res)
 
SELOGGER_API int __stdcall se_set_measurement_label (const char *measurement_id, const char *label)
 
SELOGGER_API int __stdcall se_get_measurement_id (const char *label, std::string &measurement_id)
 
SELOGGER_API int __stdcall se_get_measurement_first_run (const char *measurement_id, long &run_number)
 
static int se_clear_values2 (int run_start, int run_finish)
 
SELOGGER_API int __stdcall se_clear_values2_async (int run_start, int run_finish)
 
SELOGGER_API int __stdcall se_clear_values (int run_start, int run_finish)
 
SELOGGER_API int __stdcall se_get_blocks (int run_number, time_t ref_time, seblock_map_t &blocks)
 
SELOGGER_API int __stdcall se_get_run_status (int run_number, time_t ref_time, RUNBLOCK &blocks)
 
static void db_profile_func (void *arg, const char *sql, sqlite3_uint64 tim)
 
SELOGGER_API int __stdcall se_profile (const char *filename)
 
SELOGGER_API int __stdcall se_set_period_async (int period)
 
SELOGGER_API int __stdcall se_set_run_state_async (int run_number, const char *state, int is_start)
 
SELOGGER_API int __stdcall se_get_block_values (seblock_map_t &blocks)
 
SELOGGER_API int __stdcall se_set_block_setpoint (const char *block_name, const char *block_setpoint)
 
SELOGGER_API int __stdcall se_set_block_setpoints (const std::vector< std::string > &block_names, const std::vector< std::string > &block_setpoints)
 
SELOGGER_API int __stdcall se_get_values (long run_number, const char *source, const char *block_name, std::vector< std::string > &iso_times, std::vector< std::string > &block_values)
 
SELOGGER_API int __stdcall se_get_block_details (const char *block_name, SEBLOCK_DETAILS &block)
 
SELOGGER_API int __stdcall se_exec_sql (const char *sql, std::string &result)
 

Variables

static bool database_debug = (getenv("ICP_DATABASE_DEBUG") != NULL)
 
static const char * database_debug_file = "c:\\data\\log\\database_debug.txt"
 
static HANDLE file_complete = NULL
 
static char last_error [1024]
 
static volatile LONG num_async_requests = 0
 
static volatile uint64_t num_work_iterations = 0
 
static volatile HANDLE async_complete_event = NULL
 
static CRITICAL_SECTION work_critical
 
static volatile HANDLE work_queued = NULL
 
static std::list< workpacket * > worklist
 
static std::list
< se_log_values_t * > * 
se_worklist = NULL
 

Macro Definition Documentation

#define OPEN_DATABASE
#define SQLITE_CHECK_RC (   __rc)
Value:
if (__rc != SQLITE_OK) \
{ \
_snprintf_s(last_error, sizeof(last_error), _TRUNCATE, "SELOGGER: SQLITE error %s at %s:%d", errmsg, __FILE__, __LINE__); \
sqlite3_free(errmsg); \
return -1; \
}
static char last_error[1024]
Definition: selogger.cpp:198

Definition at line 325 of file selogger.cpp.

Referenced by se_clear_values2(), se_get_block_values(), se_get_blocks(), se_get_config_param(), se_get_measurement_first_run(), se_get_measurement_id(), se_get_measurement_label(), se_get_run_status(), se_log_run(), se_log_values(), se_log_values_list(), se_new_measurement(), se_new_seci_config(), se_set_block_details(), se_set_block_setpoints(), se_set_block_values(), se_set_config_param(), and se_set_run_state().

#define SQLITE_HANDLE_EXCEPTION (   __func_name)
Value:
catch(std::exception& ex) \
{ \
_snprintf_s(last_error, sizeof(last_error), _TRUNCATE, "SELOGGER: %s: exception %s at %s:%d", #__func_name, ex.what(), __FILE__, __LINE__); \
return -1; \
}
static char last_error[1024]
Definition: selogger.cpp:198

Definition at line 333 of file selogger.cpp.

Referenced by se_clear_values2(), se_exec_sql(), se_get_block_details(), se_get_config_param(), se_get_measurement_first_run(), se_get_measurement_id(), se_get_measurement_label(), se_get_values(), se_log_run(), se_log_values(), se_log_values_list(), se_new_measurement(), se_new_seci_config(), se_set_block_details(), se_set_block_setpoints(), se_set_block_values(), se_set_config_param(), se_set_measurement_label(), and se_set_run_state().

Function Documentation

static void appendToFileAsync ( HANDLE  h,
const char *  message,
bool  close_after_write 
)
static

Definition at line 89 of file selogger.cpp.

References my_overlap_t::data, and my_overlap().

static void appendToFileAsync ( const char *  filename,
const char *  message 
)
static

Definition at line 111 of file selogger.cpp.

References appendToFileAsync(), and createAppendFile().

static int count_rows_callback ( void *  arg,
int  argc,
char **  argv,
char **  azColName 
)
static

Definition at line 317 of file selogger.cpp.

static HANDLE createAppendFile ( const char *  filename)
static

Definition at line 71 of file selogger.cpp.

References file_complete, and my_io_complete().

static void db_profile_func ( void *  arg,
const char *  sql,
sqlite3_uint64  tim 
)
static

Definition at line 1322 of file selogger.cpp.

Referenced by se_profile().

BOOL APIENTRY DllMain ( HMODULE  hModule,
DWORD  ul_reason_for_call,
LPVOID  lpReserved 
)

Definition at line 131 of file selogger.cpp.

static int general_init ( )
static

Definition at line 290 of file selogger.cpp.

References process_requests().

Referenced by se_async(), and se_wait_for_async().

static long get_period ( )
static

Definition at line 432 of file selogger.cpp.

References se_get_config_param().

static long get_run_number ( )
static
static int ISOtime ( time_t  time,
char *  buffer,
int  len 
)
static
static int isReal ( const char *  value)
static
static void my_io_complete ( void *  arg)
static

Definition at line 57 of file selogger.cpp.

References MyOverlapped::arg, file_complete, and MyOverlapped::func.

static void my_overlap ( void *  arg)
static

Definition at line 49 of file selogger.cpp.

Referenced by appendToFileAsync().

static int my_sqlite3_exec ( sqlite3 *  db,
const char *  sql,
int(*)(void *, int, char **, char **)  callback,
void *  arg,
char **  errmsg 
)
static
static void process_requests ( void *  arg)
static

Definition at line 251 of file selogger.cpp.

References workpacket::do_work(), num_work_iterations, se_log_values_list(), and se_worklist.

Referenced by general_init().

static int __stdcall se_async ( workpacket work)
static
static int __stdcall se_async ( se_log_values_t work)
static

Definition at line 552 of file selogger.cpp.

References general_init().

SELOGGER_API int __stdcall se_clear_values ( int  run_start,
int  run_finish 
)
static int se_clear_values2 ( int  run_start,
int  run_finish 
)
static
SELOGGER_API int __stdcall se_clear_values2_async ( int  run_start,
int  run_finish 
)

Definition at line 1035 of file selogger.cpp.

References se_async().

Referenced by se_clear_values().

SELOGGER_API int __stdcall se_close ( )

Definition at line 691 of file selogger.cpp.

Referenced by Cselog::SEClose(), and ISISinstrumentControl::~ISISinstrumentControl().

SELOGGER_API int __stdcall se_exec_sql ( const char *  sql,
std::string &  result 
)
SELOGGER_API int __stdcall se_get_block_details ( const char *  block_name,
SEBLOCK_DETAILS block 
)
SELOGGER_API int __stdcall se_get_block_values ( seblock_map_t blocks)
SELOGGER_API int __stdcall se_get_blocks ( int  run_number,
time_t  ref_time,
seblock_map_t blocks 
)
static int se_get_config_param ( const char *  name,
std::string &  value 
)
static
SELOGGER_API const char* __stdcall se_get_errmsg ( )

retrieve the error message after a return code of -1 from another se_* call. The pointer is to static storage and should not be deallocated - the error message will remain there until the next error on calling a se_* function, so you should make a copy if not using it immediately.

See Also
se_log_value

Definition at line 696 of file selogger.cpp.

References last_error.

Referenced by ISISinstrumentControl::changePeriod(), ISISinstrumentControl::endRunMain(), ISISinstrumentControl::endRunTask(), InstAPILib::getBlockSetpoint(), InstAPILib::getBlockValue(), ISISinstrumentControl::getSE(), ISISinstrumentControl::ISISinstrumentControl(), InstAPILib::logBlocksNow(), ISISinstrumentControl::logEvent(), InstAPILib::pushBlockButton(), Cselog::SEClearLoggedValues(), Cselog::SEClose(), Cselog::SEExecSQL(), Cselog::SEGetMeasurementID(), Cselog::SEGetMeasurementLabel(), Cselog::SEGetSECIConfig(), Cselog::SEGetValues(), Cselog::SELogValue(), Cselog::SELogValues(), Cselog::SELogValuesAsync(), Cselog::SENewMeasurement(), Cselog::SENewSECIConfig(), Cselog::SESetBlockDetails(), Cselog::SESetBlockSetpoint(), Cselog::SESetBlockSetpoints(), Cselog::SESetBlockValue(), Cselog::SESetBlockValues(), Cselog::SESetMeasurementLabel(), InstAPILib::setBlockSetpoint(), ISISinstrumentControl::setRunStatusImp(), ISISinstrumentControl::updateFunc(), ISISinstrumentControl::updateICPTimeDiffLog(), ISISinstrumentControl::updateMonitoringLog(), ISISinstrumentControl::updateStatusLog(), NeXusWriter::writeISISNeXus(), and ISISinstrumentControl::~ISISinstrumentControl().

SELOGGER_API int __stdcall se_get_measurement_first_run ( const char *  measurement_id,
long &  run_number 
)
SELOGGER_API int __stdcall se_get_measurement_id ( const char *  label,
std::string &  measurement_id 
)
SELOGGER_API int __stdcall se_get_measurement_label ( const char *  measurement_id,
std::string &  res 
)
SELOGGER_API int __stdcall se_get_run_status ( int  run_number,
time_t  ref_time,
RUNBLOCK blocks 
)
SELOGGER_API int __stdcall se_get_seci_config ( std::string &  seci_config)
SELOGGER_API int __stdcall se_get_values ( long  run_number,
const char *  source,
const char *  block_name,
std::vector< std::string > &  iso_times,
std::vector< std::string > &  block_values 
)
SELOGGER_API int __stdcall se_log_fvalues ( long  run_number,
const char *  source,
const std::vector< std::string > &  iso_times,
const std::vector< std::string > &  block_names,
const std::vector< float > &  block_values 
)

Definition at line 578 of file selogger.cpp.

References se_log_values().

Referenced by run_epics_db().

SELOGGER_API int __stdcall se_log_run ( int  run_number,
const char *  source,
const char *  iso_time,
int  period,
int  run_status,
int  is_running,
int  is_waiting,
int  good_frames,
int  raw_frames,
float  good_uamph,
float  raw_uamph,
int64_t  monitor_sum0,
float  dae_beam_current,
int64_t  total_counts,
float  count_rate,
float  npratio_current 
)

Log run status (used by ICP only)

Definition at line 701 of file selogger.cpp.

References my_sqlite3_exec(), OPEN_DATABASE, se_log_run(), SQLITE_CHECK_RC, SQLITE_HANDLE_EXCEPTION, and unixTime().

Referenced by se_log_run(), and ISISinstrumentControl::updateStatusLog().

SELOGGER_API int __stdcall se_log_value ( long  run_number,
const char *  source,
const char *  iso_time,
const char *  block_name,
const char *  block_value 
)

Log a value to the SE sqlite database. The database is opened automatically by this call if it is not already open and kept open for subsequent calls. You should call se_close() when your process is shutting down.

Parameters
[in]run_numberRun number for which value corresponds
[in]sourceName of program generating value (e.g. SECI, ISISICP)
[in]iso_timeISO8660 time format string "2008-01-01T12:26:23" (NULL means current time)
[in]block_nameName of SE block beging logged
[in]block_valueValue of SE block block_name
Returns
status
Return values
0success
-1Error - call se_get_errmsg() to retrieve error message
See Also
se_close, se_get_errmsg

Definition at line 525 of file selogger.cpp.

References se_log_values().

Referenced by Cselog::SELogValue().

SELOGGER_API int __stdcall se_log_value_async ( long  run_number,
const char *  source,
const char *  iso_time,
const char *  block_name,
const char *  block_value 
)
SELOGGER_API int __stdcall se_log_values ( long  run_number,
const char *  source,
const std::vector< std::string > &  iso_times,
const std::vector< std::string > &  block_names,
const std::vector< std::string > &  block_values 
)
SELOGGER_API int __stdcall se_log_values_async ( long  run_number,
const char *  source,
const std::vector< std::string > &  iso_times,
const std::vector< std::string > &  block_names,
const std::vector< std::string > &  block_values 
)
static int __stdcall se_log_values_list ( const std::list< se_log_values_t * > *  tlist)
static
SELOGGER_API int __stdcall se_new_measurement ( const char *  label,
std::string &  res 
)
SELOGGER_API int __stdcall se_new_seci_config ( const char *  config_name)

called when seci opens a config. This will clear out the current block list, so this will need to be repopulated via calls to se_set_block_details()

Definition at line 764 of file selogger.cpp.

References get_run_number(), my_sqlite3_exec(), OPEN_DATABASE, se_new_seci_config(), se_set_config_param(), SQLITE_CHECK_RC, and SQLITE_HANDLE_EXCEPTION.

Referenced by se_new_seci_config(), and Cselog::SENewSECIConfig().

SELOGGER_API int __stdcall se_profile ( const char *  filename)

Definition at line 1328 of file selogger.cpp.

References db_profile_func(), and OPEN_DATABASE.

SELOGGER_API int __stdcall se_set_block_details ( const char *  block_name,
const char *  setpoint_value,
const char *  vi_name,
const char *  read_control_label,
const char *  set_control_label,
const char *  button_control_label,
unsigned  options,
const char *  nexus_name,
float  low_limit,
float  high_limit,
const char *  units,
const char *  current_value 
)

Set details of a block. This should be called for all blocks on a program startup, and then called for an individual block when its parameters change.

Parameters
[in]block_nameName of SE block
[in]setpoint_valueThe setpoint, as opposed to current value, of this block. Current values are specified via se_log_value()
[in]vi_nameName of LabVIEW VI associated with block
[in]read_control_labelLabel of control/indicator on vi_name used to obtain the current value for logging purposes
[in]set_control_labelLabel of control/indicator on vi_name used to specify setpoint_value
[in]button_control_labelLabel of button on vi_name to press after set_control_label
[in]optionsORed list of BlockOptions
[in]nexus_namepath to nexus file location for block
[in]low_limitLow limit when run control is being used
[in]high_limitHigh limit when run control is being used
[in]unitsScientific units applicable to values read from this block
[in]current_valuePass "NULL" if not known; can be set later using se_set_block_value()
See Also
se_log_value, se_set_block_value

Definition at line 784 of file selogger.cpp.

References get_run_number(), ISOtime(), isReal(), my_sqlite3_exec(), OPEN_DATABASE, se_set_block_details(), SQLITE_CHECK_RC, and SQLITE_HANDLE_EXCEPTION.

Referenced by se_set_block_details(), se_set_run_state(), and Cselog::SESetBlockDetails().

SELOGGER_API int __stdcall se_set_block_setpoint ( const char *  block_name,
const char *  block_setpoint 
)

Definition at line 1404 of file selogger.cpp.

References se_set_block_setpoints().

Referenced by Cselog::SESetBlockSetpoint().

SELOGGER_API int __stdcall se_set_block_setpoints ( const std::vector< std::string > &  block_names,
const std::vector< std::string > &  block_setpoints 
)
SELOGGER_API int __stdcall se_set_block_value ( const char *  block_name,
const char *  block_value 
)
SELOGGER_API int __stdcall se_set_block_values ( const std::vector< std::string > &  block_names,
const std::vector< std::string > &  block_values 
)
static int se_set_config_param ( const char *  name,
const char *  value 
)
static
static int se_set_config_param ( const char *  name,
long  value 
)
static

Definition at line 412 of file selogger.cpp.

References se_set_config_param().

SELOGGER_API int __stdcall se_set_measurement_label ( const char *  measurement_id,
const char *  label 
)
SELOGGER_API int __stdcall se_set_period ( int  period)
SELOGGER_API int __stdcall se_set_period_async ( int  period)

Definition at line 1356 of file selogger.cpp.

References se_async().

Referenced by ISISinstrumentControl::changePeriod().

SELOGGER_API int __stdcall se_set_run_number ( int  run_number)
SELOGGER_API int __stdcall se_set_run_state ( int  run_number,
const char *  state,
int  is_start 
)
SELOGGER_API int __stdcall se_set_run_state_async ( int  run_number,
const char *  state,
int  is_start 
)

Definition at line 1382 of file selogger.cpp.

References se_async().

SELOGGER_API int __stdcall se_start_epics_thread ( epics_thread_data_t arg)

Close database during a process shutdown.

Definition at line 469 of file selogger.cpp.

References run_epics_db().

Referenced by ISISinstrumentControl::ISISinstrumentControl().

const char* __stdcall se_version ( )

Definition at line 345 of file selogger.cpp.

References OPEN_DATABASE.

Referenced by ISISinstrumentControl::ISISinstrumentControl().

SELOGGER_API int __stdcall se_wait_for_async ( )

Definition at line 537 of file selogger.cpp.

References general_init().

Referenced by se_get_blocks(), NeXusWriter::writeISISNeXus(), and NeXusWriter::writeMuonFile().

static int seblock_rows_callback ( void *  arg,
int  argc,
char **  argv,
char **   
)
static
static time_t unixTime ( const char *  isotime)
static

Variable Documentation

volatile HANDLE async_complete_event = NULL
static

Definition at line 202 of file selogger.cpp.

bool database_debug = (getenv("ICP_DATABASE_DEBUG") != NULL)
static

Definition at line 10 of file selogger.cpp.

Referenced by se_log_values(), and se_set_block_values().

const char* database_debug_file = "c:\\data\\log\\database_debug.txt"
static

Definition at line 11 of file selogger.cpp.

Referenced by se_log_values(), and se_set_block_values().

HANDLE file_complete = NULL
static

Definition at line 55 of file selogger.cpp.

Referenced by createAppendFile(), and my_io_complete().

char last_error[1024]
static

Definition at line 198 of file selogger.cpp.

Referenced by ISISDB::closeDatabase(), ISISDB::exec(), ISISDB::ISISDB(), and se_get_errmsg().

volatile LONG num_async_requests = 0
static

Definition at line 200 of file selogger.cpp.

volatile uint64_t num_work_iterations = 0
static

Definition at line 201 of file selogger.cpp.

Referenced by process_requests().

std::list<se_log_values_t*>* se_worklist = NULL
static

Definition at line 247 of file selogger.cpp.

Referenced by process_requests().

CRITICAL_SECTION work_critical
static

Definition at line 203 of file selogger.cpp.

volatile HANDLE work_queued = NULL
static

Definition at line 204 of file selogger.cpp.

std::list<workpacket*> worklist
static

Definition at line 230 of file selogger.cpp.