CbmRoot
Loading...
Searching...
No Matches
CbmCosy2019UnpackerTaskHodo.cxx
Go to the documentation of this file.
1/* Copyright (C) 2019-2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pierre-Alain Loizeau, Florian Uhlig [committer] */
4
5// -----------------------------------------------------------------------------
6// ----- -----
7// ----- CbmCosy2019UnpackerTaskHodo -----
8// ----- Created 31/07/19 by P.-A. Loizeau -----
9// ----- -----
10// -----------------------------------------------------------------------------
11
13
14#include "CbmCosy2019HodoPar.h"
16
17//#include "CbmMcbm2018StsPar.h"
19
20#include "FairParGenericSet.h"
21#include "FairRootManager.h"
22#include "FairRun.h"
23#include "FairRunOnline.h"
24#include "FairRuntimeDb.h"
25#include <Logger.h>
26
27#include "TClonesArray.h"
28#include "THttpServer.h"
29#include "TROOT.h"
30#include "TString.h"
31#include <TFile.h>
32
33#include <chrono>
34#include <fstream>
35#include <iomanip>
36#include <iostream>
37
38#include <stdint.h>
39
41
44 , fbMonitorMode(kFALSE)
45 , fbWriteOutput(kTRUE)
46 , fvChanMasks()
47 , fulTsCounter(0)
48 , fUnpackerAlgo(nullptr)
49{
52}
53
59
61{
62 LOG(info) << "CbmCosy2019UnpackerTaskHodo::Init";
63 LOG(info) << "Initializing mCBM STS 2018 Unpacker";
64
65 FairRootManager* ioman = FairRootManager::Instance();
66 if (NULL == ioman) { LOG(fatal) << "No FairRootManager instance"; }
68 if (nullptr != ioman->InitObjectAs<std::vector<CbmStsDigi> const*>("StsDigi"))
69 LOG(fatal) << "CbmCosy2019UnpackerTaskHodo::Init => output vector already "
70 "registered,"
71 << " probably by CbmMcbm2018UnpackerTaskSts" << std::endl
72 << " THESE TWO CLASSES ARE INCOMPATIBLE!";
73
75 fpvDigiSts = new std::vector<CbmStsDigi>();
76 ioman->RegisterAny("StsDigi", fpvDigiSts, fbWriteOutput);
77
79 fpvErrorSts = new std::vector<CbmErrorMessage>();
80 ioman->RegisterAny("CbmStsError", fpvErrorSts, fbWriteOutput);
81
82 return kTRUE;
83}
84
86{
87 LOG(info) << "Setting parameter containers for " << GetName();
88
89 TList* fParCList = fUnpackerAlgo->GetParList();
90
91 for (Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC) {
92 FairParGenericSet* tempObj = (FairParGenericSet*) (fParCList->At(iparC));
93 fParCList->Remove(tempObj);
94
95 std::string sParamName {tempObj->GetName()};
96 FairParGenericSet* newObj =
97 dynamic_cast<FairParGenericSet*>(FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
98
99 if (nullptr == newObj) {
100 LOG(error) << "Failed to obtain parameter container " << sParamName << ", for parameter index " << iparC;
101 return;
102 } // if( nullptr == newObj )
103
104 fParCList->AddAt(newObj, iparC);
105 // delete tempObj;
106 } // for( Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC )
107
108 fParCList = fUnpackerAlgoSts->GetParList();
109
110 for (Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC) {
111 FairParGenericSet* tempObj = (FairParGenericSet*) (fParCList->At(iparC));
112 fParCList->Remove(tempObj);
113
114 std::string sParamName {tempObj->GetName()};
115 FairParGenericSet* newObj =
116 dynamic_cast<FairParGenericSet*>(FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
117
118 if (nullptr == newObj) {
119 LOG(error) << "Failed to obtain parameter container " << sParamName << ", for parameter index " << iparC;
120 return;
121 } // if( nullptr == newObj )
122
123 fParCList->AddAt(newObj, iparC);
124 // delete tempObj;
125 } // for( Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC )
126}
127
129{
130 LOG(info) << "Init parameter containers for " << GetName();
131
133 CbmCosy2019HodoPar* pUnpackPar =
134 dynamic_cast<CbmCosy2019HodoPar*>(FairRun::Instance()->GetRuntimeDb()->getContainer("CbmCosy2019HodoPar"));
135 if (nullptr == pUnpackPar) {
136 LOG(error) << "Failed to obtain parameter container CbmCosy2019HodoPar";
137 return kFALSE;
138 } // if( nullptr == pUnpackPar )
139 /*
140 fbMonitorMode = pUnpackPar->GetMonitorMode();
141 LOG(info) << "Monitor mode: "
142 << ( fbMonitorMode ? "ON" : "OFF" );
143
144 fbDebugMonitorMode = pUnpackPar->GetDebugMonitorMode();
145 LOG(info) << "Debug Monitor mode: "
146 << ( fbDebugMonitorMode ? "ON" : "OFF" );
147*/
148 Bool_t initOK = fUnpackerAlgo->InitContainers();
149 initOK &= fUnpackerAlgoSts->InitContainers();
150
152 if (kTRUE == fbMonitorMode) {
154 initOK &= fUnpackerAlgo->CreateHistograms();
156
158 std::vector<std::pair<TNamed*, std::string>> vHistos = fUnpackerAlgo->GetHistoVector();
159 std::vector<std::pair<TNamed*, std::string>> vHistosSts = fUnpackerAlgoSts->GetHistoVector();
160 vHistos.insert(vHistos.end(), vHistosSts.begin(), vHistosSts.end());
161
163 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
164 if (nullptr != server) {
165 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
166 server->Register(Form("/%s", vHistos[uHisto].second.data()), vHistos[uHisto].first);
167 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
168
169 server->RegisterCommand("/Reset_UnpHodo_Hist", "bCosy2019UnpackerTaskHodoResetHistos=kTRUE");
170 server->Restrict("/Reset_UnpHodo_Hist", "allow=admin");
171 } // if( nullptr != server )
172
173 } // if( kTRUE == fbMonitorMode )
174
176
178 for (std::vector<FebChanMaskSts>::iterator it = fvChanMasks.begin(); it < fvChanMasks.end(); ++it)
179 fUnpackerAlgoSts->MaskNoisyChannel((*it).uFeb, (*it).uChan, (*it).bMasked);
180
181 return initOK;
182}
183
185{
186 LOG(info) << "ReInit parameter containers for " << GetName();
187 Bool_t initOK = fUnpackerAlgo->ReInitContainers();
189
190 return initOK;
191}
192
193void CbmCosy2019UnpackerTaskHodo::AddMsComponentToList(size_t component, UShort_t usDetectorId)
194{
195 fUnpackerAlgo->AddMsComponentToList(component, usDetectorId);
196 fUnpackerAlgoSts->AddMsComponentToList(component, usDetectorId);
197}
198
199Bool_t CbmCosy2019UnpackerTaskHodo::DoUnpack(const fles::Timeslice& ts, size_t /*component*/)
200{
202 LOG(info) << "Reset Hodo + STS unpacker histos ";
206 } // if( fbMonitorMode && bCosy2019UnpackerTaskHodoResetHistos )
207
208 if (kFALSE == fUnpackerAlgo->ProcessTs(ts)) {
209 LOG(error) << "Failed processing TS " << ts.index() << " in HODO unpacker algorithm class";
210 return kTRUE;
211 } // if( kFALSE == fUnpackerAlgo->ProcessTs( ts ) )
212
213 if (kFALSE == fUnpackerAlgoSts->ProcessTs(ts)) {
214 LOG(error) << "Failed processing TS " << ts.index() << " in STS unpacker algorithm class";
215 return kTRUE;
216 } // if( kFALSE == fUnpackerAlgoSts->ProcessTs( ts ) )
217
219 fpvDigiSts->insert(fpvDigiSts->end(), fUnpackerAlgo->GetVector().begin(), fUnpackerAlgo->GetVector().end());
220 fpvDigiSts->insert(fpvDigiSts->end(), fUnpackerAlgoSts->GetVector().begin(), fUnpackerAlgoSts->GetVector().end());
221
223 sort(fpvDigiSts->begin(), fpvDigiSts->end(),
224 [](const CbmStsDigi& a, const CbmStsDigi& b) -> bool { return a.GetTime() < b.GetTime(); });
225
228
232 fpvErrorSts->insert(fpvErrorSts->end(), fUnpackerAlgo->GetErrorVector().begin(),
234 fpvErrorSts->insert(fpvErrorSts->end(), fUnpackerAlgoSts->GetErrorVector().begin(),
236
239
240 if (0 == fulTsCounter % 10000) LOG(info) << "Processed " << fulTsCounter << "TS";
241 fulTsCounter++;
242
243 return kTRUE;
244}
245
247{
248 fpvDigiSts->clear();
249 fpvErrorSts->clear();
250}
251
253{
255 if (kTRUE == fbMonitorMode) {
257 std::vector<std::pair<TNamed*, std::string>> vHistos = fUnpackerAlgo->GetHistoVector();
258 std::vector<std::pair<TNamed*, std::string>> vHistosSts = fUnpackerAlgoSts->GetHistoVector();
259 vHistos.insert(vHistos.end(), vHistosSts.begin(), vHistosSts.end());
260
262 TFile* oldFile = gFile;
263 TDirectory* oldDir = gDirectory;
264
265 TFile* histoFile = nullptr;
266
267 // open separate histo file in recreate mode
268 histoFile = new TFile("data/HistosUnpackerSts.root", "RECREATE");
269 histoFile->cd();
270
272 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
274 TString sFolder = vHistos[uHisto].second.data();
275 if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
276 gDirectory->cd(sFolder);
277
279 vHistos[uHisto].first->Write();
280
281 histoFile->cd();
282 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
283
285 gFile = oldFile;
286 gDirectory = oldDir;
287
288 histoFile->Close();
289 } // if( kTRUE == fbMonitorMode )
290}
291
297
299
301{
303}
304
305void CbmCosy2019UnpackerTaskHodo::SetTimeOffsetNsAsic(UInt_t uAsicIdx, Double_t dOffsetIn)
306{
307 fUnpackerAlgo->SetTimeOffsetNsAsic(uAsicIdx, dOffsetIn);
308}
309
310void CbmCosy2019UnpackerTaskHodo::SetTimeOffsetNsAsicSts(UInt_t uAsicIdx, Double_t dOffsetIn)
311{
312 fUnpackerAlgoSts->SetTimeOffsetNsAsic(uAsicIdx, dOffsetIn);
313}
314
315void CbmCosy2019UnpackerTaskHodo::MaskNoisyChannelSts(UInt_t uFeb, UInt_t uChan, Bool_t bMasked)
316{
317 fvChanMasks.push_back(FebChanMaskSts {uFeb, uChan, bMasked});
318}
319
321
ClassImp(CbmConverterManager)
Bool_t bCosy2019UnpackerTaskHodoResetHistos
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
void SetTimeOffsetNsAsic(UInt_t uAsicIdx, Double_t dOffsetIn=0.0)
Bool_t ProcessTs(const fles::Timeslice &ts)
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
void MaskNoisyChannelSts(UInt_t uFeb, UInt_t uChan, Bool_t bMasked=kTRUE)
CbmCosy2019UnpackerAlgoHodo * fUnpackerAlgo
Processing algo.
void SetTimeOffsetNsAsic(UInt_t uAsicIdx, Double_t dOffsetIn=0.0)
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
CbmMcbm2018UnpackerAlgoSts * fUnpackerAlgoSts
uint64_t fulTsCounter
Statistics & first TS rejection.
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
std::vector< CbmStsDigi > * fpvDigiSts
Output vectors.
void SetTimeOffsetNsAsicSts(UInt_t uAsicIdx, Double_t dOffsetIn=0.0)
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Bool_t fbWriteOutput
Switch ON the filling of a additional set of histograms.
void SetTimeOffsetNsSts(Double_t dOffsetIn=0.0)
std::vector< CbmErrorMessage > * fpvErrorSts
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
std::vector< FebChanMaskSts > fvChanMasks
If ON the output TClonesArray of digi is written to disk.
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
void SetTimeOffsetNsAsic(UInt_t uAsicIdx, Double_t dOffsetIn=0.0)
Bool_t ProcessTs(const fles::Timeslice &ts)
void MaskNoisyChannel(UInt_t uFeb, UInt_t uChan, Bool_t bMasked=kTRUE)
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
std::vector< T > & GetVector()
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Control flags.
std::vector< CbmErrorMessage > & GetErrorVector()
void ClearVector()
For unpacker algos.
Data class for a single-channel message in the STS.
Definition CbmStsDigi.h:40