DABC (Data Acquisition Backbone Core)  2.9.9
MbsTypeDefs.cxx
Go to the documentation of this file.
1 // $Id: MbsTypeDefs.cxx 4482 2020-04-15 14:47:18Z 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 "mbs/MbsTypeDefs.h"
17 
18 #include <cstring>
19 #include <cstdio>
20 
21 #if defined(__APPLE__)
22 // Mac OS X / Darwin features
23 #include <libkern/OSByteOrder.h>
24 #define bswap_16(x) OSSwapInt16(x)
25 #define bswap_32(x) OSSwapInt32(x)
26 #define bswap_64(x) OSSwapInt64(x)
27 #else
28 #include <byteswap.h>
29 #endif
30 
31 const char* mbs::protocolLmd = "lmd";
32 const char* mbs::protocolMbs = "mbs";
33 const char* mbs::protocolMbss = "mbss";
34 const char* mbs::protocolMbst = "mbst";
35 
36 // Command names used in combiner module:
37 const char* mbs::comStartServer = "StartServer";
38 const char* mbs::comStopServer = "StopServer";
39 const char* mbs::comStartFile = "StartFile";
40 const char* mbs::comStopFile = "StopFile";
41 
42 // tag names for xml config file:
43 const char* mbs::xmlServerName = "MbsServerName";
44 const char* mbs::xmlServerKind = "MbsServerKind";
45 const char* mbs::xmlServerPort = "MbsServerPort";
46 const char* mbs::xmlServerScale = "MbsServerScale";
47 const char* mbs::xmlServerLimit = "MbsServerLimit";
48 
49 const char* mbs::xmlTextDataFormat = "MbsTextFormat";
50 const char* mbs::xmlTextNumData = "MbsTextNumData";
51 const char* mbs::xmlTextHeaderLines = "MbsTextHeader";
52 const char* mbs::xmlTextCharBuffer = "MbsCharBuffer";
53 
54 
55 const char* mbs::xmlCombineCompleteOnly = "BuildCompleteEvents";
56 const char* mbs::xmlCheckSubeventIds = "CheckSubIds";
57 const char* mbs::xmlEvidMask = "EventIdMask";
58 const char* mbs::xmlEvidTolerance = "MaxDeltaEventId";
59 const char* mbs::xmlSpecialTriggerLimit = "SpecialTriggerLimit";
60 const char* mbs::xmlCombinerRatesPrefix = "CombinerRatesPrefix";
61 
62 
64 {
65  printf(" SubEv ID %6u Type %2u/%1u Length %5u[w] Control %2u Subcrate %2u\n",
66  (unsigned) ProcId(), (unsigned) Type(), (unsigned) SubType(), (unsigned) FullSize()/2, (unsigned) Control(), (unsigned) Subcrate());
67 }
68 
69 void mbs::SubeventHeader::PrintData(bool ashex, bool aslong)
70 {
71  if (aslong) {
72  uint32_t* pl_data = (uint32_t*) RawData();
73  uint32_t ll = RawDataSize() / 4;
74 
75  for(uint32_t l=0; l<ll; l++) {
76  if(l%8 == 0) printf(" ");
77  if (ashex)
78  printf("%04x.%04x ",(unsigned) ((*pl_data>>16) & 0xffff), (unsigned) (*pl_data & 0xffff));
79  else
80  printf("%8u ", (unsigned) *pl_data);
81  pl_data++;
82  if(l%8 == 7) printf("\n");
83  }
84 
85  if (ll%8 != 0) printf("\n");
86 
87  } else {
88  uint16_t* pl_data = (uint16_t*) RawData();
89  uint32_t ll = RawDataSize() / 2;
90 
91  for(uint32_t l=0; l<ll; l++) {
92  if(l%8 == 0) printf(" ");
93  printf("%8u ", (unsigned) *pl_data);
94  pl_data++;
95  if(l%8 == 7) printf("\n");
96  }
97 
98  if (ll%8 != 0) printf("\n");
99  }
100 }
101 
103 {
104  unsigned cnt = 0;
105  SubeventHeader* sub = 0;
106  while ((sub = NextSubEvent(sub)) != 0) cnt++;
107  return cnt;
108 }
109 
111 {
112  if (Type()==10) {
113  printf("Event %9u Type %2u/%1u Length %5u[w] Trigger %2u\n",
114  (unsigned) EventNumber(), (unsigned) Type(), (unsigned) SubType(), (unsigned) FullSize()/2, (unsigned) TriggerNumber());
115  } else {
116  printf("Event type %u, subtype %u, data longwords %u",
117  (unsigned) Type(), (unsigned) SubType(), (unsigned) FullSize()/2);
118  }
119 }
120 
121 
122 void mbs::BufferHeader::Init(bool newformat)
123 {
124  iWords = 0;
125  iType = newformat ? MBS_TYPE(100,1) : MBS_TYPE(10,1);
126  iBufferId = 0;
127  iNumEvents = 0;
128  iTemp = 0;
129  iSeconds = 0;
130  iNanosec = 0;
131  iEndian = 0;
132  iLast = 0;
133  iUsedWords = 0;
134  iFree3 = 0;
135  SetEndian();
136 }
137 
139 {
140  switch (iType) {
141  // new buffer type
142  case MBS_TYPE(100,1): return sizeof(BufferHeader) + iUsedWords * 2;
143 
144  // old buffer type
145  case MBS_TYPE(10,1): return sizeof(BufferHeader) + iWords * 2;
146  }
147 
148  return 0;
149 
150 }
151 
153 {
154  switch (iType) {
155  // new buffer type
156  case MBS_TYPE(100,1): return iUsedWords * 2;
157 
158  // old buffer type
159  case MBS_TYPE(10,1): return i_used * 2;
160 
161  default: break;
162  // EOUT("Uncknown buffer type %d-%d", i_type, i_subtype);
163  }
164 
165  return 0;
166 }
167 
169 {
170  switch (iType) {
171  // new buffer type
172  case MBS_TYPE(100,1):
173  iUsedWords = len / 2;
174  if (iWords==0) SetFullSize(len + sizeof(BufferHeader));
175 
176  break;
177 
178  // old buffer type
179  case MBS_TYPE(10,1):
180  i_used = len / 2;
181  if (iWords==0) SetFullSize(len + sizeof(BufferHeader));
182  break;
183 
184  default:
185  // EOUT("Uncknown buffer type %d-%d", i_type, i_subtype);
186  break;
187  }
188 }
189 
190 void mbs::SwapData(void* data, unsigned bytessize)
191 {
192  if (data==0) return;
193  unsigned cnt = bytessize / 4;
194  uint32_t* d = (uint32_t*) data;
195 
196  while (cnt-- != 0) {
197  *d = bswap_32(*d);
198  d++;
199  }
200 }
201 
202 const char* mbs::ServerKindToStr(int kind)
203 {
204  switch (kind) {
205  case TransportServer: return "Transport";
206  case StreamServer: return "Stream";
207  case OldTransportServer: return "OldTransport";
208  case OldStreamServer: return "OldStream";
209  }
210  return "NoServer";
211 }
212 
214 {
215  switch (kind) {
216  case TransportServer: return 6000;
217  case StreamServer: return 6002;
218  case OldTransportServer: return 6000;
219  case OldStreamServer: return 6002;
220  }
221  return 0;
222 }
223 
224 int mbs::StrToServerKind(const std::string &str)
225 {
226  if (str.empty()) return NoServer;
227  if (str == "Transport") return TransportServer;
228  if (str == "Stream") return StreamServer;
229  if (str == "OldTransport") return OldTransportServer;
230  if (str == "OldStream") return OldStreamServer;
231  return NoServer;
232 }
233 
234 
#define MBS_TYPE(typ, subtyp)
Definition: LmdTypeDefs.h:30
const char * comStartServer
Definition: MbsTypeDefs.cxx:37
const char * protocolMbst
Definition: MbsTypeDefs.cxx:34
void SwapData(void *data, unsigned bytessize)
const char * comStartFile
Definition: MbsTypeDefs.cxx:39
const char * xmlCombineCompleteOnly
Definition: MbsTypeDefs.cxx:55
const char * comStopFile
Definition: MbsTypeDefs.cxx:40
const char * xmlServerLimit
Definition: MbsTypeDefs.cxx:47
@ NoServer
Definition: MbsTypeDefs.h:353
@ StreamServer
Definition: MbsTypeDefs.h:355
@ TransportServer
Definition: MbsTypeDefs.h:354
@ OldTransportServer
Definition: MbsTypeDefs.h:356
@ OldStreamServer
Definition: MbsTypeDefs.h:357
const char * xmlSpecialTriggerLimit
Definition: MbsTypeDefs.cxx:59
const char * protocolMbss
Definition: MbsTypeDefs.cxx:33
const char * protocolMbs
Definition: MbsTypeDefs.cxx:32
int DefualtServerPort(int kind)
const char * xmlTextCharBuffer
Definition: MbsTypeDefs.cxx:52
const char * xmlEvidMask
Definition: MbsTypeDefs.cxx:57
int StrToServerKind(const std::string &str)
const char * comStopServer
Definition: MbsTypeDefs.cxx:38
const char * xmlServerScale
Definition: MbsTypeDefs.cxx:46
const char * xmlCheckSubeventIds
Definition: MbsTypeDefs.cxx:56
const char * xmlCombinerRatesPrefix
Definition: MbsTypeDefs.cxx:60
const char * xmlTextNumData
Definition: MbsTypeDefs.cxx:50
const char * xmlServerKind
Definition: MbsTypeDefs.cxx:44
const char * xmlEvidTolerance
Definition: MbsTypeDefs.cxx:58
const char * xmlServerPort
Definition: MbsTypeDefs.cxx:45
const char * ServerKindToStr(int kind)
const char * xmlTextHeaderLines
Definition: MbsTypeDefs.cxx:51
const char * protocolLmd
Definition: MbsTypeDefs.cxx:31
const char * xmlTextDataFormat
Definition: MbsTypeDefs.cxx:49
const char * xmlServerName
Definition: MbsTypeDefs.cxx:43
MBS buffer header.
Definition: MbsTypeDefs.h:152
void Init(bool newformat)
uint32_t UsedBufferSize() const
uint32_t BufferLength() const
void SetUsedBufferSize(uint32_t len)
unsigned NumSubevents() const
uint32_t FullSize() const
Definition: LmdTypeDefs.h:55
uint16_t SubType() const
Definition: LmdTypeDefs.h:60
uint16_t Type() const
Definition: LmdTypeDefs.h:59
MBS subevent
Definition: MbsTypeDefs.h:40
int16_t ProcId() const
Definition: MbsTypeDefs.h:81
void PrintData(bool ashex=true, bool aslong=true)
Prints sub-event data in hex/decimal and long/short form.
Definition: MbsTypeDefs.cxx:69
void PrintHeader()
Prints sub-event header.
Definition: MbsTypeDefs.cxx:63
int8_t Control() const
Definition: MbsTypeDefs.h:82
int8_t Subcrate() const
Definition: MbsTypeDefs.h:83