CbmRoot
Loading...
Searching...
No Matches
CbmMcbm2018UnpackerTaskRich2020.cxx
Go to the documentation of this file.
1/* Copyright (C) 2019-2021 Justus-Liebig-Universitaet Giessen, Giessen
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Egor Ovcharenko [committer], Pierre-Alain Loizeau */
4
11//TODO: check that all data members are initialized in the constructor
12
14
15// ROOT
16#include <TCanvas.h>
17#include <TClonesArray.h>
18#include <TFile.h>
19#include <THttpServer.h>
20#include <TROOT.h>
21
22// FairRoot
23#include <FairParGenericSet.h>
24#include <FairRootManager.h>
25#include <FairRun.h>
26#include <FairRunOnline.h>
27#include <FairRuntimeDb.h>
28#include <Logger.h>
29
30// CbmRoot
31#include "CbmMcbm2018RichPar.h"
33
34#include <thread>
35
36#include <chrono>
37
38//TODO global variable, really?
40
43 , fbMonitorMode(kFALSE)
44 , fbDebugMonitorMode(kFALSE)
45 , fbWriteOutput(kTRUE)
46 , fUnpackerAlgo(new CbmMcbm2018UnpackerAlgoRich2020())
47{
48}
49
57
59{
60 LOG(info) << "CbmMcbm2018UnpackerTaskRich2020::Init";
61 LOG(info) << "Initializing mCBM RICH 2018 Unpacker";
62
63 FairRootManager* ioman = FairRootManager::Instance();
64 if (ioman == NULL) { LOG(fatal) << "No FairRootManager instance"; }
65
68 ioman->RegisterAny("RichDigi", fpvDigiRich, fbWriteOutput);
69
70 return kTRUE;
71}
72
73Bool_t CbmMcbm2018UnpackerTaskRich2020::DoUnpack(const fles::Timeslice& ts, size_t component)
74{
75 //std::this_thread::sleep_for(std::chrono::milliseconds(10));
77 LOG(info) << "Reset RICH unpacker histos ";
80 } // if( fbMonitorMode && bMcbm2018UnpackerTaskRichResetHistos2020 )
81
82 if (kFALSE == fUnpackerAlgo->ProcessTs(ts, component)) {
83 LOG(error) << "Failed processing TS " << ts.index() << " in mRICH unpacker algorithm class";
84 return kTRUE;
85 } // if( kFALSE == fUnpackerAlgo->ProcessTs( ts, component ) )
86
87 /*
89 //=> Done in the algo!!!
90 sort(fpvDigiRich->begin(), fpvDigiRich->end(),
91 [](const CbmRichDigi & a, const CbmRichDigi & b) -> bool
92 {
93 return a.GetTime() < b.GetTime();
94 });
95*/
96
97 if (0 == fulTsCounter % 10000) LOG(info) << "Processed " << fulTsCounter << "TS";
99
100 return kTRUE;
101}
102
104
109{
111 if (kTRUE == fbMonitorMode) {
113 std::vector<std::pair<TNamed*, std::string>> vHistos = fUnpackerAlgo->GetHistoVector();
114
116 TFile* oldFile = gFile;
117 TDirectory* oldDir = gDirectory;
118
119 TFile* histoFile = nullptr;
120
121 // open separate histo file in recreate mode
122 histoFile = new TFile("data/HistosUnpackerRich.root", "RECREATE");
123 histoFile->cd();
124
126 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
128 TString sFolder = vHistos[uHisto].second.data();
129 if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
130 gDirectory->cd(sFolder);
131
133 vHistos[uHisto].first->Write();
134
135 histoFile->cd();
136 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
137
139 gFile = oldFile;
140 gDirectory = oldDir;
141
142 histoFile->Close();
143 } // if( kTRUE == fbMonitorMode )
144}
145
150{
151 LOG(info) << "Setting parameter containers for " << GetName();
152
153 TList* fParCList = fUnpackerAlgo->GetParList();
154
155 for (Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC) {
156 FairParGenericSet* tempObj = (FairParGenericSet*) (fParCList->At(iparC));
157 fParCList->Remove(tempObj);
158
159 std::string sParamName {tempObj->GetName()};
160 FairParGenericSet* newObj =
161 dynamic_cast<FairParGenericSet*>(FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
162
163 if (nullptr == newObj) {
164 LOG(error) << "Failed to obtain parameter container " << sParamName << ", for parameter index " << iparC;
165 return;
166 } // if( nullptr == newObj )
167
168 fParCList->AddAt(newObj, iparC);
169 // delete tempObj;
170 } // for( Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC )
171}
172
177{
178 LOG(info) << "Init parameter containers for " << GetName();
179
181 CbmMcbm2018RichPar* pUnpackPar =
182 dynamic_cast<CbmMcbm2018RichPar*>(FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018RichPar"));
183 if (nullptr == pUnpackPar) {
184 LOG(error) << "Failed to obtain parameter container CbmMcbm2018RichPar";
185 return kFALSE;
186 } // if( nullptr == pUnpackPar )
187 /*
188 fbMonitorMode = pUnpackPar->GetMonitorMode();
189 LOG(info) << "Monitor mode: "
190 << ( fbMonitorMode ? "ON" : "OFF" );
191
192 fbDebugMonitorMode = pUnpackPar->GetDebugMonitorMode();
193 LOG(info) << "Debug Monitor mode: "
194 << ( fbDebugMonitorMode ? "ON" : "OFF" );
195*/
196 Bool_t initOK = fUnpackerAlgo->InitContainers();
197
199 if (kTRUE == fbMonitorMode) {
201 initOK &= fUnpackerAlgo->CreateHistograms();
202
204 std::vector<std::pair<TNamed*, std::string>> vHistos = fUnpackerAlgo->GetHistoVector();
206 std::vector<std::pair<TCanvas*, std::string>> vCanvases = fUnpackerAlgo->GetCanvasVector();
207
209 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
210 if (nullptr != server) {
211 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
212 server->Register(Form("/rich/%s", vHistos[uHisto].second.data()), vHistos[uHisto].first);
213 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
214 for (UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv) {
215 server->Register(Form("/rich/%s", vCanvases[uCanv].second.data()),
216 gROOT->FindObject((vCanvases[uCanv].first)->GetName()));
217 } // for( UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv )
218
219
220 server->RegisterCommand("/Reset_UnpRich_Hist", "bMcbm2018UnpackerTaskRichResetHistos2020=kTRUE");
221 server->Restrict("/Reset_UnpRich_Hist", "allow=admin");
222 } // if( nullptr != server )
223
224 } // if( kTRUE == fbMonitorMode )
225
227
228 return initOK;
229}
230
235{
236 LOG(info) << "ReInit parameter containers for " << GetName();
237 Bool_t initOK = fUnpackerAlgo->ReInitContainers();
238
239 return initOK;
240}
241
245void CbmMcbm2018UnpackerTaskRich2020::AddMsComponentToList(size_t component, UShort_t usDetectorId)
246{
247 fUnpackerAlgo->AddMsComponentToList(component, usDetectorId);
248}
249
250void CbmMcbm2018UnpackerTaskRich2020::SetNbMsInTs(size_t /*uCoreMsNb*/, size_t /*uOverlapMsNb*/) {}
251
253
255
257
ClassImp(CbmConverterManager)
Bool_t bMcbm2018UnpackerTaskRichResetHistos2020
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
virtual Bool_t ProcessTs(const fles::Timeslice &ts)
Bool_t CreateHistograms()
Exclude from ROOT dictionnary due to missing empty constructor!!
CbmMcbm2018UnpackerAlgoRich2020 * fUnpackerAlgo
Algo implementation of the unpacking.
virtual void AddMsComponentToList(size_t component, UShort_t usDetectorId)
std::vector< CbmRichDigi > * fpvDigiRich
Output vectors.
Bool_t fbWriteOutput
Switch ON the filling of a additional set of histograms.
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
virtual void SetNbMsInTs(size_t uCoreMsNb, size_t uOverlapMsNb)
uint64_t fulTsCounter
If ON the output TClonesArray of digi is written to disk.
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
std::vector< T > & GetVector()
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Control flags.
std::vector< std::pair< TCanvas *, std::string > > GetCanvasVector()
void ClearVector()
For unpacker algos.