CbmRoot
CbmTofStarData2019.cxx
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 // ----- -----
3 // ----- CbmTofStarData2019 -----
4 // ----- Created 13.01.2017 by P.-A. Loizeau -----
5 // ----- -----
6 // -----------------------------------------------------------------------------
7 
8 #include "CbmTofStarData2019.h"
9 
10 #include <algorithm>
11 
12 #include <iomanip>
13 #include <iostream>
14 
15 /********************** CbmTofStarTrigger2019 *************************/
17  ULong64_t ulStarTsFullIn,
18  UInt_t uStarTokenIn,
19  UInt_t uStarDaqCmdIn,
20  UInt_t uStarTrigCmdIn,
21  UShort_t usGdpbId)
22  : fusGdpbId(usGdpbId)
23  , fulGdpbTsFull(ulGdpbTsFullIn)
24  , fulStarTsFull(ulStarTsFullIn)
25  , fuStarToken(uStarTokenIn)
26  , fusStarDaqCmd(uStarDaqCmdIn)
27  , fusStarTrigCmd(uStarTrigCmdIn) {}
30  const CbmTofStarTrigger2019& other) const {
31  ULong64_t uThisTs = this->GetFullGdpbTs();
32  ULong64_t uOtherTs = other.GetFullGdpbTs();
33 
34  return uThisTs < uOtherTs;
35 }
37  // trg_cmd|daq_cmd|tkn_hi|tkn_mid|tkn_lo
38  UInt_t uTrigWord = ((fusStarTrigCmd & 0x00F) << 16)
39  + ((fusStarDaqCmd & 0x00F) << 12)
40  + ((fuStarToken & 0xFFF));
41  return uTrigWord;
42 }
44  // trg_cmd|daq_cmd|tkn_hi|tkn_mid|tkn_lo
45  UInt_t uEpochIndex =
47  return uEpochIndex;
48 }
49 std::vector<gdpbv100::FullMessage>
51  gdpbv100::FullMessage mCommonData(
52  (static_cast<ULong64_t>(fusGdpbId) << 48) // GdpbId
53  + gdpbv100::MSG_STAR_TRI_A, // Message type
54  (GetFullGdpbTs() >> gdpbv100::kuCtSize) // gDPB TS in epochs
55  );
56  std::vector<gdpbv100::FullMessage> vMsgs(4, mCommonData);
57 
59  vMsgs[0].setStarTrigMsgIndex(0); // Message Subtype
60  vMsgs[0].setGdpbTsMsbStarA(
61  GetFullGdpbTs()); // 40b MSB of GDPB TS b[ 24, 63 ]
63  vMsgs[1].setStarTrigMsgIndex(1); // Message Subtype
64  vMsgs[1].setGdpbTsLsbStarB(
65  GetFullGdpbTs()); // 24b LSB of GDPB TS b[ 0, 23 ]
66  vMsgs[1].setStarTsMsbStarB(
67  GetFullStarTs()); // 16b MSB of STAR TS b[ 48, 63 ]
69  vMsgs[2].setStarTrigMsgIndex(2); // Message Subtype
70  vMsgs[2].setStarTsMidStarC(
71  GetFullStarTs()); // 40b mid bits of STAR TS b[ 8, 47 ]
73  vMsgs[3].setStarTrigMsgIndex(3); // Message Subtype
74  vMsgs[3].setStarTsLsbStarD(GetFullStarTs()); // 8b LSB of STAR TS b[ 0, 7]
75  vMsgs[3].setStarFillerD(); // 12 bits in between are set to 0
76  vMsgs[3].setStarTokenStarD(GetStarToken()); // 12b STAR Token
77  vMsgs[3].setStarDaqCmdStarD(GetStarDaqCmd()); // 4b STAR DAQ CMD
78  vMsgs[3].setStarTrigCmdStarD(GetStarTrigCmd()); // 4b STAR TRIG CMD
79 
80  return vMsgs;
81 }
82 //ClassImp(CbmTofStarTrigger2019)
83 /**********************************************************************/
84 /********************** CbmTofStarSubevent2019 ************************/
86  : fbTriggerSet(kFALSE)
87  , fTrigger(CbmTofStarTrigger2019(0, 0, 0, 0, 0))
88  , fusSourceId(0)
89  , fulEventStatusFlags(0)
90  , fuEventSizeBytes(4 * sizeof(ULong64_t))
91  , fvMsgBuffer() {}
93  UShort_t sourceIdIn)
94  : fbTriggerSet(kTRUE)
95  , fTrigger(triggerIn)
96  , fusSourceId(sourceIdIn)
97  , fulEventStatusFlags(0)
98  , fuEventSizeBytes(4 * sizeof(ULong64_t))
99  , fvMsgBuffer() {
100  SetSource(sourceIdIn);
101 }
103  const CbmTofStarSubevent2019& eventIn)
104  : fbTriggerSet(eventIn.fbTriggerSet)
105  , fTrigger(eventIn.fTrigger)
106  , fusSourceId(eventIn.fusSourceId)
107  , fulEventStatusFlags(eventIn.fulEventStatusFlags)
108  , fuEventSizeBytes(eventIn.fuEventSizeBytes)
109  , fvMsgBuffer(eventIn.fvMsgBuffer) {
111 }
114  fbTriggerSet = eventIn.fbTriggerSet;
115  fTrigger = eventIn.fTrigger;
116  fusSourceId = eventIn.fusSourceId;
119  fvMsgBuffer = eventIn.fvMsgBuffer;
121 
122  return *this;
123 }
124 
127  fbTriggerSet = kFALSE;
129  fvMsgBuffer.clear();
130 }
132  std::sort(fvMsgBuffer.begin(), fvMsgBuffer.end());
133 }
134 void* CbmTofStarSubevent2019::BuildOutput(Int_t& iOutputSizeBytes) {
135  // If trigger not set, something is wrong, we just pass
136  if (kFALSE == fbTriggerSet) {
137  iOutputSizeBytes = 0;
138  return NULL;
139  } // if( kFALSE == fbTriggerSet )
140 
141  iOutputSizeBytes = 0;
142 
143  // Size of output is
144  // 3 * Long64 for Header Star Token Info
145  // 1 * Long64 for Header Event Status Flags (version, bad/good, ...) & source ID
146  // 2 * n * Long64 for the n messages in Buffer: 1 extended Epoch + message data
147  iOutputSizeBytes = 4 + 2 * fvMsgBuffer.size();
148  iOutputSizeBytes *= sizeof(ULong64_t);
149  UInt_t uMsgsToRead = fvMsgBuffer.size();
150 
151  // Check if max size passed
152  // If it is the case, limit the number of data read + set Bad Event flag
153  if (kuMaxOutputSize < static_cast<uint32_t>(iOutputSizeBytes)) {
154  iOutputSizeBytes = kuMaxOutputSize;
155  uMsgsToRead = kuMaxNbMsgs;
157  } // if( kuMaxOutputSize < iOutputSizeBytes )
158 
160  fuEventSizeBytes = iOutputSizeBytes & kulEventSizeMask;
163  | (static_cast<ULong64_t>(fuEventSizeBytes) << kulEventSizeOffset);
164 
165  // Fills header info
168  fpulBuff[2] = (static_cast<ULong64_t>(fTrigger.GetStarToken()) << 32)
169  + (static_cast<ULong64_t>(fTrigger.GetStarDaqCmd()) << 16)
170  + (static_cast<ULong64_t>(fTrigger.GetStarTrigCmd()));
172 
173  // does not work due to "error: cannot convert ‘gdpbv100::Message’ to ‘long unsigned int’ in assignment"
174  // std::copy( fvMsgBuffer.begin(), fvMsgBuffer.begin() + uMsgsToRead, pulBuff + 4 );
175 
176  // Unoptimized replacement: item by item copy
177  for (UInt_t uMsgIdx = 0; uMsgIdx < uMsgsToRead; uMsgIdx++) {
178  fpulBuff[4 + 2 * uMsgIdx] = fvMsgBuffer[uMsgIdx].getData();
179  fpulBuff[4 + 2 * uMsgIdx + 1] = fvMsgBuffer[uMsgIdx].getExtendedEpoch();
180  } // for( UInt_t uMsgIdx = 0; uMsgIdx < uMsgsToRead; uMsgIdx++)
181 
182  return static_cast<void*>(fpulBuff);
183 }
184 Bool_t CbmTofStarSubevent2019::LoadInput(void* pBuff, Int_t iInputSizeBytes) {
185  // Check input variables are properly defined
186  if (NULL == pBuff || 0 == iInputSizeBytes) return kFALSE;
187 
188  Int_t iRestBytes = iInputSizeBytes % sizeof(ULong64_t);
189  Int_t iInputSzLg = iInputSizeBytes / sizeof(ULong64_t);
190 
191 
192  // Check event header is complete and buffer is multiple of 64b
193  if (iInputSzLg < 4 || 0 < iRestBytes) return kFALSE;
194 
195  // First clear subEvent content
196  ClearSubEvent();
197 
198  // Read the header to the SubEvent members
199  ULong64_t* pulLongBuff = static_cast<ULong64_t*>(pBuff);
200  ULong64_t ulTrgGdpbFullTs = pulLongBuff[0];
201  ULong64_t ulTrgStarFullTs = pulLongBuff[1];
202  UInt_t uStarToken = (pulLongBuff[2] >> 32) & 0xFFF;
203  UInt_t uStarDaqCmdIn = (pulLongBuff[2] >> 16) & 0x00F;
204  UInt_t uStarTrigCmdIn = (pulLongBuff[2]) & 0x00F;
205  fulEventStatusFlags = pulLongBuff[3];
206 
208 
211 
212  fTrigger.SetFullGdpbTs(ulTrgGdpbFullTs);
213  fTrigger.SetFullStarTs(ulTrgStarFullTs);
214  fTrigger.SetStarToken(uStarToken);
215  fTrigger.SetStarDaqCmd(uStarDaqCmdIn);
216  fTrigger.SetStarTRigCmd(uStarTrigCmdIn);
217 
218  // Read as many messages as left in the buffer and store them in the vector
219  UInt_t uMsgsToRead = (iInputSzLg - 4) / 2;
220  for (UInt_t uMsgIdx = 0; uMsgIdx < uMsgsToRead; uMsgIdx++) {
221  gdpbv100::FullMessage mess(pulLongBuff[4 + 2 * uMsgIdx],
222  pulLongBuff[4 + 2 * uMsgIdx + 1]);
223  fvMsgBuffer.push_back(mess);
224  } // for( UInt_t uMsgIdx = 0; uMsgIdx < uMsgsToRead; uMsgIdx++)
225 
226  return kTRUE;
227 }
229  std::cout << "-------------------------------------------------------"
230  << std::endl;
231  std::cout << "Printing CbmTofStarSubevent2019 dump" << std::endl;
232  // Print the header
233  std::cout << "Trigger info: gDPB TS = " << fTrigger.GetFullGdpbTs()
234  << " STAR TS = " << fTrigger.GetFullStarTs()
235  << " Token = " << fTrigger.GetStarToken()
236  << " DAQ CMD = " << fTrigger.GetStarDaqCmd()
237  << " TRIG CMD = " << fTrigger.GetStarTrigCmd() << std::endl;
238  std::cout << "Status flags = " << std::hex << std::setw(16)
239  << fulEventStatusFlags << std::dec << std::endl;
240 
241  // Print the messages in the buffer
242 
243  for (UInt_t uMsgIdx = 0; uMsgIdx < fvMsgBuffer.size(); uMsgIdx++) {
244  fvMsgBuffer[uMsgIdx].PrintMessage(gdpbv100::msg_print_Prefix
246  } // for( UInt_t uMsgIdx = 0; uMsgIdx < uMsgsToRead; uMsgIdx++)
247 
248  std::cout << "-------------------------------------------------------"
249  << std::endl;
250 }
251 //ClassImp(CbmTofStarSubevent2019)
252 /**********************************************************************/
gdpbv100::MSG_STAR_TRI_A
@ MSG_STAR_TRI_A
Definition: gDpbMessv100.h:63
CbmTofStarTrigger2019::fusStarTrigCmd
UShort_t fusStarTrigCmd
Definition: CbmTofStarData2019.h:64
CbmTofStarSubevent2019::fuEventSizeBytes
UInt_t fuEventSizeBytes
Definition: CbmTofStarData2019.h:192
CbmTofStarSubevent2019::fvMsgBuffer
std::vector< gdpbv100::FullMessage > fvMsgBuffer
Definition: CbmTofStarData2019.h:193
CbmTofStarSubevent2019::kulEventSizeOffset
static const uint64_t kulEventSizeOffset
Definition: CbmTofStarData2019.h:185
CbmTofStarTrigger2019::operator<
bool operator<(const CbmTofStarTrigger2019 &other) const
strict weak ordering operator, assumes same TS cycle for both triggers
Definition: CbmTofStarData2019.cxx:29
CbmTofStarSubevent2019::operator=
CbmTofStarSubevent2019 operator=(const CbmTofStarSubevent2019 &)
Definition: CbmTofStarData2019.cxx:113
CbmTofStarSubevent2019::fusSourceId
UShort_t fusSourceId
Definition: CbmTofStarData2019.h:190
CbmTofStarTrigger2019::SetFullGdpbTs
void SetFullGdpbTs(ULong64_t ulGdpbTsFullIn)
Definition: CbmTofStarData2019.h:31
CbmTofStarSubevent2019::fulEventStatusFlags
ULong64_t fulEventStatusFlags
Definition: CbmTofStarData2019.h:191
CbmTofStarTrigger2019::GetStarTrigCmd
UShort_t GetStarTrigCmd() const
Definition: CbmTofStarData2019.h:50
CbmTofStarData2019.h
CbmTofStarTrigger2019::GetStarTrigerWord
UInt_t GetStarTrigerWord() const
Definition: CbmTofStarData2019.cxx:36
CbmTofStarSubevent2019::SortMessages
void SortMessages()
Definition: CbmTofStarData2019.cxx:131
CbmTofStarTrigger2019::GetGdpbMessages
std::vector< gdpbv100::FullMessage > GetGdpbMessages() const
Definition: CbmTofStarData2019.cxx:50
gdpbv100::kuEpochCounterSz
const uint32_t kuEpochCounterSz
Definition: gDpbMessv100.h:40
gdpbv100::msg_print_Data
@ msg_print_Data
Definition: gDpbMessv100.h:89
CbmTofStarTrigger2019::fusStarDaqCmd
UShort_t fusStarDaqCmd
Definition: CbmTofStarData2019.h:63
CbmTofStarTrigger2019::CbmTofStarTrigger2019
CbmTofStarTrigger2019(ULong64_t ulGdpbTsFullIn, ULong64_t ulStarTsFullIn, UInt_t uStarTokenIn, UInt_t uStarDaqCmdIn, UInt_t uStarTrigCmdIn, UShort_t usGdpbId=0)
Definition: CbmTofStarData2019.cxx:16
CbmTofStarSubevent2019::kulSourceIdMask
static const uint64_t kulSourceIdMask
Definition: CbmTofStarData2019.h:184
CbmTofStarTrigger2019::fulGdpbTsFull
ULong64_t fulGdpbTsFull
Definition: CbmTofStarData2019.h:60
CbmTofStarSubevent2019::kuMaxOutputSize
static const uint32_t kuMaxOutputSize
Definition: CbmTofStarData2019.h:169
CbmTofStarTrigger2019::GetStarDaqCmd
UShort_t GetStarDaqCmd() const
Definition: CbmTofStarData2019.h:49
CbmTofStarTrigger2019::GetFullGdpbEpoch
UInt_t GetFullGdpbEpoch() const
Definition: CbmTofStarData2019.cxx:43
CbmTofStarSubevent2019::fpulBuff
ULong64_t fpulBuff[kuMaxOutputSize]
Definition: CbmTofStarData2019.h:194
CbmTofStarSubevent2019::PrintSubEvent
void PrintSubEvent()
Definition: CbmTofStarData2019.cxx:228
CbmTofStarSubevent2019::kulEventSizeMask
static const uint64_t kulEventSizeMask
Definition: CbmTofStarData2019.h:186
gdpbv100::msg_print_Prefix
@ msg_print_Prefix
Definition: gDpbMessv100.h:88
CbmTofStarSubevent2019::LoadInput
Bool_t LoadInput(void *pBuff, Int_t iInputSizeBytes)
Definition: CbmTofStarData2019.cxx:184
CbmTofStarTrigger2019::GetFullStarTs
ULong64_t GetFullStarTs() const
Definition: CbmTofStarData2019.h:47
CbmTofStarTrigger2019::GetStarToken
UInt_t GetStarToken() const
Definition: CbmTofStarData2019.h:48
CbmTofStarTrigger2019::fuStarToken
UInt_t fuStarToken
Definition: CbmTofStarData2019.h:62
CbmTofStarSubevent2019::SetSource
void SetSource(UShort_t sourceIdIn)
Definition: CbmTofStarData2019.h:89
CbmTofStarSubevent2019::BuildOutput
void * BuildOutput(Int_t &iOutputSizeBytes)
Definition: CbmTofStarData2019.cxx:134
CbmTofStarSubevent2019::fbTriggerSet
Bool_t fbTriggerSet
Definition: CbmTofStarData2019.h:188
CbmTofStarTrigger2019
Definition: CbmTofStarData2019.h:17
CbmTofStarTrigger2019::fusGdpbId
UShort_t fusGdpbId
Definition: CbmTofStarData2019.h:59
CbmTofStarTrigger2019::SetStarTRigCmd
void SetStarTRigCmd(UInt_t uStarTrigCmdIn)
Definition: CbmTofStarData2019.h:41
CbmTofStarSubevent2019::fTrigger
CbmTofStarTrigger2019 fTrigger
Definition: CbmTofStarData2019.h:189
CbmTofStarSubevent2019::kulSourceIdOffset
static const uint64_t kulSourceIdOffset
Incomplete event: at least one gDPB missed the trigger signal.
Definition: CbmTofStarData2019.h:183
gdpbv100::kuCtSize
const uint32_t kuCtSize
Definition: gDpbMessv100.h:18
CbmTofStarSubevent2019::kulFlagBadEvt
static const uint64_t kulFlagBadEvt
Definition: CbmTofStarData2019.h:172
gdpbv100::FullMessage
Definition: gDpbMessv100.h:362
CbmTofStarSubevent2019
Definition: CbmTofStarData2019.h:72
CbmTofStarSubevent2019::ClearSubEvent
void ClearSubEvent()
Definition: CbmTofStarData2019.cxx:126
CbmTofStarSubevent2019::CbmTofStarSubevent2019
CbmTofStarSubevent2019()
Definition: CbmTofStarData2019.cxx:85
CbmTofStarSubevent2019::kuMaxNbMsgs
static const uint32_t kuMaxNbMsgs
Definition: CbmTofStarData2019.h:170
CbmTofStarTrigger2019::GetFullGdpbTs
ULong64_t GetFullGdpbTs() const
Definition: CbmTofStarData2019.h:46
CbmTofStarTrigger2019::SetStarToken
void SetStarToken(UInt_t uStarTokenIn)
Definition: CbmTofStarData2019.h:37
CbmTofStarTrigger2019::SetStarDaqCmd
void SetStarDaqCmd(UInt_t uStarDaqCmdIn)
Definition: CbmTofStarData2019.h:38
CbmTofStarSubevent2019::~CbmTofStarSubevent2019
~CbmTofStarSubevent2019()
Definition: CbmTofStarData2019.cxx:125
CbmTofStarTrigger2019::SetFullStarTs
void SetFullStarTs(ULong64_t ulStarTsFullIn)
Definition: CbmTofStarData2019.h:34