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
 

Protected Attributes

int fDebug
 
std::string fConnectString
 
HsSchemaVector fWriterCurrentSchema
 
std::vector< HsSchema * > fEvents
 
HsSchemaVector fSchema
 

Additional Inherited Members

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

Detailed Description

Definition at line 3057 of file history_schema.cxx.

Constructor & Destructor Documentation

◆ SchemaHistoryBase()

SchemaHistoryBase::SchemaHistoryBase ( )
inline

Definition at line 3071 of file history_schema.cxx.

3072 {
3073 fDebug = 0;
3074 }

◆ ~SchemaHistoryBase()

virtual SchemaHistoryBase::~SchemaHistoryBase ( )
inlinevirtual

Definition at line 3076 of file history_schema.cxx.

3077 {
3078 for (unsigned i=0; i<fEvents.size(); i++)
3079 if (fEvents[i]) {
3080 delete fEvents[i];
3081 fEvents[i] = NULL;
3082 }
3083 fEvents.clear();
3084 }
std::vector< HsSchema * > fEvents
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 3571 of file history_schema.cxx.

3572{
3573 if (fDebug)
3574 printf("SchemaHistoryBase::hs_clear_cache!\n");
3575
3577 fSchema.clear();
3578
3579 return HS_SUCCESS;
3580}
HsSchemaVector fSchema
HsSchemaVector fWriterCurrentSchema
#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 3395 of file history_schema.cxx.

3396{
3397 if (fDebug) {
3398 printf("hs_define_event: event name [%s] with %d tags\n", event_name, ntags);
3399 if (fDebug > 1)
3400 PrintTags(ntags, tags);
3401 }
3402
3403 // delete all events with the same name
3404 for (unsigned int i=0; i<fEvents.size(); i++)
3405 if (fEvents[i])
3406 if (event_name_cmp(fEvents[i]->fEventName, event_name)==0) {
3407 if (fDebug)
3408 printf("deleting exising event %s\n", event_name);
3409 fEvents[i]->close();
3410 delete fEvents[i];
3411 fEvents[i] = NULL;
3412 }
3413
3414 // check for wrong types etc
3415 for (int i=0; i<ntags; i++) {
3416 if (strlen(tags[i].name) < 1) {
3417 cm_msg(MERROR, "hs_define_event", "Error: History event \'%s\' has empty name at index %d", event_name, i);
3418 return HS_FILE_ERROR;
3419 }
3420 if (tags[i].type <= 0 || tags[i].type >= TID_LAST) {
3421 cm_msg(MERROR, "hs_define_event", "Error: History event \'%s\' tag \'%s\' at index %d has invalid type %d",
3422 event_name, tags[i].name, i, tags[i].type);
3423 return HS_FILE_ERROR;
3424 }
3425 if (tags[i].type == TID_STRING) {
3426 cm_msg(MERROR, "hs_define_event",
3427 "Error: History event \'%s\' tag \'%s\' at index %d has forbidden type TID_STRING", event_name,
3428 tags[i].name, i);
3429 return HS_FILE_ERROR;
3430 }
3431 if (tags[i].n_data <= 0) {
3432 cm_msg(MERROR, "hs_define_event", "Error: History event \'%s\' tag \'%s\' at index %d has invalid n_data %d",
3433 event_name, tags[i].name, i, tags[i].n_data);
3434 return HS_FILE_ERROR;
3435 }
3436 }
3437
3438 // check for duplicate names. Done by sorting, since this takes only O(N*log*N))
3439 std::vector<std::string> names;
3440 for (int i=0; i<ntags; i++) {
3441 std::string str(tags[i].name);
3442 std::transform(str.begin(), str.end(), str.begin(), ::toupper);
3443 names.push_back(str);
3444 }
3445 std::sort(names.begin(), names.end());
3446 for (int i=0; i<ntags-1; i++) {
3447 if (names[i] == names[i + 1]) {
3448 cm_msg(MERROR, "hs_define_event",
3449 "Error: History event \'%s\' has duplicate tag name \'%s\'", event_name,
3450 names[i].c_str());
3451 return HS_FILE_ERROR;
3452 }
3453 }
3454
3455 HsSchema* s = new_event(event_name, timestamp, ntags, tags);
3456 if (!s)
3457 return HS_FILE_ERROR;
3458
3459 s->fDisabled = false;
3460
3462
3463 // find empty slot in events list
3464 for (unsigned int i=0; i<fEvents.size(); i++)
3465 if (!fEvents[i]) {
3466 fEvents[i] = s;
3467 s = NULL;
3468 break;
3469 }
3470
3471 // if no empty slots, add at the end
3472 if (s)
3473 fEvents.push_back(s);
3474
3475 return HS_SUCCESS;
3476}
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 3550 of file history_schema.cxx.

