DABC (Data Acquisition Backbone Core)  2.9.9
defines.cxx
Go to the documentation of this file.
1 // $Id: defines.cxx 4480 2020-04-15 14:40:06Z linev $
2 
3 /************************************************************
4  * The Data Acquisition Backbone Core (DABC) *
5  ************************************************************
6  * Copyright (C) 2009 - *
7  * GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
8  * Planckstr. 1, 64291 Darmstadt, Germany *
9  * Contact: http://dabc.gsi.de *
10  ************************************************************
11  * This software can be used under the GPL license *
12  * agreements as stated in LICENSE.txt file *
13  * which is part of the distribution. *
14  ************************************************************/
15 
16 #include "hadaq/defines.h"
17 
18 #include <cstdio>
19 #include <sys/time.h>
20 #include <ctime>
21 
23 {
24  char sbuf[50];
25  if (GetSize()!=GetPaddedSize())
26  snprintf(sbuf,sizeof(sbuf), "%u+%u", (unsigned) GetSize(), (unsigned) (GetPaddedSize() - GetSize()));
27  else
28  snprintf(sbuf,sizeof(sbuf),"%u", (unsigned) GetSize());
29 
30  printf("*** Event #0x%06x fullid=0x%04x runid=0x%08x typ %x size %s *** \n",
31  (unsigned) GetSeqNr(), (unsigned) GetId(), (unsigned) GetRunNr(), (unsigned) (GetId() & 0xf), sbuf);
32 }
33 
34 void hadaq::RawEvent::InitHeader(uint32_t id)
35 {
36  tuDecoding = EvtDecoding_64bitAligned;
37  SetId(id);
38  SetSize(sizeof(hadaq::RawEvent));
39  // timestamp at creation of structure:
40  time_t tempo = time(NULL);
41  struct tm* gmTime = gmtime(&tempo);
42  uint32_t date = 0, clock = 0;
43  date |= gmTime->tm_year << 16;
44  date |= gmTime->tm_mon << 8;
45  date |= gmTime->tm_mday;
46  SetDate(date);
47  clock |= gmTime->tm_hour << 16;
48  clock |= gmTime->tm_min << 8;
49  clock |= gmTime->tm_sec;
50  SetTime(clock);
51 }
52 
54 {
55  if (GetSize() - sizeof(hadaq::RawEvent) < sizeof(hadaq::RawSubevent)) return 0;
56 
57  return (hadaq::RawSubevent*) ((char*) this + sizeof(hadaq::RawEvent));
58 }
59 
61 {
62  if (GetPaddedSize() < sizeof(hadaq::RawEvent)) return 0;
63  return GetPaddedSize() - sizeof(hadaq::RawEvent);
64 }
65 
67 {
68  if (prev == 0) return FirstSubevent();
69 
70  char* next = (char*) prev + prev->GetPaddedSize();
71 
72  if (next >= (char*) this + GetSize()) return 0;
73 
74  return (hadaq::RawSubevent*) next;
75 }
76 
77 // ===========================================================
78 
79 void hadaq::RawSubevent::PrintRawData(unsigned ix, unsigned len, unsigned prefix)
80 {
81  unsigned sz = ((GetSize() - sizeof(RawSubevent)) / Alignment());
82 
83  if ((ix>=sz) || (len==0)) return;
84  if (ix + len > sz) len = sz - ix;
85 
86  unsigned wlen = 2;
87  if (sz>99) wlen = 3; else
88  if (sz>999) wlen = 4;
89 
90  for (unsigned cnt=0;cnt<len;cnt++,ix++)
91  printf("%*s[%*u] %08x%s", (cnt%8 ? 2 : prefix), "", wlen, ix, (unsigned) Data(ix), (cnt % 8 == 7 ? "\n" : ""));
92 
93  if (len % 8 != 0) printf("\n");
94 }
95 
96 
97 void hadaq::RawSubevent::Dump(bool print_raw_data)
98 {
99  char sbuf[50];
100  if (GetSize()!=GetPaddedSize())
101  snprintf(sbuf,sizeof(sbuf), "%4u+%u", (unsigned) GetSize(), (unsigned) (GetPaddedSize() - GetSize()));
102  else
103  snprintf(sbuf,sizeof(sbuf),"%6u", (unsigned) GetSize());
104  printf(" *** Subevent size %s decoding 0x%06x id 0x%04x trig 0x%08x typ %x %s align %u ***\n",
105  sbuf,
106  (unsigned) GetDecoding(),
107  (unsigned) GetId(),
108  (unsigned) GetTrigNr(),
109  (unsigned) GetTrigTypeTrb3(),
110  IsSwapped() ? "swapped" : "not swapped",
111  (unsigned) Alignment());
112 
113  if (print_raw_data) PrintRawData();
114 }
@ EvtDecoding_64bitAligned
Definition: defines.h:128
uint32_t GetId() const
Definition: defines.h:208
uint32_t GetSize() const
Definition: defines.h:182
uint32_t GetPaddedSize() const
Definition: defines.h:184
Hadaq event structure.
Definition: defines.h:443
RawSubevent * NextSubevent(RawSubevent *prev=0)
Definition: defines.cxx:66
RawSubevent * FirstSubevent()
Definition: defines.cxx:53
void InitHeader(uint32_t evid)
Method to set initial header value like decoding and date/time.
Definition: defines.cxx:34
int32_t GetRunNr() const
Definition: defines.h:463
uint32_t GetSeqNr() const
Definition: defines.h:460
uint32_t AllSubeventsSize()
Definition: defines.cxx:60
Hadaq subevent structure.
Definition: defines.h:262
void Dump(bool print_raw_data=false)
Print subevent header and optionally raw data.
Definition: defines.cxx:97
void PrintRawData(unsigned ix=0, unsigned len=0xffffffff, unsigned prefix=6)
Print raw data, optionally one can position and portion to print.
Definition: defines.cxx:79