MIDAS
Loading...
Searching...
No Matches
SchemaHistoryBase Class Referenceabstract
Inheritance diagram for SchemaHistoryBase:
Collaboration diagram for SchemaHistoryBase:

Classes

class  ReadBuffer
 

Public Member Functions

 SchemaHistoryBase ()
 
virtual ~SchemaHistoryBase ()
 
virtual int hs_set_debug (int debug)
 set debug level, returns previous debug level
 
virtual int hs_connect (const char *connect_string)=0
 returns HS_SUCCESS
 
virtual int hs_disconnect ()=0
 disconnect from history, returns HS_SUCCESS
 
int hs_define_event (const char *event_name, time_t timestamp, int ntags, const TAG tags[])
 see hs_define_event(), returns HS_SUCCESS or HS_FILE_ERROR
 
int hs_write_event (const char *event_name, time_t timestamp, int buffer_size, const char *buffer)
 see hs_write_event(), returns HS_SUCCESS or HS_FILE_ERROR
 
int hs_flush_buffers ()
 flush buffered data to storage where it is visible to mhttpd
 
int hs_clear_cache ()
 clear internal cache, returns HS_SUCCESS
 
int hs_get_events (time_t t, std::vector< std::string > *pevents)
 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
 
int hs_get_tags (const char *event_name, time_t t, std::vector< TAG > *ptags)
 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
 
int hs_get_last_written (time_t timestamp, int num_var, const char *const event_name[], const char *const var_name[], const int var_index[], time_t last_written[])
 
int hs_read_buffer (time_t start_time, time_t end_time, int num_var, const char *const event_name[], const char *const var_name[], const int var_index[], MidasHistoryBufferInterface *buffer[], int hs_status[])
 returns HS_SUCCESS
 
int hs_read (time_t start_time, time_t end_time, time_t interval, int num_var, const char *const event_name[], const char *const var_name[], const int var_index[], int num_entries[], time_t *time_buffer[], double *data_buffer[], int st[])
 see hs_read(), returns HS_SUCCESS
 
int hs_read_binned (time_t start_time, time_t end_time, int num_bins, int num_var, const char *const event_name[], const char *const var_name[], const int var_index[], int num_entries[], int *count_bins[], double *mean_bins[], double *rms_bins[], double *min_bins[], double *max_bins[], time_t *bins_first_time[], double *bins_first_value[], time_t *bins_last_time[], double *bins_last_value[], time_t last_time[], double last_value[], int st[])
 returns HS_SUCCESS
 
- Public Member Functions inherited from MidasHistoryInterface
 MidasHistoryInterface ()
 history type: MIDAS, ODBC, SQLITE, etc
 
virtual ~MidasHistoryInterface ()
 

Protected Member Functions

virtual int read_schema (HsSchemaVector *sv, const char *event_name, const time_t timestamp)=0
 
virtual HsSchemanew_event (const char *event_name, time_t timestamp, int ntags, const TAG tags[])=0
 
virtual HsSchemamaybe_reopen (const char *event_name, time_t timestamp, HsSchema *s)=0
 

Protected Attributes

int fDebug = 0
 
std::string fConnectString
 
HsSchemaVector fWriterSchema
 
std::vector< HsSchema * > fWriterEvents
 
HsSchemaVector fReaderSchema
 

Additional Inherited Members

- Public Attributes inherited from MidasHistoryInterface
char name [NAME_LENGTH]
 
char type [NAME_LENGTH]
 history channel name
 

Detailed Description

Definition at line 3127 of file history_schema.cxx.

Constructor & Destructor Documentation

◆ SchemaHistoryBase()

SchemaHistoryBase::SchemaHistoryBase ( )
inline

Definition at line 3141 of file history_schema.cxx.

3142 {
3143 // empty
3144 }

◆ ~SchemaHistoryBase()

virtual SchemaHistoryBase::~SchemaHistoryBase ( )
inlinevirtual

Definition at line 3146 of file history_schema.cxx.

3147 {
3148 for (size_t i=0; i<fWriterEvents.size(); i++) {
3149 //printf("fWriterEvents[%zu] is %p\n", i, fWriterEvents[i]);
3150 if (fWriterEvents[i]) {
3151 delete fWriterEvents[i];
3152 fWriterEvents[i] = NULL;
3153 }
3154 }
3155 fWriterEvents.clear();
3156 }
std::vector< HsSchema * > fWriterEvents
INT i
Definition mdump.cxx:32
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
Here is the call graph for this function:

Member Function Documentation

◆ hs_clear_cache()

int SchemaHistoryBase::hs_clear_cache ( )
virtual

clear internal cache, returns HS_SUCCESS

Implements MidasHistoryInterface.

