Mhformat
Jump to navigation
Jump to search
Links
MIDAS history data is recorded into the MIDAS .hst files. These files are formatted like this:
definition record | HIST_RECORD | |
uint32_t record_type | 0x46445348 (RT_DEF) | |
uint32_t event_id | history event id | |
uint32_t time | unix time | |
uint32_t def_offset | 0 | |
uint32_t data_size | size in bytes of following data | |
event name | char name[32] | name of this event |
TAG | ||
char name[32] | tag name | |
uint32_t type | type of the data TID_xxx | |
uint32_t n_data | array size | |
TAG | ||
... | ||
data record | HIST_RECORD | |
uint32_t record_type | 0x41445348 (RT_DATA) | |
uint32_t event_id | history event id | |
uint32_t time | unix time | |
uint32_t def_offset | location of the definition record for this event in the .def file (???) | |
uint32_t data_size | size in bytes of following data | |
event data | char[data_size] | history data for this event |
data record | ||
... | ||
definition record | ||
data record | ||
... |
To decode the "event data" blob in a data record, one should parse the data definition for this event and remember the contents of all tag definitions. One way to parse the data is by computing the "offset" for each tag by adding up the tag size for each tag. For each tag, the corresponding data size is the product of n_data and the size of the MIDAS type, given in this table (extracted from midas.c):
/* data type sizes */ int tid_size[] = { 0, /* tid == 0 not defined */ 1, /* TID_BYTE unsigned byte 0 255 */ 1, /* TID_SBYTE signed byte -128 127 */ 1, /* TID_CHAR single character 0 255 */ 2, /* TID_WORD two bytes 0 65535 */ 2, /* TID_SHORT signed word -32768 32767 */ 4, /* TID_DWORD four bytes 0 2^32-1 */ 4, /* TID_INT signed dword -2^31 2^31-1 */ 4, /* TID_BOOL four bytes bool 0 1 */ 4, /* TID_FLOAT 4 Byte float format */ 8, /* TID_DOUBLE 8 Byte float format */ 1, /* TID_BITFIELD 8 Bits Bitfield 00000000 11111111 */ 0, /* TID_STRING zero terminated string */ 0, /* TID_ARRAY variable length array of unkown type */ 0, /* TID_STRUCT C structure */ 0, /* TID_KEY key in online database */ 0 /* TID_LINK link in online database */ };
Example code for computing tag offsets:
int offset = 0; for (int itag=0; itag<ntags; itag++) { int size = tags[itag].n_data * tid_size[tags[itag].type]; type_for_tag[itag] = tags[itag].type; offset_for_tag[itag] = offset; offset += size; }
Example code for decoding the event data blob:
char *buf = new char[data_size]; fread(buf, 1, data_size, f); // read data blob from file int itag = ...; // the tag we want to look at int j = ...; // array index inside the tag int offset = offset_for_tag[itag]; void* ptr = (void*)(buf+offset); switch (type_for_tag[itag]) { default: printf("unknownType%d ",type_for_tag[itag]); break; case 6: /* DWORD */ printf("%u ",((uint32_t*)ptr)[j]); break; }
For a complete working example of reading MIDAS history files, look at mhdump.cxx