116 std::map<std::string,Tag*>
tags;
148 printf(
" Record type: 0x%x\n",
rec.record_type);
151 printf(
" Offset: 0x%x\n",
rec.def_offset);
155 switch (
rec.record_type)
158 printf(
"Unexpected record type: 0x%08x, trying to recover by skipping bad data.\n",
rec.record_type);
180 printf(
"Maybe recovered - see what looks like valid history record header.\n");
182 ((
char*)(&
rec))[0] = 0x48;
183 ((
char*)(&
rec))[1] = 0x53;
184 ((
char*)(&
rec))[2] = 0x44;
201 int size =
rec.data_size;
205 printf(
"Event %d, \"%s\", size %d, %d tags.\n",
rec.event_id, event_name, size,
ntags);
208 assert(size < 1*1024*1024);
209 assert(size ==
ntags*(
int)
sizeof(
TAG));
222 e->printAllTags =
true;
226 if (
e->printAllTags) {
228 e->tagIndexes.clear();
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);
265 e->tags[t->
name] = t;
269 e->tagNames.push_back(t->
name);
270 e->tagIndexes.push_back(-1);
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);
290 int size =
rec.data_size;
293 printf(
"Data record, size %d.\n", size);
297 fprintf(
stderr,
"Error: Invalid data record: event %d, size %d is invalid\n",
rec.event_id,
rec.data_size);
301 char *buf =
new char[size];
302 int rd =
fread(buf, 1, size, f);
312 fprintf(
stderr,
"Error: event %d, size mismatch should be %d, got %d bytes\n",
rec.event_id,
e->size, size);
317 int n =
e->tagNames.size();
322 for (
int i=0;
i<
n;
i++)
324 Tag*t =
e->tags[
e->tagNames[
i]];
332 void* ptr = (
void*)(buf+
offset);
359 printf(
"\'%c\' ",((
char*)ptr)[
j]);
377 printf(
"%.8g ",((
float*)ptr)[
j]);
380 printf(
"%.16g ",((
double*)ptr)[
j]);
423 memset(buf, 0,
sizeof(buf));
424 const char* s =
fgets(buf,
sizeof(buf)-1, f);
431 if (buf[len-1] ==
'\n')
437std::string
tagValue(
const char* tag,
const std::string& s)
440 if (
strncmp(s.c_str(), tag, len) == 0) {
441 const char*
sptr = s.c_str() + len;
442 while (
sptr[0] ==
' ')
453 printf(
"event name: [%s], time [%s]\n", event_name.c_str(), time.c_str());
457 if (
strncmp(s.c_str(),
"tag:", 4) != 0)
459 printf(
"tag: %s\n", s.c_str());
466 printf(
"record size: %zu, data offset: %zu\n", record_size, data_offset);
472 char buf[record_size];
476 size_t rd =
fread(buf, 1, record_size, f);
481 }
else if (
rd != record_size) {
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);
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);
503 if (version ==
"version: 2.0") {
507 fprintf(
stderr,
"%s: unexpected file version: %s\n", filename, version.c_str());
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");
581 fprintf(
stderr,
"Error: expected \"-E event_id\" before \"-T ...\"\n");
585 e->printAllTags =
false;
586 e->tagNames.push_back(
name);
587 e->tagIndexes.push_back(
index);
602 if (
gTags.size() == 0)
607 if (
gTags.size() == 0)
615 for (
auto&
ti:
ei.second->tags) {
620 ei.second->tags.clear();
int readMhf(const char *name)
int readMhfFileV2(const char *filename, FILE *f)
int readMhfFile(const char *filename, FILE *f)
int readHst(const char *name)
std::string readString(FILE *f)
std::map< int, Event * > gTags
std::string tagValue(const char *tag, const std::string &s)
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
std::vector< std::string > tagNames
std::vector< int > tagIndexes
std::map< std::string, Tag * > tags