Definition at line 3660 of file history_schema.cxx.

3661{
3662 if (fDebug)
3663 printf("SchemaHistoryBase::hs_clear_cache!\n");
3664
3667
3668 return HS_SUCCESS;
3669}
HsSchemaVector fWriterSchema
HsSchemaVector fReaderSchema
#define HS_SUCCESS
Definition midas.h:727
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hs_connect()

virtual int SchemaHistoryBase::hs_connect ( const char connect_string)
pure virtual

returns HS_SUCCESS

Implements MidasHistoryInterface.

Implemented in SqlHistoryBase, and FileHistory.

◆ hs_define_event()

int SchemaHistoryBase::hs_define_event ( const char event_name,
time_t  timestamp,
int  ntags,
const TAG  tags[] 
)
virtual

see hs_define_event(), returns HS_SUCCESS or HS_FILE_ERROR

Implements MidasHistoryInterface.

Definition at line 3470 of file history_schema.cxx.

3471{
3472 if (fDebug) {
3473 printf("hs_define_event: event name [%s] with %d tags\n", event_name, ntags);
3474 if (fDebug > 1)
3475 PrintTags(ntags, tags);
3476 }
3477
3478 // delete all events with the same name
3479 for (size_t i=0; i<fWriterEvents.size(); i++)
3480 if (fWriterEvents[i])
3481 if (event_name_cmp(fWriterEvents[i]->fEventName, event_name)==0) {
3482 if (fDebug)
3483 printf("deleting exising event %s\n", event_name);
3484 fWriterEvents[i]->close();
3485 delete fWriterEvents[i];
3486 fWriterEvents[i] = NULL;
3487 }
3488
3489 // check for wrong types etc
3490 for (int i=0; i<ntags; i++) {
3491 if (strlen(tags[i].name) < 1) {
3492 cm_msg(MERROR, "hs_define_event", "Error: History event \'%s\' has empty name at index %d", event_name, i);
3493 return HS_FILE_ERROR;
3494 }
3495 if (tags[i].name[0] == ' ') {
3496 cm_msg(MERROR, "hs_define_event", "Error: History event \'%s\' has name \'%s\' starting with a blank", event_name, tags[i].name);
3497 return HS_FILE_ERROR;
3498 }
3499 if (tags[i].type <= 0 || tags[i].type >= TID_LAST) {
3500 cm_msg(MERROR, "hs_define_event", "Error: History event \'%s\' tag \'%s\' at index %d has invalid type %d",
3501 event_name, tags[i].name, i, tags[i].type);
3502 return HS_FILE_ERROR;
3503 }
3504 if (tags[i].type == TID_STRING) {
3505 cm_msg(MERROR, "hs_define_event",
3506 "Error: History event \'%s\' tag \'%s\' at index %d has forbidden type TID_STRING", event_name,
3507 tags[i].name, i);
3508 return HS_FILE_ERROR;
3509 }
3510 if (tags[i].n_data <= 0) {
3511 cm_msg(MERROR, "hs_define_event", "Error: History event \'%s\' tag \'%s\' at index %d has invalid n_data %d",
3512 event_name, tags[i].name, i, tags[i].n_data);
3513 return HS_FILE_ERROR;
3514 }
3515 }
3516
3517 // check for duplicate names. Done by sorting, since this takes only O(N*log*N))
3518 std::vector<std::string> names;
3519 for (int i=0; i<ntags; i++) {
3520 std::string str(tags[i].name);
3521 std::transform(str.begin(), str.end(), str.begin(), ::toupper);
3522 names.push_back(str);
3523 }
3524 std::sort(names.begin(), names.end());
3525 for (int i=0; i<ntags-1; i++) {
3526 if (names[i] == names[i + 1]) {
3527 cm_msg(MERROR, "hs_define_event",
3528 "Error: History event \'%s\' has duplicate tag name \'%s\'", event_name,
3529 names[i].c_str());
3530 return HS_FILE_ERROR;
3531 }
3532 }
3533
3534 HsSchema* s = new_event(event_name, timestamp, ntags, tags);
3535 if (!s)
3536 return HS_FILE_ERROR;
3537
3538 s->fDisabled = false;
3539
3541
3542 // find empty slot in events list
3543 for (size_t i=0; i<fWriterEvents.size(); i++)
3544 if (!fWriterEvents[i]) {
3545 fWriterEvents[i] = s;
3546 s = NULL;
3547 break;
3548 }
3549
3550 // if no empty slots, add at the end
3551 if (s)
3552 fWriterEvents.push_back(s);
3553
3554 return HS_SUCCESS;
3555}
virtual void remove_inactive_columns()=0
char type[NAME_LENGTH]
history channel name
Definition history.h:112
char name[NAME_LENGTH]
Definition history.h:111
virtual HsSchema * new_event(const char *event_name, time_t timestamp, int ntags, const TAG tags[])=0
#define HS_FILE_ERROR
Definition midas.h:728
#define TID_STRING
Definition midas.h:346
#define MERROR
Definition midas.h:559
#define TID_LAST
Definition midas.h:354
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
Definition midas.cxx:915
static void PrintTags(int ntags, const TAG tags[])
static int event_name_cmp(const std::string &e1, const char *e2)
char str[256]
Definition odbhist.cxx:33
Here is the call graph for this function:

