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

Constructor & Destructor Documentation

◆ SchemaHistoryBase()

SchemaHistoryBase::SchemaHistoryBase ( )
inline

Definition at line 3164 of file history_schema.cxx.

3165 {
3166 // empty
3167 }

◆ ~SchemaHistoryBase()

virtual SchemaHistoryBase::~SchemaHistoryBase ( )
inlinevirtual

Definition at line 3169 of file history_schema.cxx.

3170 {
3171 for (size_t i=0; i<fWriterEvents.size(); i++) {
3172 //printf("fWriterEvents[%zu] is %p\n", i, fWriterEvents[i]);
3173 if (fWriterEvents[i]) {
3174 delete fWriterEvents[i];
3175 fWriterEvents[i] = NULL;
3176 }
3177 }
3178 fWriterEvents.clear();
3179 }
std::vector< HsSchema * > fWriterEvents
INT i
Definition mdump.cxx:32

Member Function Documentation

◆ hs_clear_cache()

int SchemaHistoryBase::hs_clear_cache ( )
virtual

clear internal cache, returns HS_SUCCESS

Implements MidasHistoryInterface.

Definition at line 3683 of file history_schema.cxx.

3684{
3685 if (fDebug)
3686 printf("SchemaHistoryBase::hs_clear_cache!\n");
3687
3690
3691 return HS_SUCCESS;
3692}
HsSchemaVector fWriterSchema
HsSchemaVector fReaderSchema
#define HS_SUCCESS
Definition midas.h:728
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 3493 of file history_schema.cxx.

3494{
3495 if (fDebug) {
3496 printf("hs_define_event: event name [%s] with %d tags\n", event_name, ntags);
3497 if (fDebug > 1)
3498 PrintTags(ntags, tags);
3499 }
3500
3501 // delete all events with the same name
3502 for (size_t i=0; i<fWriterEvents.size(); i++)
3503 if (fWriterEvents[i])
3504 if (event_name_cmp(fWriterEvents[i]->fEventName, event_name)==0) {
3505 if (fDebug)
3506 printf("deleting exising event %s\n", event_name);
3507 fWriterEvents[i]->close();
3508 delete fWriterEvents[i];
3509 fWriterEvents[i] = NULL;
3510 }
3511
3512 // check for wrong types etc
3513 for (int i=0; i<ntags; i++) {
3514 if (strlen(tags[i].name) < 1) {
3515 cm_msg(MERROR, "hs_define_event", "Error: History event \'%s\' has empty name at index %d", event_name, i);
3516 return HS_FILE_ERROR;
3517 }
3518 if (tags[i].name[0] == ' ') {
3519 cm_msg(MERROR, "hs_define_event", "Error: History event \'%s\' has name \'%s\' starting with a blank", event_name, tags[i].name);
3520 return HS_FILE_ERROR;
3521 }
3522 if (tags[i].type <= 0 || tags[i].type >= TID_LAST) {
3523 cm_msg(MERROR, "hs_define_event", "Error: History event \'%s\' tag \'%s\' at index %d has invalid type %d",
3524 event_name, tags[i].name, i, tags[i].type);
3525 return HS_FILE_ERROR;
3526 }
3527 if (tags[i].type == TID_STRING) {
3528 cm_msg(MERROR, "hs_define_event",
3529 "Error: History event \'%s\' tag \'%s\' at index %d has forbidden type TID_STRING", event_name,
3530 tags[i].name, i);
3531 return HS_FILE_ERROR;
3532 }
3533 if (tags[i].n_data <= 0) {
3534 cm_msg(MERROR, "hs_define_event", "Error: History event \'%s\' tag \'%s\' at index %d has invalid n_data %d",
3535 event_name, tags[i].name, i, tags[i].n_data);
3536 return HS_FILE_ERROR;
3537 }
3538 }
3539
3540 // check for duplicate names. Done by sorting, since this takes only O(N*log*N))
3541 std::vector<std::string> names;
3542 for (int i=0; i<ntags; i++) {
3543 std::string str(tags[i].name);
3544 std::transform(str.begin(), str.end(), str.begin(), ::toupper);
3545 names.push_back(str);
3546 }
3547 std::sort(names.begin(), names.end());
3548 for (int i=0; i<ntags-1; i++) {
3549 if (names[i] == names[i + 1]) {
3550 cm_msg(MERROR, "hs_define_event",
3551 "Error: History event \'%s\' has duplicate tag name \'%s\'", event_name,
3552 names[i].c_str());
3553 return HS_FILE_ERROR;
3554 }
3555 }
3556
3557 HsSchema* s = new_event(event_name, timestamp, ntags, tags);
3558 if (!s)
3559 return HS_FILE_ERROR;
3560
3561 s->fDisabled = false;
3562
3564
3565 // find empty slot in events list
3566 for (size_t i=0; i<fWriterEvents.size(); i++)
3567 if (!fWriterEvents[i]) {
3568 fWriterEvents[i] = s;
3569 s = NULL;
3570 break;
3571 }
3572
3573 // if no empty slots, add at the end
3574 if (s)
3575 fWriterEvents.push_back(s);
3576
3577 return HS_SUCCESS;
3578}
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:729
#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:931
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 3662 of file history_schema.cxx.

