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

3581{
3582 if (fDebug)
3583 printf("SchemaHistoryBase::hs_clear_cache!\n");
3584
3586 fSchema.clear();
3587
3588 return HS_SUCCESS;
3589}
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]->event_name, 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->disabled = false;
3460
3461 // keep only active variables
3462 std::vector<HsSchemaEntry> active_vars;
3463
3464 for (auto& var : s->variables) {
3465 if (!var.inactive) {
3466 active_vars.push_back(var);
3467 }
3468 }
3469
3471
3472 // find empty slot in events list
3473 for (unsigned int i=0; i<fEvents.size(); i++)
3474 if (!fEvents[i]) {
3475 fEvents[i] = s;
3476 s = NULL;
3477 break;
3478 }
3479
3480 // if no empty slots, add at the end
3481 if (s)
3482 fEvents.push_back(s);
3483
3484 return HS_SUCCESS;
3485}
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
std::vector< HsSchemaEntry > variables
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 3559 of file history_schema.cxx.

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

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

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

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

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

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

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

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