15#define CALLOC(num, type) (type*)calloc((num),sizeof(type))
16#define FREE(ptr) free(ptr); (ptr)=NULL;
57 for (
i = 0;
i < 100;
i++) {
64 bytes += (
sizeof(
hist) +
sizeof(
hv)) *
i;
69 }
while (
act_time - start_time < 10000);
71 printf(
"%d events (%d kB) per sec.\n",
j / (
act_time - start_time) * 1000,
72 bytes / 1024 / (
act_time - start_time) * 1000);
86 for (
i = 0;
i < 10;
i++) {
91 for (
j = 0;
j < 100;
j++)
102 std::string* event_name,
113 std::vector<std::string>
events;
121 printf(
"Available events:\n");
122 for (
unsigned i = 0;
i <
events.size();
i++) {
128 else if (
events.size() == 1)
132 printf(
"\nSelect event: ");
139 std::vector<TAG> tags;
147 printf(
"\nAvailable variables:\n");
149 for (
unsigned j = 0;
j < tags.size();
j++)
150 if (tags[
j].n_data > 1)
155 *
index = var_index = 0;
156 if (tags.size() > 1) {
157 printf(
"\nSelect variable (0..%d,-1 for all): ", (
int)tags.size() - 1);
161 if (var_index >= (
int)tags.size())
162 var_index = tags.size() - 1;
169 if (var_index >= 0) {
174 if (tags[var_index].n_data > 1 && tags[var_index].
type !=
TID_STRING) {
175 printf(
"\nSelect index (0..%d): ", tags[var_index].n_data - 1);
182 printf(
"\nHow many hours: ");
187 *start_time = (*end_time) -
hour * 3600;
189 printf(
"\nInterval [sec]: ");
211 if (
tms.tm_year < 90)
229 for (
i = 0;
i <
n;
i++) {
234 char* var_names = (
char*)
malloc(bytes);
238 for (
j = 0;
j <
nv;
j++)
299 if (
n != (
int)
sizeof(
rec)) {
300 printf(
"Error reading \"%s\", truncated data, requested %d bytes, read %d bytes\n",
file_name, (
int)
sizeof(
rec),
n);
307 n =
read(
fh, event_name,
sizeof(event_name));
308 if (
n !=
sizeof(event_name)) {
313 if (
rec.event_id ==
id ||
id == 0)
314 printf(
"Event definition %s, ID %d\n", event_name,
rec.event_id);
330 if (
rec.event_id ==
id ||
id == 0)
346 std::vector<std::string>
events;
354 for (
unsigned i = 0;
i <
events.size();
i++) {
357 std::vector<TAG> tags;
365 for (
unsigned j = 0;
j < tags.size();
j++)
366 if (tags[
j].n_data > 1)
377 const char* event_name,
383 double *buffer =
NULL;
388 status =
mh->
hs_read(start_time, end_time,
interval, 1, &event_name, &
var_name, &
index, &
n, &
tbuffer, &buffer, &
hs_status);
401 printf(
"No data for event \"%s\" variable \"%s\" found in specified time range\n", event_name,
var_name);
403 for (
int i = 0;
i <
n;
i++) {
428 const char* event_name,
436 printf(
"Wrong specified range (low>high)\n");
442 const char**
en =
CALLOC(nvars,
const char*);
443 const char**
vn =
CALLOC(nvars,
const char*);
444 int* in =
CALLOC(nvars,
int);
446 for (
int i=0;
i<nvars;
i++) {
457 status =
mh->
hs_read(start_time, end_time,
interval, nvars,
en,
vn, in,
n,
tbuffer,
vbuffer,
hs_status);
460 printf(
"Cannot read history data, hs_read() error %d\n",
status);
464 for (
int i=0;
i<nvars;
i++) {
466 printf(
"No data for event \"%s\" variable \"%s\" index %d found in specified time range\n", event_name,
var_name,
index1+
i);
472 for (
int i = 0;
i <
n[0];
i++) {
493 for (
int i=0;
i<nvars;
i++) {
511 const char* event_name,
517 std::vector<TAG> tags;
521 printf(
"Cannot get list of variables for event \'%s\', hs_get_tags() error %d\n", event_name,
status);
525 for (
unsigned j = 0;
j < tags.size();
j++) {
526 if (tags[
j].n_data > 1)
534 for (
unsigned i=0;
i<tags.size();
i++) {
535 if (tags[
i].n_data == 1) {
538 for (
unsigned j=0;
j<tags[
i].n_data;
j++) {
551 for (
unsigned i=0;
i<tags.size();
i++) {
552 if (tags[
i].
name[0] ==
'/')
554 if (tags[
i].n_data == 1) {
555 en[nvars] = event_name;
556 vn[nvars] = tags[
i].name;
558 n_data[nvars] = tags[
i].n_data;
561 for (
unsigned j=0;
j<tags[
i].n_data;
j++) {
562 en[nvars] = event_name;
563 vn[nvars] = tags[
i].name;
565 n_data[nvars] = tags[
i].n_data;
571 assert(nvars <=
xvars);
578 status =
mh->
hs_read(start_time, end_time,
interval, nvars,
en,
vn, in,
n,
tbuffer,
vbuffer,
hs_status);
581 printf(
"Cannot read history data, hs_read() error %d\n",
status);
590 for (
int i=0;
i<nvars;
i++) {
592 printf(
"No data for event \"%s\" variable \"%s\" index %d found in specified time range\n",
en[
i],
vn[
i], in[
i]);
598 printf(
"Number of entries for event \"%s\" variable \"%s\" index %d is %d instead of %d\n",
en[
i],
vn[
i], in[
i],
n[
i],
nread);
607 printf(
"No data, nothing to print\n");
612 printf(
"Cannot print history data because of timestamp skew\n");
616 printf(
"Event \'%s\', %d variables, %d entries\n", event_name, nvars,
nread);
620 for (
int i=0;
i<nvars;
i++) {
621 if (n_data[
i] == 1) {
647 for (
int j=0;
j<nvars;
j++) {
649 printf(
"Cannot print history data because of timestamp skew\n");
659 for (
int i=0;
i<nvars;
i++) {
686 tms.tm_year = 10 * (t[0] -
'0') + (t[1] -
'0');
687 tms.tm_mon = 10 * (t[2] -
'0') + (t[3] -
'0') - 1;
688 tms.tm_mday = 10 * (t[4] -
'0') + (t[5] -
'0');
689 if (
tms.tm_year < 90)
692 tms.tm_hour = 10 * (t[7] -
'0') + (t[8] -
'0');
693 tms.tm_min = 10 * (t[9] -
'0') + (t[10] -
'0');
695 tms.tm_sec = 10 * (t[11] -
'0') + (t[12] -
'0');
707 tms.tm_year = 10 * (t[0] -
'0') + (t[1] -
'0');
708 tms.tm_mon = 10 * (t[2] -
'0') + (t[3] -
'0') - 1;
709 tms.tm_mday = 10 * (t[4] -
'0') + (t[5] -
'0');
710 if (
tms.tm_year < 90)
713 tms.tm_hour = 10 * (t[7] -
'0') + (t[8] -
'0');
714 tms.tm_min = 10 * (t[9] -
'0') + (t[10] -
'0');
716 tms.tm_sec = 10 * (t[11] -
'0') + (t[12] -
'0');
726 printf(
"\nusage: mhist [-e Event Name] [-v Variable Name]\n");
727 printf(
" [-i Index] index of variables which are arrays\n");
728 printf(
" [-i Index1:Index2] index range of variables which are arrays (max 50)\n");
729 printf(
" [-t Interval] minimum interval in sec. between two displayed records\n");
730 printf(
" [-h Hours] display between some hours ago and now\n");
731 printf(
" [-d Days] display between some days ago and now\n");
732 printf(
" [-f File] specify history file explicitly\n");
733 printf(
" [-s Start date] specify start date YYMMDD[.HHMM[SS]]\n");
734 printf(
" [-p End date] specify end date YYMMDD[.HHMM[SS]]\n");
735 printf(
" [-l] list available events and variables\n");
736 printf(
" [-b] display time stamp in decimal format\n");
743 DWORD start_time = 0;
755 std::string event_name;
790 start_time = end_time - 3600;
801 else if (
argv[
i][0] ==
'-' &&
argv[
i][1] ==
'l')
803 else if (
argv[
i][0] ==
'-') {
805 printf(
"Error: command line switch value after \"%s\" is missing\n",
argv[
i]);
807 }
else if (
argv[
i+1][0] ==
'-') {
808 printf(
"Error: command line switch value after \"%s\" starts with a dash: %s\n",
argv[
i],
argv[
i+1]);
811 event_name =
argv[++
i];
838 printf(
"Error: unknown command line switch: %s\n",
argv[
i]);
virtual 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 tag_name[], const int var_index[], int num_entries[], time_t *time_buffer[], double *data_buffer[], int status[])=0
see hs_read(), returns HS_SUCCESS
virtual int hs_get_events(time_t time_from, std::vector< std::string > *pevents)=0
get list of events that exist(ed) at given time and later (value 0 means "return all events from begi...
virtual int hs_get_tags(const char *event_name, time_t time_from, std::vector< TAG > *ptags)=0
get list of history variables for given event (use event names returned by hs_get_events()) that exis...
INT cm_get_experiment_database(HNDLE *hDB, HNDLE *hKeyClient)
INT cm_connect_experiment1(const char *host_name, const char *default_exp_name, const char *client_name, void(*func)(char *), INT odb_size, DWORD watchdog_timeout)
INT cm_disconnect_experiment(void)
INT cm_get_environment(char *host_name, int host_name_size, char *exp_name, int exp_name_size)
static INT hs_enum_vars(DWORD ltime, DWORD event_id, char *var_name, DWORD *size, DWORD *var_n, DWORD *n_size)
static INT hs_define_event(DWORD event_id, const char *name, const TAG *tag, DWORD size)
static INT hs_count_vars(DWORD ltime, DWORD event_id, DWORD *count)
static INT hs_count_events(DWORD ltime, DWORD *count)
static INT hs_enum_events(DWORD ltime, char *event_name, DWORD *name_size, INT event_id[], DWORD *id_size)
static INT hs_dump(DWORD event_id, DWORD start_time, DWORD end_time, DWORD interval, BOOL binary_time)
static INT hs_write_event(DWORD event_id, const void *data, DWORD size)
time_t ss_mktime(struct tm *tms)
INT ss_sleep(INT millisec)
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
INT cm_set_msg_print(INT system_mask, INT user_mask, int(*func)(const char *))
int hs_get_history(HNDLE hDB, HNDLE hKey, int flags, int debug_flag, MidasHistoryInterface **mh)
BOOL debug
debug printouts
char host_name[HOST_NAME_LENGTH]
char expt_name[NAME_LENGTH]
static void display_all_hist(MidasHistoryInterface *mh, const char *event_name, time_t start_time, time_t end_time, time_t interval)
static void display_single_hist(MidasHistoryInterface *mh, const char *event_name, time_t start_time, time_t end_time, time_t interval, const char *var_name, int index)
static DWORD convert_time(char *t)
#define CALLOC(num, type)
static INT query_params(MidasHistoryInterface *mh, std::string *event_name, DWORD *start_time, DWORD *end_time, DWORD *interval, char *var_name, DWORD *var_type, INT *var_n_data, DWORD *index)
static INT display_vars(MidasHistoryInterface *mh, time_t t)
static INT hs_fdump(const char *file_name, DWORD id, BOOL binary_time)
static void display_range_hist(MidasHistoryInterface *mh, const char *event_name, time_t start_time, time_t end_time, time_t interval, const char *var_name, int index1, int index2)
MidasHistoryInterface * mh
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)