LCOV - code coverage report
Current view: top level - include - history.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 8 0
Test Date: 2025-11-11 10:26:08 Functions: 0.0 % 4 0

            Line data    Source code
       1              : /********************************************************************\
       2              : 
       3              :   Name:         history.h
       4              :   Created by:   Konstantin Olchanski / TRIUMF
       5              : 
       6              :   Contents:     Interface for the MIDAS history system
       7              : 
       8              :   $Id$
       9              : 
      10              : \********************************************************************/
      11              : 
      12              : #ifndef HISTORY_H
      13              : #define HISTORY_H
      14              : 
      15              : #include <string>
      16              : #include <vector>
      17              : 
      18              : #include "midas.h"
      19              : 
      20              : /// \file history.h
      21              : ///
      22              : 
      23              : class MidasHistoryInterface;
      24              : 
      25              : // "factory" pattern
      26              : 
      27              : MidasHistoryInterface* MakeMidasHistory();
      28              : MidasHistoryInterface* MakeMidasHistoryODBC();
      29              : MidasHistoryInterface* MakeMidasHistorySqlite();
      30              : MidasHistoryInterface* MakeMidasHistorySqlDebug();
      31              : MidasHistoryInterface* MakeMidasHistoryMysql();
      32              : MidasHistoryInterface* MakeMidasHistoryPgsql();
      33              : MidasHistoryInterface* MakeMidasHistoryFile();
      34              : 
      35              : #define HS_GET_READER   1
      36              : #define HS_GET_WRITER   2
      37              : #define HS_GET_INACTIVE 4
      38              : #define HS_GET_DEFAULT  8
      39              : 
      40              : // construct history interface class from logger history channel definition in /Logger/History/0/...
      41              : int hs_get_history(HNDLE hDB, HNDLE hKey, int flags, int debug_flag, MidasHistoryInterface **mh);
      42              : 
      43              : // find history reader channel, returns ODB handle to the history channel definition in /Logger/History/...
      44              : int hs_find_reader_channel(HNDLE hDB, HNDLE* hKey, int debug_flag);
      45              : 
      46              : // save list of active events
      47              : int hs_save_event_list(const std::vector<std::string> *pevents);
      48              : 
      49              : // get list of active events
      50              : int hs_read_event_list(std::vector<std::string> *pevents);
      51              : 
      52              : // define history panel
      53              : int hs_define_panel(const char *group, const char *panel, const std::vector<std::string> vars);
      54              : INT hs_define_panel2(const char *group, const char *panel, const std::vector<std::string> var,
      55              :                      const std::vector<std::string> label, const std::vector<std::string> formula = {},
      56              :                      const std::vector<std::string> color = {});
      57              : 
      58              : // MIDAS history data buffer interface class
      59              : 
      60              : class MidasHistoryBufferInterface
      61              : {
      62              :  public:
      63            0 :    MidasHistoryBufferInterface() { }; // ctor
      64            0 :    virtual ~MidasHistoryBufferInterface() { }; // dtor
      65              :  public:
      66              :    virtual void Add(time_t time, double value) = 0;
      67              : };
      68              : 
      69              : class MidasHistoryBinnedBuffer: public MidasHistoryBufferInterface
      70              : {
      71              :  public:
      72              :    int fNumBins = 0;
      73              :    time_t fFirstTime = 0;
      74              :    time_t fLastTime  = 0;
      75              : 
      76              :    int fNumEntries = 0;
      77              :    double *fSum0 = NULL;
      78              :    double *fSum1 = NULL;
      79              :    double *fSum2 = NULL;
      80              : 
      81              :  public: // following arrays are owned by the caller of hs_read_binned()
      82              :    int    *fCount = NULL;
      83              :    double *fMean  = NULL;
      84              :    double *fRms   = NULL;
      85              :    double *fMin   = NULL;
      86              :    double *fMax   = NULL;
      87              : 
      88              :    time_t *fBinsFirstTime  = NULL;
      89              :    double *fBinsFirstValue = NULL;
      90              :    time_t *fBinsLastTime   = NULL;
      91              :    double *fBinsLastValue  = NULL;
      92              : 
      93              :    time_t *fLastTimePtr  = NULL;
      94              :    double *fLastValuePtr = NULL;
      95              : 
      96              :  public:
      97              :    MidasHistoryBinnedBuffer(time_t first_time, time_t last_time, int num_bins); // ctor
      98              :    ~MidasHistoryBinnedBuffer();
      99              : 
     100              :  public:
     101              :    void Start();
     102              :    void Add(time_t t, double v);
     103              :    void Finish();
     104              : };
     105              : 
     106              : // MIDAS history interface class
     107              : 
     108              : class MidasHistoryInterface
     109              : {
     110              :  public:
     111              :    char name[NAME_LENGTH]; /// history channel name
     112              :    char type[NAME_LENGTH]; /// history type: MIDAS, ODBC, SQLITE, etc
     113              : 
     114              :  public:
     115            0 :    MidasHistoryInterface() // ctor
     116            0 :       {
     117            0 :          name[0] = 0;
     118            0 :          type[0] = 0;
     119            0 :       }
     120              : 
     121            0 :    virtual ~MidasHistoryInterface() { }; // dtor
     122              : 
     123              :  public:
     124              :   virtual int hs_connect(const char* connect_string) = 0; ///< returns HS_SUCCESS
     125              :   virtual int hs_disconnect() = 0;                  ///< disconnect from history, returns HS_SUCCESS
     126              : 
     127              :   virtual int hs_set_debug(int debug) = 0;          ///< set debug level, returns previous debug level
     128              : 
     129              :   virtual int hs_clear_cache() = 0; ///< clear internal cache, returns HS_SUCCESS
     130              : 
     131              :   // functions for writing into the history, used by mlogger
     132              : 
     133              :   virtual int hs_define_event(const char* event_name, time_t timestamp, int ntags, const TAG tags[]) = 0; ///< see hs_define_event(), returns HS_SUCCESS or HS_FILE_ERROR
     134              : 
     135              :   virtual int hs_write_event(const char*  event_name, time_t timestamp, int data_size, const char* data) = 0; ///< see hs_write_event(), returns HS_SUCCESS or HS_FILE_ERROR
     136              : 
     137              :   virtual int hs_flush_buffers() = 0; ///< flush buffered data to storage where it is visible to mhttpd
     138              : 
     139              :   // functions for reading from the history, used by mhttpd, mhist
     140              : 
     141              :   virtual int hs_get_events(time_t time_from, std::vector<std::string> *pevents) = 0; ///< get list of events that exist(ed) at given time and later (value 0 means "return all events from beginning of time"), returns HS_SUCCESS
     142              : 
     143              :   virtual int hs_get_tags(const char* event_name, time_t time_from, std::vector<TAG> *ptags) = 0; ///< get list of history variables for given event (use event names returned by hs_get_events()) that exist(ed) at given time and later (value 0 means "all variables for this event that ever existed"), also see hs_get_tags(), returns HS_SUCCESS
     144              : 
     145              :   virtual int hs_get_last_written(time_t start_time,
     146              :                                   int num_var, const char* const event_name[], const char* const tag_name[], const int var_index[],
     147              :                                   time_t last_written[]) = 0;
     148              : 
     149              :   virtual int hs_read_buffer(time_t start_time, time_t end_time,
     150              :                              int num_var, const char* const event_name[], const char* const tag_name[], const int var_index[],
     151              :                              MidasHistoryBufferInterface* buffer[],
     152              :                              int status[]) = 0; ///< returns HS_SUCCESS
     153              : 
     154              :   virtual int hs_read(time_t start_time, time_t end_time, time_t interval,
     155              :                       int num_var, const char* const event_name[], const char* const tag_name[], const int var_index[],
     156              :                       int num_entries[], time_t* time_buffer[], double* data_buffer[],
     157              :                       int status[]) = 0; ///< see hs_read(), returns HS_SUCCESS
     158              : 
     159              :   virtual int hs_read_binned(time_t start_time, time_t end_time, int num_bins,
     160              :                              int num_var, const char* const event_name[], const char* const tag_name[], const int var_index[],
     161              :                              int num_entries[],
     162              :                              int* count_bins[], double* mean_bins[], double* rms_bins[], double* min_bins[], double* max_bins[],
     163              :                              time_t* bins_first_time[], double* bins_first_value[],
     164              :                              time_t* bins_last_time[], double* bins_last_value[],
     165              :                              time_t last_time[], double last_value[],
     166              :                              int status[]) = 0; ///< returns HS_SUCCESS
     167              : };
     168              : 
     169              : #endif
     170              : // end
        

Generated by: LCOV version 2.0-1