Mhformat: Difference between revisions

From MidasWiki
Jump to navigation Jump to search
m (New page: <p> MIDAS history data is recorded into the MIDAS .hst files. These files are formatted like this:</p> <table> <tbody> <tr> <td rowspan="13">definition record</td> <td rowspan="6">HIST_REC...)
 
No edit summary
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
<p>
{{Pagelinks}}
MIDAS history data is recorded into the MIDAS .hst files. These files are formatted like this:</p>
= Links =
<table>
<div style="column-count:3;-moz-column-count:3;-webkit-column-count:3">
<tbody>
* [[History System]]
* [[mh2sql]]
</div>
MIDAS history data is recorded into the MIDAS .hst files. These files are formatted like this:
<table border="1">
<tr>
<tr>
<td rowspan="13">definition record</td>
<td rowspan="13">definition record</td>
Line 97: Line 101:
<td>...</td>
<td>...</td>
</tr>
</tr>
</tbody>
</table>
</table>
<p>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):</p>
<p>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):</p>
Line 150: Line 153:
<p>
<p>
         For a complete working example of reading MIDAS history files, look at mhdump.cxx</p>
         For a complete working example of reading MIDAS history files, look at mhdump.cxx</p>
[[Category:History]]

Latest revision as of 16:19, 31 July 2015


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