CbmRoot
CbmMcbm2018UnpackerTaskRich.cxx
Go to the documentation of this file.
1 
7 //TODO: check that all data members are initialized in the constructor
8 
10 
11 // ROOT
12 #include <TCanvas.h>
13 #include <TClonesArray.h>
14 #include <TFile.h>
15 #include <THttpServer.h>
16 #include <TROOT.h>
17 
18 // FairRoot
19 #include <FairLogger.h>
20 #include <FairParGenericSet.h>
21 #include <FairRootManager.h>
22 #include <FairRun.h>
23 #include <FairRunOnline.h>
24 #include <FairRuntimeDb.h>
25 
26 // CbmRoot
27 #include "CbmMcbm2018RichPar.h"
29 
30 #include <chrono>
31 #include <thread>
32 
33 //TODO global variable, really?
35 
37  : CbmMcbmUnpack()
38  , fbMonitorMode(kFALSE)
39  , fbDebugMonitorMode(kFALSE)
40  , fbWriteOutput(kTRUE)
41  , fUnpackerAlgo(new CbmMcbm2018UnpackerAlgoRich()) {}
42 
44  if (fUnpackerAlgo) {
45  delete fUnpackerAlgo;
46  fUnpackerAlgo = nullptr;
47  }
48 }
49 
51  LOG(info) << "CbmMcbm2018UnpackerTaskRich::Init";
52  LOG(info) << "Initializing mCBM RICH 2018 Unpacker";
53 
54  FairRootManager* ioman = FairRootManager::Instance();
55  if (ioman == NULL) { LOG(fatal) << "No FairRootManager instance"; }
56 
59  ioman->RegisterAny("RichDigi", fpvDigiRich, fbWriteOutput);
60 
61  return kTRUE;
62 }
63 
64 Bool_t CbmMcbm2018UnpackerTaskRich::DoUnpack(const fles::Timeslice& ts,
65  size_t component) {
66  //std::this_thread::sleep_for(std::chrono::milliseconds(10));
68  LOG(info) << "Reset RICH unpacker histos ";
71  } // if( fbMonitorMode && bMcbm2018UnpackerTaskRichResetHistos )
72 
73  if (kFALSE == fUnpackerAlgo->ProcessTs(ts, component)) {
74  LOG(error) << "Failed processing TS " << ts.index()
75  << " in mRICH unpacker algorithm class";
76  return kTRUE;
77  } // if( kFALSE == fUnpackerAlgo->ProcessTs( ts, component ) )
78 
79  /*
81  //=> Done in the algo!!!
82  sort(fpvDigiRich->begin(), fpvDigiRich->end(),
83  [](const CbmRichDigi & a, const CbmRichDigi & b) -> bool
84  {
85  return a.GetTime() < b.GetTime();
86  });
87 */
88 
89  if (0 == fulTsCounter % 10000)
90  LOG(info) << "Processed " << fulTsCounter << "TS";
91  fulTsCounter++;
92 
93  return kTRUE;
94 }
95 
97 
103  if (kTRUE == fbMonitorMode) {
105  std::vector<std::pair<TNamed*, std::string>> vHistos =
107 
109  TDirectory* oldDir = NULL;
110  TFile* histoFile = NULL;
111  // Store current directory position to allow restore later
112  oldDir = gDirectory;
113  // open separate histo file in recreate mode
114  histoFile = new TFile("data/HistosUnpackerRich.root", "RECREATE");
115  histoFile->cd();
116 
118  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
120  TString sFolder = vHistos[uHisto].second.data();
121  if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
122  gDirectory->cd(sFolder);
123 
125  vHistos[uHisto].first->Write();
126 
127  histoFile->cd();
128  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
129 
130  // Restore original directory position
131  oldDir->cd();
132  histoFile->Close();
133  } // if( kTRUE == fbMonitorMode )
134 }
135 
140  LOG(info) << "Setting parameter containers for " << GetName();
141 
142  TList* fParCList = fUnpackerAlgo->GetParList();
143 
144  for (Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC) {
145  FairParGenericSet* tempObj = (FairParGenericSet*) (fParCList->At(iparC));
146  fParCList->Remove(tempObj);
147 
148  std::string sParamName {tempObj->GetName()};
149  FairParGenericSet* newObj = dynamic_cast<FairParGenericSet*>(
150  FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
151 
152  if (nullptr == newObj) {
153  LOG(error) << "Failed to obtain parameter container " << sParamName
154  << ", for parameter index " << iparC;
155  return;
156  } // if( nullptr == newObj )
157 
158  fParCList->AddAt(newObj, iparC);
159  // delete tempObj;
160  } // for( Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC )
161 }
162 
167  LOG(info) << "Init parameter containers for " << GetName();
168 
170  CbmMcbm2018RichPar* pUnpackPar = dynamic_cast<CbmMcbm2018RichPar*>(
171  FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018RichPar"));
172  if (nullptr == pUnpackPar) {
173  LOG(error) << "Failed to obtain parameter container CbmMcbm2018RichPar";
174  return kFALSE;
175  } // if( nullptr == pUnpackPar )
176  /*
177  fbMonitorMode = pUnpackPar->GetMonitorMode();
178  LOG(info) << "Monitor mode: "
179  << ( fbMonitorMode ? "ON" : "OFF" );
180 
181  fbDebugMonitorMode = pUnpackPar->GetDebugMonitorMode();
182  LOG(info) << "Debug Monitor mode: "
183  << ( fbDebugMonitorMode ? "ON" : "OFF" );
184 */
185  Bool_t initOK = fUnpackerAlgo->InitContainers();
186 
188  if (kTRUE == fbMonitorMode) {
190  initOK &= fUnpackerAlgo->CreateHistograms();
191 
193  std::vector<std::pair<TNamed*, std::string>> vHistos =
196  std::vector<std::pair<TCanvas*, std::string>> vCanvases =
198 
200  THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
201  if (nullptr != server) {
202  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
203  server->Register(Form("/rich/%s", vHistos[uHisto].second.data()),
204  vHistos[uHisto].first);
205  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
206  for (UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv) {
207  server->Register(
208  Form("/rich/%s", vCanvases[uCanv].second.data()),
209  gROOT->FindObject((vCanvases[uCanv].first)->GetName()));
210  } // for( UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv )
211 
212 
213  server->RegisterCommand("/Reset_UnpRich_Hist",
214  "bMcbm2018UnpackerTaskRichResetHistos=kTRUE");
215  server->Restrict("/Reset_UnpRich_Hist", "allow=admin");
216  } // if( nullptr != server )
217 
218  } // if( kTRUE == fbMonitorMode )
219 
221 
222  return initOK;
223 }
224 
229  LOG(info) << "ReInit parameter containers for " << GetName();
230  Bool_t initOK = fUnpackerAlgo->ReInitContainers();
231 
232  return initOK;
233 }
234 
239  UShort_t usDetectorId) {
240  fUnpackerAlgo->AddMsComponentToList(component, usDetectorId);
241 }
242 
244  size_t /*uOverlapMsNb*/) {}
245 
248 }
249 
251  fUnpackerAlgo->SetTimeOffsetNs(dOffsetIn);
252 }
253 
254 void CbmMcbm2018UnpackerTaskRich::DoTotCorr(Bool_t bDoToTCorr) {
255  fUnpackerAlgo->DoTotCorr(bDoToTCorr);
256 }
257 
CbmMcbm2018UnpackerTaskRich.h
CbmMcbm2018UnpackerTaskRich::AddMsComponentToList
virtual void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Definition: CbmMcbm2018UnpackerTaskRich.cxx:238
CbmMcbm2018UnpackerTaskRich::SetNbMsInTs
virtual void SetNbMsInTs(size_t uCoreMsNb, size_t uOverlapMsNb)
Definition: CbmMcbm2018UnpackerTaskRich.cxx:243
CbmMcbm2018RichPar.h
CbmStar2019Algo::GetCanvasVector
std::vector< std::pair< TCanvas *, std::string > > GetCanvasVector()
Definition: CbmStar2019Algo.h:91
CbmStar2019Algo::GetHistoVector
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
Definition: CbmStar2019Algo.h:84
CbmMcbm2018UnpackerAlgoRich::ProcessTs
virtual Bool_t ProcessTs(const fles::Timeslice &ts)
Definition: CbmMcbm2018UnpackerAlgoRich.cxx:193
CbmMcbm2018UnpackerTaskRich::fUnpackerAlgo
CbmMcbm2018UnpackerAlgoRich * fUnpackerAlgo
Algo implementation of the unpacking.
Definition: CbmMcbm2018UnpackerTaskRich.h:69
CbmStar2019Algo::GetVector
std::vector< T > & GetVector()
Definition: CbmStar2019Algo.h:97
CbmMcbm2018UnpackerTaskRich
Definition: CbmMcbm2018UnpackerTaskRich.h:17
CbmMcbm2018RichPar
Definition: CbmMcbm2018RichPar.h:13
CbmMcbm2018UnpackerAlgoRich::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Definition: CbmMcbm2018UnpackerAlgoRich.cxx:171
CbmMcbm2018UnpackerTaskRich::InitContainers
virtual Bool_t InitContainers()
Definition: CbmMcbm2018UnpackerTaskRich.cxx:166
CbmMcbm2018UnpackerAlgoRich::InitContainers
virtual Bool_t InitContainers()
Definition: CbmMcbm2018UnpackerAlgoRich.cxx:128
CbmMcbm2018UnpackerTaskRich::ReInitContainers
virtual Bool_t ReInitContainers()
Definition: CbmMcbm2018UnpackerTaskRich.cxx:228
CbmMcbm2018UnpackerAlgoRich::GetParList
virtual TList * GetParList()
Definition: CbmMcbm2018UnpackerAlgoRich.cxx:147
CbmMcbm2018UnpackerTaskRich::SetTimeOffsetNs
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerTaskRich.cxx:250
CbmMcbm2018UnpackerTaskRich::SetParContainers
virtual void SetParContainers()
Definition: CbmMcbm2018UnpackerTaskRich.cxx:139
CbmMcbm2018UnpackerTaskRich::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018UnpackerTaskRich.cxx:246
CbmMcbm2018UnpackerTaskRich::Reset
virtual void Reset()
Definition: CbmMcbm2018UnpackerTaskRich.cxx:96
CbmMcbm2018UnpackerTaskRich::Finish
virtual void Finish()
Definition: CbmMcbm2018UnpackerTaskRich.cxx:101
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmMcbm2018UnpackerTaskRich::fpvDigiRich
std::vector< CbmRichDigi > * fpvDigiRich
Output vectors.
Definition: CbmMcbm2018UnpackerTaskRich.h:72
CbmMcbm2018UnpackerTaskRich::fbWriteOutput
Bool_t fbWriteOutput
Switch ON the filling of a additional set of histograms.
Definition: CbmMcbm2018UnpackerTaskRich.h:63
CbmMcbm2018UnpackerTaskRich::CbmMcbm2018UnpackerTaskRich
CbmMcbm2018UnpackerTaskRich()
Definition: CbmMcbm2018UnpackerTaskRich.cxx:36
CbmMcbm2018UnpackerTaskRich::~CbmMcbm2018UnpackerTaskRich
virtual ~CbmMcbm2018UnpackerTaskRich()
Definition: CbmMcbm2018UnpackerTaskRich.cxx:43
CbmMcbm2018UnpackerAlgoRich::ReInitContainers
virtual Bool_t ReInitContainers()
Definition: CbmMcbm2018UnpackerAlgoRich.cxx:135
CbmMcbm2018UnpackerAlgoRich::SetTimeOffsetNs
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerAlgoRich.h:80
CbmMcbm2018UnpackerAlgoRich::SetMonitorMode
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018UnpackerAlgoRich.h:78
CbmMcbm2018UnpackerAlgoRich
Definition: CbmMcbm2018UnpackerAlgoRich.h:44
CbmMcbm2018UnpackerAlgoRich.h
CbmMcbm2018UnpackerTaskRich::Init
virtual Bool_t Init()
Definition: CbmMcbm2018UnpackerTaskRich.cxx:50
CbmMcbm2018UnpackerTaskRich::fbMonitorMode
Bool_t fbMonitorMode
Control flags.
Definition: CbmMcbm2018UnpackerTaskRich.h:59
CbmMcbm2018UnpackerTaskRich::DoTotCorr
void DoTotCorr(Bool_t bDoToTCorr=kTRUE)
Definition: CbmMcbm2018UnpackerTaskRich.cxx:254
CbmMcbm2018UnpackerTaskRich::DoUnpack
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
Definition: CbmMcbm2018UnpackerTaskRich.cxx:64
CbmMcbm2018UnpackerAlgoRich::DoTotCorr
void DoTotCorr(Bool_t bDoToTCorr=kTRUE)
Definition: CbmMcbm2018UnpackerAlgoRich.h:84
CbmMcbm2018UnpackerAlgoRich::ResetHistograms
Bool_t ResetHistograms()
Definition: CbmMcbm2018UnpackerAlgoRich.cxx:1931
CbmStar2019Algo::ClearVector
void ClearVector()
For unpacker algos.
Definition: CbmStar2019Algo.h:96
CbmMcbmUnpack
Definition: CbmMcbmUnpack.h:15
CbmMcbm2018UnpackerAlgoRich::CreateHistograms
Bool_t CreateHistograms()
Exclude from ROOT dictionnary due to missing empty constructor!!
Definition: CbmMcbm2018UnpackerAlgoRich.cxx:1537
bMcbm2018UnpackerTaskRichResetHistos
Bool_t bMcbm2018UnpackerTaskRichResetHistos
Definition: CbmMcbm2018UnpackerTaskRich.cxx:34
CbmStar2019Algo::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Control flags.
Definition: CbmStar2019Algo.h:102
CbmMcbm2018UnpackerTaskRich::fulTsCounter
uint64_t fulTsCounter
If ON the output TClonesArray of digi is written to disk.
Definition: CbmMcbm2018UnpackerTaskRich.h:66