3663{
3664 int status = HS_SUCCESS;
3665
3666 if (fDebug)
3667 printf("hs_flush_buffers!\n");
3668
3669 for (size_t i=0; i<fWriterEvents.size(); i++)
3670 if (fWriterEvents[i]) {
3671 int xstatus = fWriterEvents[i]->flush_buffers();
3672 if (xstatus != HS_SUCCESS)
3673 status = xstatus;
3674 }
3675
3676 return status;
3677}
DWORD status
Definition odbhist.cxx:39
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 3694 of file history_schema.cxx.

3695{
3696 if (fDebug)
3697 printf("hs_get_events, time %s\n", TimeToString(t).c_str());
3698
3699 int status = read_schema(&fReaderSchema, NULL, t);
3700 if (status != HS_SUCCESS)
3701 return status;
3702
3703 if (fDebug) {
3704 printf("hs_get_events: available schema:\n");
3705 fReaderSchema.print(false);
3706 }
3707
3708 assert(pevents);
3709
3710 for (size_t i=0; i<fReaderSchema.size(); i++) {
3711 HsSchema* s = fReaderSchema[i];
3712 if (t && s->fTimeTo && s->fTimeTo < t)
3713 continue;
3714 bool dupe = false;
3715 for (size_t j=0; j<pevents->size(); j++)
3716 if (event_name_cmp((*pevents)[j], s->fEventName.c_str())==0) {
3717 dupe = true;
3718 break;
3719 }
3720
3721 if (!dupe)
3722 pevents->push_back(s->fEventName);
3723 }
3724
3725 std::sort(pevents->begin(), pevents->end());
3726
3727 if (fDebug) {
3728 printf("hs_get_events: returning %zu events\n", pevents->size());
3729 for (size_t i=0; i<pevents->size(); i++) {
3730 printf(" %zu: [%s]\n", i, (*pevents)[i].c_str());
3731 }
3732 }
3733
3734 return HS_SUCCESS;
3735}
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 3795 of file history_schema.cxx.

3796{
3797 if (fDebug) {
3798 printf("hs_get_last_written: timestamp %s, num_var %d\n", TimeToString(timestamp).c_str(), num_var);
3799 }
3800
3801 for (int j=0; j<num_var; j++) {
3802 last_written[j] = 0;
3803 }
3804
3805 for (int i=0; i<num_var; i++) {
3806 int status = read_schema(&fReaderSchema, event_name[i], 0);
3807 if (status != HS_SUCCESS)
3808 return status;
3809 }
3810
3811 //fReaderSchema.print(false);
3812
3813 for (int i=0; i<num_var; i++) {
3814 for (size_t ss=0; ss<fReaderSchema.size(); ss++) {
3815 HsSchema* s = fReaderSchema[ss];
3816 // schema is too new
3817 if (s->fTimeFrom && s->fTimeFrom >= timestamp)
3818 continue;
3819 // this schema is newer than last_written and may contain newer data?
3820 if (s->fTimeFrom && s->fTimeFrom < last_written[i])
3821 continue;
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 time_t lw = 0;
3828
3829 int status = s->read_last_written(timestamp, fDebug, &lw);
3830
3831 if (status == HS_SUCCESS && lw != 0) {
3832 for (int j=0; j<num_var; j++) {
3833 int sj = s->match_event_var(event_name[j], var_name[j], var_index[j]);
3834 if (sj < 0)
3835 continue;
3836
3837 if (lw > last_written[j])
3838 last_written[j] = lw;
3839 }
3840 }
3841 }
3842 }
3843
3844 if (fDebug) {
3845 printf("hs_get_last_written: timestamp time %s, num_var %d, result:\n", TimeToString(timestamp).c_str(), num_var);
3846 for (int i=0; i<num_var; i++) {
3847 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());
3848 }
3849 }
3850
3851 return HS_SUCCESS;
3852}
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 3737 of file history_schema.cxx.