◆ hs_disconnect()

virtual int SchemaHistoryBase::hs_disconnect ( )
pure virtual

disconnect from history, returns HS_SUCCESS

Implements MidasHistoryInterface.

Implemented in SqlHistoryBase, and FileHistory.

◆ hs_flush_buffers()

int SchemaHistoryBase::hs_flush_buffers ( )
virtual

flush buffered data to storage where it is visible to mhttpd

Implements MidasHistoryInterface.

Definition at line 3639 of file history_schema.cxx.

3640{
3641 int status = HS_SUCCESS;
3642
3643 if (fDebug)
3644 printf("hs_flush_buffers!\n");
3645
3646 for (size_t i=0; i<fWriterEvents.size(); i++)
3647 if (fWriterEvents[i]) {
3648 int xstatus = fWriterEvents[i]->flush_buffers();
3649 if (xstatus != HS_SUCCESS)
3650 status = xstatus;
3651 }
3652
3653 return status;
3654}
DWORD status
Definition odbhist.cxx:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hs_get_events()

int SchemaHistoryBase::hs_get_events ( time_t  time_from,
std::vector< std::string > *  pevents 
)
virtual

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

Implements MidasHistoryInterface.

Definition at line 3671 of file history_schema.cxx.

3672{
3673 if (fDebug)
3674 printf("hs_get_events, time %s\n", TimeToString(t).c_str());
3675
3677 if (status != HS_SUCCESS)
3678 return status;
3679
3680 if (fDebug) {
3681 printf("hs_get_events: available schema:\n");
3682 fReaderSchema.print(false);
3683 }
3684
3685 assert(pevents);
3686
3687 for (size_t i=0; i<fReaderSchema.size(); i++) {
3688 HsSchema* s = fReaderSchema[i];
3689 if (t && s->fTimeTo && s->fTimeTo < t)
3690 continue;
3691 bool dupe = false;
3692 for (size_t j=0; j<pevents->size(); j++)
3693 if (event_name_cmp((*pevents)[j], s->fEventName.c_str())==0) {
3694 dupe = true;
3695 break;
3696 }
3697
3698 if (!dupe)
3699 pevents->push_back(s->fEventName);
3700 }
3701
3702 std::sort(pevents->begin(), pevents->end());
3703
3704 if (fDebug) {
3705 printf("hs_get_events: returning %zu events\n", pevents->size());
3706 for (size_t i=0; i<pevents->size(); i++) {
3707 printf(" %zu: [%s]\n", i, (*pevents)[i].c_str());
3708 }
3709 }
3710
3711 return HS_SUCCESS;
3712}
std::string fEventName
void print(bool print_tags=true) const
size_t size() const
virtual int read_schema(HsSchemaVector *sv, const char *event_name, const time_t timestamp)=0
static std::string TimeToString(time_t t)
INT j
Definition odbhist.cxx:40
Here is the call graph for this function:

◆ hs_get_last_written()

int SchemaHistoryBase::hs_get_last_written ( time_t  timestamp,
int  num_var,
const char *const  event_name[],
const char *const  var_name[],
const int  var_index[],
time_t  last_written[] 
)
virtual

Implements MidasHistoryInterface.

Definition at line 3772 of file history_schema.cxx.