3551{
3552 int status = HS_SUCCESS;
3553
3554 if (fDebug)
3555 printf("hs_flush_buffers!\n");
3556
3557 for (unsigned int i=0; i<fEvents.size(); i++)
3558 if (fEvents[i]) {
3559 int xstatus = fEvents[i]->flush_buffers();
3560 if (xstatus != HS_SUCCESS)
3561 status = xstatus;
3562 }
3563
3564 return status;
3565}
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 3582 of file history_schema.cxx.

3583{
3584 if (fDebug)
3585 printf("hs_get_events, time %s\n", TimeToString(t).c_str());
3586
3587 int status = read_schema(&fSchema, NULL, t);
3588 if (status != HS_SUCCESS)
3589 return status;
3590
3591 if (fDebug) {
3592 printf("hs_get_events: available schema:\n");
3593 fSchema.print(false);
3594 }
3595
3596 assert(pevents);
3597
3598 for (unsigned i=0; i<fSchema.size(); i++) {
3599 HsSchema* s = fSchema[i];
3600 if (t && s->fTimeTo && s->fTimeTo < t)
3601 continue;
3602 bool dupe = false;
3603 for (unsigned j=0; j<pevents->size(); j++)
3604 if (event_name_cmp((*pevents)[j], s->fEventName.c_str())==0) {
3605 dupe = true;
3606 break;
3607 }
3608
3609 if (!dupe)
3610 pevents->push_back(s->fEventName);
3611 }
3612
3613 std::sort(pevents->begin(), pevents->end());
3614
3615 if (fDebug) {
3616 printf("hs_get_events: returning %d events\n", (int)pevents->size());
3617 for (unsigned i=0; i<pevents->size(); i++) {
3618 printf(" %d: [%s]\n", i, (*pevents)[i].c_str());
3619 }
3620 }
3621
3622 return HS_SUCCESS;
3623}
std::string fEventName
unsigned size() const
void print(bool print_tags=true) 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 3683 of file history_schema.cxx.

3684{
3685 if (fDebug) {
3686 printf("hs_get_last_written: timestamp %s, num_var %d\n", TimeToString(timestamp).c_str(), num_var);
3687 }
3688
3689 for (int j=0; j<num_var; j++) {
3690 last_written[j] = 0;
3691 }
3692
3693 for (int i=0; i<num_var; i++) {
3694 int status = read_schema(&fSchema, event_name[i], 0);
3695 if (status != HS_SUCCESS)
3696 return status;
3697 }
3698
3699 //fSchema.print(false);
3700
3701 for (int i=0; i<num_var; i++) {
3702 for (unsigned ss=0; ss<fSchema.size(); ss++) {
3703 HsSchema* s = fSchema[ss];
3704 // schema is too new
3705 if (s->fTimeFrom && s->fTimeFrom >= timestamp)
3706 continue;
3707 // this schema is newer than last_written and may contain newer data?
3708 if (s->fTimeFrom && s->fTimeFrom < last_written[i])
3709 continue;
3710 // schema for the variables we want?
3711 int sindex = s->match_event_var(event_name[i], var_name[i], var_index[i]);
3712 if (sindex < 0)
3713 continue;
3714
3715 time_t lw = 0;
3716
3717 int status = s->read_last_written(timestamp, fDebug, &lw);
3718
3719 if (status == HS_SUCCESS && lw != 0) {
3720 for (int j=0; j<num_var; j++) {
3721 int sj = s->match_event_var(event_name[j], var_name[j], var_index[j]);
3722 if (sj < 0)
3723 continue;
3724
3725 if (lw > last_written[j])
3726 last_written[j] = lw;
3727 }
3728 }
3729 }
3730 }
3731
3732 if (fDebug) {
3733 printf("hs_get_last_written: timestamp time %s, num_var %d, result:\n", TimeToString(timestamp).c_str(), num_var);
3734 for (int i=0; i<num_var; i++) {
3735 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());
3736 }
3737 }
3738
3739 return HS_SUCCESS;
3740}
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 3625 of file history_schema.cxx.