3738{
3739 if (fDebug)
3740 printf("hs_get_tags: event [%s], time %s\n", event_name, TimeToString(t).c_str());
3741
3742 assert(ptags);
3743
3744 int status = read_schema(&fReaderSchema, event_name, t);
3745 if (status != HS_SUCCESS)
3746 return status;
3747
3748 bool found_event = false;
3749 for (size_t i=0; i<fReaderSchema.size(); i++) {
3750 HsSchema* s = fReaderSchema[i];
3751 if (t && s->fTimeTo && s->fTimeTo < t)
3752 continue;
3753
3754 if (event_name_cmp(s->fEventName, event_name) != 0)
3755 continue;
3756
3757 found_event = true;
3758
3759 for (size_t i=0; i<s->fVariables.size(); i++) {
3760 const char* tagname = s->fVariables[i].name.c_str();
3761 //printf("event_name [%s], table_name [%s], column name [%s], tag name [%s]\n", event_name, tn.c_str(), cn.c_str(), tagname);
3762
3763 bool dupe = false;
3764
3765 for (size_t k=0; k<ptags->size(); k++)
3766 if (strcasecmp((*ptags)[k].name, tagname) == 0) {
3767 dupe = true;
3768 break;
3769 }
3770
3771 if (!dupe) {
3772 TAG t;
3773 mstrlcpy(t.name, tagname, sizeof(t.name));
3774 t.type = s->fVariables[i].type;
3775 t.n_data = s->fVariables[i].n_data;
3776
3777 ptags->push_back(t);
3778 }
3779 }
3780 }
3781
3782 if (!found_event)
3783 return HS_UNDEFINED_EVENT;
3784
3785 if (fDebug) {
3786 printf("hs_get_tags: event [%s], returning %zu tags\n", event_name, ptags->size());
3787 for (size_t i=0; i<ptags->size(); i++) {
3788 printf(" tag[%zu]: %s[%d] type %d\n", i, (*ptags)[i].name, (*ptags)[i].n_data, (*ptags)[i].type);
3789 }
3790 }
3791
3792 return HS_SUCCESS;
3793}
std::vector< HsSchemaEntry > fVariables
#define HS_UNDEFINED_EVENT
Definition midas.h:733
INT k
Definition odbhist.cxx:40
Definition midas.h:1233
DWORD type
Definition midas.h:1235
DWORD n_data
Definition midas.h:1236
char name[NAME_LENGTH]
Definition midas.h:1234
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 4015 of file history_schema.cxx.

4021{
4022 int status;
4023
4024 ReadBuffer** buffer = new ReadBuffer*[num_var];
4026
4027 for (int i=0; i<num_var; i++) {
4028 buffer[i] = new ReadBuffer(start_time, end_time, interval);
4029 bi[i] = buffer[i];
4030
4031 // make sure outputs are initialized to something sane
4032 if (num_entries)
4033 num_entries[i] = 0;
4034 if (time_buffer)
4035 time_buffer[i] = NULL;
4036 if (data_buffer)
4037 data_buffer[i] = NULL;
4038 if (st)
4039 st[i] = 0;
4040
4041 if (num_entries)
4042 buffer[i]->fNumEntries = &num_entries[i];
4043 if (time_buffer)
4044 buffer[i]->fTimeBuffer = &time_buffer[i];
4045 if (data_buffer)
4046 buffer[i]->fDataBuffer = &data_buffer[i];
4047 }
4048
4049 status = hs_read_buffer(start_time, end_time,
4050 num_var, event_name, var_name, var_index,
4051 bi, st);
4052
4053 for (int i=0; i<num_var; i++) {
4054 buffer[i]->Finish();
4055 delete buffer[i];
4056 }
4057
4058 delete[] buffer;
4059 delete[] bi;
4060
4061 return status;
4062}
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 4064 of file history_schema.cxx.