3773{
3774 if (fDebug) {
3775 printf("hs_get_last_written: timestamp %s, num_var %d\n", TimeToString(timestamp).c_str(), num_var);
3776 }
3777
3778 for (int j=0; j<num_var; j++) {
3779 last_written[j] = 0;
3780 }
3781
3782 for (int i=0; i<num_var; i++) {
3783 int status = read_schema(&fReaderSchema, event_name[i], 0);
3784 if (status != HS_SUCCESS)
3785 return status;
3786 }
3787
3788 //fReaderSchema.print(false);
3789
3790 for (int i=0; i<num_var; i++) {
3791 for (size_t ss=0; ss<fReaderSchema.size(); ss++) {
3793 // schema is too new
3794 if (s->fTimeFrom && s->fTimeFrom >= timestamp)
3795 continue;
3796 // this schema is newer than last_written and may contain newer data?
3797 if (s->fTimeFrom && s->fTimeFrom < last_written[i])
3798 continue;
3799 // schema for the variables we want?
3800 int sindex = s->match_event_var(event_name[i], var_name[i], var_index[i]);
3801 if (sindex < 0)
3802 continue;
3803
3804 time_t lw = 0;
3805
3806 int status = s->read_last_written(timestamp, fDebug, &lw);
3807
3808 if (status == HS_SUCCESS && lw != 0) {
3809 for (int j=0; j<num_var; j++) {
3810 int sj = s->match_event_var(event_name[j], var_name[j], var_index[j]);
3811 if (sj < 0)
3812 continue;
3813
3814 if (lw > last_written[j])
3815 last_written[j] = lw;
3816 }
3817 }
3818 }
3819 }
3820
3821 if (fDebug) {
3822 printf("hs_get_last_written: timestamp time %s, num_var %d, result:\n", TimeToString(timestamp).c_str(), num_var);
3823 for (int i=0; i<num_var; i++) {
3824 printf(" event [%s] tag [%s] index [%d] last_written %s\n", event_name[i], var_name[i], var_index[i], TimeToString(last_written[i]).c_str());
3825 }
3826 }
3827
3828 return HS_SUCCESS;
3829}
virtual int read_last_written(const time_t timestamp, const int debug, time_t *last_written)=0
virtual int match_event_var(const char *event_name, const char *var_name, const int var_index)
char var_name[256]
Definition odbhist.cxx:41
Here is the call graph for this function:

◆ hs_get_tags()

int SchemaHistoryBase::hs_get_tags ( const char event_name,
time_t  time_from,
std::vector< TAG > *  ptags 
)
virtual

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

Implements MidasHistoryInterface.

Definition at line 3714 of file history_schema.cxx.

3715{
3716 if (fDebug)
3717 printf("hs_get_tags: event [%s], time %s\n", event_name, TimeToString(t).c_str());
3718
3719 assert(ptags);
3720
3721 int status = read_schema(&fReaderSchema, event_name, t);
3722 if (status != HS_SUCCESS)
3723 return status;
3724
3725 bool found_event = false;
3726 for (size_t i=0; i<fReaderSchema.size(); i++) {
3727 HsSchema* s = fReaderSchema[i];
3728 if (t && s->fTimeTo && s->fTimeTo < t)
3729 continue;
3730
3731 if (event_name_cmp(s->fEventName, event_name) != 0)
3732 continue;
3733
3734 found_event = true;
3735
3736 for (size_t i=0; i<s->fVariables.size(); i++) {
3737 const char* tagname = s->fVariables[i].name.c_str();
3738 //printf("event_name [%s], table_name [%s], column name [%s], tag name [%s]\n", event_name, tn.c_str(), cn.c_str(), tagname);
3739
3740 bool dupe = false;
3741
3742 for (size_t k=0; k<ptags->size(); k++)
3743 if (strcasecmp((*ptags)[k].name, tagname) == 0) {
3744 dupe = true;
3745 break;
3746 }
3747
3748 if (!dupe) {
3749 TAG t;
3750 mstrlcpy(t.name, tagname, sizeof(t.name));
3751 t.type = s->fVariables[i].type;
3752 t.n_data = s->fVariables[i].n_data;
3753
3754 ptags->push_back(t);
3755 }
3756 }
3757 }
3758
3759 if (!found_event)
3760 return HS_UNDEFINED_EVENT;
3761
3762 if (fDebug) {
3763 printf("hs_get_tags: event [%s], returning %zu tags\n", event_name, ptags->size());
3764 for (size_t i=0; i<ptags->size(); i++) {
3765 printf(" tag[%zu]: %s[%d] type %d\n", i, (*ptags)[i].name, (*ptags)[i].n_data, (*ptags)[i].type);
3766 }
3767 }
3768
3769 return HS_SUCCESS;
3770}
std::vector< HsSchemaEntry > fVariables
#define HS_UNDEFINED_EVENT
Definition midas.h:732
INT k
Definition odbhist.cxx:40
Definition midas.h:1232
DWORD type
Definition midas.h:1234
DWORD n_data
Definition midas.h:1235
char name[NAME_LENGTH]
Definition midas.h:1233
Here is the call graph for this function:

◆ hs_read()

int SchemaHistoryBase::hs_read ( time_t  start_time,
time_t  end_time,
time_t  interval,
int  num_var,
const char *const  event_name[],
const char *const  tag_name[],
const int  var_index[],
int  num_entries[],
time_t time_buffer[],
double data_buffer[],
int  status[] 
)
virtual

see hs_read(), returns HS_SUCCESS

