CbmRoot
Loading...
Searching...
No Matches
CbmMcbm2018UnpackerTaskMuch.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// ----- CbmMcbm2018UnpackerTaskMuch -----
8// ----- Created 02.02.2019 by P.-A. Loizeau -----
9// ----- -----
10// -----------------------------------------------------------------------------
11
13
14#include "CbmMcbm2018MuchPar.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 "THttpServer.h"
26#include "TROOT.h"
27#include "TString.h"
28#include <TFile.h>
29
30#include <chrono>
31#include <fstream>
32#include <iomanip>
33#include <iostream>
34
35#include <stdint.h>
36
38
41 , fbMonitorMode(kFALSE)
42 , fbWriteOutput(kTRUE)
43 , fvChanMasks()
44 , fulTsCounter(0)
45 , fUnpackerAlgo(nullptr)
46{
48}
49
51
53{
54 LOG(info) << "CbmMcbm2018UnpackerTaskMuch::Init";
55 LOG(info) << "Initializing mCBM MUCH 2018 Unpacker";
56
57 FairRootManager* ioman = FairRootManager::Instance();
58 if (NULL == ioman) { LOG(fatal) << "No FairRootManager instance"; }
59
62 ioman->RegisterAny("MuchBeamTimeDigi", fpvDigiMuch, fbWriteOutput);
63
66 ioman->RegisterAny("CbmMuchError", fpvErrorMuch, fbWriteOutput);
67
68 return kTRUE;
69}
70
72{
73 LOG(info) << "Setting parameter containers for " << GetName();
74
75 TList* fParCList = fUnpackerAlgo->GetParList();
76
77 for (Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC) {
78 FairParGenericSet* tempObj = (FairParGenericSet*) (fParCList->At(iparC));
79 fParCList->Remove(tempObj);
80
81 std::string sParamName {tempObj->GetName()};
82 FairParGenericSet* newObj =
83 dynamic_cast<FairParGenericSet*>(FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
84
85 if (nullptr == newObj) {
86 LOG(error) << "Failed to obtain parameter container " << sParamName << ", for parameter index " << iparC;
87 return;
88 } // if( nullptr == newObj )
89
90 fParCList->AddAt(newObj, iparC);
91 // delete tempObj;
92 } // for( Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC )
93}
94
96{
97 LOG(info) << "Init parameter containers for " << GetName();
98
100 CbmMcbm2018MuchPar* pUnpackPar =
101 dynamic_cast<CbmMcbm2018MuchPar*>(FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018MuchPar"));
102 if (nullptr == pUnpackPar) {
103 LOG(error) << "Failed to obtain parameter container CbmMcbm2018MuchPar";
104 return kFALSE;
105 } // if( nullptr == pUnpackPar )
106 /*
107 fbMonitorMode = pUnpackPar->GetMonitorMode();
108 LOG(info) << "Monitor mode: "
109 << ( fbMonitorMode ? "ON" : "OFF" );
110
111 fbDebugMonitorMode = pUnpackPar->GetDebugMonitorMode();
112 LOG(info) << "Debug Monitor mode: "
113 << ( fbDebugMonitorMode ? "ON" : "OFF" );
114*/
115 Bool_t initOK = fUnpackerAlgo->InitContainers();
116
118 if (kTRUE == fbMonitorMode) {
120 initOK &= fUnpackerAlgo->CreateHistograms();
121
123 std::vector<std::pair<TNamed*, std::string>> vHistos = fUnpackerAlgo->GetHistoVector();
124
126 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
127 if (nullptr != server) {
128 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
129 server->Register(Form("/%s", vHistos[uHisto].second.data()), vHistos[uHisto].first);
130 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
131
132 server->RegisterCommand("/Reset_UnpMuch_Hist", "bMcbm2018UnpackerTaskMuchResetHistos=kTRUE");
133 server->Restrict("/Reset_UnpMuch_Hist", "allow=admin");
134 } // if( nullptr != server )
135
136 } // if( kTRUE == fbMonitorMode )
137
139
140 for (std::vector<MuchFebChanMask>::iterator it = fvChanMasks.begin(); it < fvChanMasks.end(); ++it)
141 fUnpackerAlgo->MaskNoisyChannel((*it).uFeb, (*it).uChan, (*it).bMasked);
142
143 return initOK;
144}
145
147{
148 LOG(info) << "ReInit parameter containers for " << GetName();
149 Bool_t initOK = fUnpackerAlgo->ReInitContainers();
150
151 return initOK;
152}
153
154void CbmMcbm2018UnpackerTaskMuch::AddMsComponentToList(size_t component, UShort_t usDetectorId)
155{
156 fUnpackerAlgo->AddMsComponentToList(component, usDetectorId);
157}
158
159Bool_t CbmMcbm2018UnpackerTaskMuch::DoUnpack(const fles::Timeslice& ts, size_t /*component*/)
160{
162 LOG(info) << "Reset MUCH unpacker histos ";
165 } // if( fbMonitorMode && bMcbm2018UnpackerTaskMuchResetHistos )
166
167 if (kFALSE == fUnpackerAlgo->ProcessTs(ts)) {
168 LOG(error) << "Failed processing TS " << ts.index() << " in unpacker algorithm class";
169 return kTRUE;
170 } // if( kFALSE == fUnpackerAlgo->ProcessTs( ts ) )
171
172 /*
174 => Done in the algo!!!
175 sort(fpvDigiMuch->begin(), fpvDigiMuch->end(),
176 [](const CbmMuchBeamTimeDigi & a, const CbmMuchBeamTimeDigi & b) -> bool
177 {
178 return a.GetTime() < b.GetTime();
179 });
180*/
181
182 if (0 == fulTsCounter % 10000) LOG(info) << "Processed " << fulTsCounter << "TS";
183 fulTsCounter++;
184
185 return kTRUE;
186}
187
193
195{
197 if (kTRUE == fbMonitorMode) {
199 std::vector<std::pair<TNamed*, std::string>> vHistos = fUnpackerAlgo->GetHistoVector();
200
202 TFile* oldFile = gFile;
203 TDirectory* oldDir = gDirectory;
204
205 TFile* histoFile = nullptr;
206
207 // open separate histo file in recreate mode
208 histoFile = new TFile("data/HistosUnpackerMuch.root", "RECREATE");
209 histoFile->cd();
210
212 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
214 TString sFolder = vHistos[uHisto].second.data();
215 if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
216 gDirectory->cd(sFolder);
217
219 vHistos[uHisto].first->Write();
220
221 histoFile->cd();
222 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
223
225 gFile = oldFile;
226 gDirectory = oldDir;
227
228 histoFile->Close();
229 } // if( kTRUE == fbMonitorMode )
230}
231
233
235
236void CbmMcbm2018UnpackerTaskMuch::SetTimeOffsetNsAsic(UInt_t uAsicIdx, Double_t dOffsetIn)
237{
238 return fUnpackerAlgo->SetTimeOffsetNsAsic(uAsicIdx, dOffsetIn);
239}
240
242
244
245void CbmMcbm2018UnpackerTaskMuch::MaskNoisyChannel(UInt_t uFeb, UInt_t uChan, Bool_t bMasked)
246{
247
248 fvChanMasks.push_back(MuchFebChanMask {uFeb, uChan, bMasked});
249}
250
252
253
ClassImp(CbmConverterManager)
Bool_t bMcbm2018UnpackerTaskMuchResetHistos
void SetBinningFwFlag(Bool_t bEnable=kTRUE)
=> Quick and dirty hack for binning FW!!!
void MaskNoisyChannel(UInt_t uFeb, UInt_t uChan, Bool_t bMasked=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 AddMsComponentToList(size_t component, UShort_t usDetectorId)
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
void MaskNoisyChannel(UInt_t uFeb, UInt_t uChan, Bool_t bMasked=kTRUE)
void SetTimeOffsetNsAsic(UInt_t uAsicIdx, Double_t dOffsetIn=0.0)
std::vector< CbmMuchBeamTimeDigi > * fpvDigiMuch
Output vectors.
void SetBinningFwFlag(Bool_t bEnable=kTRUE)
=> Quick and dirty hack for binning FW!!!
Bool_t fbWriteOutput
Switch ON the filling of a additional set of histograms.
CbmMcbm2018UnpackerAlgoMuch * fUnpackerAlgo
Processing algo.
std::vector< CbmErrorMessage > * fpvErrorMuch
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
uint64_t fulTsCounter
Statistics & first TS rejection.
std::vector< MuchFebChanMask > fvChanMasks
If ON the output TClonesArray of digi is written to disk.
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
void SetIgnoreOverlapMs(Bool_t bFlagIn=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.