4072{
4073 int status;
4074
4075 MidasHistoryBinnedBuffer** buffer = new MidasHistoryBinnedBuffer*[num_var];
4077
4078 for (int i=0; i<num_var; i++) {
4079 buffer[i] = new MidasHistoryBinnedBuffer(start_time, end_time, num_bins);
4080 xbuffer[i] = buffer[i];
4081
4082 if (count_bins)
4083 buffer[i]->fCount = count_bins[i];
4084 if (mean_bins)
4085 buffer[i]->fMean = mean_bins[i];
4086 if (rms_bins)
4087 buffer[i]->fRms = rms_bins[i];
4088 if (min_bins)
4089 buffer[i]->fMin = min_bins[i];
4090 if (max_bins)
4091 buffer[i]->fMax = max_bins[i];
4092 if (bins_first_time)
4093 buffer[i]->fBinsFirstTime = bins_first_time[i];
4094 if (bins_first_value)
4095 buffer[i]->fBinsFirstValue = bins_first_value[i];
4096 if (bins_last_time)
4097 buffer[i]->fBinsLastTime = bins_last_time[i];
4098 if (bins_last_value)
4099 buffer[i]->fBinsLastValue = bins_last_value[i];
4100 if (last_time)
4101 buffer[i]->fLastTimePtr = &last_time[i];
4102 if (last_value)
4103 buffer[i]->fLastValuePtr = &last_value[i];
4104
4105 buffer[i]->Start();
4106 }
4107
4108 status = hs_read_buffer(start_time, end_time,
4109 num_var, event_name, var_name, var_index,
4110 xbuffer,
4111 st);
4112
4113 for (int i=0; i<num_var; i++) {
4114 buffer[i]->Finish();
4115 if (num_entries)
4116 num_entries[i] = buffer[i]->fNumEntries;
4117 if (0) {
4118 for (int j=0; j<num_bins; j++) {
4119 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]);
4120 }
4121 }
4122 delete buffer[i];
4123 }
4124
4125 delete[] buffer;
4126 delete[] xbuffer;
4127
4128 return status;
4129}
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 3854 of file history_schema.cxx.