Implements MidasHistoryInterface.

Definition at line 3990 of file history_schema.cxx.

3996{
3997 int status;
3998
3999 ReadBuffer** buffer = new ReadBuffer*[num_var];
4001
4002 for (int i=0; i<num_var; i++) {
4003 buffer[i] = new ReadBuffer(start_time, end_time, interval);
4004 bi[i] = buffer[i];
4005
4006 // make sure outputs are initialized to something sane
4007 if (num_entries)
4008 num_entries[i] = 0;
4009 if (time_buffer)
4010 time_buffer[i] = NULL;
4011 if (data_buffer)
4012 data_buffer[i] = NULL;
4013 if (st)
4014 st[i] = 0;
4015
4016 if (num_entries)
4017 buffer[i]->fNumEntries = &num_entries[i];
4018 if (time_buffer)
4019 buffer[i]->fTimeBuffer = &time_buffer[i];
4020 if (data_buffer)
4021 buffer[i]->fDataBuffer = &data_buffer[i];
4022 }
4023
4024 status = hs_read_buffer(start_time, end_time,
4025 num_var, event_name, var_name, var_index,
4026 bi, st);
4027
4028 for (int i=0; i<num_var; i++) {
4029 buffer[i]->Finish();
4030 delete buffer[i];
4031 }
4032
4033 delete[] buffer;
4034 delete[] bi;
4035
4036 return status;
4037}
int hs_read_buffer(time_t start_time, time_t end_time, int num_var, const char *const event_name[], const char *const var_name[], const int var_index[], MidasHistoryBufferInterface *buffer[], int hs_status[])
returns HS_SUCCESS
Here is the call graph for this function:

◆ hs_read_binned()

int SchemaHistoryBase::hs_read_binned ( time_t  start_time,
time_t  end_time,
int  num_bins,
int  num_var,
const char *const  event_name[],
const char *const  tag_name[],
const int  var_index[],
int  num_entries[],
int count_bins[],
double mean_bins[],
double rms_bins[],
double min_bins[],
double max_bins[],
time_t bins_first_time[],
double bins_first_value[],
time_t bins_last_time[],
double bins_last_value[],
time_t  last_time[],
double  last_value[],
int  status[] 
)
virtual

returns HS_SUCCESS

Implements MidasHistoryInterface.

Definition at line 4039 of file history_schema.cxx.

4047{
4048 int status;
4049
4052
4053 for (int i=0; i<num_var; i++) {
4054 buffer[i] = new MidasHistoryBinnedBuffer(start_time, end_time, num_bins);
4055 xbuffer[i] = buffer[i];
4056
4057 if (count_bins)
4058 buffer[i]->fCount = count_bins[i];
4059 if (mean_bins)
4060 buffer[i]->fMean = mean_bins[i];
4061 if (rms_bins)
4062 buffer[i]->fRms = rms_bins[i];
4063 if (min_bins)
4064 buffer[i]->fMin = min_bins[i];
4065 if (max_bins)
4066 buffer[i]->fMax = max_bins[i];
4067 if (bins_first_time)
4068 buffer[i]->fBinsFirstTime = bins_first_time[i];
4069 if (bins_first_value)
4070 buffer[i]->fBinsFirstValue = bins_first_value[i];
4071 if (bins_last_time)
4072 buffer[i]->fBinsLastTime = bins_last_time[i];
4073 if (bins_last_value)
4074 buffer[i]->fBinsLastValue = bins_last_value[i];
4075 if (last_time)
4076 buffer[i]->fLastTimePtr = &last_time[i];
4077 if (last_value)
4078 buffer[i]->fLastValuePtr = &last_value[i];
4079
4080 buffer[i]->Start();
4081 }
4082
4083 status = hs_read_buffer(start_time, end_time,
4084 num_var, event_name, var_name, var_index,
4085 xbuffer,
4086 st);
4087
4088 for (int i=0; i<num_var; i++) {
4089 buffer[i]->Finish();
4090 if (num_entries)
4091 num_entries[i] = buffer[i]->fNumEntries;
4092 if (0) {
4093 for (int j=0; j<num_bins; j++) {
4094 printf("var %d bin %d count %d, first %s last %s value first %f last %f\n", i, j, count_bins[i][j], TimeToString(bins_first_time[i][j]).c_str(), TimeToString(bins_last_time[i][j]).c_str(), bins_first_value[i][j], bins_last_value[i][j]);
4095 }
4096 }
4097 delete buffer[i];
4098 }
4099
4100 delete[] buffer;
4101 delete[] xbuffer;
4102
4103 return status;
4104}
DWORD last_time
Definition mana.cxx:3070
Here is the call graph for this function:

◆ hs_read_buffer()

