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