45 int rd = fread(&rec,
sizeof(rec), 1, f);
50 printf(
"HIST_RECORD:\n");
52 printf(
" Event ID: %d\n", rec.
event_id);
53 printf(
" Time: %d\n", rec.
time);
61 fprintf(stderr,
"Error: %s: Unexpected record type: 0x%x\n", filename, rec.
record_type);
73 fprintf(stderr,
"Error: %s: Error reading RT_DEF record, fread(%d) returned %d, errno %d (%s)\n", filename,
NAME_LENGTH, rd, errno, strerror(errno));
88 int ntags = size/
sizeof(
TAG);
93 (size < 1*1024*1024) &&
94 (size == ntags*(
int)
sizeof(
TAG)))) {
96 fprintf(stderr,
"Error: %s: Invalid length of RT_DEF record: %d (0x%x)\n", filename, size, size);
103 TAG *tags =
new TAG[ntags];
104 rd = fread(tags, 1, size, f);
107 fprintf(stderr,
"Error: %s: Error reading RT_DEF record, fread(%d) returned %d, errno %d (%s)\n", filename, size, rd, errno, strerror(errno));
116 for (
int i=0;
i<ntags;
i++) {
119 fprintf(stderr,
"Warning: %s: Event \"%s\": Fixed by truncation at forbidden TID_STRING tag \"%s\" at index %d\n", filename, event_name, tags[
i].
name,
i);
125 if (strlen(tags[
i].
name) < 1) {
126 sprintf(tags[
i].
name,
"empty_%d",
i);
128 fprintf(stderr,
"Warning: %s: Event \"%s\": Fixed empty tag name for tag %d: replaced with \"%s\"\n", filename, event_name,
i, tags[
i].
name);
132 for (
int j=
i+1;
j<ntags;
j++) {
133 if (strcmp(tags[
i].
name, tags[
j].
name) == 0) {
135 sprintf(
str,
"_dup%d",
j);
138 fprintf(stderr,
"Warning: %s: Event \"%s\": Fixed duplicate tag names: tag \"%s\" at index %d duplicate at index %d replaced with \"%s\"\n", filename, event_name, tags[
i].
name,
i,
j, tags[
j].
name);
157 printf(
"Data record, size %d.\n", size);
160 (size < 1*1024*1024))) {
162 fprintf(stderr,
"Error: %s: Invalid length of RT_DATA record: %d (0x%x)\n", filename, size, size);
171 bufSize = 1024*((size+1023)/1024);
172 char *newbuf = (
char*)realloc(buf, bufSize);
174 if (newbuf == NULL) {
175 fprintf(stderr,
"Error: %s: Cannot realloc(%d), errno %d (%s)\n", filename, bufSize, errno, strerror(errno));
185 rd = fread(buf, 1, size, f);
188 fprintf(stderr,
"Error: %s: Error reading RT_DATA record, fread(%d) returned %d, errno %d (%s)\n", filename, size, rd, errno, strerror(errno));
195 time_t t = (time_t)rec.
time;
214 FILE* f = fopen(
name,
"r");
217 fprintf(stderr,
"Error: Cannot open \'%s\', errno %d (%s)\n",
name, errno, strerror(errno));
221 fprintf(stderr,
"Reading %s\n",
name);
228 fprintf(stderr,
"Notice: Automatically repaired some empty tag names\n");
233 fprintf(stderr,
"Notice: Automatically repaired some duplicate tag names\n");
238 fprintf(stderr,
"Notice: Automatically truncated events that contain tags of forbidden type TID_STRING\n");
246 fprintf(stderr,
"Usage: mh2sql [-h] [switches...] file1.hst file2.hst ...\n");
247 fprintf(stderr,
"\n");
248 fprintf(stderr,
"Switches:\n");
249 fprintf(stderr,
" -h --- print this help message\n");
250 fprintf(stderr,
" --report-repaired-tags --- print messages about all repaired empty and duplicate tag names\n");
251 fprintf(stderr,
" --hs-debug <hs_debug_flag> --- set the history debug flag\n");
252 fprintf(stderr,
" --odbc <ODBC_DSN> --- write to ODBC (SQL) history using given ODBC DSN\n");
253 fprintf(stderr,
" --sqlite <path> --- write to SQLITE database at the given path\n");
254 fprintf(stderr,
" --mysql mysql_writer.txt --- write to MYSQL database\n");
255 fprintf(stderr,
" --pgsql pgsql_writer.txt --- write to PGSQL database\n");
256 fprintf(stderr,
" --file <path> --- write to FILE database at the given path\n");
257 fprintf(stderr,
"\n");
258 fprintf(stderr,
"Examples:\n");
259 fprintf(stderr,
" mh2sql --hs-debug 1 --sqlite . 130813.hst\n");
266 int hs_debug_flag = 0;
283 for (
int iarg=1; iarg<argc; iarg++) {
284 const char* arg = argv[iarg];
288 if (strcmp(arg,
"-h")==0) {
290 }
else if (strcmp(arg,
"--report-repaired-tags") == 0) {
294 }
else if (strcmp(arg,
"--hs-debug") == 0) {
295 hs_debug_flag = atoi(argv[iarg+1]);
297 }
else if (strcmp(arg,
"--odbc") == 0) {
305 }
else if (strcmp(arg,
"--sqlite") == 0) {
313 }
else if (strcmp(arg,
"--mysql") == 0) {
321 }
else if (strcmp(arg,
"--pgsql") == 0) {
329 }
else if (strcmp(arg,
"--file") == 0) {
346 for (
int iarg=1; iarg<argc; iarg++) {
347 const char* arg = argv[iarg];
352 if (strcmp(arg,
"--hs-debug") == 0) {
358 for (
int iarg=1; iarg<argc; iarg++) {
359 const char* arg = argv[iarg];
361 if (strstr(arg,
".hst") != NULL) {
virtual int hs_set_debug(int debug)=0
set debug level, returns previous debug level
virtual int hs_disconnect()=0
disconnect from history, returns HS_SUCCESS
virtual int hs_connect(const char *connect_string)=0
returns HS_SUCCESS
virtual int hs_flush_buffers()=0
flush buffered data to storage where it is visible to mhttpd
virtual int hs_write_event(const char *event_name, time_t timestamp, int data_size, const char *data)=0
see hs_write_event(), returns HS_SUCCESS or HS_FILE_ERROR
virtual int hs_define_event(const char *event_name, time_t timestamp, int ntags, const TAG tags[])=0
see hs_define_event(), returns HS_SUCCESS or HS_FILE_ERROR
INT cm_get_experiment_database(HNDLE *hDB, HNDLE *hKeyClient)
INT cm_connect_experiment(const char *host_name, const char *exp_name, const char *client_name, void(*func)(char *))
INT cm_disconnect_experiment(void)
INT cm_set_watchdog_params(BOOL call_watchdog, DWORD timeout)
INT cm_msg_flush_buffer()
int hs_get_history(HNDLE hDB, HNDLE hKey, int flags, int debug_flag, MidasHistoryInterface **mh)
MidasHistoryInterface * MakeMidasHistoryODBC()
MidasHistoryInterface * MakeMidasHistorySqlite()
MidasHistoryInterface * MakeMidasHistoryMysql()
MidasHistoryInterface * MakeMidasHistoryPgsql()
MidasHistoryInterface * MakeMidasHistoryFile()
int copyHstFile(const char *filename, FILE *f, MidasHistoryInterface *mh)
int copyHst(const char *name, MidasHistoryInterface *mh)
std::map< int, const char * > gEventName
MidasHistoryInterface * mh