int SchemaHistoryBase::hs_read_buffer ( time_t  start_time,
time_t  end_time,
int  num_var,
const char *const  event_name[],
const char *const  tag_name[],
const int  var_index[],
MidasHistoryBufferInterface buffer[],
int  status[] 
)
virtual

returns HS_SUCCESS

Implements MidasHistoryInterface.

Definition at line 3831 of file history_schema.cxx.

3835{
3836 if (fDebug)
3837 printf("hs_read_buffer: %d variables, start time %s, end time %s\n", num_var, TimeToString(start_time).c_str(), TimeToString(end_time).c_str());
3838
3839 for (int i=0; i<num_var; i++) {
3840 int status = read_schema(&fReaderSchema, event_name[i], start_time);
3841 if (status != HS_SUCCESS)
3842 return status;
3843 }
3844
3845#if 0
3846 if (fDebug)
3847 fReaderSchema.print(false);
3848#endif
3849
3850 for (int i=0; i<num_var; i++) {
3852 }
3853
3854 //for (size_t ss=0; ss<fReaderSchema.size(); ss++) {
3855 // HsSchema* s = fReaderSchema[ss];
3856 // HsFileSchema* fs = dynamic_cast<HsFileSchema*>(s);
3857 // assert(fs != NULL);
3858 // printf("schema %d from %s to %s, filename %s\n", ss, TimeToString(fs->fTimeFrom).c_str(), TimeToString(fs->fTimeTo).c_str(), fs->fFileName.c_str());
3859 //}
3860
3861 // check that schema are sorted by time
3862
3863#if 0
3864 // check that schema list is sorted by time, descending fTimeFrom, newest schema first
3865 for (size_t ss=0; ss<fReaderSchema.size(); ss++) {
3866 if (fDebug) {
3867 //printf("Check schema %zu/%zu: prev from %s, this from %s to %s, compare %d %d %d\n", ss, fReaderSchema.size(),
3868 // TimeToString(fReaderSchema[ss-1]->fTimeFrom).c_str(),
3869 // TimeToString(fReaderSchema[ss]->fTimeFrom).c_str(),
3870 // TimeToString(fReaderSchema[ss]->fTimeTo).c_str(),
3871 // fReaderSchema[ss-1]->fTimeFrom >= fReaderSchema[ss]->fTimeTo,
3872 // fReaderSchema[ss-1]->fTimeFrom > fReaderSchema[ss]->fTimeFrom,
3873 // (fReaderSchema[ss-1]->fTimeFrom >= fReaderSchema[ss]->fTimeTo) && (fReaderSchema[ss-1]->fTimeFrom > fReaderSchema[ss]->fTimeFrom));
3874 printf("Schema %zu/%zu: from %s to %s, name %s\n", ss, fReaderSchema.size(),
3875 TimeToString(fReaderSchema[ss]->fTimeFrom).c_str(),
3876 TimeToString(fReaderSchema[ss]->fTimeTo).c_str(),
3877 fReaderSchema[ss]->fEventName.c_str());
3878 }
3879
3880 if (ss > 0) {
3881 //if ((fReaderSchema[ss-1]->fTimeFrom >= fReaderSchema[ss]->fTimeTo) && (fReaderSchema[ss-1]->fTimeFrom > fReaderSchema[ss]->fTimeFrom)) {
3882 if ((fReaderSchema[ss-1]->fTimeFrom >= fReaderSchema[ss]->fTimeFrom)) {
3883 // good
3884 } else {
3885 cm_msg(MERROR, "SchemaHistoryBase::hs_read_buffer", "History internal error, schema is not ordered by time. Please report this error to the midas forum.");
3886 return HS_FILE_ERROR;
3887 }
3888 }
3889 }
3890#endif
3891
3892 std::vector<HsSchema*> slist;
3893 std::vector<std::vector<int>> smap;
3894
3895 for (size_t ss=0; ss<fReaderSchema.size(); ss++) {
3897 // schema is too new?
3898 if (s->fTimeFrom && s->fTimeFrom > end_time)
3899 continue;
3900 // schema is too old
3901 if (s->fTimeTo && s->fTimeTo < start_time)
3902 continue;
3903
3904 std::vector<int> sm;
3905
3906 for (int i=0; i<num_var; i++) {
3907 // schema for the variables we want?
3908 int sindex = s->match_event_var(event_name[i], var_name[i], var_index[i]);
3909 if (sindex < 0)
3910 continue;
3911
3912 if (sm.empty()) {
3913 for (int i=0; i<num_var; i++) {
3914 sm.push_back(-1);
3915 }
3916 }
3917
3918 sm[i] = sindex;
3919 }
3920
3921 if (!sm.empty()) {
3922 slist.push_back(s);
3923 smap.push_back(sm);
3924 }
3925 }
3926
3927 if (0||fDebug) {
3928 printf("Found %zu matching schema:\n", slist.size());
3929
3930 for (size_t i=0; i<slist.size(); i++) {
3931 HsSchema* s = slist[i];
3932 s->print();
3933 for (int k=0; k<num_var; k++)
3934 printf(" tag %s[%d] sindex %d\n", var_name[k], var_index[k], smap[i][k]);
3935 }
3936 }
3937
3938 //for (size_t ss=0; ss<slist.size(); ss++) {
3939 // HsSchema* s = slist[ss];
3940 // HsFileSchema* fs = dynamic_cast<HsFileSchema*>(s);
3941 // assert(fs != NULL);
3942 // printf("schema %zu from %s to %s, filename %s", ss, TimeToString(fs->fTimeFrom).c_str(), TimeToString(fs->fTimeTo).c_str(), fs->fFileName.c_str());
3943 // printf(" smap ");
3944 // for (int k=0; k<num_var; k++)
3945 // printf(" %2d", smap[ss][k]);
3946 // printf("\n");
3947 //}
3948
3949 for (size_t ss=1; ss<slist.size(); ss++) {
3950 if (fDebug) {
3951 printf("Check schema %zu/%zu: prev from %s, this from %s to %s, compare %d\n", ss, slist.size(),
3952 TimeToString(slist[ss-1]->fTimeFrom).c_str(),
3953 TimeToString(slist[ss]->fTimeFrom).c_str(),
3954 TimeToString(slist[ss]->fTimeTo).c_str(),
3955 slist[ss-1]->fTimeFrom >= slist[ss]->fTimeFrom);
3956 }
3957 if (slist[ss-1]->fTimeFrom >= slist[ss]->fTimeFrom) {
3958 // good
3959 } else {
3960 cm_msg(MERROR, "SchemaHistoryBase::hs_read_buffer", "History internal error, selected schema is not ordered by time. Please report this error to the midas forum.");
3961 return HS_FILE_ERROR;
3962 }
3963 }
3964
3965 std::vector<time_t> last_time;
3966
3967 for (int i=0; i<num_var; i++) {
3968 last_time.push_back(start_time);
3969 }
3970
3971 for (size_t i=slist.size()-1; ; i--) {
3972 HsSchema* s = slist[i];
3973
3974 int status = s->read_data(start_time, end_time, num_var, smap[i], var_index, fDebug, last_time, buffer);
3975
3976 if (status == HS_SUCCESS) {
3977 for (int j=0; j<num_var; j++) {
3978 if (smap[i][j] >= 0)
3980 }
3981 }
3982
3983 if (i==0)
3984 break;
3985 }
3986
3987 return HS_SUCCESS;
3988}
virtual void print(bool print_tags=true) const
virtual int read_data(const time_t start_time, const time_t end_time, const int num_var, const std::vector< int > &var_schema_index, const int var_index[], const int debug, std::vector< time_t > &last_time, MidasHistoryBufferInterface *buffer[])=0
#define HS_UNDEFINED_VAR
Definition midas.h:733
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hs_set_debug()

