CbmRoot
Loading...
Searching...
No Matches
CbmDeviceUnpack.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
12#include "CbmDeviceUnpack.h"
13
14#include "CbmBmonUnpackConfig.h"
15#include "CbmFlesCanvasTools.h"
16#include "CbmMQDefs.h"
17#include "CbmMuchUnpackConfig.h"
18#include "CbmPsdUnpackConfig.h"
19#include "CbmRichUnpackConfig.h"
20#include "CbmSetup.h"
21#include "CbmStsUnpackConfig.h"
22#include "CbmTofUnpackConfig.h"
23#include "CbmTrdUnpackConfig.h"
25
26#include "StorableTimeslice.hpp"
27#include "TimesliceMetaData.h"
28
29#include "FairMQLogger.h"
30#include "FairMQProgOptions.h" // device->fConfig
31#include "FairParGenericSet.h"
32
33#include "TCanvas.h"
34#include "TFile.h"
35#include "TH1.h"
36#include "TList.h"
37#include "TNamed.h"
38
39#include "BoostSerializer.h"
40#include <boost/archive/binary_iarchive.hpp>
41#include <boost/serialization/utility.hpp>
42
43#include <array>
44#include <iomanip>
45#include <stdexcept>
46#include <string>
47#include <utility>
48
49#include "RootSerializer.h"
50struct InitTaskError : std::runtime_error {
51 using std::runtime_error::runtime_error;
52};
53
54using namespace std;
55
56//Bool_t bMcbm2018MonitorTaskBmonResetHistos = kFALSE;
57
59
61try {
63 LOG(info) << "Init options for CbmDeviceUnpack.";
64 fsSetupName = fConfig->GetValue<std::string>("Setup");
65 fuRunId = fConfig->GetValue<uint32_t>("RunId");
66 fbUnpBmon = fConfig->GetValue<bool>("UnpBmon");
67 fbUnpSts = fConfig->GetValue<bool>("UnpSts");
68 fbUnpMuch = fConfig->GetValue<bool>("UnpMuch");
69 fbUnpTrd1D = fConfig->GetValue<bool>("UnpTrd1d");
70 fbUnpTrd2D = fConfig->GetValue<bool>("UnpTrd2d");
71 fbUnpTof = fConfig->GetValue<bool>("UnpTof");
72 fbUnpRich = fConfig->GetValue<bool>("UnpRich");
73 fbUnpPsd = fConfig->GetValue<bool>("UnpPsd");
74 fbIgnoreOverlapMs = fConfig->GetValue<bool>("IgnOverMs");
75 fbOutputFullTimeSorting = fConfig->GetValue<bool>("FullTimeSort");
76 fvsSetTimeOffs = fConfig->GetValue<std::vector<std::string>>("SetTimeOffs");
77 fsChannelNameDataInput = fConfig->GetValue<std::string>("TsNameIn");
78 fsChannelNameDataOutput = fConfig->GetValue<std::string>("TsNameOut");
79 fuPublishFreqTs = fConfig->GetValue<uint32_t>("PubFreqTs");
80 fdMinPublishTime = fConfig->GetValue<double_t>("PubTimeMin");
81 fdMaxPublishTime = fConfig->GetValue<double_t>("PubTimeMax");
82 fsChannelNameHistosInput = fConfig->GetValue<std::string>("ChNameIn");
83}
84catch (InitTaskError& e) {
85 LOG(error) << e.what();
86 // Wrapper defined in CbmMQDefs.h to support different FairMQ versions
88}
89
91{
92 LOG(info) << "Init parameter containers for CbmDeviceUnpack.";
93
94 // ----- FIXME: Environment settings? or binary option?
95 TString srcDir = std::getenv("VMCWORKDIR"); // top source directory, standard C++ library
96 // TString srcDir = gSystem->Getenv("VMCWORKDIR"); // top source directory
97
98 // ----- CbmSetup -----------------------------------------------------
99 // TODO: support for multiple setups on Par Server? with request containing setup name?
100 CbmSetup* cbmsetup = CbmSetup::Instance();
101 FairMQMessagePtr req(NewSimpleMessage("setup"));
102 FairMQMessagePtr rep(NewMessage());
103
104 if (Send(req, "parameters") > 0) {
105 if (Receive(rep, "parameters") >= 0) {
106 if (0 != rep->GetSize()) {
107 CbmSetupStorable* exchangableSetup;
108
109 CbmMqTMessage tmsg(rep->GetData(), rep->GetSize());
110 exchangableSetup = dynamic_cast<CbmSetupStorable*>(tmsg.ReadObject(tmsg.GetClass()));
111
112 if (nullptr != exchangableSetup) {
114 cbmsetup->LoadStoredSetup(exchangableSetup);
115 }
116 else {
117 LOG(error) << "Received corrupt reply. Setup not available";
118 throw InitTaskError("Setup not received from par-server.");
119 }
120 } // if( 0 != rep->GetSize() )
121 else {
122 LOG(error) << "Received empty reply. Setup not available";
123 throw InitTaskError("Setup not received from par-server.");
124 } // else of if( 0 != rep->GetSize() )
125 } // if( Receive( rep, "parameters" ) >= 0)
126 } // if( Send(req, "parameters") > 0 )
127 // ------------------------------------------------------------------------
128
130 // ---- BMON ----
131 std::shared_ptr<CbmBmonUnpackConfig> bmonconfig = nullptr;
132 if (fbUnpBmon) {
133 bmonconfig = std::make_shared<CbmBmonUnpackConfig>("", fuRunId);
134 if (bmonconfig) {
135 // bmonconfig->SetDebugState();
136 bmonconfig->SetDoWriteOutput();
137 // bmonconfig->SetDoWriteOptOutA("CbmBmonErrors");
138 std::string parfilesbasepathBmon = Form("%s/macro/beamtime/mcbm2022/", srcDir.Data());
139 bmonconfig->SetParFilesBasePath(parfilesbasepathBmon);
140 bmonconfig->SetParFileName("mBmonCriPar.par");
141 bmonconfig->SetSystemTimeOffset(-1220); // [ns] value to be updated
142 if (2160 <= fuRunId) {
143 bmonconfig->SetSystemTimeOffset(-80); // [ns] value to be updated
144 }
145 if (2350 <= fuRunId) {
146 bmonconfig->SetSystemTimeOffset(0); // [ns] value to be updated
147 }
149 // bmonconfig->SetMonitor(GetTofMonitor(outfilename, true)); // FIXME: Unsupported for now
150 }
151 }
152 // -------------
153 // ---- STS ----
154 std::shared_ptr<CbmStsUnpackConfig> stsconfig = nullptr;
155 TString stsSetupTag = "";
156 cbmsetup->GetGeoTag(ECbmModuleId::kSts, stsSetupTag);
157 if ("" != stsSetupTag && fbUnpSts) {
158 LOG(info) << "From received setup, using STS tag: " << stsSetupTag;
159 stsconfig = std::make_shared<CbmStsUnpackConfig>(std::string(fsSetupName), fuRunId);
160 if (stsconfig) {
161 // stsconfig->SetDebugState();
162 stsconfig->SetDoWriteOutput();
163 stsconfig->SetDoWriteOptOutA("StsDigiPulser");
164 std::string parfilesbasepathSts = Form("%s/macro/beamtime/mcbm2021/", srcDir.Data());
165 if (2060 <= fuRunId) {
167 parfilesbasepathSts = Form("%s/macro/beamtime/mcbm2022/", srcDir.Data());
168 }
169 stsconfig->SetParFilesBasePath(parfilesbasepathSts);
171 stsconfig->SetDuplicatesRejection(true, true);
173 // stsconfig->SetMonitor(GetStsMonitor(outfilename, true)); // FIXME: Unsupported for now
174 stsconfig->SetSystemTimeOffset(-2221); // [ns] value to be updated
175 if (2160 <= fuRunId) {
176 stsconfig->SetSystemTimeOffset(-1075); // [ns] value to be updated
177 }
178 if (2350 <= fuRunId) {
179 stsconfig->SetSystemTimeOffset(-970); // [ns] value to be updated
180 }
181
182 stsconfig->SetMinAdcCut(1, 1);
183 stsconfig->SetMinAdcCut(2, 1);
184 stsconfig->SetMinAdcCut(3, 1);
185 stsconfig->SetMinAdcCut(4, 1);
186
187 stsconfig->MaskNoisyChannel(3, 56);
188 stsconfig->MaskNoisyChannel(3, 75);
189 stsconfig->MaskNoisyChannel(3, 79);
190 stsconfig->MaskNoisyChannel(3, 85);
191 stsconfig->MaskNoisyChannel(7, 123);
192 stsconfig->MaskNoisyChannel(7, 124);
193 stsconfig->MaskNoisyChannel(7, 125);
194 stsconfig->MaskNoisyChannel(7, 158);
195 stsconfig->MaskNoisyChannel(7, 159);
196 stsconfig->MaskNoisyChannel(7, 162);
197 stsconfig->MaskNoisyChannel(7, 715);
198 stsconfig->MaskNoisyChannel(9, 709);
199 stsconfig->MaskNoisyChannel(12, 119);
200
201 // Time Walk correction
202 std::map<uint32_t, CbmStsParModule> walkMap;
203 auto parAsic = new CbmStsParAsic(128, 31, 31., 1., 5., 800., 1000., 3.9789e-3);
204
205 // Module params: number of channels, number of channels per ASIC
206 auto parMod = new CbmStsParModule(2048, 128);
207
208 // default
209 double p0 = 0, p1 = 0, p2 = 0, p3 = 0;
210 parAsic->SetWalkCoef({p0, p1, p2, p3});
211 parMod->SetAllAsics(*parAsic);
212
213 walkMap[0x10107C02] = CbmStsParModule(*parMod); // Make a copy for storage
214 walkMap[0x101FFC02] = CbmStsParModule(*parMod); // Make a copy for storage
215
217 int sensor, asic;
218 std::ifstream asicTimeWalk_par(Form("%s/mStsAsicTimeWalk.par", parfilesbasepathSts.data()));
219 while (asicTimeWalk_par >> std::hex >> sensor >> std::dec >> asic >> p0 >> p1 >> p2 >> p3) {
220 std::cout << Form("Setting time-walk parametersfor: module %x, ASIC %u\n", sensor, asic);
221 parAsic->SetWalkCoef({p0, p1, p2, p3});
222
223 if (walkMap.find(sensor) == walkMap.end()) { walkMap[sensor] = CbmStsParModule(*parMod); }
224 walkMap[sensor].SetAsic(asic, *parAsic);
225 }
226
227 stsconfig->SetWalkMap(walkMap);
228 }
229 } // if ("" != stsSetupTag)
230 // -------------
231 // ---- MUCH ----
232 std::shared_ptr<CbmMuchUnpackConfig> muchconfig = nullptr;
233 TString muchSetupTag = "";
234 cbmsetup->GetGeoTag(ECbmModuleId::kMuch, muchSetupTag);
235 if ("" != muchSetupTag && fbUnpMuch) {
236 LOG(info) << "From received setup, using MUCH tag: " << muchSetupTag;
237
238 muchconfig = std::make_shared<CbmMuchUnpackConfig>(std::string(fsSetupName), fuRunId);
239 if (muchconfig) {
240 // muchconfig->SetDebugState();
241 muchconfig->SetDoWriteOutput();
242 muchconfig->SetDoWriteOptOutA("MuchDigiPulser");
243 std::string parfilesbasepathMuch = Form("%s/macro/beamtime/mcbm2022/", srcDir.Data());
244 muchconfig->SetParFilesBasePath(parfilesbasepathMuch);
245 if (2060 <= fuRunId && fuRunId <= 2162) {
247 muchconfig->SetParFileName("mMuchParUpto26032022.par");
248 }
249 else if (2163 <= fuRunId && fuRunId <= 2291) {
251 muchconfig->SetParFileName("mMuchParUpto03042022.par");
252 }
253 else if (2311 <= fuRunId && fuRunId <= 2315) {
255 muchconfig->SetParFileName("mMuchParUpto10042022.par");
256 }
257 else if (2316 <= fuRunId && fuRunId <= 2366) {
259 muchconfig->SetParFileName("mMuchParUpto23052022.par");
260 }
261 else if (2367 <= fuRunId && fuRunId <= 2397) {
263 muchconfig->SetParFileName("mMuchParUpto26052022.par");
264 }
265
267 muchconfig->SetDuplicatesRejection(true, true);
269 //muchconfig->SetMonitor(GetMuchMonitor(outfilename, true));
270 muchconfig->SetSystemTimeOffset(-2221); // [ns] value to be updated
271 if (2160 <= fuRunId) {
272 muchconfig->SetSystemTimeOffset(-1020); // [ns] value to be updated
273 }
274 if (2350 <= fuRunId) {
275 muchconfig->SetSystemTimeOffset(-980); // [ns] value to be updated
276 }
277
278 // muchconfig->SetMinAdcCut(1, 1);
279
280 // muchconfig->MaskNoisyChannel(3, 56);
281 }
282 }
283 // -------------
284 // ---- TRD ----
285 std::shared_ptr<CbmTrdUnpackConfig> trd1Dconfig = nullptr;
286 TString trdsetuptag = "";
287 cbmsetup->GetGeoTag(ECbmModuleId::kTrd, trdsetuptag);
288 if ("" != trdsetuptag && fbUnpTrd1D) {
289 LOG(info) << "From received setup, using TRD tag: " << trdsetuptag;
290 // trd1Dconfig = std::make_shared<CbmTrdUnpackConfig>(trdsetuptag.Data(), fuRunId);
291 trd1Dconfig = std::make_shared<CbmTrdUnpackConfig>(trdsetuptag.Data(), 3);
292 if (trd1Dconfig) {
293 trd1Dconfig->SetDoWriteOutput();
294 // Activate the line below to write Trd1D digis to a separate "TrdSpadicDigi" branch. Can be used to separate between Fasp and Spadic digis
295 // trd1Dconfig->SetOutputBranchName("TrdSpadicDigi");
296 // trd1Dconfig->SetDoWriteOptOutA(CbmTrdRawMessageSpadic::GetBranchName());
297 // trd1Dconfig->SetDoWriteOptOutB("SpadicInfoMessages"); // SpadicInfoMessages
298
299 std::string parfilesbasepathTrd = Form("%s/parameters/trd", srcDir.Data());
300 trd1Dconfig->SetParFilesBasePath(parfilesbasepathTrd);
301 // trd1Dconfig->SetMonitor(GetTrdMonitor(outfilename)); // FIXME: Unsupported for now
302 // Get the spadic configuration true = avg baseline active / false plain sample 0
303 trd1Dconfig->SetSpadicObject(GetTrdSpadic(true));
304 trd1Dconfig->SetSystemTimeOffset(0); // [ns] value to be updated
305 if (2160 <= fuRunId) {
306 trd1Dconfig->SetSystemTimeOffset(1140); // [ns] value to be updated
307 }
308 if (2350 <= fuRunId) {
309 trd1Dconfig->SetSystemTimeOffset(1300); // [ns] value to be updated
310 }
311 }
312 } // if ("" != trdsetuptag)
313 // -------------
314 // ---- TRDFASP2D ----
315 std::shared_ptr<CbmTrdUnpackFaspConfig> trdfasp2dconfig = nullptr;
316 if ("" != trdsetuptag && fbUnpTrd2D) {
317 trdfasp2dconfig = std::make_shared<CbmTrdUnpackFaspConfig>(trdsetuptag.Data());
318 if (trdfasp2dconfig) {
319 // trdfasp2dconfig->SetDebugState();
320 trdfasp2dconfig->SetDoWriteOutput();
321 // Activate the line below to write Trd1D digis to a separate "TrdFaspDigi" branch. Can be used to separate between Fasp and Spadic digis
322 //trdfasp2dconfig->SetOutputBranchName("TrdFaspDigi");
323 // uint16_t crob_map[NCROBMOD];
324 // if (fuRunId <= 1588) {
325 // uint16_t crob_map21[] = {0x00f0, 0, 0, 0, 0};
326 // for (uint32_t i(0); i < NCROBMOD; i++)
327 // crob_map[i] = crob_map21[i];
328 // }
329 // else if (fuRunId >= 2335) {
330 // uint16_t crob_map22[] = {0xffc2, 0xffc5, 0xffc1, 0, 0};
331 // for (uint32_t i(0); i < NCROBMOD; i++)
332 // crob_map[i] = crob_map22[i];
333 // }
334 // trdfasp2dconfig->SetCrobMapping(5, crob_map);
335 std::string parfilesbasepathTrdfasp2d = Form("%s/parameters/trd", srcDir.Data());
336 trdfasp2dconfig->SetParFilesBasePath(parfilesbasepathTrdfasp2d);
337 trdfasp2dconfig->SetSystemTimeOffset(-1800); // [ns] value to be updated
338 if (2160 <= fuRunId) {
339 trdfasp2dconfig->SetSystemTimeOffset(-570); // [ns] value to be updated
340 }
341 if (2350 <= fuRunId) {
342 trdfasp2dconfig->SetSystemTimeOffset(-510); // [ns] value to be updated
343 }
344 }
345 } // if ("" != trdsetuptag)
346 // -------------
347 // ---- TOF ----
348 std::shared_ptr<CbmTofUnpackConfig> tofconfig = nullptr;
349 TString tofSetupTag = "";
350 cbmsetup->GetGeoTag(ECbmModuleId::kTof, tofSetupTag);
351 if ("" != tofSetupTag && fbUnpTof) {
352 LOG(info) << "From received setup, using TOF tag: " << tofSetupTag;
353 tofconfig = std::make_shared<CbmTofUnpackConfig>("", fuRunId);
354 if (tofconfig) {
355 // tofconfig->SetDebugState();
356 tofconfig->SetDoWriteOutput();
357 // tofconfig->SetDoWriteOptOutA("CbmTofErrors");
358 std::string parfilesbasepathTof = Form("%s/macro/beamtime/mcbm2021/", srcDir.Data());
359 std::string parFileNameTof = "mTofCriPar.par";
360 if (2060 <= fuRunId) {
362 parfilesbasepathTof = Form("%s/macro/beamtime/mcbm2022/", srcDir.Data());
364 if (fuRunId <= 2065) {
366 parFileNameTof = "mTofCriParCarbon.par";
367 }
368 else if (2150 <= fuRunId && fuRunId <= 2160) {
370 parFileNameTof = "mTofCriParIron.par";
371 }
372 else if (2176 <= fuRunId && fuRunId <= 2310) {
374 parFileNameTof = "mTofCriParUranium.par";
375 }
376 else if (2335 <= fuRunId && fuRunId <= 2497) {
379 parFileNameTof = "mTofCriParNickel.par";
380 }
381 else {
382 parFileNameTof = "mTofCriPar.par";
383 }
384 }
385 tofconfig->SetParFilesBasePath(parfilesbasepathTof);
386 tofconfig->SetParFileName(parFileNameTof);
387 tofconfig->SetSystemTimeOffset(-1220); // [ns] value to be updated
388 if (2160 <= fuRunId) {
389 tofconfig->SetSystemTimeOffset(0); // [ns] value to be updated
390 }
391 if (2350 <= fuRunId) {
392 tofconfig->SetSystemTimeOffset(45); // [ns] value to be updated
393 }
394 if (fuRunId <= 1659) {
396 tofconfig->SetFlagEpochCountHack2021();
397 }
398 }
399 } // if ("" != tofSetupTag)
400 // -------------
401 // ---- RICH ----
402 std::shared_ptr<CbmRichUnpackConfig> richconfig = nullptr;
403 TString richSetupTag = "";
404 cbmsetup->GetGeoTag(ECbmModuleId::kRich, richSetupTag);
405 if ("" != richSetupTag && fbUnpRich) {
406 LOG(info) << "From received setup, using RICH tag: " << richSetupTag;
407 richconfig = std::make_shared<CbmRichUnpackConfig>("", fuRunId);
408 if (richconfig) {
409 if (1904 < fuRunId) {
411 richconfig->SetUnpackerVersion(CbmRichUnpackerVersion::v03);
412 }
413 richconfig->DoTotOffsetCorrection(); // correct ToT offset
414 richconfig->SetDebugState();
415 richconfig->SetDoWriteOutput();
416 std::string parfilesbasepathRich = Form("%s/macro/beamtime/mcbm2024/", srcDir.Data());
417 richconfig->SetParFilesBasePath(parfilesbasepathRich);
418 richconfig->SetSystemTimeOffset(256000 - 1200); // [ns] 1 MS and additional correction
419 if (1904 < fuRunId) richconfig->SetSystemTimeOffset(-1200);
420 if (2160 <= fuRunId) {
421 richconfig->SetSystemTimeOffset(50); // [ns] value to be updated
422 }
423 if (2350 <= fuRunId) {
424 richconfig->SetSystemTimeOffset(100); // [ns] value to be updated
425 }
426 if (1588 == fuRunId) richconfig->MaskDiRICH(0x7150);
427 }
428 } // if ("" != richSetupTag)
429 // -------------
430 // ---- PSD ----
431 std::shared_ptr<CbmPsdUnpackConfig> psdconfig = nullptr;
432 TString psdSetupTag = "";
433 cbmsetup->GetGeoTag(ECbmModuleId::kPsd, psdSetupTag);
434 if ("" != psdSetupTag && fbUnpPsd) {
435 LOG(info) << "From received setup, using PSD tag: " << psdSetupTag;
436 psdconfig = std::make_shared<CbmPsdUnpackConfig>("", fuRunId);
437 if (psdconfig) {
438 // psdconfig->SetDebugState();
439 psdconfig->SetDoWriteOutput();
440 // psdconfig->SetDoWriteOptOutA("CbmPsdDsp");
441 std::string parfilesbasepathPsd = Form("%s/macro/beamtime/mcbm2021/", srcDir.Data());
442 psdconfig->SetParFilesBasePath(parfilesbasepathPsd);
443 psdconfig->SetSystemTimeOffset(0); // [ns] value to be updated
444 }
445 } // if ("" != psdSetupTag)
446 // -------------
447
449 if (stsconfig) SetUnpackConfig(stsconfig);
450 if (muchconfig) SetUnpackConfig(muchconfig);
451 if (trd1Dconfig) SetUnpackConfig(trd1Dconfig);
452 if (trdfasp2dconfig) SetUnpackConfig(trdfasp2dconfig);
453 if (tofconfig) SetUnpackConfig(tofconfig);
454 if (bmonconfig) SetUnpackConfig(bmonconfig);
455 if (richconfig) SetUnpackConfig(richconfig);
456 if (psdconfig) SetUnpackConfig(psdconfig);
457
459 for (std::vector<std::string>::iterator itStrOffs = fvsSetTimeOffs.begin(); itStrOffs != fvsSetTimeOffs.end();
460 ++itStrOffs) {
461 size_t charPosDel = (*itStrOffs).find(',');
462 if (std::string::npos == charPosDel) {
463 LOG(info) << "CbmDeviceUnpack::InitContainers => "
464 << "Trying to set trigger window with invalid option pattern, ignored! "
465 << " (Should be ECbmModuleId,dWinBeg,dWinEnd but instead found " << (*itStrOffs) << " )";
466 } // if( std::string::npos == charPosDel )
467
469 std::string sSelDet = (*itStrOffs).substr(0, charPosDel);
471 charPosDel++;
472 int32_t iOffset = std::stoi((*itStrOffs).substr(charPosDel));
473
474 if ("kBmon" == sSelDet && fBmonConfig) { //
475 fBmonConfig->SetSystemTimeOffset(iOffset);
476 } // else if( "kBmon" == sSelDet )
477 else if ("kSTS" == sSelDet && fStsConfig) { //
478 fStsConfig->SetSystemTimeOffset(iOffset);
479 } // if( "kSTS" == sSelDet && fStsConfig)
480 else if ("kMUCH" == sSelDet && fMuchConfig) {
481 fMuchConfig->SetSystemTimeOffset(iOffset);
482 } // else if( "kMUCH" == sSelDet )
483 else if ("kTRD" == sSelDet && fTrd1DConfig) {
484 fTrd1DConfig->SetSystemTimeOffset(iOffset);
485 } // else if( "kTRD" == sSelDet && fTrd2DConfig )
486 else if ("kTRD2D" == sSelDet && fTrd2DConfig) {
487 fTrd2DConfig->SetSystemTimeOffset(iOffset);
488 } // else if( "kTRD" == sSelDet && fTrd2DConfig )
489 else if ("kTOF" == sSelDet && fTofConfig) {
490 fTofConfig->SetSystemTimeOffset(iOffset);
491 } // else if( "kTOF" == sSelDet && fTofConfig)
492 else if ("kRICH" == sSelDet && fRichConfig) {
493 fRichConfig->SetSystemTimeOffset(iOffset);
494 } // else if( "kRICH" == sSelDet && fRichConfig)
495 else if ("kPSD" == sSelDet && fPsdConfig) {
496 fPsdConfig->SetSystemTimeOffset(iOffset);
497 } // else if( "kPSD" == sSelDet )
498 else {
499 LOG(info) << "CbmDeviceUnpack::InitContainers => Trying to set time "
500 "offset for unsupported detector, ignored! "
501 << (sSelDet);
502 continue;
503 } // else of detector enum detection
504 } // for( std::vector< std::string >::iterator itStrAdd = fvsAddDet.begin(); itStrAdd != fvsAddDet.end(); ++itStrAdd )
505
506 Bool_t initOK = kTRUE;
507 // --- Sts
508 if (fStsConfig) {
509 fStsConfig->InitOutput();
510 // RegisterOutputs( ioman, fStsConfig ); /// Framework bound work = kept in this Task
511 fStsConfig->SetDoIgnoreOverlappMs(fbIgnoreOverlapMs);
512 fStsConfig->SetAlgo();
513 initOK &= InitParameters(fStsConfig->GetParContainerRequest());
514 fStsConfig->InitAlgo();
515 // initPerformanceMaps(fkFlesSts, "STS");
516 }
517 // --- Much
518 if (fMuchConfig) {
519 fMuchConfig->InitOutput();
520 // RegisterOutputs(ioman, fMuchConfig); /// Framework bound work = kept in this Task
521 fMuchConfig->SetAlgo();
522 initOK &= InitParameters(fMuchConfig->GetParContainerRequest());
523 fMuchConfig->InitAlgo();
524 // initPerformanceMaps(fkFlesMuch, "MUCH");
525 }
526 // --- Trd
527 if (fTrd1DConfig) {
528 fTrd1DConfig->InitOutput();
529 // RegisterOutputs( ioman, fTrd1DConfig ); /// Framework bound work = kept in this Task
530 fTrd1DConfig->SetDoIgnoreOverlappMs(fbIgnoreOverlapMs);
531 fTrd1DConfig->SetAlgo();
532 initOK &= InitParameters(fTrd1DConfig->GetParContainerRequest());
533 fTrd1DConfig->InitAlgo();
534 // initPerformanceMaps(fkFlesTrd, "TRD1D");
535 }
536 // --- TRD2D
537 if (fTrd2DConfig) {
538 if (fTrd1DConfig && (fTrd2DConfig->GetOutputBranchName() == fTrd1DConfig->GetOutputBranchName())) {
539 LOG(info) << fTrd2DConfig->GetName() << "::Init() ---------------------------------";
540 fTrd2DConfig->SetOutputVec(fTrd1DConfig->GetOutputVec());
541 }
542 else {
543 fTrd2DConfig->InitOutput();
544 // RegisterOutputs( ioman, fTrd2DConfig ); /// Framework bound work = kept in this Task
545 }
546 fTrd2DConfig->SetDoIgnoreOverlappMs(fbIgnoreOverlapMs);
547 fTrd2DConfig->SetAlgo();
548 initOK &= InitParameters(fTrd2DConfig->GetParContainerRequest());
549 fTrd2DConfig->InitAlgo();
550 // initPerformanceMaps(fkFlesTrd2D, "TRD2D");
551 }
552 // This is an ugly work around, because the TRD and TRD2D want to access the same vector and there is no
553 // function to retrieve a writeable vector<obj> from the FairRootManager, especially before the branches
554 // are created, as far as I am aware.
555 // The second option workaround is in in Init() to look for the fasp config and create a separate branch
556 // for fasp created CbmTrdDigis PR 072021
557 // --- Tof
558 if (fTofConfig) {
559 fTofConfig->InitOutput();
560 // RegisterOutputs( ioman, fTofConfig ); /// Framework bound work = kept in this Task
561 fTofConfig->SetDoIgnoreOverlappMs(fbIgnoreOverlapMs);
562 fTofConfig->SetAlgo();
563 initOK &= InitParameters(fTofConfig->GetParContainerRequest());
564 LOG(info) << "TOF call InitAlgo()";
565 fTofConfig->InitAlgo();
566 // initPerformanceMaps(fkFlesTof, "TOF");
567 }
568 // --- Bmon
569 if (fBmonConfig) {
570 fBmonConfig->InitOutput();
571 // RegisterOutputs(ioman, fBmonConfig); /// Framework bound work = kept in this Task
572 fBmonConfig->SetAlgo();
573 fBmonConfig->LoadParFileName();
574 initOK &= InitParameters(fBmonConfig->GetParContainerRequest());
575 fBmonConfig->InitAlgo();
576 // initPerformanceMaps(fkFlesBmon, "Bmon");
577 }
578 // --- Rich
579 if (fRichConfig) {
580 fRichConfig->InitOutput();
581 // RegisterOutputs( ioman, fRichConfig ); /// Framework bound work = kept in this Task
582 fRichConfig->SetDoIgnoreOverlappMs(fbIgnoreOverlapMs);
583 fRichConfig->SetAlgo();
584 initOK &= InitParameters(fRichConfig->GetParContainerRequest());
585 fRichConfig->InitAlgo();
586 // initPerformanceMaps(fkFlesRich, "RICH");
587 }
588 // --- Psd
589 if (fPsdConfig) {
590 fPsdConfig->InitOutput();
591 // RegisterOutputs( ioman, fPsdConfig ); /// Framework bound work = kept in this Task
592 fPsdConfig->SetDoIgnoreOverlappMs(fbIgnoreOverlapMs);
593 fPsdConfig->SetAlgo();
594 initOK &= InitParameters(fPsdConfig->GetParContainerRequest());
595 fPsdConfig->InitAlgo();
596 // initPerformanceMaps(fkFlesPsd, "PSD");
597 }
598
601
602 return initOK;
603}
604
605Bool_t
606CbmDeviceUnpack::InitParameters(std::vector<std::pair<std::string, std::shared_ptr<FairParGenericSet>>>* reqparvec)
607{
608 LOG(info) << "CbmDeviceUnpack::InitParameters";
609 if (!reqparvec) {
610 LOG(info) << "CbmDeviceUnpack::InitParameters - empty requirements vector no parameters initialized.";
611 return kTRUE;
612 }
613
614 // Now get the actual ascii files and init the containers with the asciiIo
615 for (auto& pair : *reqparvec) {
616 /*
617 auto filepath = pair.first;
618 auto parset = pair.second;
619 FairParAsciiFileIo asciiInput;
620 if (!filepath.empty()) {
621 if (asciiInput.open(filepath.data())) { parset->init(&asciiInput); }
622 }
623 * */
624 std::string paramName {pair.second->GetName()};
625 // NewSimpleMessage creates a copy of the data and takes care of its destruction (after the transfer takes place).
626 // Should only be used for small data because of the cost of an additional copy
627
628 // Here must come the proper Runid
629 std::string message = paramName + ",111";
630 LOG(info) << "Requesting parameter container " << paramName << ", sending message: " << message;
631
632 FairMQMessagePtr req(NewSimpleMessage(message));
633 FairMQMessagePtr rep(NewMessage());
634
635 FairParGenericSet* newObj = nullptr;
636
637 if (Send(req, "parameters") > 0) {
638 if (Receive(rep, "parameters") >= 0) {
639 if (0 != rep->GetSize()) {
640 CbmMqTMessage tmsg(rep->GetData(), rep->GetSize());
641 newObj = static_cast<FairParGenericSet*>(tmsg.ReadObject(tmsg.GetClass()));
642 LOG(info) << "Received unpack parameter from the server: " << newObj->GetName();
643 newObj->print();
644 } // if( 0 != rep->GetSize() )
645 else {
646 LOG(error) << "Received empty reply. Parameter not available";
647 return kFALSE;
648 } // else of if( 0 != rep->GetSize() )
649 } // if( Receive( rep, "parameters" ) >= 0)
650 } // if( Send(req, "parameters") > 0 )
651 pair.second.reset(newObj);
652 //delete newObj;
653 }
654 return kTRUE;
655}
656
658{
661 // ALGO: bool initOK = fMonitorAlgo->CreateHistograms();
662 bool initOK = true;
663
665 // ALGO: std::vector<std::pair<TNamed*, std::string>> vHistos = fMonitorAlgo->GetHistoVector();
666 std::vector<std::pair<TNamed*, std::string>> vHistos = {};
668 // ALGO: std::vector<std::pair<TCanvas*, std::string>> vCanvases = fMonitorAlgo->GetCanvasVector();
669 std::vector<std::pair<TCanvas*, std::string>> vCanvases = {};
670
675 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
676 // LOG(info) << "Registering " << vHistos[ uHisto ].first->GetName()
677 // << " in " << vHistos[ uHisto ].second.data()
678 // ;
679 fArrayHisto.Add(vHistos[uHisto].first);
680 std::pair<std::string, std::string> psHistoConfig(vHistos[uHisto].first->GetName(), vHistos[uHisto].second);
681 fvpsHistosFolder.push_back(psHistoConfig);
682
683 LOG(info) << "Config of hist " << psHistoConfig.first.data() << " in folder " << psHistoConfig.second.data();
684 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
685
689 for (UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv) {
690 // LOG(info) << "Registering " << vCanvases[ uCanv ].first->GetName()
691 // << " in " << vCanvases[ uCanv ].second.data();
692 std::string sCanvName = (vCanvases[uCanv].first)->GetName();
693 std::string sCanvConf = GenerateCanvasConfigString(vCanvases[uCanv].first);
694
695 std::pair<std::string, std::string> psCanvConfig(sCanvName, sCanvConf);
696
697 fvpsCanvasConfig.push_back(psCanvConfig);
698
699 LOG(info) << "Config string of Canvas " << psCanvConfig.first.data() << " is " << psCanvConfig.second.data();
700 } // for( UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv )
701
702 return initOK;
703}
704
705// Method called by run loop and requesting new data from the TS source whenever
707{
709 if (0 == fulNumMessages) {
710 try {
712 }
713 catch (InitTaskError& e) {
714 LOG(error) << e.what();
715 ChangeState(fair::mq::Transition::ErrorFound);
716 }
717 } // if( 0 == fulNumMessages)
718
719 if (0 == fulNumMessages) InitHistograms();
720
722 std::string message = "full";
723 LOG(debug) << "Requesting new TS by sending message: full" << message;
724 FairMQMessagePtr req(NewSimpleMessage(message));
725 FairMQMessagePtr rep(NewMessage());
726
727 if (Send(req, fsChannelNameDataInput) <= 0) {
728 LOG(error) << "Failed to send the request! message was " << message;
729 return false;
730 } // if (Send(req, fsChannelNameDataInput) <= 0)
731 else if (Receive(rep, fsChannelNameDataInput) < 0) {
732 LOG(error) << "Failed to receive a reply to the request! message was " << message;
733 return false;
734 } // else if (Receive(rep, fsChannelNameDataInput) < 0)
735 else if (rep->GetSize() == 0) {
736 LOG(error) << "Received empty reply. Something went wrong with the timeslice generation! message was " << message;
737 return false;
738 } // else if (rep->GetSize() == 0)
739
741 LOG(debug) << "Received message number " << fulNumMessages << " with size " << rep->GetSize();
742
743 if (0 == fulNumMessages % 10000) LOG(info) << "Received " << fulNumMessages << " messages";
744
745 std::string msgStr(static_cast<char*>(rep->GetData()), rep->GetSize());
746 std::istringstream iss(msgStr);
747 boost::archive::binary_iarchive inputArchive(iss);
748
750 fles::StorableTimeslice ts {0};
751 inputArchive >> ts;
752
754 if (-1.0 == fdTsCoreSizeInNs) {
755 fuNbCoreMsPerTs = ts.num_core_microslices();
756 fuNbOverMsPerTs = ts.num_microslices(0) - ts.num_core_microslices();
757 fdMsSizeInNs = (ts.descriptor(0, fuNbCoreMsPerTs).idx - ts.descriptor(0, 0).idx) / fuNbCoreMsPerTs;
761 LOG(info) << "Timeslice parameters: each TS has " << fuNbCoreMsPerTs << " Core MS and " << fuNbOverMsPerTs
762 << " Overlap MS, for a MS duration of " << fdMsSizeInNs << " ns, a core duration of " << fdTsCoreSizeInNs
763 << " ns and a full duration of " << fdTsFullSizeInNs << " ns";
764 fTsMetaData = new TimesliceMetaData(ts.descriptor(0, 0).idx, fdTsCoreSizeInNs, fdTsOverSizeInNs, ts.index());
765 } // if( -1.0 == fdTsCoreSizeInNs )
766 else {
768 fTsMetaData->SetStartTime(ts.descriptor(0, 0).idx);
769 fTsMetaData->SetIndex(ts.index());
770 }
771
773 DoUnpack(ts, 0);
774
775 LOG(debug) << "Unpack: Sending TS index " << ts.index();
777 if (!SendUnpData()) return false;
778 LOG(debug) << "Unpack: Sent TS index " << ts.index();
779
780 // Reset the event header for a new timeslice
782
783 // Reset the unpackers for a new timeslice, e.g. clear the output vectors
784 // ---- Bmon ----
785 if (fBmonConfig) fBmonConfig->Reset();
786 // ---- Sts ----
787 if (fStsConfig) fStsConfig->Reset();
788 // ----Much ----
789 if (fMuchConfig) fMuchConfig->Reset();
790 // ---- Trd ----
791 if (fTrd1DConfig) fTrd1DConfig->Reset();
792 // ---- Trd2D ----
793 if (fTrd2DConfig) fTrd2DConfig->Reset();
794 // ---- Tof ----
795 if (fTofConfig) fTofConfig->Reset();
796 // ---- Rich ----
797 if (fRichConfig) fRichConfig->Reset();
798 // ---- Psd ----
799 if (fPsdConfig) fPsdConfig->Reset();
800
804 std::chrono::system_clock::time_point currentTime = std::chrono::system_clock::now();
805 std::chrono::duration<double_t> elapsedSeconds = currentTime - fLastPublishTime;
806 if ((fdMaxPublishTime < elapsedSeconds.count())
807 || (0 == fulNumMessages % fuPublishFreqTs && fdMinPublishTime < elapsedSeconds.count())) {
808 if (!fbConfigSent) {
809 // Send the configuration only once per run!
811 } // if( !fbConfigSent )
812 else
814
815 fLastPublishTime = std::chrono::system_clock::now();
816 } // if( ( fdMaxPublishTime < elapsedSeconds.count() ) || ( 0 == fulNumMessages % fuPublishFreqTs && fdMinPublishTime < elapsedSeconds.count() ) )
817
818 return true;
819}
820
822{
823 FairMQParts parts;
824
826 FairMQMessagePtr messTsHeader(NewMessage());
827 // Serialize<RootSerializer>(*messTsHeader, fCbmTsEventHeader);
828 RootSerializer().Serialize(*messTsHeader, fCbmTsEventHeader);
829
830 parts.AddPart(std::move(messTsHeader));
831
832 // ---- Bmon ----
833 std::stringstream ossBmon;
834 boost::archive::binary_oarchive oaBmon(ossBmon);
835 if (fBmonConfig) { //
836 oaBmon << *(fBmonConfig->GetOutputVec());
837 }
838 else {
839 oaBmon << (std::vector<CbmBmonDigi>());
840 }
841 std::string* strMsgBmon = new std::string(ossBmon.str());
842
843 parts.AddPart(NewMessage(
844 const_cast<char*>(strMsgBmon->c_str()), // data
845 strMsgBmon->length(), // size
846 [](void*, void* object) { delete static_cast<std::string*>(object); },
847 strMsgBmon)); // object that manages the data
848
849 // ---- Sts ----
850 std::stringstream ossSts;
851 boost::archive::binary_oarchive oaSts(ossSts);
852 if (fStsConfig) { //
853 oaSts << *(fStsConfig->GetOutputVec());
854 }
855 else {
856 oaSts << (std::vector<CbmStsDigi>());
857 }
858 std::string* strMsgSts = new std::string(ossSts.str());
859
860 parts.AddPart(NewMessage(
861 const_cast<char*>(strMsgSts->c_str()), // data
862 strMsgSts->length(), // size
863 [](void*, void* object) { delete static_cast<std::string*>(object); },
864 strMsgSts)); // object that manages the data
865
866 // ---- Much ----
867 std::stringstream ossMuch;
868 boost::archive::binary_oarchive oaMuch(ossMuch);
869 if (fMuchConfig) { //
870 oaMuch << *(fMuchConfig->GetOutputVec());
871 }
872 else {
873 oaMuch << (std::vector<CbmMuchDigi>());
874 }
875 std::string* strMsgMuch = new std::string(ossMuch.str());
876
877 parts.AddPart(NewMessage(
878 const_cast<char*>(strMsgMuch->c_str()), // data
879 strMsgMuch->length(), // size
880 [](void*, void* object) { delete static_cast<std::string*>(object); },
881 strMsgMuch)); // object that manages the data
882
883
884 // ---- Trd ----
885 std::stringstream ossTrd;
886 boost::archive::binary_oarchive oaTrd(ossTrd);
887 if (fTrd1DConfig || fTrd2DConfig) { //
888 oaTrd << *(fTrd1DConfig ? fTrd1DConfig->GetOutputVec() : fTrd2DConfig->GetOutputVec());
889 }
890 else {
891 oaTrd << (std::vector<CbmTrdDigi>());
892 }
893 std::string* strMsgTrd = new std::string(ossTrd.str());
894
895 parts.AddPart(NewMessage(
896 const_cast<char*>(strMsgTrd->c_str()), // data
897 strMsgTrd->length(), // size
898 [](void*, void* object) { delete static_cast<std::string*>(object); },
899 strMsgTrd)); // object that manages the data
900
901 // ---- Tof ----
902 std::stringstream ossTof;
903 boost::archive::binary_oarchive oaTof(ossTof);
904 if (fTofConfig) { //
905 oaTof << *(fTofConfig->GetOutputVec());
906 }
907 else {
908 oaTof << (std::vector<CbmTofDigi>());
909 }
910 std::string* strMsgTof = new std::string(ossTof.str());
911
912 parts.AddPart(NewMessage(
913 const_cast<char*>(strMsgTof->c_str()), // data
914 strMsgTof->length(), // size
915 [](void*, void* object) { delete static_cast<std::string*>(object); },
916 strMsgTof)); // object that manages the data
917
918 // ---- Rich ----
919 std::stringstream ossRich;
920 boost::archive::binary_oarchive oaRich(ossRich);
921 if (fRichConfig) { //
922 oaRich << *(fRichConfig->GetOutputVec());
923 }
924 else {
925 oaRich << (std::vector<CbmRichDigi>());
926 }
927 std::string* strMsgRich = new std::string(ossRich.str());
928
929 parts.AddPart(NewMessage(
930 const_cast<char*>(strMsgRich->c_str()), // data
931 strMsgRich->length(), // size
932 [](void*, void* object) { delete static_cast<std::string*>(object); },
933 strMsgRich)); // object that manages the data
934
935 // ---- Psd ----
936 std::stringstream ossPsd;
937 boost::archive::binary_oarchive oaPsd(ossPsd);
938 if (fPsdConfig) { //
939 oaPsd << *(fPsdConfig->GetOutputVec());
940 }
941 else {
942 oaPsd << (std::vector<CbmPsdDigi>());
943 }
944 std::string* strMsgPsd = new std::string(ossPsd.str());
945
946 parts.AddPart(NewMessage(
947 const_cast<char*>(strMsgPsd->c_str()), // data
948 strMsgPsd->length(), // size
949 [](void*, void* object) { delete static_cast<std::string*>(object); },
950 strMsgPsd)); // object that manages the data
951
955 FairMQMessagePtr messTsMeta(NewMessage());
956 // Serialize<RootSerializer>(*messTsMeta, fTsMetaData);
957 RootSerializer().Serialize(*messTsMeta, fTsMetaData);
958 parts.AddPart(std::move(messTsMeta));
959
960 if (Send(parts, fsChannelNameDataOutput) < 0) {
961 LOG(error) << "Problem sending data to " << fsChannelNameDataOutput;
962 return false;
963 }
964
965 return true;
966}
967
968
970{
972 std::pair<uint32_t, uint32_t> pairHeader(fvpsHistosFolder.size(), fvpsCanvasConfig.size());
973 FairMQMessagePtr messageHeader(NewMessage());
974 // Serialize<BoostSerializer<std::pair<uint32_t, uint32_t>>>(*messageHeader, pairHeader);
975 BoostSerializer<std::pair<uint32_t, uint32_t>>().Serialize(*messageHeader, pairHeader);
976 FairMQParts partsOut;
977 partsOut.AddPart(std::move(messageHeader));
978
979 for (UInt_t uHisto = 0; uHisto < fvpsHistosFolder.size(); ++uHisto) {
981 FairMQMessagePtr messageHist(NewMessage());
982 // Serialize<BoostSerializer<std::pair<std::string, std::string>>>(*messageHist, fvpsHistosFolder[uHisto]);
983 BoostSerializer<std::pair<std::string, std::string>>().Serialize(*messageHist, fvpsHistosFolder[uHisto]);
984
985 partsOut.AddPart(std::move(messageHist));
986 } // for (UInt_t uHisto = 0; uHisto < fvpsHistosFolder.size(); ++uHisto)
987
990 if (0 == fvpsHistosFolder.size()) {
991 FairMQMessagePtr messageHist(NewMessage());
992 partsOut.AddPart(std::move(messageHist));
993 }
994
995 for (UInt_t uCanv = 0; uCanv < fvpsCanvasConfig.size(); ++uCanv) {
997 FairMQMessagePtr messageCan(NewMessage());
998 // Serialize<BoostSerializer<std::pair<std::string, std::string>>>(*messageCan, fvpsCanvasConfig[uCanv]);
999 BoostSerializer<std::pair<std::string, std::string>>().Serialize(*messageCan, fvpsCanvasConfig[uCanv]);
1000
1001 partsOut.AddPart(std::move(messageCan));
1002 } // for (UInt_t uCanv = 0; uCanv < fvpsCanvasConfig.size(); ++uCanv)
1003
1006 if (0 == fvpsCanvasConfig.size()) {
1007 FairMQMessagePtr messageHist(NewMessage());
1008 partsOut.AddPart(std::move(messageHist));
1009 }
1010
1012 FairMQMessagePtr msgHistos(NewMessage());
1013 // Serialize<RootSerializer>(*msgHistos, &fArrayHisto);
1014 RootSerializer().Serialize(*msgHistos, &fArrayHisto);
1015 partsOut.AddPart(std::move(msgHistos));
1016
1018 if (Send(partsOut, fsChannelNameHistosInput) < 0) {
1019 LOG(error) << "CbmTsConsumerReqDevExample::SendHistoConfAndData => Problem sending data";
1020 return false;
1021 } // if( Send( partsOut, fsChannelNameHistosInput ) < 0 )
1022
1024 // ALGO: fMonitorAlgo->ResetHistograms(kFALSE);
1025
1026 return true;
1027}
1028
1030{
1032 FairMQMessagePtr message(NewMessage());
1033 // Serialize<RootSerializer>(*message, &fArrayHisto);
1034 RootSerializer().Serialize(*message, &fArrayHisto);
1035
1037 if (Send(message, fsChannelNameHistosInput) < 0) {
1038 LOG(error) << "Problem sending data";
1039 return false;
1040 } // if( Send( message, fsChannelNameHistosInput ) < 0 )
1041
1043 // ALGO: fMonitorAlgo->ResetHistograms(kFALSE);
1044
1045 return true;
1046}
1047
1048
1050{
1051 if (fBmonConfig) fBmonConfig->GetUnpacker()->Finish();
1052 if (fStsConfig) fStsConfig->GetUnpacker()->Finish();
1053 if (fMuchConfig) fMuchConfig->GetUnpacker()->Finish();
1054 if (fTrd1DConfig) fTrd1DConfig->GetUnpacker()->Finish();
1055 if (fTrd2DConfig) fTrd2DConfig->GetUnpacker()->Finish();
1056 if (fTofConfig) fTofConfig->GetUnpacker()->Finish();
1057 if (fRichConfig) fRichConfig->GetUnpacker()->Finish();
1058 if (fPsdConfig) fPsdConfig->GetUnpacker()->Finish();
1059}
1060
1061Bool_t CbmDeviceUnpack::DoUnpack(const fles::Timeslice& ts, size_t /*component*/)
1062{
1063 fulTsCounter++;
1064 // Prepare timeslice
1065 // const fles::Timeslice& timeslice = *ts;
1066
1067 fCbmTsEventHeader->SetTsIndex(ts.index());
1068 fCbmTsEventHeader->SetTsStartTime(ts.start_time());
1069
1070 uint64_t nComponents = ts.num_components();
1071 // if (fDoDebugPrints) LOG(info) << "Unpack: TS index " << ts.index() << " components " << nComponents;
1072 LOG(debug) << "Unpack: TS index " << ts.index() << " components " << nComponents;
1073
1074 for (uint64_t component = 0; component < nComponents; component++) {
1075 auto systemId = static_cast<std::uint16_t>(ts.descriptor(component, 0).sys_id);
1076
1077 switch (systemId) {
1078 case fkFlesBmon: {
1079 if (fBmonConfig) {
1081 unpack(systemId, &ts, component, fBmonConfig, fBmonConfig->GetOptOutAVec(), fBmonConfig->GetOptOutBVec()));
1082 }
1083 break;
1084 }
1085 case fkFlesSts: {
1086 if (fStsConfig) {
1088 unpack(systemId, &ts, component, fStsConfig, fStsConfig->GetOptOutAVec(), fStsConfig->GetOptOutBVec()));
1089 }
1090 break;
1091 }
1092 case fkFlesMuch: {
1093 if (fMuchConfig) {
1095 unpack(systemId, &ts, component, fMuchConfig, fMuchConfig->GetOptOutAVec(), fMuchConfig->GetOptOutBVec()));
1096 }
1097 break;
1098 }
1099 case fkFlesTrd: {
1100 if (fTrd1DConfig) {
1101 fCbmTsEventHeader->AddNDigisTrd1D(unpack(systemId, &ts, component, fTrd1DConfig,
1102 fTrd1DConfig->GetOptOutAVec(), fTrd1DConfig->GetOptOutBVec()));
1103 }
1104 break;
1105 }
1106 case fkFlesTrd2D: {
1107 if (fTrd2DConfig) {
1108 fCbmTsEventHeader->AddNDigisTrd2D(unpack(systemId, &ts, component, fTrd2DConfig,
1109 fTrd2DConfig->GetOptOutAVec(), fTrd2DConfig->GetOptOutBVec()));
1110 }
1111 break;
1112 }
1113 case fkFlesTof: {
1114 if (fTofConfig) {
1116 unpack(systemId, &ts, component, fTofConfig, fTofConfig->GetOptOutAVec(), fTofConfig->GetOptOutBVec()));
1117 }
1118 break;
1119 }
1120 case fkFlesRich: {
1121 if (fRichConfig) {
1123 unpack(systemId, &ts, component, fRichConfig, fRichConfig->GetOptOutAVec(), fRichConfig->GetOptOutBVec()));
1124 }
1125 break;
1126 }
1127 case fkFlesPsd: {
1128 if (fPsdConfig) {
1130 unpack(systemId, &ts, component, fPsdConfig, fPsdConfig->GetOptOutAVec(), fPsdConfig->GetOptOutBVec()));
1131 }
1132 break;
1133 }
1134 default: {
1135 if (fDoDebugPrints) LOG(error) << "Unpack: Unknown system ID " << systemId << " for component " << component;
1136 break;
1137 }
1138 }
1139 }
1140
1143 if (fBmonConfig && fBmonConfig->GetOutputVec()) { timesort(fBmonConfig->GetOutputVec()); }
1144 if (fStsConfig && fStsConfig->GetOutputVec()) { timesort(fStsConfig->GetOutputVec()); }
1145 if (fMuchConfig && fMuchConfig->GetOutputVec()) { timesort(fMuchConfig->GetOutputVec()); }
1146 if (fTrd1DConfig && fTrd1DConfig->GetOutputVec()) { timesort(fTrd1DConfig->GetOutputVec()); }
1147 if (fTrd2DConfig && fTrd2DConfig->GetOutputVec()) { timesort(fTrd2DConfig->GetOutputVec()); }
1148 if (fTofConfig && fTofConfig->GetOutputVec()) { timesort(fTofConfig->GetOutputVec()); }
1149 if (fRichConfig && fRichConfig->GetOutputVec()) { timesort(fRichConfig->GetOutputVec()); }
1150 if (fPsdConfig && fPsdConfig->GetOutputVec()) { timesort(fPsdConfig->GetOutputVec()); }
1151
1153 if (fBmonConfig && fBmonConfig->GetOptOutAVec()) { timesort(fBmonConfig->GetOptOutAVec()); }
1154 if (fStsConfig && fStsConfig->GetOptOutAVec()) { timesort(fStsConfig->GetOptOutAVec()); }
1155 if (fMuchConfig && fMuchConfig->GetOptOutAVec()) { timesort(fMuchConfig->GetOptOutAVec()); }
1156 if (fTrd1DConfig && fTrd1DConfig->GetOptOutAVec()) { timesort(fTrd1DConfig->GetOptOutAVec()); }
1157 if (fTrd2DConfig && fTrd2DConfig->GetOptOutAVec()) { timesort(fTrd2DConfig->GetOptOutAVec()); }
1158 if (fTofConfig && fTofConfig->GetOptOutAVec()) { timesort(fTofConfig->GetOptOutAVec()); }
1159 if (fRichConfig && fRichConfig->GetOptOutAVec()) { timesort(fRichConfig->GetOptOutAVec()); }
1160 if (fPsdConfig && fPsdConfig->GetOptOutAVec()) { timesort(fPsdConfig->GetOptOutAVec()); }
1161 }
1162
1163 if (0 == fulTsCounter % 10000) LOG(info) << "Processed " << fulTsCounter << " time slices";
1164
1165 return kTRUE;
1166}
1171std::shared_ptr<CbmTrdSpadic> CbmDeviceUnpack::GetTrdSpadic(bool useAvgBaseline)
1172{
1173 auto spadic = std::make_shared<CbmTrdSpadic>();
1174 spadic->SetUseBaselineAverage(useAvgBaseline);
1175 spadic->SetMaxAdcToEnergyCal(1.0);
1176
1177 return spadic;
1178}
1179
@ kTrd
Transition Radiation Detector.
@ kTof
Time-of-flight Detector.
@ kPsd
Projectile spectator detector.
@ kSts
Silicon Tracking System.
@ kMuch
Muon detection system.
@ kRich
Ring-Imaging Cherenkov Detector.
std::string GenerateCanvasConfigString(TCanvas *pCanv)
Configuration class for an unpacker algorithm.
Configuration class for an unpacker algorithm.
Configuration class for an unpacker algorithm.
Configuration class for an unpacker algorithm.
Configuration class for an unpacker algorithm.
Configuration class for an unpacker algorithm.
Configuration class for an unpacker algorithm.
bool first
bool fDoDebugPrints
Flag if extended debug output is to be printed or not.
std::string fsChannelNameDataInput
message queues
static constexpr std::uint16_t fkFlesMuch
static constexpr std::uint16_t fkFlesTrd
CbmTsEventHeader * fCbmTsEventHeader
Pointer to the Timeslice header conatining start time and index.
std::shared_ptr< CbmTofUnpackConfig > fTofConfig
std::shared_ptr< CbmBmonUnpackConfig > fBmonConfig
Configuration of the unpackers. Provides the configured algorithm.
uint32_t fuPublishFreqTs
Histograms management.
static constexpr std::uint16_t fkFlesBmon
Constants.
std::chrono::system_clock::time_point fLastPublishTime
static constexpr std::uint16_t fkFlesTrd2D
std::vector< std::pair< std::string, std::string > > fvpsCanvasConfig
uint64_t fulNumMessages
Statistics & first TS rejection.
TObjArray fArrayHisto
Array of histograms to send to the histogram server.
std::shared_ptr< CbmPsdUnpackConfig > fPsdConfig
Bool_t fbIgnoreOverlapMs
Control flags.
void SetUnpackConfig(std::shared_ptr< CbmBmonUnpackConfig > config)
Set the Bmon Unpack Config.
std::vector< std::pair< std::string, std::string > > fvpsHistosFolder
Vector of string pairs with ( HistoName, FolderPath ) to send to the histogram server.
size_t fuNbCoreMsPerTs
TS MetaData storage: stable so should be moved somehow to parameters handling (not transmitted with e...
static constexpr std::uint16_t fkFlesSts
std::shared_ptr< CbmMuchUnpackConfig > fMuchConfig
static constexpr std::uint16_t fkFlesPsd
TimesliceMetaData * fTsMetaData
Total size of all MS in a TS, [nanoseconds].
Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
std::enable_if< std::is_same< TVecobj, std::nullptr_t >::value==true, void >::type timesort(std::vector< TVecobj > *)
Sort a vector timewise vector type has to provide GetTime()
std::shared_ptr< CbmTrdSpadic > GetTrdSpadic(bool useAvgBaseline)
Get the Trd Spadic.
std::vector< std::string > fvsSetTimeOffs
Time offsets.
std::shared_ptr< CbmTrdUnpackConfig > fTrd1DConfig
virtual void InitTask()
size_t unpack(const std::uint16_t subsysid, const fles::Timeslice *ts, std::uint16_t icomp, TConfig config, std::vector< TOptOutA > *optouttargetvecA=nullptr, std::vector< TOptOutB > *optouttargetvecB=nullptr)
Template for the unpacking call of a given algorithm.
static constexpr std::uint16_t fkFlesTof
bool fbConfigSent
Flag indicating whether the histograms and canvases configurations were already published.
Double_t fdTsOverSizeInNs
Total size of the core MS in a TS, [nanoseconds].
double_t fdMinPublishTime
std::shared_ptr< CbmStsUnpackConfig > fStsConfig
double_t fdMaxPublishTime
static constexpr std::uint16_t fkFlesRich
std::shared_ptr< CbmRichUnpackConfig > fRichConfig
std::string fsChannelNameDataOutput
std::string fsChannelNameHistosInput
Double_t fdTsCoreSizeInNs
Size of a single MS, [nanoseconds].
Bool_t InitParameters(std::vector< std::pair< std::string, std::shared_ptr< FairParGenericSet > > > *reqparvec)
Parameters management.
bool fbOutputFullTimeSorting
Flag to Enable/disable a full time sorting. If off, time sorting happens per link/FLIM source.
bool fbUnpBmon
---> for selective unpacking
std::shared_ptr< CbmTrdUnpackFaspConfig > fTrd2DConfig
std::string fsSetupName
User settings parameters.
Double_t fdTsFullSizeInNs
Total size of the overlap MS in a TS, [nanoseconds].
void LoadStoredSetup(CbmSetupStorable *setupIn)
Definition CbmSetup.cxx:46
Bool_t GetGeoTag(ECbmModuleId moduleId, TString &tag)
Definition CbmSetup.cxx:127
static CbmSetup * Instance()
Definition CbmSetup.cxx:160
Parameters of the STS readout ASIC.
Parameters for one STS module.
void AddNDigisTof(uint64_t value)
Add a number of digis from this Ts.
void AddNDigisMuch(uint64_t value)
Add a number of digis from this Ts.
void AddNDigisTrd1D(uint64_t value)
Add a number of digis from this Ts.
void AddNDigisBmon(uint64_t value)
Add a number of digis from this Ts.
void AddNDigisPsd(uint64_t value)
Add a number of digis from this Ts.
void AddNDigisSts(uint64_t value)
Add a number of digis from this Ts.
void Reset()
Resets counters and variables for a new Timeslice, e.g. the NDigis counter are set back to 0.
void AddNDigisRich(uint64_t value)
Add a number of digis from this Ts.
void SetTsStartTime(uint64_t value)
Set the Ts Start Time.
void AddNDigisTrd2D(uint64_t value)
Add a number of digis from this Ts.
void SetTsIndex(uint64_t value)
Set the Ts Start Time.
void SetStartTime(uint64_t ulStart)
void SetIndex(uint64_t ulIdx)
void ChangeState(FairMQDevice *device, cbm::mq::Transition transition)
Definition CbmMQDefs.h:26
Hash for CbmL1LinkKey.