3626{
3627 if (fDebug)
3628 printf("hs_get_tags: event [%s], time %s\n", event_name, TimeToString(t).c_str());
3629
3630 assert(ptags);
3631
3632 int status = read_schema(&fSchema, event_name, t);
3633 if (status != HS_SUCCESS)
3634 return status;
3635
3636 bool found_event = false;
3637 for (unsigned i=0; i<fSchema.size(); i++) {
3638 HsSchema* s = fSchema[i];
3639 if (t && s->fTimeTo && s->fTimeTo < t)
3640 continue;
3641
3642 if (event_name_cmp(s->fEventName, event_name) != 0)
3643 continue;
3644
3645 found_event = true;
3646
3647 for (unsigned i=0; i<s->fVariables.size(); i++) {
3648 const char* tagname = s->fVariables[i].name.c_str();
3649 //printf("event_name [%s], table_name [%s], column name [%s], tag name [%s]\n", event_name, tn.c_str(), cn.c_str(), tagname);
3650
3651 bool dupe = false;
3652
3653 for (unsigned k=0; k<ptags->size(); k++)
3654 if (strcasecmp((*ptags)[k].name, tagname) == 0) {
3655 dupe = true;
3656 break;
3657 }
3658
3659 if (!dupe) {
3660 TAG t;
3661 mstrlcpy(t.name, tagname, sizeof(t.name));
3662 t.type = s->fVariables[i].type;
3663 t.n_data = s->fVariables[i].n_data;
3664
3665 ptags->push_back(t);
3666 }
3667 }
3668 }
3669
3670 if (!found_event)
3671 return HS_UNDEFINED_EVENT;
3672
3673 if (fDebug) {
3674 printf("hs_get_tags: event [%s], returning %d tags\n", event_name, (int)ptags->size());
3675 for (unsigned i=0; i<ptags->size(); i++) {
3676 printf(" tag[%d]: %s[%d] type %d\n", i, (*ptags)[i].name, (*ptags)[i].n_data, (*ptags)[i].type);
3677 }
3678 }
3679
3680 return HS_SUCCESS;
3681}
std::vector< HsSchemaEntry > fVariables
#define HS_UNDEFINED_EVENT
Definition midas.h:732
INT k
Definition odbhist.cxx:40
Definition midas.h:1234
DWORD type
Definition midas.h:1236
DWORD n_data
Definition midas.h:1237
char name[NAME_LENGTH]
Definition midas.h:1235
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 3898 of file history_schema.cxx.

3904{
3905 int status;
3906
3907 ReadBuffer** buffer = new ReadBuffer*[num_var];
3909
3910 for (int i=0; i<num_var; i++) {
3911 buffer[i] = new ReadBuffer(start_time, end_time, interval);
3912 bi[i] = buffer[i];
3913
3914 // make sure outputs are initialized to something sane
3915 if (num_entries)
3916 num_entries[i] = 0;
3917 if (time_buffer)
3918 time_buffer[i] = NULL;
3919 if (data_buffer)
3920 data_buffer[i] = NULL;
3921 if (st)
3922 st[i] = 0;
3923
3924 if (num_entries)
3925 buffer[i]->fNumEntries = &num_entries[i];
3926 if (time_buffer)
3927 buffer[i]->fTimeBuffer = &time_buffer[i];
3928 if (data_buffer)
3929 buffer[i]->fDataBuffer = &data_buffer[i];
3930 }
3931
3932 status = hs_read_buffer(start_time, end_time,
3933 num_var, event_name, var_name, var_index,
3934 bi, st);
3935
3936 for (int i=0; i<num_var; i++) {
3937 buffer[i]->Finish();
3938 delete buffer[i];
3939 }
3940
3941 delete[] buffer;
3942 delete[] bi;
3943
3944 return status;
3945}
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 3947 of file history_schema.cxx.

