#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <string>
#include <map>
#include <vector>
#include <ctime>
Go to the source code of this file.
◆ DWORD
◆ NAME_LENGTH
length of names, mult.of 8!
Definition at line 33 of file mhdump.cxx.
◆ help()
Definition at line 524 of file mhdump.cxx.
525{
526 fprintf(
stderr,
"Usage: mhdump [-h] [-L] [-n] [-t] [-E event_id] [-T tag_name] file1.hst file2.hst ...\n");
527 fprintf(
stderr,
"Usage: mhdump [-L] [-n] [-t] [-T tag_name] mhf_file1.dat mhf_file2.dat ...\n");
536 fprintf(
stderr,
" To list all existing tags: mhdump -L file1.hst file2.hst ...\n");
537 fprintf(
stderr,
" To show data for all events, all tags: mhdump file1.hst file2.hst ...\n");
538 fprintf(
stderr,
" To show all data for event 0: mhdump -E 0 file1.hst file2.hst ...\n");
539 fprintf(
stderr,
" To show data for event 0, tag \"State\": mhdump -n -E 0 -T State file1.hst file2.hst ...\n");
540 fprintf(
stderr,
" To show data for event 3, tag \"MCRT\", array index 5: mhdump -n -E 3 -T MCRT[5] file1.hst file2.hst ...\n");
541 exit(1);
542}
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
◆ main()
Definition at line 544 of file mhdump.cxx.
545{
547
550
553 {
555 }
557 {
563 }
565 {
569 if (s)
570 {
572 *s = 0;
573 }
574
576
578
580 {
581 fprintf(
stderr,
"Error: expected \"-E event_id\" before \"-T ...\"\n");
582 exit(1);
583 }
584
585 e->printAllTags =
false;
586 e->tagNames.push_back(
name);
587 e->tagIndexes.push_back(
index);
588 }
592 {
595 }
601
602 if (
gTags.size() == 0)
605 } else {
606
607 if (
gTags.size() == 0)
610 }
611
612
618 }
619 }
620 ei.second->tags.clear();
622 }
623 }
625
626 return 0;
627}
int readMhf(const char *name)
int readHst(const char *name)
std::map< int, Event * > gTags
◆ readHst()
Definition at line 406 of file mhdump.cxx.
407{
409 if (!f)
410 {
412 exit(1);
413 }
414
417 return 0;
418}
◆ readHstFile()
Definition at line 128 of file mhdump.cxx.
129{
131
133
134 while (1)
135 {
137
139 {
142 break;
143 }
144
146#if 0
148 printf(
" Record type: 0x%x\n",
rec.record_type);
151 printf(
" Offset: 0x%x\n",
rec.def_offset);
153#endif
154
155 switch (
rec.record_type)
156 {
157 default:
158 printf(
"Unexpected record type: 0x%08x, trying to recover by skipping bad data.\n",
rec.record_type);
159 while (1)
160 {
162
164 return 0;
166 continue;
167
170 return 0;
172 continue;
173
176 return 0;
178 continue;
179
180 printf(
"Maybe recovered - see what looks like valid history record header.\n");
181
182 ((
char*)(&
rec))[0] = 0x48;
183 ((
char*)(&
rec))[1] = 0x53;
184 ((
char*)(&
rec))[2] = 0x44;
185
188 return 0;
189
191 break;
192 }
193 break;
194
195 case 0x46445348:
196 {
200
201 int size =
rec.data_size;
203
205 printf(
"Event %d, \"%s\", size %d, %d tags.\n",
rec.event_id, event_name, size,
ntags);
206
207 assert(size > 0);
208 assert(size < 1*1024*1024);
209 assert(size ==
ntags*(
int)
sizeof(
TAG));
210
214
217 {
222 e->printAllTags =
true;
223 }
224 else
225 {
226 if (
e->printAllTags) {
228 e->tagIndexes.clear();
229 }
230 }
231
233
235
237 {
239
242
244
246
247
248 fprintf(
stderr,
"Error: Event %d, \"%s\", has a tag \"%s\" of type TID_STRING, which is forbidden and cannot be decoded, all data after this tag will be gibberish\n",
rec.event_id, event_name, tags[
itag].name);
249 size = 0;
250 }
251
254
256
264
265 e->tags[t->
name] = t;
266
268 {
269 e->tagNames.push_back(t->
name);
270 e->tagIndexes.push_back(-1);
271 }
272
274 printf(
" Tag %d: \"%s\"[%d], type \"%s\" (%d), type size %d, offset %d+%d\n",
itag, tags[
itag].
name, tags[
itag].n_data,
tid_name[tags[
itag].
type], tags[
itag].
type,
tid_size[tags[
itag].
type],
offset, size);
275
277 }
278
280
281
282
283
284 delete[] tags;
285 break;
286 }
287
288 case 0x41445348:
289 {
290 int size =
rec.data_size;
291
292 if (0)
293 printf(
"Data record, size %d.\n", size);
294
296 {
297 fprintf(
stderr,
"Error: Invalid data record: event %d, size %d is invalid\n",
rec.event_id,
rec.data_size);
298 continue;
299 }
300
301 char *buf = new char[size];
302 int rd =
fread(buf, 1, size, f);
304
306
309 {
311 {
312 fprintf(
stderr,
"Error: event %d, size mismatch should be %d, got %d bytes\n",
rec.event_id,
e->size, size);
313 }
314
315
316
317 int n =
e->tagNames.size();
318
321
322 for (
int i=0;
i<
n;
i++)
323 {
324 Tag*t =
e->tags[
e->tagNames[
i]];
326
327
328
329 if (t)
330 {
332 void* ptr = (
void*)(buf+
offset);
333
335 {
338 else
340 }
341
343 {
346
348 {
349 default:
351 break;
352 case 1:
354 break;
355 case 2:
357 break;
358 case 3:
359 printf(
"\'%c\' ",((
char*)ptr)[
j]);
360 break;
361 case 4:
363 break;
364 case 5:
366 break;
367 case 6:
369 break;
370 case 7:
372 break;
373 case 8:
375 break;
376 case 9:
377 printf(
"%.8g ",((
float*)ptr)[
j]);
378 break;
379 case 10:
380 printf(
"%.16g ",((
double*)ptr)[
j]);
381 break;
382
383
384
385 }
386
388 break;
389 }
390 }
391 }
392
395 }
396
397 delete[] buf;
398 break;
399 }
400 }
401 }
402
403 return 0;
404}
◆ readMhf()
Definition at line 511 of file mhdump.cxx.
512{
514 if (!f) {
516 exit(1);
517 }
518
521 return 0;
522}
int readMhfFile(const char *filename, FILE *f)
◆ readMhfFile()
Definition at line 500 of file mhdump.cxx.
501{
503 if (version == "version: 2.0") {
505 }
506
507 fprintf(
stderr,
"%s: unexpected file version: %s\n", filename, version.c_str());
508 return -1;
509}
int readMhfFileV2(const char *filename, FILE *f)
std::string readString(FILE *f)
◆ readMhfFileV2()
Definition at line 449 of file mhdump.cxx.
450{
453 printf(
"event name: [%s], time [%s]\n", event_name.c_str(), time.c_str());
454 std::string s;
455 while (1) {
457 if (
strncmp(s.c_str(),
"tag:", 4) != 0)
458 break;
459 printf(
"tag: %s\n", s.c_str());
460 }
465
466 printf(
"record size: %zu, data offset: %zu\n", record_size, data_offset);
470 return -1;
471 }
472 char buf[record_size];
476 size_t rd =
fread(buf, 1, record_size, f);
477
479
480 break;
481 }
else if (
rd != record_size) {
482
483 fprintf(
stderr,
"%s: short read at the end of file, last data record is truncated from %zu to %zu bytes\n", filename, record_size,
rd);
484 break;
485 }
487 printf(
"record %d, time %lu, incr %lu\n",
count, (
long unsigned int)t, (
long unsigned int)(t-
last_time));
490 printf(
"duplicate time %lu -> %lu\n", (
long unsigned int)
last_time, (
long unsigned int)t);
492 printf(
"non-monotonic time %lu -> %lu\n", (
long unsigned int)
last_time, (
long unsigned int)t);
493 }
495 }
497 return 0;
498}
std::string tagValue(const char *tag, const std::string &s)
◆ readString()
std::string readString |
( |
FILE * |
f | ) |
|
Definition at line 420 of file mhdump.cxx.
421{
422 char buf[1024];
423 memset(buf, 0,
sizeof(buf));
424 const char* s =
fgets(buf,
sizeof(buf)-1, f);
425 if (!s)
426 return "";
427
429 if (len > 0) {
430
431 if (buf[len-1] == '\n')
432 buf[len-1] = 0;
433 }
434 return buf;
435}
◆ tagValue()
Definition at line 437 of file mhdump.cxx.
438{
440 if (
strncmp(s.c_str(), tag, len) == 0) {
441 const char*
sptr = s.c_str() + len;
442 while (
sptr[0] ==
' ')
445 }
446 return "";
447}
◆ doAll
◆ doPrintData
◆ doPrintNames
◆ doPrintTags
◆ gTags
◆ tid_name
Initial value:= {
"NULL",
"BYTE",
"SBYTE",
"CHAR",
"UINT16",
"INT16",
"UINT32",
"INT32",
"BOOL",
"FLOAT",
"DOUBLE",
"BITFIELD",
"STRING",
"ARRAY",
"STRUCT",
"KEY",
"LINK",
"INT64",
"UINT64"
}
Definition at line 78 of file mhdump.cxx.
78 {
79 "NULL",
80 "BYTE",
81 "SBYTE",
82 "CHAR",
83 "UINT16",
84 "INT16",
85 "UINT32",
86 "INT32",
87 "BOOL",
88 "FLOAT",
89 "DOUBLE",
90 "BITFIELD",
91 "STRING",
92 "ARRAY",
93 "STRUCT",
94 "KEY",
95 "LINK",
96 "INT64",
97 "UINT64"
98};
◆ tid_size
Initial value:= {
0,
1,
1,
1,
2,
2,
4,
4,
4,
4,
8,
1,
0,
0,
0,
0,
0,
8,
8
}
Definition at line 55 of file mhdump.cxx.
55 {
56 0,
57 1,
58 1,
59 1,
60 2,
61 2,
62 4,
63 4,
64 4,
65 4,
66 8,
67 1,
68 0,
69 0,
70 0,
71 0,
72 0,
73 8,
74 8
75};