virtual int SchemaHistoryBase::hs_set_debug ( int  debug)
inlinevirtual

set debug level, returns previous debug level

Implements MidasHistoryInterface.

Reimplemented in SqlHistoryBase.

Definition at line 3158 of file history_schema.cxx.

3159 {
3160 int old = fDebug;
3161 fDebug = debug;
3162 return old;
3163 }
BOOL debug
debug printouts
Definition mana.cxx:254
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hs_write_event()

int SchemaHistoryBase::hs_write_event ( const char event_name,
time_t  timestamp,
int  data_size,
const char data 
)
virtual

see hs_write_event(), returns HS_SUCCESS or HS_FILE_ERROR

Implements MidasHistoryInterface.

Definition at line 3557 of file history_schema.cxx.

3558{
3559 if (fDebug)
3560 printf("hs_write_event: write event \'%s\', time %d, size %d\n", event_name, (int)timestamp, xbuffer_size);
3561
3562 assert(xbuffer_size > 0);
3563
3564 size_t buffer_size = xbuffer_size;
3565
3566 HsSchema *s = NULL;
3567
3568 // find this event
3569 for (size_t i=0; i<fWriterEvents.size(); i++)
3570 if (fWriterEvents[i] && (event_name_cmp(fWriterEvents[i]->fEventName, event_name)==0)) {
3571 s = fWriterEvents[i];
3572 break;
3573 }
3574
3575 // not found
3576 if (!s)
3577 return HS_UNDEFINED_EVENT;
3578
3579 // deactivated because of error?
3580 if (s->fDisabled) {
3581 //printf("HERE!\n");
3582 return HS_FILE_ERROR;
3583 }
3584
3585 s = maybe_reopen(event_name, timestamp, s);
3586
3587 assert(s != NULL);
3588
3589 if (s->fNumBytes == 0) { // compute expected data size
3590 // NB: history data does not have any padding!
3591 for (size_t i=0; i<s->fVariables.size(); i++) {
3592 s->fNumBytes += s->fVariables[i].n_bytes;
3593 }
3594 }
3595
3596 int status;
3597
3598 if (buffer_size > s->fNumBytes) { // too many bytes!
3599 if (s->fCountWriteOversize == 0) {
3600 // only report first occurence
3601 // count of all occurences is reported by HsSchema destructor
3602 cm_msg(MERROR, "hs_write_event", "Event \'%s\' data size mismatch: expected %zu bytes, got %zu bytes", s->fEventName.c_str(), s->fNumBytes, buffer_size);
3603 }
3605 if (buffer_size > s->fWriteMaxSize)
3606 s->fWriteMaxSize = buffer_size;
3607 status = s->write_event(timestamp, buffer, s->fNumBytes);
3608 } else if (buffer_size < s->fNumBytes) { // too few bytes
3609 if (s->fCountWriteUndersize == 0) {
3610 // only report first occurence
3611 // count of all occurences is reported by HsSchema destructor
3612 cm_msg(MERROR, "hs_write_event", "Event \'%s\' data size mismatch: expected %zu bytes, got %zu bytes", s->fEventName.c_str(), s->fNumBytes, buffer_size);
3613 }
3615 if (s->fWriteMinSize == 0)
3616 s->fWriteMinSize = buffer_size;
3617 else if (buffer_size < s->fWriteMinSize)
3618 s->fWriteMinSize = buffer_size;
3619 char* tmp = (char*)malloc(s->fNumBytes);
3620 memcpy(tmp, buffer, buffer_size);
3621 memset(tmp + buffer_size, 0, s->fNumBytes - buffer_size);
3622 status = s->write_event(timestamp, tmp, s->fNumBytes);
3623 free(tmp);
3624 } else {
3625 assert(buffer_size == s->fNumBytes); // obviously
3626 status = s->write_event(timestamp, buffer, buffer_size);
3627 }
3628
3629 // if could not write event, deactivate it
3630 if (status != HS_SUCCESS) {
3631 s->fDisabled = true;
3632 cm_msg(MERROR, "hs_write_event", "Event \'%s\' disabled after write error %d", event_name, status);
3633 return HS_FILE_ERROR;
3634 }
3635
3636 return HS_SUCCESS;
3637}
int fCountWriteUndersize
size_t fWriteMinSize
virtual int write_event(const time_t t, const char *data, const size_t data_size)=0
int fCountWriteOversize
size_t fWriteMaxSize
virtual HsSchema * maybe_reopen(const char *event_name, time_t timestamp, HsSchema *s)=0
Here is the call graph for this function:

