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