CbmRoot
CbmMcbm2018UnpackerTaskHodo.cxx
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 // ----- -----
3 // ----- CbmMcbm2018UnpackerTaskHodo -----
4 // ----- Created 31/07/19 by P.-A. Loizeau -----
5 // ----- -----
6 // -----------------------------------------------------------------------------
7 
9 
10 #include "CbmMcbm2018HodoPar.h"
12 
13 #include "CbmMcbm2018StsPar.h"
15 
16 #include "FairLogger.h"
17 #include "FairParGenericSet.h"
18 #include "FairRootManager.h"
19 #include "FairRun.h"
20 #include "FairRunOnline.h"
21 #include "FairRuntimeDb.h"
22 
23 #include "TClonesArray.h"
24 #include "THttpServer.h"
25 #include "TROOT.h"
26 #include "TString.h"
27 #include <TFile.h>
28 
29 #include <chrono>
30 #include <fstream>
31 #include <iomanip>
32 #include <iostream>
33 #include <stdint.h>
34 
36 
38  : CbmMcbmUnpack()
39  , fbMonitorMode(kFALSE)
40  , fbWriteOutput(kTRUE)
41  , fvChanMasks()
42  , fulTsCounter(0)
43  , fUnpackerAlgo(nullptr) {
46 }
47 
49  delete fUnpackerAlgo;
50  delete fUnpackerAlgoSts;
51 }
52 
54  LOG(info) << "CbmMcbm2018UnpackerTaskHodo::Init";
55  LOG(info) << "Initializing mCBM STS 2018 Unpacker";
56 
57  FairRootManager* ioman = FairRootManager::Instance();
58  if (NULL == ioman) { LOG(fatal) << "No FairRootManager instance"; }
60  if (nullptr != ioman->InitObjectAs<std::vector<CbmStsDigi> const*>("StsDigi"))
61  LOG(fatal) << "CbmMcbm2018UnpackerTaskHodo::Init => output vector already "
62  "registered,"
63  << " probably by CbmMcbm2018UnpackerTaskSts" << std::endl
64  << " THESE TWO CLASSES ARE INCOMPATIBLE!";
65 
67  fpvDigiSts = new std::vector<CbmStsDigi>();
68  ioman->RegisterAny("StsDigi", fpvDigiSts, fbWriteOutput);
69 
71  fpvErrorSts = new std::vector<CbmErrorMessage>();
72  ioman->RegisterAny("CbmStsError", fpvErrorSts, fbWriteOutput);
73 
74  return kTRUE;
75 }
76 
78  LOG(info) << "Setting parameter containers for " << GetName();
79 
80  TList* fParCList = fUnpackerAlgo->GetParList();
81 
82  for (Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC) {
83  FairParGenericSet* tempObj = (FairParGenericSet*) (fParCList->At(iparC));
84  fParCList->Remove(tempObj);
85 
86  std::string sParamName {tempObj->GetName()};
87  FairParGenericSet* newObj = dynamic_cast<FairParGenericSet*>(
88  FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
89 
90  if (nullptr == newObj) {
91  LOG(error) << "Failed to obtain parameter container " << sParamName
92  << ", for parameter index " << iparC;
93  return;
94  } // if( nullptr == newObj )
95 
96  fParCList->AddAt(newObj, iparC);
97  // delete tempObj;
98  } // for( Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC )
99 
100  fParCList = fUnpackerAlgoSts->GetParList();
101 
102  for (Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC) {
103  FairParGenericSet* tempObj = (FairParGenericSet*) (fParCList->At(iparC));
104  fParCList->Remove(tempObj);
105 
106  std::string sParamName {tempObj->GetName()};
107  FairParGenericSet* newObj = dynamic_cast<FairParGenericSet*>(
108  FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
109 
110  if (nullptr == newObj) {
111  LOG(error) << "Failed to obtain parameter container " << sParamName
112  << ", for parameter index " << iparC;
113  return;
114  } // if( nullptr == newObj )
115 
116  fParCList->AddAt(newObj, iparC);
117  // delete tempObj;
118  } // for( Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC )
119 }
120 
122  LOG(info) << "Init parameter containers for " << GetName();
123 
125  CbmMcbm2018HodoPar* pUnpackPar = dynamic_cast<CbmMcbm2018HodoPar*>(
126  FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018HodoPar"));
127  if (nullptr == pUnpackPar) {
128  LOG(error) << "Failed to obtain parameter container CbmMcbm2018HodoPar";
129  return kFALSE;
130  } // if( nullptr == pUnpackPar )
131  /*
132  fbMonitorMode = pUnpackPar->GetMonitorMode();
133  LOG(info) << "Monitor mode: "
134  << ( fbMonitorMode ? "ON" : "OFF" );
135 
136  fbDebugMonitorMode = pUnpackPar->GetDebugMonitorMode();
137  LOG(info) << "Debug Monitor mode: "
138  << ( fbDebugMonitorMode ? "ON" : "OFF" );
139 */
140  Bool_t initOK = fUnpackerAlgo->InitContainers();
141  initOK &= fUnpackerAlgoSts->InitContainers();
142 
144  if (kTRUE == fbMonitorMode) {
146  initOK &= fUnpackerAlgo->CreateHistograms();
147  initOK &= fUnpackerAlgoSts->CreateHistograms();
148 
150  std::vector<std::pair<TNamed*, std::string>> vHistos =
152  std::vector<std::pair<TNamed*, std::string>> vHistosSts =
154  vHistos.insert(vHistos.end(), vHistosSts.begin(), vHistosSts.end());
155 
157  THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
158  if (nullptr != server) {
159  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
160  server->Register(Form("/%s", vHistos[uHisto].second.data()),
161  vHistos[uHisto].first);
162  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
163 
164  server->RegisterCommand("/Reset_UnpHodo_Hist",
165  "bMcbm2018UnpackerTaskHodoResetHistos=kTRUE");
166  server->Restrict("/Reset_UnpHodo_Hist", "allow=admin");
167  } // if( nullptr != server )
168 
169  } // if( kTRUE == fbMonitorMode )
170 
172 
174  for (std::vector<FebChanMaskSts>::iterator it = fvChanMasks.begin();
175  it < fvChanMasks.end();
176  ++it)
177  fUnpackerAlgoSts->MaskNoisyChannel((*it).uFeb, (*it).uChan, (*it).bMasked);
178 
179  return initOK;
180 }
181 
183  LOG(info) << "ReInit parameter containers for " << GetName();
184  Bool_t initOK = fUnpackerAlgo->ReInitContainers();
185  initOK &= fUnpackerAlgoSts->ReInitContainers();
186 
187  return initOK;
188 }
189 
191  UShort_t usDetectorId) {
192  fUnpackerAlgo->AddMsComponentToList(component, usDetectorId);
193  fUnpackerAlgoSts->AddMsComponentToList(component, usDetectorId);
194 }
195 
196 Bool_t CbmMcbm2018UnpackerTaskHodo::DoUnpack(const fles::Timeslice& ts,
197  size_t /*component*/) {
199  LOG(info) << "Reset Hodo + STS unpacker histos ";
203  } // if( fbMonitorMode && bMcbm2018UnpackerTaskHodoResetHistos )
204 
205  if (kFALSE == fUnpackerAlgo->ProcessTs(ts)) {
206  LOG(error) << "Failed processing TS " << ts.index()
207  << " in HODO unpacker algorithm class";
208  return kTRUE;
209  } // if( kFALSE == fUnpackerAlgo->ProcessTs( ts ) )
210 
211  if (kFALSE == fUnpackerAlgoSts->ProcessTs(ts)) {
212  LOG(error) << "Failed processing TS " << ts.index()
213  << " in STS unpacker algorithm class";
214  return kTRUE;
215  } // if( kFALSE == fUnpackerAlgoSts->ProcessTs( ts ) )
216 
218  fpvDigiSts->insert(fpvDigiSts->end(),
219  fUnpackerAlgo->GetVector().begin(),
220  fUnpackerAlgo->GetVector().end());
221  fpvDigiSts->insert(fpvDigiSts->end(),
222  fUnpackerAlgoSts->GetVector().begin(),
223  fUnpackerAlgoSts->GetVector().end());
224 
226  sort(fpvDigiSts->begin(),
227  fpvDigiSts->end(),
228  [](const CbmStsDigi& a, const CbmStsDigi& b) -> bool {
229  return a.GetTime() < b.GetTime();
230  });
231 
234 
238  fpvErrorSts->insert(fpvErrorSts->end(),
239  fUnpackerAlgo->GetErrorVector().begin(),
240  fUnpackerAlgo->GetErrorVector().end());
241  fpvErrorSts->insert(fpvErrorSts->end(),
242  fUnpackerAlgoSts->GetErrorVector().begin(),
244 
247 
248  if (0 == fulTsCounter % 10000)
249  LOG(info) << "Processed " << fulTsCounter << "TS";
250  fulTsCounter++;
251 
252  return kTRUE;
253 }
254 
256  fpvDigiSts->clear();
257  fpvErrorSts->clear();
258 }
259 
262  if (kTRUE == fbMonitorMode) {
264  std::vector<std::pair<TNamed*, std::string>> vHistos =
266  std::vector<std::pair<TNamed*, std::string>> vHistosSts =
268  vHistos.insert(vHistos.end(), vHistosSts.begin(), vHistosSts.end());
269 
271  TDirectory* oldDir = NULL;
272  TFile* histoFile = NULL;
273  // Store current directory position to allow restore later
274  oldDir = gDirectory;
275  // open separate histo file in recreate mode
276  histoFile = new TFile("data/HistosUnpackerSts.root", "RECREATE");
277  histoFile->cd();
278 
280  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
282  TString sFolder = vHistos[uHisto].second.data();
283  if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
284  gDirectory->cd(sFolder);
285 
287  vHistos[uHisto].first->Write();
288 
289  histoFile->cd();
290  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
291 
292  // Restore original directory position
293  oldDir->cd();
294  histoFile->Close();
295  } // if( kTRUE == fbMonitorMode )
296 }
297 
301 }
302 
304  fUnpackerAlgo->SetTimeOffsetNs(dOffsetIn);
305 }
306 
308  fUnpackerAlgoSts->SetTimeOffsetNs(dOffsetIn);
309 }
310 
312  Double_t dOffsetIn) {
313  fUnpackerAlgo->SetTimeOffsetNsAsic(uAsicIdx, dOffsetIn);
314 }
315 
317  Double_t dOffsetIn) {
318  fUnpackerAlgoSts->SetTimeOffsetNsAsic(uAsicIdx, dOffsetIn);
319 }
320 
322  UInt_t uChan,
323  Bool_t bMasked) {
324  fvChanMasks.push_back(FebChanMaskSts {uFeb, uChan, bMasked});
325 }
326 
329 }
330 
CbmMcbm2018UnpackerTaskHodo::SetParContainers
void SetParContainers()
Definition: CbmMcbm2018UnpackerTaskHodo.cxx:77
CbmMcbm2018UnpackerTaskHodo::fpvDigiSts
std::vector< CbmStsDigi > * fpvDigiSts
Output vectors.
Definition: CbmMcbm2018UnpackerTaskHodo.h:84
CbmMcbm2018UnpackerAlgoSts::CreateHistograms
Bool_t CreateHistograms()
Definition: CbmMcbm2018UnpackerAlgoSts.cxx:1061
CbmMcbm2018UnpackerTaskHodo::fpvErrorSts
std::vector< CbmErrorMessage > * fpvErrorSts
Definition: CbmMcbm2018UnpackerTaskHodo.h:85
CbmMcbm2018UnpackerTaskHodo::fvChanMasks
std::vector< FebChanMaskSts > fvChanMasks
If ON the output TClonesArray of digi is written to disk.
Definition: CbmMcbm2018UnpackerTaskHodo.h:78
CbmMcbm2018UnpackerTaskHodo::Init
virtual Bool_t Init()
Definition: CbmMcbm2018UnpackerTaskHodo.cxx:53
CbmStar2019Algo::GetHistoVector
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
Definition: CbmStar2019Algo.h:84
CbmStar2019Algo::GetErrorVector
std::vector< CbmErrorMessage > & GetErrorVector()
Definition: CbmStar2019Algo.h:99
CbmStar2019Algo::GetVector
std::vector< T > & GetVector()
Definition: CbmStar2019Algo.h:97
CbmMcbm2018UnpackerTaskHodo::SetTimeOffsetNsSts
void SetTimeOffsetNsSts(Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerTaskHodo.cxx:307
CbmMcbm2018HodoPar.h
CbmMcbm2018UnpackerAlgoHodo::SetTimeOffsetNs
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerAlgoHodo.h:66
CbmMcbm2018UnpackerTaskHodo
Definition: CbmMcbm2018UnpackerTaskHodo.h:26
CbmStar2019Algo::ClearErrorVector
void ClearErrorVector()
Definition: CbmStar2019Algo.h:98
CbmMcbm2018UnpackerAlgoHodo::SetMonitorMode
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018UnpackerAlgoHodo.h:63
CbmMcbm2018UnpackerTaskHodo::SetTimeOffsetNs
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerTaskHodo.cxx:303
CbmMcbm2018UnpackerAlgoSts::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Definition: CbmMcbm2018UnpackerAlgoSts.cxx:351
CbmMcbm2018UnpackerAlgoHodo
Definition: CbmMcbm2018UnpackerAlgoHodo.h:36
CbmMcbm2018UnpackerTaskHodo::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018UnpackerTaskHodo.cxx:182
CbmMcbm2018UnpackerAlgoHodo::ResetHistograms
Bool_t ResetHistograms()
Definition: CbmMcbm2018UnpackerAlgoHodo.cxx:999
CbmMcbm2018UnpackerTaskHodo::Finish
virtual void Finish()
Definition: CbmMcbm2018UnpackerTaskHodo.cxx:260
CbmMcbm2018UnpackerTaskHodo::fulTsCounter
uint64_t fulTsCounter
Statistics & first TS rejection.
Definition: CbmMcbm2018UnpackerTaskHodo.h:81
CbmMcbm2018UnpackerAlgoSts::SetTimeOffsetNsAsic
void SetTimeOffsetNsAsic(UInt_t uAsicIdx, Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerAlgoSts.cxx:1387
CbmMcbm2018UnpackerTaskHodo::fbWriteOutput
Bool_t fbWriteOutput
Switch ON the filling of a additional set of histograms.
Definition: CbmMcbm2018UnpackerTaskHodo.h:75
CbmMcbm2018UnpackerAlgoSts::ResetHistograms
Bool_t ResetHistograms()
Definition: CbmMcbm2018UnpackerAlgoSts.cxx:1350
CbmMcbm2018UnpackerTaskHodo::fbMonitorMode
Bool_t fbMonitorMode
Control flags.
Definition: CbmMcbm2018UnpackerTaskHodo.h:71
CbmMcbm2018UnpackerAlgoHodo::GetParList
TList * GetParList()
Definition: CbmMcbm2018UnpackerAlgoHodo.cxx:119
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmMcbm2018UnpackerAlgoSts.h
CbmMcbm2018UnpackerTaskHodo::~CbmMcbm2018UnpackerTaskHodo
virtual ~CbmMcbm2018UnpackerTaskHodo()
Definition: CbmMcbm2018UnpackerTaskHodo.cxx:48
CbmStsDigi
Data class for a single-channel message in the STS.
Definition: CbmStsDigi.h:29
CbmMcbm2018UnpackerAlgoHodo::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018UnpackerAlgoHodo.cxx:107
CbmMcbm2018UnpackerAlgoHodo::CreateHistograms
Bool_t CreateHistograms()
Definition: CbmMcbm2018UnpackerAlgoHodo.cxx:732
CbmMcbm2018UnpackerAlgoSts
Definition: CbmMcbm2018UnpackerAlgoSts.h:37
CbmMcbm2018UnpackerAlgoHodo.h
CbmMcbm2018UnpackerTaskHodo::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
Definition: CbmMcbm2018UnpackerTaskHodo.cxx:190
FebChanMaskSts
Definition: CbmMcbm2018UnpackerTaskHodo.h:20
CbmMcbm2018UnpackerTaskHodo::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018UnpackerTaskHodo.cxx:121
bMcbm2018UnpackerTaskHodoResetHistos
Bool_t bMcbm2018UnpackerTaskHodoResetHistos
Definition: CbmMcbm2018UnpackerTaskHodo.cxx:35
CbmMcbm2018UnpackerTaskHodo::fUnpackerAlgoSts
CbmMcbm2018UnpackerAlgoSts * fUnpackerAlgoSts
Definition: CbmMcbm2018UnpackerTaskHodo.h:89
CbmMcbm2018UnpackerAlgoSts::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018UnpackerAlgoSts.cxx:113
CbmMcbm2018UnpackerAlgoHodo::ProcessTs
Bool_t ProcessTs(const fles::Timeslice &ts)
Definition: CbmMcbm2018UnpackerAlgoHodo.cxx:273
CbmMcbm2018UnpackerAlgoHodo::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Definition: CbmMcbm2018UnpackerAlgoHodo.cxx:258
CbmMcbm2018UnpackerAlgoSts::SetTimeOffsetNs
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerAlgoSts.h:67
CbmMcbm2018UnpackerAlgoHodo::SetTimeOffsetNsAsic
void SetTimeOffsetNsAsic(UInt_t uAsicIdx, Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerAlgoHodo.cxx:1036
CbmMcbm2018UnpackerTaskHodo::DoUnpack
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
Definition: CbmMcbm2018UnpackerTaskHodo.cxx:196
CbmMcbm2018UnpackerTaskHodo::Reset
virtual void Reset()
Definition: CbmMcbm2018UnpackerTaskHodo.cxx:255
CbmMcbm2018UnpackerAlgoSts::MaskNoisyChannel
void MaskNoisyChannel(UInt_t uFeb, UInt_t uChan, Bool_t bMasked=kTRUE)
Definition: CbmMcbm2018UnpackerAlgoSts.cxx:1396
CbmMcbm2018UnpackerTaskHodo::fUnpackerAlgo
CbmMcbm2018UnpackerAlgoHodo * fUnpackerAlgo
Processing algo.
Definition: CbmMcbm2018UnpackerTaskHodo.h:88
CbmMcbm2018UnpackerTaskHodo::SetTimeOffsetNsAsicSts
void SetTimeOffsetNsAsicSts(UInt_t uAsicIdx, Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerTaskHodo.cxx:316
CbmMcbm2018UnpackerTaskHodo::MaskNoisyChannelSts
void MaskNoisyChannelSts(UInt_t uFeb, UInt_t uChan, Bool_t bMasked=kTRUE)
Definition: CbmMcbm2018UnpackerTaskHodo.cxx:321
CbmMcbm2018UnpackerAlgoSts::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018UnpackerAlgoSts.cxx:119
CbmMcbm2018UnpackerAlgoSts::SetMonitorMode
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018UnpackerAlgoSts.h:64
CbmMcbm2018UnpackerAlgoSts::GetParList
TList * GetParList()
Definition: CbmMcbm2018UnpackerAlgoSts.cxx:130
CbmMcbm2018StsPar.h
CbmMcbm2018UnpackerTaskHodo::SetAdcCutSts
void SetAdcCutSts(UInt_t uAdc)
Definition: CbmMcbm2018UnpackerTaskHodo.cxx:327
CbmMcbm2018UnpackerAlgoSts::SetAdcCut
void SetAdcCut(UInt_t uAdc)
Definition: CbmMcbm2018UnpackerAlgoSts.h:72
CbmMcbm2018UnpackerTaskHodo.h
CbmStar2019Algo::ClearVector
void ClearVector()
For unpacker algos.
Definition: CbmStar2019Algo.h:96
CbmMcbm2018UnpackerAlgoHodo::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018UnpackerAlgoHodo.cxx:101
CbmMcbmUnpack
Definition: CbmMcbmUnpack.h:15
CbmMcbm2018UnpackerTaskHodo::SetTimeOffsetNsAsic
void SetTimeOffsetNsAsic(UInt_t uAsicIdx, Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerTaskHodo.cxx:311
CbmMcbm2018UnpackerTaskHodo::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018UnpackerTaskHodo.cxx:298
CbmMcbm2018UnpackerTaskHodo::CbmMcbm2018UnpackerTaskHodo
CbmMcbm2018UnpackerTaskHodo(UInt_t uNbSdpb=1)
Definition: CbmMcbm2018UnpackerTaskHodo.cxx:37
CbmMcbm2018HodoPar
Definition: CbmMcbm2018HodoPar.h:18
CbmMcbm2018UnpackerAlgoSts::ProcessTs
Bool_t ProcessTs(const fles::Timeslice &ts)
Definition: CbmMcbm2018UnpackerAlgoSts.cxx:366
CbmStar2019Algo::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Control flags.
Definition: CbmStar2019Algo.h:102