CbmRoot
Loading...
Searching...
No Matches
CbmStar2019TofFeeThr.cxx
Go to the documentation of this file.
1/* Copyright (C) 2018-2019 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// ----- CbmStar2019TofFeeThr -----
8// ----- Created 10.07.2018 by P.-A. Loizeau -----
9// ----- -----
10// -----------------------------------------------------------------------------
11
13
14#include "CbmHistManager.h"
15#include "CbmStar2019TofPar.h"
16#include "FairRootManager.h"
17#include "FairRun.h"
18#include "FairRunOnline.h"
19#include "FairRuntimeDb.h"
20#include "Rtypes.h"
21#include "TCanvas.h"
22#include "TClonesArray.h"
23#include "TF1.h"
24#include "TH1.h"
25#include "TH2.h"
26#include "THStack.h"
27#include "THttpServer.h"
28#include "TMath.h"
29#include "TPaveStats.h"
30#include "TProfile.h"
31#include "TProfile2D.h"
32#include "TROOT.h"
33#include "TString.h"
34#include "TStyle.h"
35
36#include <Logger.h>
37
38#include <algorithm>
39#include <cstdint>
40#include <ctime>
41#include <iomanip>
42#include <iostream>
43
46
52 , fbIgnoreOverlapMs(kFALSE)
53 , fsHistoFileFullname("data/TofPulserHistos.root")
55 , fuTotalMsNb(0)
56 , fuOverlapMsNb(0)
57 , fuCoreMs(0)
58 , fdMsSizeInNs(0.0)
59 , fdTsCoreSizeInNs(0.0)
60 , fuMinNbGdpb(0)
61 , fuCurrNbGdpb(0)
62 , fUnpackPar()
63 , fuNrOfGdpbs(0)
68 , fuNrOfGet4(0)
72 , fuCurrentMs(0)
74 , fdMsIndex(0)
75 , fuGdpbId(0)
76 , fuGdpbNr(0)
77 , fuGet4Id(0)
78 , fuGet4Nr(0)
79 , fiEquipmentId(0)
80 , fviMsgCounter(11, 0)
81 , // length of enum MessageTypes initialized with 0
82 fhGdpbAsicSpiCounts(nullptr)
87{
88}
89
91
93{
94 LOG(info) << "Initializing Get4 monitor";
95
96 FairRootManager* ioman = FairRootManager::Instance();
97 if (ioman == NULL) { LOG(fatal) << "No FairRootManager instance"; } // if( ioman == NULL )
98
99 return kTRUE;
100}
101
103{
104 LOG(info) << "Setting parameter containers for " << GetName();
105 fUnpackPar = (CbmStar2019TofPar*) (FairRun::Instance()->GetRuntimeDb()->getContainer("CbmStar2019TofPar"));
106}
107
109{
110 LOG(info) << "Init parameter containers for " << GetName();
111 Bool_t initOK = ReInitContainers();
112
114
115 return initOK;
116}
117
119{
120 LOG(info) << "ReInit parameter containers for " << GetName();
121
122 fuNrOfGdpbs = fUnpackPar->GetNrOfGdpbs();
123 LOG(info) << "Nr. of Tof GDPBs: " << fuNrOfGdpbs;
125
126 fuNrOfFeePerGdpb = 30;
127 LOG(info) << "Nr. of FEEs per Tof GDPB: " << fuNrOfFeePerGdpb;
128
129 fuNrOfGet4PerFee = fUnpackPar->GetNrOfGet4PerFee();
130 LOG(info) << "Nr. of GET4 per Tof FEE: " << fuNrOfGet4PerFee;
131
132 fuNrOfChannelsPerGet4 = fUnpackPar->GetNrOfChannelsPerGet4();
133 LOG(info) << "Nr. of channels per GET4: " << fuNrOfChannelsPerGet4;
134
136 LOG(info) << "Nr. of channels per FEE: " << fuNrOfChannelsPerFee;
137
139 LOG(info) << "Nr. of GET4s: " << fuNrOfGet4;
140
142 LOG(info) << "Nr. of GET4s per GDPB: " << fuNrOfGet4PerGdpb;
143
145 LOG(info) << "Nr. of channels per GDPB: " << fuNrOfChannelsPerGdpb;
146
147 fGdpbIdIndexMap.clear();
148 for (UInt_t i = 0; i < fuNrOfGdpbs; ++i) {
149 fGdpbIdIndexMap[fUnpackPar->GetGdpbId(i)] = i;
150 LOG(info) << "GDPB Id of TOF " << i << " : " << std::hex << fUnpackPar->GetGdpbId(i) << std::dec;
151 } // for( UInt_t i = 0; i < fuNrOfGdpbs; ++i )
152
153 fuNrOfGbtx = fUnpackPar->GetNrOfGbtx();
154 LOG(info) << "Nr. of GBTx: " << fuNrOfGbtx;
155
157 fdMsSizeInNs = fUnpackPar->GetSizeMsInNs();
159 LOG(info) << "Timeslice parameters: " << fuTotalMsNb << " MS per link, of which " << fuOverlapMsNb
160 << " overlap MS, each MS is " << fdMsSizeInNs << " ns";
161
165 /*
166 UInt_t uGet4topadi[32] = {
167 4, 3, 2, 1, // provided by Jochen
168 24, 23, 22, 21,
169 8, 7, 6, 5,
170 28, 27, 26, 25,
171 12, 11, 10, 9,
172 32, 31, 30, 29,
173 16, 15, 14, 13,
174 20, 19, 18, 17 };
175*/
177 UInt_t uGet4topadi[32] = {4, 3, 2, 1, // provided by Jochen
178 8, 7, 6, 5, 12, 11, 10, 9, 16, 15, 14, 13, 20, 19,
179 18, 17, 24, 23, 22, 21, 28, 27, 26, 25, 32, 31, 30, 29};
180
181 UInt_t uPaditoget4[32] = {4, 3, 2, 1, // provided by Jochen
182 12, 11, 10, 9, 20, 19, 18, 17, 28, 27, 26, 25, 32, 31,
183 30, 29, 8, 7, 6, 5, 16, 15, 14, 13, 24, 23, 22, 21};
184
185 for (UInt_t uChan = 0; uChan < fuNrOfChannelsPerFee; ++uChan) {
186 fvuPadiToGet4[uChan] = uPaditoget4[uChan] - 1;
187 fvuGet4ToPadi[uChan] = uGet4topadi[uChan] - 1;
188 } // for( UInt_t uChan = 0; uChan < fuNrOfChannelsPerFee; ++uChan )
189
190
194 UInt_t kuElinkToGet4[kuNbGet4PerGbtx] = {27, 2, 7, 3, 31, 26, 30, 1, 33, 37, 32, 13, 9, 14,
195 10, 15, 17, 21, 16, 35, 34, 38, 25, 24, 0, 6, 20, 23,
196 18, 22, 28, 4, 29, 5, 19, 36, 39, 8, 12, 11};
197 UInt_t kuGet4ToElink[kuNbGet4PerGbtx] = {24, 7, 1, 3, 31, 33, 25, 2, 37, 12, 14, 39, 38, 11,
198 13, 15, 18, 16, 28, 34, 26, 17, 29, 27, 23, 22, 5, 0,
199 30, 32, 6, 4, 10, 8, 20, 19, 35, 9, 21, 36};
200
201 for (UInt_t uLinkAsic = 0; uLinkAsic < kuNbGet4PerGbtx; ++uLinkAsic) {
202 fvuElinkToGet4[uLinkAsic] = kuElinkToGet4[uLinkAsic];
203 fvuGet4ToElink[uLinkAsic] = kuGet4ToElink[uLinkAsic];
204 } // for( UInt_t uChan = 0; uChan < fuNrOfChannelsPerFee; ++uChan )
205
206 return kTRUE;
207}
208
209
210void CbmStar2019TofFeeThr::AddMsComponentToList(size_t component, UShort_t usDetectorId)
211{
213 for (UInt_t uCompIdx = 0; uCompIdx < fvMsComponentsList.size(); ++uCompIdx)
214 if (component == fvMsComponentsList[uCompIdx]) return;
215
217 fvMsComponentsList.push_back(component);
218}
219void CbmStar2019TofFeeThr::SetNbMsInTs(size_t uCoreMsNb, size_t uOverlapMsNb)
220{
221 fuNbCoreMsPerTs = uCoreMsNb;
222 fuNbOverMsPerTs = uOverlapMsNb;
223
224 // UInt_t uNbMsTotal = fuNbCoreMsPerTs + fuNbOverMsPerTs;
225}
226
228{
229 LOG(info) << "create Histos for " << fuNrOfGdpbs << " gDPBs ";
230
231 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
232
234 new TH2I("hGdpbAsicSpiCounts", "SPI messages count per GDPB and ASIC; ASIC Idx []; GDPB []; SPI msg[]",
236
237 if (server) {
238 server->Register("/", fhGdpbAsicSpiCounts);
239 server->RegisterCommand("/Reset_All_eTOF", "bStar2019TofFeeThrResetHistos=kTRUE");
240 server->RegisterCommand("/Save_All_eTof", "bStar2019TofFeeThrSaveHistos=kTRUE");
241
242 server->Restrict("/Reset_All_eTof", "allow=admin");
243 server->Restrict("/Save_All_eTof", "allow=admin");
244 } // if( server )
245
246 LOG(info) << "Leaving CreateHistograms";
247}
248
249Bool_t CbmStar2019TofFeeThr::DoUnpack(const fles::Timeslice& ts, size_t component)
250{
252 LOG(info) << "Reset eTOF STAR histos ";
255 } // if( bStar2019TofFeeThrResetHistos )
257 LOG(info) << "Start saving eTOF STAR histos ";
258 SaveAllHistos("data/histos_Shift_StarTof.root");
260 } // if( bSaveStsHistos )
261
262
263 LOG(debug1) << "Timeslice contains " << ts.num_microslices(component) << "microslices.";
264
266 UInt_t uNbMsLoop = fuNbCoreMsPerTs;
267 if (kFALSE == fbIgnoreOverlapMs) uNbMsLoop += fuNbOverMsPerTs;
268
269 Int_t messageType = -111;
270 Double_t dTsStartTime = -1;
271
273 for (UInt_t uMsIdx = 0; uMsIdx < uNbMsLoop; uMsIdx++) {
274 if (fuMsAcceptsPercent < uMsIdx) continue;
275
276 fuCurrentMs = uMsIdx;
277
278 if (0 == fulCurrentTsIndex && 0 == uMsIdx) {
279 for (UInt_t uMsCompIdx = 0; uMsCompIdx < fvMsComponentsList.size(); ++uMsCompIdx) {
280 UInt_t uMsComp = fvMsComponentsList[uMsCompIdx];
281 auto msDescriptor = ts.descriptor(uMsComp, uMsIdx);
282 LOG(info) << "hi hv eqid flag si sv idx/start crc size offset";
283 LOG(info) << Form(
284 "%02x %02x %04x %04x %02x %02x %016lx %08x %08x %016lx", static_cast<unsigned int>(msDescriptor.hdr_id),
285 static_cast<unsigned int>(msDescriptor.hdr_ver), msDescriptor.eq_id, msDescriptor.flags,
286 static_cast<unsigned int>(msDescriptor.sys_id), static_cast<unsigned int>(msDescriptor.sys_ver),
287 msDescriptor.idx, msDescriptor.crc, msDescriptor.size, msDescriptor.offset);
288 } // for( UInt_t uMsCompIdx = 0; uMsCompIdx < fvMsComponentsList.size(); ++uMsCompIdx )
289 } // if( 0 == fulCurrentTsIndex && 0 == uMsIdx )
290
292 for (UInt_t uMsCompIdx = 0; uMsCompIdx < fvMsComponentsList.size(); ++uMsCompIdx) {
293 constexpr uint32_t kuBytesPerMessage = 8;
294
295 UInt_t uMsComp = fvMsComponentsList[uMsCompIdx];
296 auto msDescriptor = ts.descriptor(uMsComp, uMsIdx);
297 fiEquipmentId = msDescriptor.eq_id;
298 fdMsIndex = static_cast<double>(msDescriptor.idx);
299 fuCurrentMsSysId = static_cast<unsigned int>(msDescriptor.sys_id);
300 const uint8_t* msContent = reinterpret_cast<const uint8_t*>(ts.content(uMsComp, uMsIdx));
301
302 uint32_t size = msDescriptor.size;
303 // fulLastMsIdx = msDescriptor.idx;
304 if (size > 0) LOG(debug) << "Microslice: " << msDescriptor.idx << " has size: " << size;
305
306 // If not integer number of message in input buffer, print warning/error
307 if (0 != (size % kuBytesPerMessage))
308 LOG(error) << "The input microslice buffer does NOT "
309 << "contain only complete nDPB messages!";
310
311 // Compute the number of complete messages in the input microslice buffer
312 uint32_t uNbMessages = (size - (size % kuBytesPerMessage)) / kuBytesPerMessage;
313
314 // Get the gDPB ID from the MS header
316
318 auto it = fGdpbIdIndexMap.find(fuGdpbId);
319 if (it == fGdpbIdIndexMap.end()) {
320 LOG(info) << "---------------------------------------------------------------";
321 LOG(info) << "hi hv eqid flag si sv idx/start crc size offset";
322 LOG(info) << Form(
323 "%02x %02x %04x %04x %02x %02x %016lx %08x %08x %016lx", static_cast<unsigned int>(msDescriptor.hdr_id),
324 static_cast<unsigned int>(msDescriptor.hdr_ver), msDescriptor.eq_id, msDescriptor.flags,
325 static_cast<unsigned int>(msDescriptor.sys_id), static_cast<unsigned int>(msDescriptor.sys_ver),
326 msDescriptor.idx, msDescriptor.crc, msDescriptor.size, msDescriptor.offset);
327 LOG(warning) << "Could not find the gDPB index for AFCK id 0x" << std::hex << fuGdpbId << std::dec
328 << " in timeslice " << fulCurrentTsIndex << " in microslice " << fdMsIndex << " component "
329 << uMsCompIdx << "\n"
330 << "If valid this index has to be added in the TOF "
331 "parameter file in the RocIdArray field";
332 continue;
333 } // if( it == fGdpbIdIndexMap.end() )
334 else
336
337 // Prepare variables for the loop on contents
338 const uint64_t* pInBuff = reinterpret_cast<const uint64_t*>(msContent);
339 for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx++) {
340 // Fill message
341 uint64_t ulData = static_cast<uint64_t>(pInBuff[uIdx]);
342
344 if (0 == uIdx) { continue; } // if( 0 == uIdx )
345
346 gdpbv100::Message mess(ulData);
347
348 // Increment counter for different message types
349 // and fill the corresponding histogram
350 messageType = mess.getMessageType();
351 fviMsgCounter[messageType]++;
352
356 if (0x90 == fuCurrentMsSysId) fuGet4Id = mess.getGdpbGenChipId();
358
360 LOG(warning) << "Message with Get4 ID too high: " << fuGet4Id << " VS " << fuNrOfGet4PerGdpb
361 << " set in parameters.";
362
363 switch (messageType) {
365 case gdpbv100::MSG_EPOCH: break;
366 case gdpbv100::MSG_SLOWC: {
367 PrintSlcInfo(mess);
368 break;
369 } // case gdpbv100::MSG_SLOWC:
374 case gdpbv100::MSG_STAR_TRI_D: break;
375 default:
376 LOG(error) << "Message type " << std::hex << std::setw(2) << static_cast<uint16_t>(messageType)
377 << " not included in Get4 unpacker.";
378 } // switch( mess.getMessageType() )
379 } // for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx ++)
380 } // for( UInt_t uMsCompIdx = 0; uMsCompIdx < fvMsComponentsList.size(); ++uMsCompIdx )
381 } // for( UInt_t uMsIdx = 0; uMsIdx < uNbMsLoop; uMsIdx ++ )
382
383
385
386 return kTRUE;
387}
388
390{
391 if (fGdpbIdIndexMap.end() != fGdpbIdIndexMap.find(fuGdpbId)) {
392 UInt_t uChan = mess.getGdpbSlcChan();
393 UInt_t uEdge = mess.getGdpbSlcEdge();
394 UInt_t uData = mess.getGdpbSlcData();
395 UInt_t uType = mess.getGdpbSlcType();
396
397 Double_t dGdpbChId = fuGet4Id * fuNrOfChannelsPerGet4 + mess.getGdpbSlcChan() + 0.5 * mess.getGdpbSlcEdge();
398 Double_t dFullChId = fuGet4Nr * fuNrOfChannelsPerGet4 + mess.getGdpbSlcChan() + 0.5 * mess.getGdpbSlcEdge();
399 Double_t dMessTime = fdMsIndex * 1e-9;
400
402 if (gdpbv100::GET4_32B_SLC_SPIREAD == uType) {
404 LOG(info) << "GET4 Slow Control message, time " << Form("%3.3f", dMessTime) << " s "
405 << Form(" for board %02u (ID %04x, sector %2u)", fuGdpbNr, fuGdpbId, fuGdpbNr + 13) << "\n"
406 << " +++++++ > Chip = " << std::setw(3) << fuGet4Id << ", Chan = " << std::setw(1) << uChan
407 << ", Edge = " << std::setw(1) << uEdge << ", Type = " << std::setw(1) << mess.getGdpbSlcType() << ", "
408 << Form("channel %1u,", (uData >> 10) & 0xF) << Form("value 0x%03x ", uData & 0x3FF)
409 << Form("(Data = 0x%06x)", uData);
410 } // if( gdpbv100::GET4_32B_SLC_SPIREAD == uType )
411 }
412}
413
415
417{
418 // Printout some stats on what was unpacked
419 TString message_type;
420 for (unsigned int i = 0; i < fviMsgCounter.size(); ++i) {
421 switch (i) {
422 case 0: message_type = "NOP"; break;
423 case 1: message_type = "HIT"; break;
424 case 2: message_type = "EPOCH"; break;
425 case 3: message_type = "SYNC"; break;
426 case 4: message_type = "AUX"; break;
427 case 5: message_type = "EPOCH2"; break;
428 case 6: message_type = "GET4"; break;
429 case 7: message_type = "SYS"; break;
430 case 8: message_type = "GET4_SLC"; break;
431 case 9: message_type = "GET4_32B"; break;
432 case 10: message_type = "GET4_SYS"; break;
433 default: message_type = "UNKNOWN"; break;
434 } // switch(i)
435 LOG(info) << message_type << " messages: " << fviMsgCounter[i];
436 } // for (unsigned int i=0; i< fviMsgCounter.size(); ++i)
437
439 // SaveAllHistos();
440}
441
443{
444 TDirectory* oldDir = NULL;
445 TFile* histoFile = NULL;
446 if ("" != sFileName) {
447 // Store current directory position to allow restore later
448 oldDir = gDirectory;
449 // open separate histo file in recreate mode
450 histoFile = new TFile(sFileName, "RECREATE");
451 histoFile->cd();
452 } // if( "" != sFileName )
453
454 if ("" != sFileName) {
455 // Restore original directory position
456 histoFile->Close();
457 oldDir->cd();
458 } // if( "" != sFileName )
459}
460
462{
463 LOG(info) << "Reseting all TOF histograms.";
464 fhGdpbAsicSpiCounts->Reset();
465}
ClassImp(CbmConverterManager)
Histogram manager.
Bool_t bStar2019TofFeeThrSaveHistos
Bool_t bStar2019TofFeeThrResetHistos
static double dTsStartTime
static constexpr size_t size()
Definition KfSimdPseudo.h:2
int Int_t
bool Bool_t
TString fsHistoFileFullname
/‍** Ignore Overlap Ms: all fuOverlapMsNb MS at the end of timeslice **‍/
UInt_t ConvertElinkToGet4(UInt_t uElinkIdx)
std::vector< size_t > fvMsComponentsList
FLES containers.
TH2 * fhGdpbAsicSpiCounts
Histograms.
virtual void AddMsComponentToList(size_t component, UShort_t usDetectorId)
void SaveAllHistos(TString sFileName="")
std::vector< UInt_t > fvuGet4ToElink
size_t fuMsAcceptsPercent
OLD, to be cleaned out !!!!!
CbmStar2019TofPar * fUnpackPar
std::vector< UInt_t > fvuGet4ToPadi
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
std::vector< UInt_t > fvuPadiToGet4
virtual void SetNbMsInTs(size_t uCoreMsNb, size_t uOverlapMsNb)
void PrintSlcInfo(gdpbv100::Message)
static const UInt_t kuNbGet4PerGbtx
std::vector< int > fviMsgCounter
std::vector< UInt_t > fvuElinkToGet4
5 FEE with 8 GET4 each
std::map< UInt_t, UInt_t > fGdpbIdIndexMap
Map of ID to index for the gDPBs.
uint32_t getGdpbSlcChan() const
uint32_t getGdpbSlcData() const
uint32_t getGdpbSlcType() const
bool isStarTrigger() const
Returns true is message type is MSG_STAR_TRI_A, _B, _C, _D (STAR Trigger message)
uint16_t getGdpbGenChipId() const
uint32_t getGdpbSlcEdge() const
uint8_t getMessageType() const
Returns the message type. Valid for all message types. 4 bit.
@ GET4_32B_SLC_SPIREAD
const uint32_t kuChipIdMergedEpoch