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 3575 of file history_schema.cxx.

3576{
3577 if (fDebug)
3578 printf("SchemaHistoryBase::hs_clear_cache!\n");
3579
3581 fSchema.clear();
3582
3583 return HS_SUCCESS;
3584}
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].name[0] == ' ') {
3421 cm_msg(MERROR, "hs_define_event", "Error: History event \'%s\' has name \'%s\' starting with a blank", event_name, tags[i].name);
3422 return HS_FILE_ERROR;
3423 }
3424 if (tags[i].type <= 0 || tags[i].type >= TID_LAST) {
3425 cm_msg(MERROR, "hs_define_event", "Error: History event \'%s\' tag \'%s\' at index %d has invalid type %d",
3426 event_name, tags[i].name, i, tags[i].type);
3427 return HS_FILE_ERROR;
3428 }
3429 if (tags[i].type == TID_STRING) {
3430 cm_msg(MERROR, "hs_define_event",
3431 "Error: History event \'%s\' tag \'%s\' at index %d has forbidden type TID_STRING", event_name,
3432 tags[i].name, i);
3433 return HS_FILE_ERROR;
3434 }
3435 if (tags[i].n_data <= 0) {
3436 cm_msg(MERROR, "hs_define_event", "Error: History event \'%s\' tag \'%s\' at index %d has invalid n_data %d",
3437 event_name, tags[i].name, i, tags[i].n_data);
3438 return HS_FILE_ERROR;
3439 }
3440 }
3441
3442 // check for duplicate names. Done by sorting, since this takes only O(N*log*N))
3443 std::vector<std::string> names;
3444 for (int i=0; i<ntags; i++) {
3445 std::string str(tags[i].name);
3446 std::transform(str.begin(), str.end(), str.begin(), ::toupper);
3447 names.push_back(str);
3448 }
3449 std::sort(names.begin(), names.end());
3450 for (int i=0; i<ntags-1; i++) {
3451 if (names[i] == names[i + 1]) {
3452 cm_msg(MERROR, "hs_define_event",
3453 "Error: History event \'%s\' has duplicate tag name \'%s\'", event_name,
3454 names[i].c_str());
3455 return HS_FILE_ERROR;
3456 }
3457 }
3458
3459 HsSchema* s = new_event(event_name, timestamp, ntags, tags);
3460 if (!s)
3461 return HS_FILE_ERROR;
3462
3463 s->fDisabled = false;
3464
3466
3467 // find empty slot in events list
3468 for (unsigned int i=0; i<fEvents.size(); i++)
3469 if (!fEvents[i]) {
3470 fEvents[i] = s;
3471 s = NULL;
3472 break;
3473 }
3474
3475 // if no empty slots, add at the end
3476 if (s)
3477 fEvents.push_back(s);
3478
3479 return HS_SUCCESS;
3480}
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 3554 of file history_schema.cxx.

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

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

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

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

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

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

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

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