stream  0.10.0
stream analysis framework
definess.h
1 #ifndef HADAQ_DEFINESS_H
2 #define HADAQ_DEFINESS_H
3 
4 #include <cstdint>
5 
6 //Description of the Event Structure
7 //
8 //An event consists of an event header and of varying number of subevents, each with a subevent header. The size of the event header is fixed to 0x20 bytes
9 //
10 //Event header
11 //evtHeader
12 //evtSize evtDecoding evtId evtSeqNr evtDate evtTime runNr expId
13 //
14 // * evtSize - total size of the event including the event header, it is measured in bytes.
15 // * evtDecoding - event decoding type: Tells the analysis the binary format of the event data, so that it can be handed to a corresponding routine for unpacking into a software usable data structure. For easier decoding of this word, the meaning of some bits is already predefined:
16 // evtDecoding
17 // msB --- --- lsB
18 // 0 alignment decoding type nonzero
19 // o The first (most significant) byte is always zero.
20 // o The second byte contains the alignment of the subevents in the event. 0 = byte, 1 = 16 bit word, 2 = 32 bit word...
21 // o The remaining two bytes form the actual decoding type, e.g. fixed length, zero suppressed etc.
22 // o The last byte must not be zero, so the whole evtDecoding can be used to check for correct or swapped byte order.
23 //
24 //It is stated again, that the whole evtDecoding is one 32bit word. The above bit assignments are merely a rule how to select this 32bit numbers.
25 //
26 // * evtId - event identifier: Tells the analysis the semantics of the event data, e.g. if this is a run start event, data event, simulated event, slow control data, end file event, etc..
27 // evtId
28 // 31 30 - 16 15 - 12 11 - 8 5 - 7 4 3- 0
29 // error bit reserved version reserved MU decision DS flag ID
30 // o error bit - set if one of the subsystems has set the error bit
31 // o version - 0 meaning of event ID before SEP03; 1 event ID after SEP03
32 // o MU decision - 0 = negative LVL2 decision; >0 positive LVL2 decision
33 // MU trigger algo result
34 // 1 negative decision
35 // 2 positive decision
36 // 3 positive decision due to too many leptons or dileptons
37 // 4 reserved
38 // 5 reserved
39 // o DS flag - LVL1 downscaling flag; 1 = this event is written to the tape independent on the LVL2 trigger decision
40 // o ID - defines the trigger code
41 // ID before SEP03 description
42 // 0 simulation
43 // 1 real
44 // 2,3,4,5,6,7,8,9 calibration
45 // 13 beginrun
46 // 14 endrun
47 //
48 // ID after SEP03 description
49 // 0 simulation
50 // 1,2,3,4,5 real
51 // 7,9 calibration
52 // 1 real1
53 // 2 real2
54 // 3 real3
55 // 4 real4
56 // 5 real5
57 // 6 special1
58 // 7 offspill
59 // 8 special3
60 // 9 MDCcalibration
61 // 10 special5
62 // 13 beginrun
63 // 14 endrun
64 // * evtSeqNr - event number: This is the sequence number of the event in the file. The pair evtFileNr/evtSeqNr
65 //
66 //is unique throughout all events ever acquired by the system.
67 //
68 // * evtDate - date of event assembly (filled by the event builder, rough precision):
69 // evtDate ISO-C date format
70 // msB --- --- lsB
71 // 0 year month day
72 //
73 // 1. The first (most significant) byte is zero
74 // 2. The second byte contains the years since 1900
75 // 3. The third the months since January [0-11]
76 // 4. The last the day of the month [1-31]
77 //
78 // * evtTime - time of assembly (filled by the event builder, rough precision):
79 // evtTime ISO-C time format
80 // msB --- --- lsB
81 // 0 hour minute second
82 //
83 // 1. The first (most significant) byte is zero
84 // 2. The second byte contains the hours since midnight [0-23]
85 // 3. The third the minutes after the hour [0-59]
86 // 4. The last the seconds after the minute [0-60]
87 //
88 // * runNr - file number: A unique number assigned to the file. The runNr is used as key for the RTDB.
89 // * evtPad - padding: Makes the event header a multiple of 64 bits long.
90 
91 #ifndef __CINT__
92 #pragma pack(push, 1)
93 #endif
94 
95 // use another namespace to avoid duplication with DABC/HYDRA
96 namespace hadaqs {
97 
98  enum {
99  HADAQ_TIMEOFFSET = 1200000000 /* needed to reconstruct time from runId */
100  };
101 
102  enum EvtId {
103  EvtId_data = 0x00000001,
104  EvtId_DABC = 0x00003001, // hades DAQVERSION=3 (evtbuild.c uses DAQVERSION=2)
105  EvtId_runStart = 0x00010002,
106  EvtId_runStop = 0x00010003
107  };
108 
109  enum EvtDecoding {
110  EvtDecoding_default = 1,
111  EvtDecoding_AloneSubevt = 0x8, // subevent contains the only subsubevent, taking same id
112  EvtDecoding_64bitAligned = (0x03 << 16) | 0x0001
113  };
114 
115 #define HADAQ_SWAP4(value) (((value & 0xFF) << 24) | ((value & 0xFF00) << 8) | ((value & 0xFF0000) >> 8) | ((value & 0xFF000000) >> 24))
116 
117 // #define HADAQ_SWAP4(value) __builtin_bswap32(value)
118 
125  struct HadTu {
126  protected:
127  uint32_t tuSize;
128  uint32_t tuDecoding;
129 
130  public:
131 
133  HadTu() {}
135  ~HadTu() {}
136 
138  inline bool IsSwapped() const { return tuDecoding > 0xffffff; }
139 
141  inline uint32_t Value(const uint32_t *member) const
142  {
143 // return IsSwapped() ? __builtin_bswap32 (*member) : *member;
144 
145  return IsSwapped() ? HADAQ_SWAP4(*member) : *member;
146 
147 // return IsSwapped() ? ((((uint8_t *) member)[0] << 24) |
148 // (((uint8_t *) member)[1] << 16) |
149 // (((uint8_t *) member)[2] << 8) |
150 // (((uint8_t *) member)[3])) : *member;
151  }
152 
154  inline void SetValue(uint32_t *member, uint32_t val)
155  {
156  *member = IsSwapped() ? HADAQ_SWAP4(val) : val;
157 
158 // *member = IsSwapped() ? __builtin_bswap32 (val) : val;
159 // *member = IsSwapped() ?
160 // ((((uint8_t *) &val)[0] << 24) |
161 // (((uint8_t *) &val)[1] << 16) |
162 // (((uint8_t *) &val)[2] << 8) |
163 // (((uint8_t *) &val)[3])) : val;
164  }
165 
166 
168  uint32_t GetDecoding() const { return Value(&tuDecoding); }
169 
171  inline uint32_t GetSize() const { return Value(&tuSize); }
172 
174  inline uint32_t GetPaddedSize() const
175  {
176  uint32_t hedsize = GetSize();
177  uint32_t rest = hedsize % 8;
178  return (rest==0) ? hedsize : (hedsize + 8 - rest);
179  }
180 
182  void SetSize(uint32_t bytes) { SetValue(&tuSize, bytes); }
183 
185  void SetDecoding(uint32_t decod) { SetValue(&tuDecoding, decod); }
186  };
187 
188  // ======================================================================
189 
193  struct HadTuId : public HadTu {
194  protected:
195  uint32_t tuId;
196 
197  public:
198 
200  HadTuId() {}
202  ~HadTuId() {}
203 
205  inline uint32_t GetId() const { return Value(&tuId); }
206 
208  void SetId(uint32_t id) { SetValue(&tuId, id); }
209 
211  inline bool GetDataError() const { return (GetId() & 0x80000000) != 0; }
212 
214  void SetDataError(bool on)
215  {
216  if(on)
217  SetId(GetId() | 0x80000000);
218  else
219  SetId(GetId() & ~0x80000000);
220  }
221  };
222 
223  // =================================================================================
224 
225  //Description of the Event Structure
226  //
227  //An event consists of an event header and of varying number of subevents, each with a subevent header. The size of the event header is fixed to 0x20 bytes
228  //
229  //Event header
230  //evtHeader
231  //evtSize evtDecoding evtId evtSeqNr evtDate evtTime runNr expId
232  //
233  // * evtSize - total size of the event including the event header, it is measured in bytes.
234  // * evtDecoding - event decoding type: Tells the analysis the binary format of the event data, so that it can be handed to a corresponding routine for unpacking into a software usable data structure. For easier decoding of this word, the meaning of some bits is already predefined:
235  // evtDecoding
236  // msB --- --- lsB
237  // 0 alignment decoding type nonzero
238  // o The first (most significant) byte is always zero.
239  // o The second byte contains the alignment of the subevents in the event. 0 = byte, 1 = 16 bit word, 2 = 32 bit word...
240  // o The remaining two bytes form the actual decoding type, e.g. fixed length, zero suppressed etc.
241  // o The last byte must not be zero, so the whole evtDecoding can be used to check for correct or swapped byte order.
242  //
243  //It is stated again, that the whole evtDecoding is one 32bit word. The above bit assignments are merely a rule how to select this 32bit numbers.
244  //
245  // * evtId - event identifier: Tells the analysis the semantics of the event data, e.g. if this is a run start event, data event, simulated event, slow control data, end file event, etc..
246  // evtId
247  // 31 30 - 16 15 - 12 11 - 8 5 - 7 4 3- 0
248  // error bit reserved version reserved MU decision DS flag ID
249  // o error bit - set if one of the subsystems has set the error bit
250  // o version - 0 meaning of event ID before SEP03; 1 event ID after SEP03
251  // o MU decision - 0 = negative LVL2 decision; >0 positive LVL2 decision
252  // MU trigger algo result
253  // 1 negative decision
254  // 2 positive decision
255  // 3 positive decision due to too many leptons or dileptons
256  // 4 reserved
257  // 5 reserved
258  // o DS flag - LVL1 downscaling flag; 1 = this event is written to the tape independent on the LVL2 trigger decision
259  // o ID - defines the trigger code
260  // ID before SEP03 description
261  // 0 simulation
262  // 1 real
263  // 2,3,4,5,6,7,8,9 calibration
264  // 13 beginrun
265  // 14 endrun
266  //
267  // ID after SEP03 description
268  // 0 simulation
269  // 1,2,3,4,5 real
270  // 7,9 calibration
271  // 1 real1
272  // 2 real2
273  // 3 real3
274  // 4 real4
275  // 5 real5
276  // 6 special1
277  // 7 offspill
278  // 8 special3
279  // 9 MDCcalibration
280  // 10 special5
281  // 13 beginrun
282  // 14 endrun
283  // * evtSeqNr - event number: This is the sequence number of the event in the file. The pair evtFileNr/evtSeqNr
284  //
285  //is unique throughout all events ever acquired by the system.
286  //
287  // * evtDate - date of event assembly (filled by the event builder, rough precision):
288  // evtDate ISO-C date format
289  // msB --- --- lsB
290  // 0 year month day
291  //
292  // 1. The first (most significant) byte is zero
293  // 2. The second byte contains the years since 1900
294  // 3. The third the months since January [0-11]
295  // 4. The last the day of the month [1-31]
296  //
297  // * evtTime - time of assembly (filled by the event builder, rough precision):
298  // evtTime ISO-C time format
299  // msB --- --- lsB
300  // 0 hour minute second
301  //
302  // 1. The first (most significant) byte is zero
303  // 2. The second byte contains the hours since midnight [0-23]
304  // 3. The third the minutes after the hour [0-59]
305  // 4. The last the seconds after the minute [0-60]
306  //
307  // * runNr - file number: A unique number assigned to the file. The runNr is used as key for the RTDB.
308  // * evtPad - padding: Makes the event header a multiple of 64 bits long.
309 
310 
315  struct RawEvent : public HadTuId {
316 
317  protected:
318  uint32_t evtSeqNr;
319  uint32_t evtDate;
320  uint32_t evtTime;
321  uint32_t evtRunNr;
322  uint32_t evtPad;
323 
325  void InitHeader(uint32_t evid);
326 
327 
328  public:
329 
331  RawEvent() {}
334 
336  uint32_t GetSeqNr() const { return Value(&evtSeqNr); }
338  void SetSeqNr(uint32_t n) { SetValue(&evtSeqNr, n); }
339 
341  int32_t GetRunNr() const { return Value(&evtRunNr); }
343  void SetRunNr(uint32_t n) { SetValue(&evtRunNr, n); }
344 
346  int32_t GetDate() const { return Value(&evtDate); }
348  void SetDate(uint32_t d) { SetValue(&evtDate, d); }
349 
351  int32_t GetTime() const { return Value(&evtTime); }
353  void SetTime(uint32_t t) { SetValue(&evtTime, t); }
354 
356  void Init(uint32_t evnt, uint32_t run=0, uint32_t id=EvtId_DABC)
357  {
358  InitHeader(id);
359  SetSeqNr(evnt);
360  SetRunNr(run);
361  evtPad = 0;
362  }
363 
364  void Dump();
365  };
366 
367 /*
368 //Subevent
369 //
370 //Every event contains zero to unspecified many subevents. As an empty event is allowed, data outside of any subevent are not allowed. A subevents consists out of a fixed size subevent header and a varying number of data words.
371 //
372 // * The subevent header
373 // subEvtHeader
374 // subEvtSize subEvtDecoding subEvtId subEvtTrigNr
375 // o subEvtSize - size of the subevent: This includes the the subevent header, it is measured in bytes.
376 // o subEvtDecoding - subevent decoding type: Tells the analysis the binary format of the subevent data, so that it can be handed to a corresponding routine for unpacking into a software usable data structure. For easier decoding of this word, the meaning of some bits is already predefined:
377 // subEvtDecoding
378 // msB --- --- lsB
379 // 0 data type decoding type nonzero
380 // + The first (most significant) byte is always zero
381 // + The second byte contains the word length of the subevent data. 0 = byte, 1 = 16 bit word, 2 = 32 bit word...
382 // + The remaining two bytes form the actual decoding type, e.g. fixed length, zero suppressed etc.
383 // + The last byte must not be zero, so the whole subEvtDecoding can be used to check for correct or swapped byte order. It is stated again, that the whole subEvtDecoding is one 32bit word. The above bit assignments are merely a rule how to select this 32bit numbers.
384 // o subEvtId - subevent identifier: Tells the analysis the semantics of the subevent data, e.g. every subevent builder may get its own subEvtId. So the data structure can be analyzed by the corresponding routine after unpacking.
385 // 1-99 DAQ
386 // 100-199 RICH
387 // 200-299 MDC
388 // 300-399 SHOWER
389 // 400-499 TOF
390 // 500-599 TRIG
391 // 600-699 SLOW
392 // 700-799 TRB_RPC common TRB, but contents is RPC
393 // 800-899 TRB_HOD pion-hodoscope
394 // 900-999 TRB_FW forward wall
395 // 1000-1099 TRB_START start detector
396 // 1100-1199 TRB_TOF TOF detector
397 // 1200-1299 TRB RICH RICH detector
398 //
399 //Additionally, all subEvtIds may have the MSB set. This indicates a sub event of the corresponding id that contains broken data (e.g. parity check failed, sub event was too long etc.).
400 //
401 // *
402 // o subEvtTrigNr - subevent Trigger Number: This is the event tag that is produced by the trigger system and is used for checking the correct assembly of several sub entities. In general, this number is not counting sequentially. The lowest significant byte represents the trigger tag generated by the CTU and has to be same for all detector subsystems in one event. The rest is filled by the EB.
403 // * The data words: The format of the data words (word length, compression algorithm, sub-sub-event format) is defined by the subEvtDecoding and apart from this it is completely free. The meaning of the data words (detector, geographical position, error information) is defined by the subEvtId and apart from this it is completely unknown to the data acquisition system.
404 */
405 
408  struct RawSubevent : public HadTuId {
409 
410  protected:
411 
412  uint32_t subEvtTrigNr;
413 
414  public:
415 
416  RawSubevent() {}
417  ~RawSubevent() {}
418 
420  unsigned Alignment() const { return 1 << ( GetDecoding() >> 16 & 0xff); }
421 
423  uint32_t GetTrigNr() const { return Value(&subEvtTrigNr); }
425  void SetTrigNr(uint32_t trigger) { SetValue(&subEvtTrigNr, trigger); }
426 
428  uint8_t GetTrigTypeTrb3() const { return (GetDecoding() & 0xF0) >> 4; }
429 
431  void Init(uint32_t trigger = 0)
432  {
433  SetTrigNr(trigger);
434  }
435 
437  uint32_t* GetDataPtr(unsigned indx) const
438  {
439  return (uint32_t*) (this) + sizeof(hadaqs::RawSubevent)/sizeof(uint32_t) + indx;
440  }
441 
443  unsigned GetNrOfDataWords() const
444  {
445  unsigned datasize = GetSize() - sizeof(hadaqs::RawSubevent);
446  switch (Alignment()) {
447  case 4: return datasize / sizeof(uint32_t);
448  case 2: return datasize / sizeof(uint16_t);
449  }
450  return datasize / sizeof(uint8_t);
451  }
452 
454  uint32_t Data(unsigned idx) const
455  {
456  const void* my = (char*) (this) + sizeof(hadaqs::RawSubevent);
457 
458  switch (Alignment()) {
459  case 4:
460  return Value((uint32_t *) my + idx);
461 
462  case 2: {
463  uint16_t tmp = ((uint16_t *) my)[idx];
464 
465  if (IsSwapped()) tmp = ((tmp >> 8) & 0xff) | ((tmp << 8) & 0xff00);
466 
467  return tmp;
468  }
469  }
470 
471  return ((uint8_t*) my)[idx];
472  }
473 
475  void SetData(unsigned idx, uint32_t value)
476  {
477  const void* my = (char*) (this) + sizeof(hadaqs::RawSubevent);
478 
479  switch (Alignment()) {
480  case 4:
481  return SetValue((uint32_t *) my + idx, value);
482 
483  case 2: {
484  if (IsSwapped()) value = ((value & 0xff00) >> 8) | ((value & 0xff) << 8);
485 
486  ((uint16_t *) my)[idx] = value & 0xffff;
487  }
488  }
489  }
490 
492  uint32_t GetErrBits()
493  {
494  return Data(GetNrOfDataWords()-1);
495  }
496 
498  void CopyDataTo(void* buf, unsigned indx, unsigned datalen)
499  {
500  if (buf==0) return;
501  while (datalen-- > 0) {
502  *((uint32_t*) buf) = Data(indx++);
503  buf = ((uint32_t*) buf) + 1;
504  }
505  }
506 
508  void* RawData(unsigned ix = 0) const { return (char*) (this) + sizeof(hadaqs::RawSubevent) + ix*4; }
509 
510  void Dump(bool print_raw_data = false);
511  };
512 
513 }
514 
515 #ifndef __CINT__
516 #pragma pack(pop)
517 #endif
518 
519 #endif
Intermediate hierarchy class as common base for event and subevent.
Definition: definess.h:193
bool GetDataError() const
get data error
Definition: definess.h:211
void SetId(uint32_t id)
set id
Definition: definess.h:208
uint32_t GetId() const
get id
Definition: definess.h:205
void SetDataError(bool on)
set data error
Definition: definess.h:214
uint32_t tuId
id
Definition: definess.h:195
HadTuId()
constructor
Definition: definess.h:200
~HadTuId()
destructor
Definition: definess.h:202
HADES transport unit header used as base for event and subevent also common envelope for trd network ...
Definition: definess.h:125
uint32_t tuSize
size
Definition: definess.h:127
void SetValue(uint32_t *member, uint32_t val)
swap-save method to set value stolen from hadtu.h
Definition: definess.h:154
uint32_t tuDecoding
decoding
Definition: definess.h:128
uint32_t GetDecoding() const
get decoding
Definition: definess.h:168
HadTu()
constructor
Definition: definess.h:133
~HadTu()
destructor
Definition: definess.h:135
uint32_t GetSize() const
get size
Definition: definess.h:171
void SetDecoding(uint32_t decod)
set decoding
Definition: definess.h:185
uint32_t GetPaddedSize() const
get padded size
Definition: definess.h:174
void SetSize(uint32_t bytes)
set size
Definition: definess.h:182
uint32_t Value(const uint32_t *member) const
access value
Definition: definess.h:141
bool IsSwapped() const
msb of decode word is always non zero...?
Definition: definess.h:138
HADES raw event.
Definition: definess.h:315
uint32_t evtSeqNr
event sequence number
Definition: definess.h:318
void SetRunNr(uint32_t n)
set run nr
Definition: definess.h:343
void SetDate(uint32_t d)
set date
Definition: definess.h:348
void InitHeader(uint32_t evid)
Method to set initial header value like decoding and date/time.
Definition: definess.cxx:19
int32_t GetTime() const
get time
Definition: definess.h:351
void SetTime(uint32_t t)
set time
Definition: definess.h:353
void Init(uint32_t evnt, uint32_t run=0, uint32_t id=EvtId_DABC)
initialize subevent
Definition: definess.h:356
~RawEvent()
destructor
Definition: definess.h:333
RawEvent()
constructor
Definition: definess.h:331
void Dump()
dump raw event
Definition: definess.cxx:10
uint32_t evtRunNr
event run number
Definition: definess.h:321
int32_t GetRunNr() const
get run nr
Definition: definess.h:341
int32_t GetDate() const
get date
Definition: definess.h:346
uint32_t evtPad
event padding
Definition: definess.h:322
void SetSeqNr(uint32_t n)
set seq nr
Definition: definess.h:338
uint32_t evtTime
event time
Definition: definess.h:320
uint32_t evtDate
event date
Definition: definess.h:319
uint32_t GetSeqNr() const
get seq nr
Definition: definess.h:336
Raw hades subevent.
Definition: definess.h:408
unsigned GetNrOfDataWords() const
returns number of payload data words, not maximum index!
Definition: definess.h:443
uint32_t * GetDataPtr(unsigned indx) const
Return pointer on data by index - user should care itself about swapping.
Definition: definess.h:437
void SetData(unsigned idx, uint32_t value)
set data
Definition: definess.h:475
uint8_t GetTrigTypeTrb3() const
for trb3: each subevent contains trigger type in decoding word
Definition: definess.h:428
void CopyDataTo(void *buf, unsigned indx, unsigned datalen)
copy data to provided buffer
Definition: definess.h:498
void SetTrigNr(uint32_t trigger)
set trigger number
Definition: definess.h:425
uint32_t GetTrigNr() const
get trigger number
Definition: definess.h:423
uint32_t GetErrBits()
get error bits
Definition: definess.h:492
void Init(uint32_t trigger=0)
init header
Definition: definess.h:431
uint32_t Data(unsigned idx) const
swap-save access to any data.
Definition: definess.h:454
unsigned Alignment() const
get alignment
Definition: definess.h:420
uint32_t subEvtTrigNr
subevent trigger number
Definition: definess.h:412
void * RawData(unsigned ix=0) const
Return pointer where raw data should starts.
Definition: definess.h:508
void Dump(bool print_raw_data=false)
dump subevent
Definition: definess.cxx:41