3955{
3956 int status;
3957
3960
3961 for (int i=0; i<num_var; i++) {
3962 buffer[i] = new MidasHistoryBinnedBuffer(start_time, end_time, num_bins);
3963 xbuffer[i] = buffer[i];
3964
3965 if (count_bins)
3966 buffer[i]->fCount = count_bins[i];
3967 if (mean_bins)
3968 buffer[i]->fMean = mean_bins[i];
3969 if (rms_bins)
3970 buffer[i]->fRms = rms_bins[i];
3971 if (min_bins)
3972 buffer[i]->fMin = min_bins[i];
3973 if (max_bins)
3974 buffer[i]->fMax = max_bins[i];
3975 if (bins_first_time)
3976 buffer[i]->fBinsFirstTime = bins_first_time[i];
3977 if (bins_first_value)
3978 buffer[i]->fBinsFirstValue = bins_first_value[i];
3979 if (bins_last_time)
3980 buffer[i]->fBinsLastTime = bins_last_time[i];
3981 if (bins_last_value)
3982 buffer[i]->fBinsLastValue = bins_last_value[i];
3983 if (last_time)
3984 buffer[i]->fLastTimePtr = &last_time[i];
3985 if (last_value)
3986 buffer[i]->fLastValuePtr = &last_value[i];
3987
3988 buffer[i]->Start();
3989 }
3990
3991 status = hs_read_buffer(start_time, end_time,
3992 num_var, event_name, var_name, var_index,
3993 xbuffer,
3994 st);
3995
3996 for (int i=0; i<num_var; i++) {
3997 buffer[i]->Finish();
3998 if (num_entries)
3999 num_entries[i] = buffer[i]->fNumEntries;
4000 if (0) {
4001 for (int j=0; j<num_bins; j++) {
4002 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]);
4003 }
4004 }
4005 delete buffer[i];
4006 }
4007
4008 delete[] buffer;
4009 delete[] xbuffer;
4010
4011 return status;
4012}
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 3742 of file history_schema.cxx.