3858{
3859 if (fDebug)
3860 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());
3861
3862 for (int i=0; i<num_var; i++) {
3863 int status = read_schema(&fReaderSchema, event_name[i], start_time);
3864 if (status != HS_SUCCESS)
3865 return status;
3866 }
3867
3868#if 0
3869 if (fDebug)
3870 fReaderSchema.print(false);
3871#endif
3872
3873 for (int i=0; i<num_var; i++) {
3874 hs_status[i] = HS_UNDEFINED_VAR;
3875 }
3876
3877 //for (size_t ss=0; ss<fReaderSchema.size(); ss++) {
3878 // HsSchema* s = fReaderSchema[ss];
3879 // HsFileSchema* fs = dynamic_cast<HsFileSchema*>(s);
3880 // assert(fs != NULL);
3881 // 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());
3882 //}
3883
3884 // check that schema are sorted by time
3885
3886#if 0
3887 // check that schema list is sorted by time, descending fTimeFrom, newest schema first
3888 for (size_t ss=0; ss<fReaderSchema.size(); ss++) {
3889 if (fDebug) {
3890 //printf("Check schema %zu/%zu: prev from %s, this from %s to %s, compare %d %d %d\n", ss, fReaderSchema.size(),
3891 // TimeToString(fReaderSchema[ss-1]->fTimeFrom).c_str(),
3892 // TimeToString(fReaderSchema[ss]->fTimeFrom).c_str(),
3893 // TimeToString(fReaderSchema[ss]->fTimeTo).c_str(),
3894 // fReaderSchema[ss-1]->fTimeFrom >= fReaderSchema[ss]->fTimeTo,
3895 // fReaderSchema[ss-1]->fTimeFrom > fReaderSchema[ss]->fTimeFrom,
3896 // (fReaderSchema[ss-1]->fTimeFrom >= fReaderSchema[ss]->fTimeTo) && (fReaderSchema[ss-1]->fTimeFrom > fReaderSchema[ss]->fTimeFrom));
3897 printf("Schema %zu/%zu: from %s to %s, name %s\n", ss, fReaderSchema.size(),
3898 TimeToString(fReaderSchema[ss]->fTimeFrom).c_str(),
3899 TimeToString(fReaderSchema[ss]->fTimeTo).c_str(),
3900 fReaderSchema[ss]->fEventName.c_str());
3901 }
3902
3903 if (ss > 0) {
3904 //if ((fReaderSchema[ss-1]->fTimeFrom >= fReaderSchema[ss]->fTimeTo) && (fReaderSchema[ss-1]->fTimeFrom > fReaderSchema[ss]->fTimeFrom)) {
3905 if ((fReaderSchema[ss-1]->fTimeFrom >= fReaderSchema[ss]->fTimeFrom)) {
3906 // good
3907 } else {
3908 cm_msg(MERROR, "SchemaHistoryBase::hs_read_buffer", "History internal error, schema is not ordered by time. Please report this error to the midas forum.");
3909 return HS_FILE_ERROR;
3910 }
3911 }
3912 }
3913#endif
3914
3915 std::vector<HsSchema*> slist;
3916 std::vector<std::vector<int>> smap;
3917
3918 for (size_t ss=0; ss<fReaderSchema.size(); ss++) {
3919 HsSchema* s = fReaderSchema[ss];
3920 // schema is too new?
3921 if (s->fTimeFrom && s->fTimeFrom > end_time)
3922 continue;
3923 // schema is too old
3924 if (s->fTimeTo && s->fTimeTo < start_time)
3925 continue;
3926
3927 std::vector<int> sm;
3928
3929 for (int i=0; i<num_var; i++) {
3930 // schema for the variables we want?
3931 int sindex = s->match_event_var(event_name[i], var_name[i], var_index[i]);
3932 if (sindex < 0)
3933 continue;
3934
3935 if (sm.empty()) {
3936 for (int i=0; i<num_var; i++) {
3937 sm.push_back(-1);
3938 }
3939 }
3940
3941 sm[i] = sindex;
3942 }
3943
3944 if (!sm.empty()) {
3945 slist.push_back(s);
3946 smap.push_back(sm);
3947 }
3948 }
3949
3950 if (0||fDebug) {
3951 printf("Found %zu matching schema:\n", slist.size());
3952
3953 for (size_t i=0; i<slist.size(); i++) {
3954 HsSchema* s = slist[i];
3955 s->print();
3956 for (int k=0; k<num_var; k++)
3957 printf(" tag %s[%d] sindex %d\n", var_name[k], var_index[k], smap[i][k]);
3958 }
3959 }
3960
3961 //for (size_t ss=0; ss<slist.size(); ss++) {
3962 // HsSchema* s = slist[ss];
3963 // HsFileSchema* fs = dynamic_cast<HsFileSchema*>(s);
3964 // assert(fs != NULL);
3965 // printf("schema %zu from %s to %s, filename %s", ss, TimeToString(fs->fTimeFrom).c_str(), TimeToString(fs->fTimeTo).c_str(), fs->fFileName.c_str());
3966 // printf(" smap ");
3967 // for (int k=0; k<num_var; k++)
3968 // printf(" %2d", smap[ss][k]);
3969 // printf("\n");
3970 //}
3971
3972 for (size_t ss=1; ss<slist.size(); ss++) {
3973 if (fDebug) {
3974 printf("Check schema %zu/%zu: prev from %s, this from %s to %s, compare %d\n", ss, slist.size(),
3975 TimeToString(slist[ss-1]->fTimeFrom).c_str(),
3976 TimeToString(slist[ss]->fTimeFrom).c_str(),
3977 TimeToString(slist[ss]->fTimeTo).c_str(),
3978 slist[ss-1]->fTimeFrom >= slist[ss]->fTimeFrom);
3979 }
3980 if (slist[ss-1]->fTimeFrom >= slist[ss]->fTimeFrom) {
3981 // good
3982 } else {
3983 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.");
3984 return HS_FILE_ERROR;
3985 }
3986 }
3987
3988 std::vector<time_t> last_time;
3989
3990 for (int i=0; i<num_var; i++) {
3991 last_time.push_back(start_time);
3992 }
3993
3994 if (slist.size() > 0) {
3995 for (size_t i=slist.size()-1; ; i--) {
3996 HsSchema* s = slist[i];
3997
3998 int status = s->read_data(start_time, end_time, num_var, smap[i], var_index, fDebug, last_time, buffer);
3999
4000 if (status == HS_SUCCESS) {
4001 for (int j=0; j<num_var; j++) {
4002 if (smap[i][j] >= 0)
4003 hs_status[j] = HS_SUCCESS;
4004 }
4005 }
4006
4007 if (i==0)
4008 break;
4009 }
4010 }
4011
4012 return HS_SUCCESS;
4013}
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:734
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 3181 of file history_schema.cxx.

