CbmRoot
Loading...
Searching...
No Matches
CbmMcbm2018UnpackerTaskTof.cxx
Go to the documentation of this file.
1/* Copyright (C) 2019-2020 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// ----- CbmMcbm2018UnpackerTaskTof -----
8// ----- Created 10.02.2019 by P.-A. Loizeau -----
9// ----- -----
10// -----------------------------------------------------------------------------
11
13
14#include "CbmMcbm2018TofPar.h"
16
17#include "FairParGenericSet.h"
18#include "FairRootManager.h"
19#include "FairRun.h"
20#include "FairRunOnline.h"
21#include "FairRuntimeDb.h"
22#include <Logger.h>
23
24#include "TClonesArray.h"
25#include "TH1.h"
26#include "THttpServer.h"
27#include "TROOT.h"
28#include "TString.h"
29#include <TFile.h>
30
31#include <chrono>
32#include <fstream>
33#include <iomanip>
34#include <iostream>
35
36#include <stdint.h>
37
39
42 , fbMonitorMode(kFALSE)
43 , fbDebugMonitorMode(kFALSE)
44 , fbSeparateArrayBmon(kFALSE)
45 , fbWriteOutput(kTRUE)
46 , fuDigiMaskedIdBmon(0x00002806)
47 , fuDigiMaskId(0x001FFFFF)
48 , fulTsCounter(0)
49 , fUnpackerAlgo(nullptr)
50{
52}
53
55
57{
58 LOG(info) << "CbmMcbm2018UnpackerTaskTof::Init";
59 LOG(info) << "Initializing mCBM TOF 2018 Unpacker";
60
61 FairRootManager* ioman = FairRootManager::Instance();
62 if (NULL == ioman) { LOG(fatal) << "No FairRootManager instance"; }
63
64 fpvDigiTof = new std::vector<CbmTofDigi>();
65 ioman->RegisterAny("TofDigi", fpvDigiTof, fbWriteOutput);
66
67 if (kTRUE == fbSeparateArrayBmon) {
68 fpvDigiBmon = new std::vector<CbmTofDigi>();
69 ioman->RegisterAny("BmonDigi", fpvDigiBmon, fbWriteOutput);
70 } // if( kTRUE == fbSeparateArrayBmon )
71
72 return kTRUE;
73}
74
76{
77 LOG(info) << "Setting parameter containers for " << GetName();
78
79 TList* fParCList = fUnpackerAlgo->GetParList();
80
81 for (Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC) {
82 FairParGenericSet* tempObj = (FairParGenericSet*) (fParCList->At(iparC));
83 fParCList->Remove(tempObj);
84
85 std::string sParamName {tempObj->GetName()};
86 FairParGenericSet* newObj =
87 dynamic_cast<FairParGenericSet*>(FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
88
89 if (nullptr == newObj) {
90 LOG(error) << "Failed to obtain parameter container " << sParamName << ", for parameter index " << iparC;
91 return;
92 } // if( nullptr == newObj )
93
94 fParCList->AddAt(newObj, iparC);
95 // delete tempObj;
96 } // for( Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC )
97}
98
100{
101 LOG(info) << "Init parameter containers for " << GetName();
102
104 CbmMcbm2018TofPar* pUnpackPar =
105 dynamic_cast<CbmMcbm2018TofPar*>(FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018TofPar"));
106 if (nullptr == pUnpackPar) {
107 LOG(error) << "Failed to obtain parameter container CbmMcbm2018TofPar";
108 return kFALSE;
109 } // if( nullptr == pUnpackPar )
110 /*
111 fbMonitorMode = pUnpackPar->GetMonitorMode();
112 LOG(info) << "Monitor mode: "
113 << ( fbMonitorMode ? "ON" : "OFF" );
114
115 fbDebugMonitorMode = pUnpackPar->GetDebugMonitorMode();
116 LOG(info) << "Debug Monitor mode: "
117 << ( fbDebugMonitorMode ? "ON" : "OFF" );
118*/
119 Bool_t initOK = fUnpackerAlgo->InitContainers();
120
122 if (kTRUE == fbMonitorMode) {
124 initOK &= fUnpackerAlgo->CreateHistograms();
125
126 fhArraySize = new TH1I("fhArraySize", "Size of the Array VS TS index; TS index; Size [bytes]", 10000, 0., 10000.);
128 new TH1I("fhArrayCapacity", "Size of the Array VS TS index; TS index; Size [bytes]", 10000, 0., 10000.);
129
131 std::vector<std::pair<TNamed*, std::string>> vHistos = fUnpackerAlgo->GetHistoVector();
132
134 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
135 if (nullptr != server) {
136 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
137 server->Register(Form("/%s", vHistos[uHisto].second.data()), vHistos[uHisto].first);
138 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
139
140 server->RegisterCommand("/Reset_UnpTof_Hist", "bMcbm2018UnpackerTaskTofResetHistos=kTRUE");
141 server->Restrict("/Reset_UnpTof_Hist", "allow=admin");
142
143 server->Register("/Array", fhArraySize);
144 server->Register("/Array", fhArrayCapacity);
145 } // if( nullptr != server )
146 } // if( kTRUE == fbMonitorMode )
147
149
150 return initOK;
151}
152
154{
155 LOG(info) << "ReInit parameter containers for " << GetName();
156 Bool_t initOK = fUnpackerAlgo->ReInitContainers();
157
158 return initOK;
159}
160
161void CbmMcbm2018UnpackerTaskTof::AddMsComponentToList(size_t component, UShort_t usDetectorId)
162{
163 fUnpackerAlgo->AddMsComponentToList(component, usDetectorId);
164}
165
166Bool_t CbmMcbm2018UnpackerTaskTof::DoUnpack(const fles::Timeslice& ts, size_t /*component*/)
167{
169 LOG(info) << "Reset TOF unpacker histos ";
172 } // if( fbMonitorMode && bMcbm2018UnpackerTaskTofResetHistos )
173
174 if (kFALSE == fUnpackerAlgo->ProcessTs(ts)) {
175 LOG(error) << "Failed processing TS " << ts.index() << " in unpacker algorithm class";
176 return kTRUE;
177 } // if( kFALSE == fUnpackerAlgo->ProcessTs( ts ) )
178
180 std::vector<CbmTofDigi>& vDigi = fUnpackerAlgo->GetVector();
181 LOG(debug) << "Found " << vDigi.size() << " TOF digis during unpacking";
182
183 /*
185 => Done in the algo!!!
186 sort(vDigi.begin(), vDigi.end(),
187 [](const CbmTofDigi & a, const CbmTofDigi & b) -> bool
188 {
189 return a.GetTime() < b.GetTime();
190 });
191*/
192
193 for (auto digi : vDigi) {
194 if (kTRUE == fbSeparateArrayBmon && fuDigiMaskedIdBmon == (digi.GetAddress() & fuDigiMaskId)) {
196 LOG(debug) << "Fill digi Bmon vector with " << Form("0x%08x", digi.GetAddress()) << " at " << fpvDigiBmon->size();
197 fpvDigiBmon->emplace_back(digi);
198 } // if( kTRUE == fbSeparateArrayBmon && fuDigiMaskedIdBmon == ( digi.GetAddress() & fuDigiMaskId ) )
199 else {
201 LOG(debug) << "Fill digi TOF vector with " << Form("0x%08x", digi.GetAddress()) << " at " << fpvDigiTof->size();
202 fpvDigiTof->emplace_back(digi);
203 } // else of if( kTRUE == fbSeparateArrayBmon && fuDigiMaskedIdBmon == ( digi.GetAddress() & fuDigiMaskId ) )
204 }
205
206 vDigi.clear();
208 if (kTRUE == fbMonitorMode) {
209 if (kTRUE == fbSeparateArrayBmon) {
210 fhArraySize->Fill(fulTsCounter, fpvDigiTof->size() + fpvDigiBmon->size());
211 fhArrayCapacity->Fill(fulTsCounter, fpvDigiTof->capacity() + fpvDigiBmon->capacity());
212 } // if( kTRUE == fbSeparateArrayBmon )
213 else {
214 fhArraySize->Fill(fulTsCounter, fpvDigiTof->size());
215 fhArrayCapacity->Fill(fulTsCounter, fpvDigiTof->capacity());
216 } // else of if( kTRUE == fbSeparateArrayBmon )
217 } // if( kTRUE == fbMonitorMode )
218
219 if (0 == fulTsCounter % 10000) LOG(info) << "Processed " << fulTsCounter << "TS";
220 fulTsCounter++;
221
222 return kTRUE;
223}
224
226{
227 fpvDigiTof->clear();
228
229 if (kTRUE == fbSeparateArrayBmon) { fpvDigiBmon->clear(); } // if( kTRUE == fbSeparateArrayBmon )
230}
231
232
234{
236 if (kTRUE == fbMonitorMode) {
238 std::vector<std::pair<TNamed*, std::string>> vHistos = fUnpackerAlgo->GetHistoVector();
239
241 TFile* oldFile = gFile;
242 TDirectory* oldDir = gDirectory;
243
244 TFile* histoFile = nullptr;
245
246 // open separate histo file in recreate mode
247 histoFile = new TFile("data/HistosUnpackerTof.root", "RECREATE");
248 histoFile->cd();
249
251 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
253 TString sFolder = vHistos[uHisto].second.data();
254 if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
255 gDirectory->cd(sFolder);
256
258 vHistos[uHisto].first->Write();
259
260 histoFile->cd();
261 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
262
263 fhArraySize->Write();
264 fhArrayCapacity->Write();
265
267 gFile = oldFile;
268 gDirectory = oldDir;
269
270 histoFile->Close();
271 } // if( kTRUE == fbMonitorMode )
272}
273
275
278
ClassImp(CbmConverterManager)
Bool_t bMcbm2018UnpackerTaskTofResetHistos
Bool_t ProcessTs(const fles::Timeslice &ts)
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
std::vector< CbmTofDigi > * fpvDigiTof
Output vectors.
uint64_t fulTsCounter
Statistics & first TS rejection.
CbmMcbm2018UnpackerAlgoTof * fUnpackerAlgo
Processing algo.
Bool_t fbSeparateArrayBmon
Switch ON the filling of a additional set of histograms.
std::vector< CbmTofDigi > * fpvDigiBmon
UInt_t fuDigiMaskedIdBmon
If ON the output TClonesArray of digi is written to disk.
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
Bool_t fbWriteOutput
If ON, Bmon digis are saved in separate TClonesArray.
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
std::vector< T > & GetVector()
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Control flags.
void ClearVector()
For unpacker algos.