3746{
3747 if (fDebug)
3748 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());
3749
3750 for (int i=0; i<num_var; i++) {
3751 int status = read_schema(&fSchema, event_name[i], start_time);
3752 if (status != HS_SUCCESS)
3753 return status;
3754 }
3755
3756#if 0
3757 if (fDebug)
3758 fSchema.print(false);
3759#endif
3760
3761 for (int i=0; i<num_var; i++) {
3763 }
3764
3765 //for (unsigned ss=0; ss<fSchema.size(); ss++) {
3766 // HsSchema* s = fSchema[ss];
3767 // HsFileSchema* fs = dynamic_cast<HsFileSchema*>(s);
3768 // assert(fs != NULL);
3769 // 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());
3770 //}
3771
3772 // check that schema are sorted by time
3773
3774#if 0
3775 // check that schema list is sorted by time, descending fTimeFrom, newest schema first
3776 for (unsigned ss=0; ss<fSchema.size(); ss++) {
3777 if (fDebug) {
3778 //printf("Check schema %zu/%zu: prev from %s, this from %s to %s, compare %d %d %d\n", ss, fSchema.size(),
3779 // TimeToString(fSchema[ss-1]->fTimeFrom).c_str(),
3780 // TimeToString(fSchema[ss]->fTimeFrom).c_str(),
3781 // TimeToString(fSchema[ss]->fTimeTo).c_str(),
3782 // fSchema[ss-1]->fTimeFrom >= fSchema[ss]->fTimeTo,
3783 // fSchema[ss-1]->fTimeFrom > fSchema[ss]->fTimeFrom,
3784 // (fSchema[ss-1]->fTimeFrom >= fSchema[ss]->fTimeTo) && (fSchema[ss-1]->fTimeFrom > fSchema[ss]->fTimeFrom));
3785 printf("Schema %zu/%zu: from %s to %s, name %s\n", ss, fSchema.size(),
3786 TimeToString(fSchema[ss]->fTimeFrom).c_str(),
3787 TimeToString(fSchema[ss]->fTimeTo).c_str(),
3788 fSchema[ss]->fEventName.c_str());
3789 }
3790
3791 if (ss > 0) {
3792 //if ((fSchema[ss-1]->fTimeFrom >= fSchema[ss]->fTimeTo) && (fSchema[ss-1]->fTimeFrom > fSchema[ss]->fTimeFrom)) {
3793 if ((fSchema[ss-1]->fTimeFrom >= fSchema[ss]->fTimeFrom)) {
3794 // good
3795 } else {
3796 cm_msg(MERROR, "SchemaHistoryBase::hs_read_buffer", "History internal error, schema is not ordered by time. Please report this error to the midas forum.");
3797 return HS_FILE_ERROR;
3798 }
3799 }
3800 }
3801#endif
3802
3803 std::vector<HsSchema*> slist;
3804 std::vector<std::vector<int>> smap;
3805
3806 for (unsigned ss=0; ss<fSchema.size(); ss++) {
3807 HsSchema* s = fSchema[ss];
3808 // schema is too new?
3809 if (s->fTimeFrom && s->fTimeFrom > end_time)
3810 continue;
3811 // schema is too old
3812 if (s->fTimeTo && s->fTimeTo < start_time)
3813 continue;
3814
3815 std::vector<int> sm;
3816
3817 for (int i=0; i<num_var; i++) {
3818 // schema for the variables we want?
3819 int sindex = s->match_event_var(event_name[i], var_name[i], var_index[i]);
3820 if (sindex < 0)
3821 continue;
3822
3823 if (sm.empty()) {
3824 for (int i=0; i<num_var; i++) {
3825 sm.push_back(-1);
3826 }
3827 }
3828
3829 sm[i] = sindex;
3830 }
3831
3832 if (!sm.empty()) {
3833 slist.push_back(s);
3834 smap.push_back(sm);
3835 }
3836 }
3837
3838 if (0||fDebug) {
3839 printf("Found %d matching schema:\n", (int)slist.size());
3840
3841 for (size_t i=0; i<slist.size(); i++) {
3842 HsSchema* s = slist[i];
3843 s->print();
3844 for (int k=0; k<num_var; k++)
3845 printf(" tag %s[%d] sindex %d\n", var_name[k], var_index[k], smap[i][k]);
3846 }
3847 }
3848
3849 //for (size_t ss=0; ss<slist.size(); ss++) {
3850 // HsSchema* s = slist[ss];
3851 // HsFileSchema* fs = dynamic_cast<HsFileSchema*>(s);
3852 // assert(fs != NULL);
3853 // printf("schema %zu from %s to %s, filename %s", ss, TimeToString(fs->fTimeFrom).c_str(), TimeToString(fs->fTimeTo).c_str(), fs->fFileName.c_str());
3854 // printf(" smap ");
3855 // for (int k=0; k<num_var; k++)
3856 // printf(" %2d", smap[ss][k]);
3857 // printf("\n");
3858 //}
3859
3860 for (size_t ss=1; ss<slist.size(); ss++) {
3861 if (fDebug) {
3862 printf("Check schema %zu/%zu: prev from %s, this from %s to %s, compare %d\n", ss, slist.size(),
3863 TimeToString(slist[ss-1]->fTimeFrom).c_str(),
3864 TimeToString(slist[ss]->fTimeFrom).c_str(),
3865 TimeToString(slist[ss]->fTimeTo).c_str(),
3866 slist[ss-1]->fTimeFrom >= slist[ss]->fTimeFrom);
3867 }
3868 if (slist[ss-1]->fTimeFrom >= slist[ss]->fTimeFrom) {
3869 // good
3870 } else {
3871 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.");
3872 return HS_FILE_ERROR;
3873 }
3874 }
3875
3876 std::vector<time_t> last_time;
3877
3878 for (int i=0; i<num_var; i++) {
3879 last_time.push_back(start_time);
3880 }
3881
3882 for (int i=slist.size()-1; i>=0; i--) {
3883 HsSchema* s = slist[i];
3884
3885 int status = s->read_data(start_time, end_time, num_var, smap[i], var_index, fDebug, last_time, buffer);
3886
3887 if (status == HS_SUCCESS) {
3888 for (int j=0; j<num_var; j++) {
3889 if (smap[i][j] >= 0)
3891 }
3892 }
3893 }
3894
3895 return HS_SUCCESS;
3896}
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 3086 of file history_schema.cxx.

