CbmRoot
Loading...
Searching...
No Matches
CbmCriGet4RawPrint.cxx
Go to the documentation of this file.
1/* Copyright (C) 2021 Facility for Antiproton and Ion Research in Europe, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pierre-Alain Loizeau [committer] */
4
6
8
9#include "FairParGenericSet.h"
10#include "FairRootManager.h"
11#include "FairRun.h"
12#include "FairRunOnline.h"
13#include "FairRuntimeDb.h"
14#include <Logger.h>
15
16#include <iomanip>
17
20 , fvMsComponentsList()
21 , fuNbCoreMsPerTs(0)
22 , fuNbOverMsPerTs(0)
23 , fuNbMsLoop(0)
24 , fbIgnoreOverlapMs(kFALSE)
25 , fdMsSizeInNs(-1.0)
26 , fdTsCoreSizeInNs(-1.0)
27 , fulCurrentTsIdx(0)
28 , fulCurrentMsIdx(0)
29 , fdTsStartTime(0.0)
30 , fdTsStopTimeCore(0.0)
31 , fdMsTime(0.0)
32 , fuMsIndex(0)
33 , fuCurrentEquipmentId(0)
34{
35}
36
38
40{
41 LOG(info) << "CbmCriGet4RawPrint::Init";
42 LOG(info) << "Initializing mCBM gDPB 2018 Raw Messages Converter";
43
44 return kTRUE;
45}
46
47void CbmCriGet4RawPrint::SetParContainers() { LOG(info) << "Setting parameter containers for " << GetName(); }
48
50{
51 LOG(info) << "Init parameter containers for " << GetName();
52
53 return kTRUE;
54}
55
57{
58 LOG(info) << "ReInit parameter containers for " << GetName();
59
60 return kTRUE;
61}
62
63void CbmCriGet4RawPrint::AddMsComponentToList(size_t component, UShort_t usDetectorId)
64{
66 for (UInt_t uCompIdx = 0; uCompIdx < fvMsComponentsList.size(); ++uCompIdx)
67 if (component == fvMsComponentsList[uCompIdx]) return;
68
70 fvMsComponentsList.push_back(component);
71
72 LOG(info) << "CbmCriGet4RawPrint::AddMsComponentToList => Component " << component << " with detector ID 0x"
73 << std::hex << usDetectorId << std::dec << " added to list";
74}
75
76Bool_t CbmCriGet4RawPrint::DoUnpack(const fles::Timeslice& ts, size_t /*component*/)
77{
78
79 static const uint8_t NGET4 = 80;
80 // static const uint8_t NERROR = 0x16;
81
82 char buf[256];
83
84 static uint32_t lastGlobalEpoch = 0;
85 uint32_t nGet4, epoch, msgType;
86 static int32_t pEpochDiff[NGET4];
87 int32_t epochDiff;
88 // static uint32_t pErrorCnt[NGET4] = {0};
89 // static uint32_t pHitsCnt[NGET4] = {0};
90 // static uint32_t pTotCnt[NGET4] = {0};
91
92 // static uint32_t pErrorCntMatrix[NGET4][NERROR];
93
94 static uint32_t procEpochUntilError = 0;
95
96 fulCurrentTsIdx = ts.index();
97 fdTsStartTime = static_cast<Double_t>(ts.descriptor(0, 0).idx);
98
100 if (0 == fulCurrentTsIdx) { return kTRUE; } // if( 0 == fulCurrentTsIdx )
101
103 if (-1.0 == fdTsCoreSizeInNs) {
104 fuNbCoreMsPerTs = ts.num_core_microslices();
105 fuNbOverMsPerTs = ts.num_microslices(0) - ts.num_core_microslices();
108 LOG(info) << "Timeslice parameters: each TS has " << fuNbCoreMsPerTs << " Core MS and " << fuNbOverMsPerTs
109 << " Overlap MS, for a core duration of " << fdTsCoreSizeInNs << " ns and a full duration of "
110 << fdTsFullSizeInNs << " ns";
111
115 LOG(info) << "In each TS " << fuNbMsLoop << " MS will be looped over";
116 } // if( -1.0 == fdTsCoreSizeInNs )
117
120
122 for (UInt_t uMsCompIdx = 0; uMsCompIdx < fvMsComponentsList.size(); ++uMsCompIdx) {
124 for (fuMsIndex = 0; fuMsIndex < fuNbMsLoop; fuMsIndex++) {
125 UInt_t uMsComp = fvMsComponentsList[uMsCompIdx];
126
127 auto msDescriptor = ts.descriptor(uMsComp, fuMsIndex);
128 fuCurrentEquipmentId = msDescriptor.eq_id;
129 const uint8_t* msContent = reinterpret_cast<const uint8_t*>(ts.content(uMsComp, fuMsIndex));
130
131 uint32_t uSize = msDescriptor.size;
132 fulCurrentMsIdx = msDescriptor.idx;
133 // Double_t dMsTime = (1e-9) * static_cast<double>(fulCurrentMsIdx);
134 LOG(debug) << "Microslice: " << fulCurrentMsIdx << " from EqId " << std::hex << fuCurrentEquipmentId << std::dec
135 << " has size: " << uSize;
136
138 LOG(info) << "---------------------------------------------------------------";
139 LOG(info) << FormatMsHeaderPrintout(msDescriptor);
140
142 if (0 != (uSize % kuBytesPerMessage))
143 LOG(error) << "The input microslice buffer does NOT "
144 << "contain only complete gDPB messages!";
145
147 uint32_t uNbMessages = (uSize - (uSize % kuBytesPerMessage)) / kuBytesPerMessage;
148
150 const uint64_t* pInBuff = reinterpret_cast<const uint64_t*>(msContent);
151 for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx++) {
153 uint64_t ulData = static_cast<uint64_t>(pInBuff[uIdx]);
154
155 critof001::Message mess(ulData);
156
158 //mess.printDataCout( critof001::msg_print_Hex );
159 //mess.printDataCout( critof001::msg_print_Hex | critof001::msg_print_Prefix | critof001::msg_print_Data );
160
161 msgType = ulData & 0xF;
162 nGet4 = (ulData >> 40) & 0xFF;
163 epoch = (ulData >> 8) & 0xFFFFFF;
164 epoch &= 0xFFFFFF;
165 /*snprintf(buf, sizeof(buf),
166 "Data: 0x%016lx - %d - 0x06%X ",
167 ulData, nGet4, epoch);
168
169 std::cout << buf << std::endl;
170 */
171
172 //if (fuCurrentEquipmentId == 0xabc0)
173 {
174 //------------------- TLAST ----------------------------//
175 if ((ulData & 0xFFFFFFFFFFFF) == 0xdeadbeeeeeef) {}
176 //------------------- EPOCH ----------------------------//
177 else if (msgType == 0x01) {
178 if (nGet4 == 0xFF) {
179
180 procEpochUntilError++;
181 if (lastGlobalEpoch != 0xFFFFFF) {
182 if ((lastGlobalEpoch + 1) != epoch) {
183 // Cast required to silence a warning on macos (there a uint64_t is a llu)
184 snprintf(buf, sizeof(buf),
185 "Error global epoch, last epoch, current epoch, diff 0x%06x 0x%06x %d 0x%016lx %d",
186 lastGlobalEpoch, epoch, lastGlobalEpoch - epoch, static_cast<size_t>(ulData),
187 procEpochUntilError);
188
189 std::cout << buf << std::endl;
190 procEpochUntilError = 0;
191 }
192 }
193 else {
194 snprintf(buf, sizeof(buf), "Global epoch overflow, last epoch, current epoch 0x%06x 0x%06x",
195 lastGlobalEpoch, epoch);
196
197 std::cout << buf << std::endl;
198 }
199
200
201 lastGlobalEpoch = epoch;
202 snprintf(buf, sizeof(buf), "Global epoch %d", epoch);
203 std::cout << Form("%5d/%5d ", uIdx, uNbMessages) << buf << std::endl;
204 }
205 else if (nGet4 <= 120) {
206
207 if (lastGlobalEpoch > epoch) epochDiff = lastGlobalEpoch - epoch;
208 else
209 epochDiff = 0xFFFFFF + lastGlobalEpoch - epoch;
210
211 if (epochDiff != pEpochDiff[nGet4]) {
212 snprintf(
213 buf, sizeof(buf),
214 "eTime %d - Error epoch drift Get4 %3d , last epoch diff, current epoch diff 0x%06x 0x%06x %d",
215 lastGlobalEpoch, nGet4, pEpochDiff[nGet4], epochDiff, pEpochDiff[nGet4] - epochDiff);
216 std::cout << buf << std::endl;
218 }
219 pEpochDiff[nGet4] = epochDiff;
220 }
221 }
222 /*
223 //------------------- CTRL ----------------------------//
224 else if (msgType == 0x02)
225 {
226 snprintf(buf, sizeof(buf),
227 "eTime %d - Ctrl Msg: 0x%016lx, Get4 %3d" ,
228 lastGlobalEpoch, ulData, nGet4);
229 std::cout << buf << std::endl;
230 mess.printDataCout( critof001::msg_print_Hex | critof001::msg_print_Prefix | critof001::msg_print_Data );
231 }
232 //------------------- ERROR ----------------------------//
233 else if (msgType == 0x03)
234 {
235 uint32_t errorCode = (ulData >> 4) & 0x7F;
236 snprintf(buf, sizeof(buf),
237 "eTime %d - Error Msg: 0x%016lx, Get4 %3d, Error code 0x%02x",
238 lastGlobalEpoch, ulData, nGet4, errorCode);
239 std::cout << buf << std::endl;
240 mess.printDataCout( critof001::msg_print_Hex | critof001::msg_print_Prefix | critof001::msg_print_Data );
241
242 if (nGet4 < NGET4)
243 pErrorCnt[nGet4] = pErrorCnt[nGet4] +1;
244 if (errorCode == 0x12)
245 if (nGet4 < NGET4)
246 pTotCnt[nGet4]=pTotCnt[nGet4]+1;
247 if ( (nGet4 < NGET4) && (errorCode<NERROR) )
248 pErrorCntMatrix[nGet4][errorCode]=pErrorCntMatrix[nGet4][errorCode]+1;
249
250 }
251 //------------------- HITS ----------------------------//
252 else if (msgType == 0x0)
253 {
254 snprintf(buf, sizeof(buf),
255 "eTime %d - Hit Msg: 0x%016lx, Get4 %3d",
256 lastGlobalEpoch, ulData, nGet4);
257 std::cout << buf << std::endl;
258 mess.printDataCout( critof001::msg_print_Hex | critof001::msg_print_Prefix | critof001::msg_print_Data );
259 if (nGet4 < NGET4)
260 pHitsCnt[nGet4]=pHitsCnt[nGet4]+1;
261 }
262 */
263 /*snprintf(buf, sizeof(buf),
264 "Data: 0x%016lx",
265 ulData);
266
267 std::cout << buf << std::endl;*/
268 }
269
270 } // for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx ++)
271 } // for( fuMsIndex = 0; fuMsIndex < uNbMsLoop; fuMsIndex ++ )
272 } // for( UInt_t uMsCompIdx = 0; uMsCompIdx < fvMsComponentsList.size(); ++uMsCompIdx )
273
274 if (0 == fulCurrentTsIdx % 10000) LOG(info) << "Processed TS " << fulCurrentTsIdx;
275
276 /*
277 uint32_t nPulses = 4*10000;
278 float effi;
279 for(uint32_t i =0; i < NGET4 ; i++)
280 {
281 effi = float(pHitsCnt[i])/float(nPulses) * 100.0;
282 snprintf(buf, sizeof(buf),
283 "Hit counter %d: Hits: %d Errors: %d ErrTot: %d Effi: %f",
284 i, pHitsCnt[i], pErrorCnt[i], pTotCnt[i], effi);
285 std::cout << buf << std::endl;
286 for(uint32_t j = 0; j<NERROR ; j++){
287 if (pErrorCntMatrix[i][j] != 0){
288 snprintf(buf, sizeof(buf),
289 "Error counter %d: error code: 0x%02x, times: %d",
290 i, j, pErrorCntMatrix[i][j]);
291 std::cout << buf << std::endl;
292 }
293 }
294 }
295 */
296
297
298 return kTRUE;
299}
300
302
304
ClassImp(CbmConverterManager)
std::string FormatMsHeaderPrintout(const fles::MicrosliceDescriptor &msDescriptor)
ULong64_t fulCurrentTsIdx
Total size of the core MS in a TS, [nanoseconds].
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
Double_t fdTsCoreSizeInNs
Size of a single MS, [nanoseconds].
Double_t fdTsFullSizeInNs
Total size of the core MS in a TS, [nanoseconds].
std::vector< size_t > fvMsComponentsList
Parameters related to FLES containers.
Double_t fdTsStopTimeCore
Time in ns of current TS from the index of the first MS first component.
UInt_t fuMsIndex
Start Time in ns of current MS from its index field in header.
Double_t fdMsSizeInNs
/‍** Ignore Overlap Ms: all fuNbOverMsPerTs MS at the end of timeslice **‍/
static const UInt_t kuBytesPerMessage
void printDataCout(unsigned kind=msg_print_Prefix|msg_print_Data, uint32_t epoch=0) const
Print message in human readable format to cout.