CbmRoot
CbmMcbm2018UnpackerTaskTof.cxx
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 // ----- -----
3 // ----- CbmMcbm2018UnpackerTaskTof -----
4 // ----- Created 10.02.2019 by P.-A. Loizeau -----
5 // ----- -----
6 // -----------------------------------------------------------------------------
7 
9 
10 #include "CbmMcbm2018TofPar.h"
12 
13 #include "FairLogger.h"
14 #include "FairParGenericSet.h"
15 #include "FairRootManager.h"
16 #include "FairRun.h"
17 #include "FairRunOnline.h"
18 #include "FairRuntimeDb.h"
19 
20 #include "TClonesArray.h"
21 #include "TH1.h"
22 #include "THttpServer.h"
23 #include "TROOT.h"
24 #include "TString.h"
25 #include <TFile.h>
26 
27 #include <chrono>
28 #include <fstream>
29 #include <iomanip>
30 #include <iostream>
31 #include <stdint.h>
32 
34 
36  : CbmMcbmUnpack()
37  , fbMonitorMode(kFALSE)
38  , fbDebugMonitorMode(kFALSE)
39  , fbSeparateArrayT0(kFALSE)
40  , fbWriteOutput(kTRUE)
41  , fuDigiMaskedIdT0(0x00005006)
42  , fuDigiMaskId(0x0001FFFF)
43  , fulTsCounter(0)
44  , fUnpackerAlgo(nullptr) {
46 }
47 
49  delete fUnpackerAlgo;
50 }
51 
53  LOG(info) << "CbmMcbm2018UnpackerTaskTof::Init";
54  LOG(info) << "Initializing mCBM TOF 2018 Unpacker";
55 
56  FairRootManager* ioman = FairRootManager::Instance();
57  if (NULL == ioman) { LOG(fatal) << "No FairRootManager instance"; }
58 
59  fpvDigiTof = new std::vector<CbmTofDigi>();
60  ioman->RegisterAny("TofDigi", fpvDigiTof, fbWriteOutput);
61 
62  if (kTRUE == fbSeparateArrayT0) {
63  fpvDigiT0 = new std::vector<CbmTofDigi>();
64  ioman->RegisterAny("T0Digi", fpvDigiT0, fbWriteOutput);
65  } // if( kTRUE == fbSeparateArrayT0 )
66 
67  return kTRUE;
68 }
69 
71  LOG(info) << "Setting parameter containers for " << GetName();
72 
73  TList* fParCList = fUnpackerAlgo->GetParList();
74 
75  for (Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC) {
76  FairParGenericSet* tempObj = (FairParGenericSet*) (fParCList->At(iparC));
77  fParCList->Remove(tempObj);
78 
79  std::string sParamName {tempObj->GetName()};
80  FairParGenericSet* newObj = dynamic_cast<FairParGenericSet*>(
81  FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
82 
83  if (nullptr == newObj) {
84  LOG(error) << "Failed to obtain parameter container " << sParamName
85  << ", for parameter index " << iparC;
86  return;
87  } // if( nullptr == newObj )
88 
89  fParCList->AddAt(newObj, iparC);
90  // delete tempObj;
91  } // for( Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC )
92 }
93 
95  LOG(info) << "Init parameter containers for " << GetName();
96 
98  CbmMcbm2018TofPar* pUnpackPar = dynamic_cast<CbmMcbm2018TofPar*>(
99  FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018TofPar"));
100  if (nullptr == pUnpackPar) {
101  LOG(error) << "Failed to obtain parameter container CbmMcbm2018TofPar";
102  return kFALSE;
103  } // if( nullptr == pUnpackPar )
104  /*
105  fbMonitorMode = pUnpackPar->GetMonitorMode();
106  LOG(info) << "Monitor mode: "
107  << ( fbMonitorMode ? "ON" : "OFF" );
108 
109  fbDebugMonitorMode = pUnpackPar->GetDebugMonitorMode();
110  LOG(info) << "Debug Monitor mode: "
111  << ( fbDebugMonitorMode ? "ON" : "OFF" );
112 */
113  Bool_t initOK = fUnpackerAlgo->InitContainers();
114 
116  if (kTRUE == fbMonitorMode) {
118  initOK &= fUnpackerAlgo->CreateHistograms();
119 
120  fhArraySize =
121  new TH1I("fhArraySize",
122  "Size of the Array VS TS index; TS index; Size [bytes]",
123  10000,
124  0.,
125  10000.);
127  new TH1I("fhArrayCapacity",
128  "Size of the Array VS TS index; TS index; Size [bytes]",
129  10000,
130  0.,
131  10000.);
132 
134  std::vector<std::pair<TNamed*, std::string>> vHistos =
136 
138  THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
139  if (nullptr != server) {
140  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
141  server->Register(Form("/%s", vHistos[uHisto].second.data()),
142  vHistos[uHisto].first);
143  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
144 
145  server->RegisterCommand("/Reset_UnpTof_Hist",
146  "bMcbm2018UnpackerTaskTofResetHistos=kTRUE");
147  server->Restrict("/Reset_UnpTof_Hist", "allow=admin");
148 
149  server->Register("/Array", fhArraySize);
150  server->Register("/Array", fhArrayCapacity);
151  } // if( nullptr != server )
152  } // if( kTRUE == fbMonitorMode )
153 
155 
156  return initOK;
157 }
158 
160  LOG(info) << "ReInit parameter containers for " << GetName();
161  Bool_t initOK = fUnpackerAlgo->ReInitContainers();
162 
163  return initOK;
164 }
165 
167  UShort_t usDetectorId) {
168  fUnpackerAlgo->AddMsComponentToList(component, usDetectorId);
169 }
170 
171 Bool_t CbmMcbm2018UnpackerTaskTof::DoUnpack(const fles::Timeslice& ts,
172  size_t /*component*/) {
174  LOG(info) << "Reset TOF unpacker histos ";
177  } // if( fbMonitorMode && bMcbm2018UnpackerTaskTofResetHistos )
178 
179  if (kFALSE == fUnpackerAlgo->ProcessTs(ts)) {
180  LOG(error) << "Failed processing TS " << ts.index()
181  << " in unpacker algorithm class";
182  return kTRUE;
183  } // if( kFALSE == fUnpackerAlgo->ProcessTs( ts ) )
184 
186  std::vector<CbmTofDigi>& vDigi = fUnpackerAlgo->GetVector();
187  LOG(debug) << "Found " << vDigi.size() << " TOF digis during unpacking";
188 
189  /*
191  => Done in the algo!!!
192  sort(vDigi.begin(), vDigi.end(),
193  [](const CbmTofDigi & a, const CbmTofDigi & b) -> bool
194  {
195  return a.GetTime() < b.GetTime();
196  });
197 */
198 
199  for (auto digi : vDigi) {
200  if (kTRUE == fbSeparateArrayT0
201  && fuDigiMaskedIdT0 == (digi.GetAddress() & fuDigiMaskId)) {
203  LOG(debug) << "Fill digi T0 vector with "
204  << Form("0x%08x", digi.GetAddress()) << " at "
205  << fpvDigiT0->size();
206  fpvDigiT0->emplace_back(digi);
207  } // if( kTRUE == fbSeparateArrayT0 && fuDigiMaskedIdT0 == ( digi.GetAddress() & fuDigiMaskId ) )
208  else {
210  LOG(debug) << "Fill digi TOF vector with "
211  << Form("0x%08x", digi.GetAddress()) << " at "
212  << fpvDigiTof->size();
213  fpvDigiTof->emplace_back(digi);
214  } // else of if( kTRUE == fbSeparateArrayT0 && fuDigiMaskedIdT0 == ( digi.GetAddress() & fuDigiMaskId ) )
215  }
216 
217  vDigi.clear();
219  if (kTRUE == fbMonitorMode) {
220  if (kTRUE == fbSeparateArrayT0) {
221  fhArraySize->Fill(fulTsCounter, fpvDigiTof->size() + fpvDigiT0->size());
223  fpvDigiTof->capacity() + fpvDigiT0->capacity());
224  } // if( kTRUE == fbSeparateArrayT0 )
225  else {
226  fhArraySize->Fill(fulTsCounter, fpvDigiTof->size());
227  fhArrayCapacity->Fill(fulTsCounter, fpvDigiTof->capacity());
228  } // else of if( kTRUE == fbSeparateArrayT0 )
229  } // if( kTRUE == fbMonitorMode )
230 
231  if (0 == fulTsCounter % 10000)
232  LOG(info) << "Processed " << fulTsCounter << "TS";
233  fulTsCounter++;
234 
235  return kTRUE;
236 }
237 
239  fpvDigiTof->clear();
240 
241  if (kTRUE == fbSeparateArrayT0) {
242  fpvDigiT0->clear();
243  } // if( kTRUE == fbSeparateArrayT0 )
244 }
245 
246 
249  if (kTRUE == fbMonitorMode) {
251  std::vector<std::pair<TNamed*, std::string>> vHistos =
253 
255  TDirectory* oldDir = NULL;
256  TFile* histoFile = NULL;
257  // Store current directory position to allow restore later
258  oldDir = gDirectory;
259  // open separate histo file in recreate mode
260  histoFile = new TFile("data/HistosUnpackerTof.root", "RECREATE");
261  histoFile->cd();
262 
264  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
266  TString sFolder = vHistos[uHisto].second.data();
267  if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
268  gDirectory->cd(sFolder);
269 
271  vHistos[uHisto].first->Write();
272 
273  histoFile->cd();
274  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
275 
276  fhArraySize->Write();
277  fhArrayCapacity->Write();
278  // Restore original directory position
279  oldDir->cd();
280  histoFile->Close();
281  } // if( kTRUE == fbMonitorMode )
282 }
283 
286 }
287 
289  fUnpackerAlgo->SetTimeOffsetNs(dOffsetIn);
290 }
293 }
294 
CbmMcbm2018UnpackerAlgoTof
Definition: CbmMcbm2018UnpackerAlgoTof.h:35
CbmStar2019Algo::GetHistoVector
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
Definition: CbmStar2019Algo.h:84
CbmStar2019Algo::GetVector
std::vector< T > & GetVector()
Definition: CbmStar2019Algo.h:97
CbmMcbm2018TofPar.h
CbmMcbm2018UnpackerTaskTof::CbmMcbm2018UnpackerTaskTof
CbmMcbm2018UnpackerTaskTof(UInt_t uNbSdpb=1)
Definition: CbmMcbm2018UnpackerTaskTof.cxx:35
CbmMcbm2018UnpackerTaskTof::Finish
virtual void Finish()
Definition: CbmMcbm2018UnpackerTaskTof.cxx:247
CbmMcbm2018UnpackerTaskTof::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018UnpackerTaskTof.cxx:284
CbmMcbm2018UnpackerTaskTof::fhArrayCapacity
TH1 * fhArrayCapacity
Definition: CbmMcbm2018UnpackerTaskTof.h:88
CbmMcbm2018UnpackerTaskTof::~CbmMcbm2018UnpackerTaskTof
virtual ~CbmMcbm2018UnpackerTaskTof()
Definition: CbmMcbm2018UnpackerTaskTof.cxx:48
CbmMcbm2018UnpackerAlgoTof::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018UnpackerAlgoTof.cxx:137
CbmMcbm2018UnpackerTaskTof::fbSeparateArrayT0
Bool_t fbSeparateArrayT0
Switch ON the filling of a additional set of histograms.
Definition: CbmMcbm2018UnpackerTaskTof.h:71
CbmMcbm2018UnpackerAlgoTof.h
CbmMcbm2018UnpackerTaskTof::fulTsCounter
uint64_t fulTsCounter
Statistics & first TS rejection.
Definition: CbmMcbm2018UnpackerTaskTof.h:80
CbmMcbm2018UnpackerTaskTof::fUnpackerAlgo
CbmMcbm2018UnpackerAlgoTof * fUnpackerAlgo
Processing algo.
Definition: CbmMcbm2018UnpackerTaskTof.h:91
CbmMcbm2018UnpackerAlgoTof::SetMonitorMode
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018UnpackerAlgoTof.h:62
CbmMcbm2018UnpackerTaskTof::fbWriteOutput
Bool_t fbWriteOutput
If ON, T0 digis are saved in separate TClonesArray.
Definition: CbmMcbm2018UnpackerTaskTof.h:73
bMcbm2018UnpackerTaskTofResetHistos
Bool_t bMcbm2018UnpackerTaskTofResetHistos
Definition: CbmMcbm2018UnpackerTaskTof.cxx:33
CbmMcbm2018UnpackerAlgoTof::ResetHistograms
Bool_t ResetHistograms()
Definition: CbmMcbm2018UnpackerAlgoTof.cxx:1516
CbmMcbm2018UnpackerTaskTof::fpvDigiT0
std::vector< CbmTofDigi > * fpvDigiT0
Definition: CbmMcbm2018UnpackerTaskTof.h:84
CbmMcbm2018UnpackerTaskTof::SetTimeOffsetNs
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerTaskTof.cxx:288
CbmMcbm2018UnpackerTaskTof::DoUnpack
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
Definition: CbmMcbm2018UnpackerTaskTof.cxx:171
CbmMcbm2018UnpackerTaskTof.h
CbmMcbm2018UnpackerAlgoTof::SetDiamondDpbIdx
void SetDiamondDpbIdx(UInt_t uIdx=2)
Definition: CbmMcbm2018UnpackerAlgoTof.h:68
CbmMcbm2018UnpackerTaskTof::Init
virtual Bool_t Init()
Definition: CbmMcbm2018UnpackerTaskTof.cxx:52
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmMcbm2018UnpackerAlgoTof::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018UnpackerAlgoTof.cxx:144
CbmMcbm2018UnpackerTaskTof::Reset
virtual void Reset()
Definition: CbmMcbm2018UnpackerTaskTof.cxx:238
CbmMcbm2018UnpackerTaskTof::SetParContainers
void SetParContainers()
Definition: CbmMcbm2018UnpackerTaskTof.cxx:70
CbmMcbm2018UnpackerTaskTof::SetDiamondDpbIdx
void SetDiamondDpbIdx(UInt_t uIdx=2)
Definition: CbmMcbm2018UnpackerTaskTof.cxx:291
CbmMcbm2018UnpackerTaskTof::fuDigiMaskId
UInt_t fuDigiMaskId
Definition: CbmMcbm2018UnpackerTaskTof.h:77
CbmMcbm2018UnpackerTaskTof::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
Definition: CbmMcbm2018UnpackerTaskTof.cxx:166
CbmMcbm2018UnpackerAlgoTof::ProcessTs
Bool_t ProcessTs(const fles::Timeslice &ts)
Definition: CbmMcbm2018UnpackerAlgoTof.cxx:535
CbmMcbm2018UnpackerTaskTof::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018UnpackerTaskTof.cxx:94
CbmMcbm2018TofPar
Definition: CbmMcbm2018TofPar.h:18
CbmMcbm2018UnpackerTaskTof::fhArraySize
TH1 * fhArraySize
Histograms.
Definition: CbmMcbm2018UnpackerTaskTof.h:87
CbmMcbm2018UnpackerTaskTof::fbMonitorMode
Bool_t fbMonitorMode
Control flags.
Definition: CbmMcbm2018UnpackerTaskTof.h:67
CbmMcbm2018UnpackerAlgoTof::SetTimeOffsetNs
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerAlgoTof.h:65
CbmMcbm2018UnpackerTaskTof
Definition: CbmMcbm2018UnpackerTaskTof.h:20
CbmMcbm2018UnpackerTaskTof::fuDigiMaskedIdT0
UInt_t fuDigiMaskedIdT0
If ON the output TClonesArray of digi is written to disk.
Definition: CbmMcbm2018UnpackerTaskTof.h:76
CbmMcbm2018UnpackerAlgoTof::CreateHistograms
Bool_t CreateHistograms()
Definition: CbmMcbm2018UnpackerAlgoTof.cxx:1319
CbmMcbm2018UnpackerTaskTof::fpvDigiTof
std::vector< CbmTofDigi > * fpvDigiTof
Output vectors.
Definition: CbmMcbm2018UnpackerTaskTof.h:83
CbmMcbm2018UnpackerAlgoTof::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Definition: CbmMcbm2018UnpackerAlgoTof.cxx:520
CbmStar2019Algo::ClearVector
void ClearVector()
For unpacker algos.
Definition: CbmStar2019Algo.h:96
CbmMcbmUnpack
Definition: CbmMcbmUnpack.h:15
CbmMcbm2018UnpackerAlgoTof::GetParList
TList * GetParList()
Definition: CbmMcbm2018UnpackerAlgoTof.cxx:157
CbmMcbm2018UnpackerTaskTof::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018UnpackerTaskTof.cxx:159
CbmStar2019Algo::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Control flags.
Definition: CbmStar2019Algo.h:102