3087 {
3088 int old = fDebug;
3089 fDebug = debug;
3090 return old;
3091 }
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 3478 of file history_schema.cxx.

3479{
3480 if (fDebug)
3481 printf("hs_write_event: write event \'%s\', time %d, size %d\n", event_name, (int)timestamp, buffer_size);
3482
3483 HsSchema *s = NULL;
3484
3485 // find this event
3486 for (size_t i=0; i<fEvents.size(); i++)
3487 if (fEvents[i] && (event_name_cmp(fEvents[i]->fEventName, event_name)==0)) {
3488 s = fEvents[i];
3489 break;
3490 }
3491
3492 // not found
3493 if (!s)
3494 return HS_UNDEFINED_EVENT;
3495
3496 // deactivated because of error?
3497 if (s->fDisabled)
3498 return HS_FILE_ERROR;
3499
3500 if (s->fNumBytes == 0) { // compute expected data size
3501 // NB: history data does not have any padding!
3502 for (unsigned i=0; i<s->fVariables.size(); i++) {
3503 s->fNumBytes += s->fVariables[i].n_bytes;
3504 }
3505 }
3506
3507 int status;
3508
3509 if (buffer_size > s->fNumBytes) { // too many bytes!
3510 if (s->fCountWriteOversize == 0) {
3511 // only report first occurence
3512 // count of all occurences is reported by HsSchema destructor
3513 cm_msg(MERROR, "hs_write_event", "Event \'%s\' data size mismatch: expected %d bytes, got %d bytes", s->fEventName.c_str(), s->fNumBytes, buffer_size);
3514 }
3516 if (buffer_size > s->fWriteMaxSize)
3517 s->fWriteMaxSize = buffer_size;
3518 status = s->write_event(timestamp, buffer, s->fNumBytes);
3519 } else if (buffer_size < s->fNumBytes) { // too few bytes
3520 if (s->fCountWriteUndersize == 0) {
3521 // only report first occurence
3522 // count of all occurences is reported by HsSchema destructor
3523 cm_msg(MERROR, "hs_write_event", "Event \'%s\' data size mismatch: expected %d bytes, got %d bytes", s->fEventName.c_str(), s->fNumBytes, buffer_size);
3524 }
3526 if (s->fWriteMinSize == 0)
3527 s->fWriteMinSize = buffer_size;
3528 else if (buffer_size < s->fWriteMinSize)
3529 s->fWriteMinSize = buffer_size;
3530 char* tmp = (char*)malloc(s->fNumBytes);
3531 memcpy(tmp, buffer, buffer_size);
3532 memset(tmp + buffer_size, 0, s->fNumBytes - buffer_size);
3533 status = s->write_event(timestamp, tmp, s->fNumBytes);
3534 free(tmp);
3535 } else {
3536 assert(buffer_size == s->fNumBytes); // obviously
3537 status = s->write_event(timestamp, buffer, buffer_size);
3538 }
3539
3540 // if could not write event, deactivate it
3541 if (status != HS_SUCCESS) {
3542 s->fDisabled = true;
3543 cm_msg(MERROR, "hs_write_event", "Event \'%s\' disabled after write error %d", event_name, status);
3544 return HS_FILE_ERROR;
3545 }
3546
3547 return HS_SUCCESS;
3548}
int fCountWriteUndersize
virtual int write_event(const time_t t, const char *data, const int data_size)=0
int fCountWriteOversize
Here is the call 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 3061 of file history_schema.cxx.

◆ fDebug

int SchemaHistoryBase::fDebug
protected

Definition at line 3060 of file history_schema.cxx.

◆ fEvents

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

Definition at line 3065 of file history_schema.cxx.

◆ fSchema

HsSchemaVector SchemaHistoryBase::fSchema
protected

Definition at line 3068 of file history_schema.cxx.

◆ fWriterCurrentSchema

HsSchemaVector SchemaHistoryBase::fWriterCurrentSchema
protected

Definition at line 3064 of file history_schema.cxx.


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