3182 {
3183 int old = fDebug;
3184 fDebug = debug;
3185 return old;
3186 }
BOOL debug
debug printouts
Definition mana.cxx:254
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 3580 of file history_schema.cxx.

3581{
3582 if (fDebug)
3583 printf("hs_write_event: write event \'%s\', time %d, size %d\n", event_name, (int)timestamp, xbuffer_size);
3584
3585 assert(xbuffer_size > 0);
3586
3587 size_t buffer_size = xbuffer_size;
3588
3589 HsSchema *s = NULL;
3590
3591 // find this event
3592 for (size_t i=0; i<fWriterEvents.size(); i++)
3593 if (fWriterEvents[i] && (event_name_cmp(fWriterEvents[i]->fEventName, event_name)==0)) {
3594 s = fWriterEvents[i];
3595 break;
3596 }
3597
3598 // not found
3599 if (!s)
3600 return HS_UNDEFINED_EVENT;
3601
3602 // deactivated because of error?
3603 if (s->fDisabled) {
3604 //printf("HERE!\n");
3605 return HS_FILE_ERROR;
3606 }
3607
3608 s = maybe_reopen(event_name, timestamp, s);
3609
3610 assert(s != NULL);
3611
3612 if (s->fNumBytes == 0) { // compute expected data size
3613 // NB: history data does not have any padding!
3614 for (size_t i=0; i<s->fVariables.size(); i++) {
3615 s->fNumBytes += s->fVariables[i].n_bytes;
3616 }
3617 }
3618
3619 int status;
3620
3621 if (buffer_size > s->fNumBytes) { // too many bytes!
3622 if (s->fCountWriteOversize == 0) {
3623 // only report first occurence
3624 // count of all occurences is reported by HsSchema destructor
3625 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);
3626 }
3628 if (buffer_size > s->fWriteMaxSize)
3629 s->fWriteMaxSize = buffer_size;
3630 status = s->write_event(timestamp, buffer, s->fNumBytes);
3631 } else if (buffer_size < s->fNumBytes) { // too few bytes
3632 if (s->fCountWriteUndersize == 0) {
3633 // only report first occurence
3634 // count of all occurences is reported by HsSchema destructor
3635 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);
3636 }
3638 if (s->fWriteMinSize == 0)
3639 s->fWriteMinSize = buffer_size;
3640 else if (buffer_size < s->fWriteMinSize)
3641 s->fWriteMinSize = buffer_size;
3642 char* tmp = (char*)malloc(s->fNumBytes);
3643 memcpy(tmp, buffer, buffer_size);
3644 memset(tmp + buffer_size, 0, s->fNumBytes - buffer_size);
3645 status = s->write_event(timestamp, tmp, s->fNumBytes);
3646 free(tmp);
3647 } else {
3648 assert(buffer_size == s->fNumBytes); // obviously
3649 status = s->write_event(timestamp, buffer, buffer_size);
3650 }
3651
3652 // if could not write event, deactivate it
3653 if (status != HS_SUCCESS) {
3654 s->fDisabled = true;
3655 cm_msg(MERROR, "hs_write_event", "Event \'%s\' disabled after write error %d", event_name, status);
3656 return HS_FILE_ERROR;
3657 }
3658
3659 return HS_SUCCESS;
3660}
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 3154 of file history_schema.cxx.

◆ fDebug

int SchemaHistoryBase::fDebug = 0
protected

Definition at line 3153 of file history_schema.cxx.

◆ fReaderSchema

HsSchemaVector SchemaHistoryBase::fReaderSchema
protected

Definition at line 3161 of file history_schema.cxx.

◆ fWriterEvents

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

Definition at line 3158 of file history_schema.cxx.

◆ fWriterSchema

HsSchemaVector SchemaHistoryBase::fWriterSchema
protected

Definition at line 3157 of file history_schema.cxx.


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