◆ maybe_reopen()

virtual HsSchema * SchemaHistoryBase::maybe_reopen ( const char event_name,
time_t  timestamp,
HsSchema s 
)
protectedpure virtual

Implemented in SqlHistoryBase, and FileHistory.

Here is the caller graph for this function:

◆ new_event()

virtual HsSchema * SchemaHistoryBase::new_event ( const char event_name,
time_t  timestamp,
int  ntags,
const TAG  tags[] 
)
protectedpure virtual

Implemented in SqlHistoryBase, and FileHistory.

Here is the caller graph for this function:

◆ read_schema()

virtual int SchemaHistoryBase::read_schema ( HsSchemaVector sv,
const char event_name,
const time_t  timestamp 
)
protectedpure virtual

Implemented in SqlHistoryBase, and FileHistory.

Here is the caller graph for this function:

Member Data Documentation

◆ fConnectString

std::string SchemaHistoryBase::fConnectString
protected

Definition at line 3131 of file history_schema.cxx.

◆ fDebug

int SchemaHistoryBase::fDebug = 0
protected

Definition at line 3130 of file history_schema.cxx.

◆ fReaderSchema

HsSchemaVector SchemaHistoryBase::fReaderSchema
protected

Definition at line 3138 of file history_schema.cxx.

◆ fWriterEvents

std::vector<HsSchema*> SchemaHistoryBase::fWriterEvents
protected

Definition at line 3135 of file history_schema.cxx.

◆ fWriterSchema

HsSchemaVector SchemaHistoryBase::fWriterSchema
protected

Definition at line 3134 of file history_schema.cxx.


The documentation for this class was generated from the following file: