CbmRoot
CbmMcbm2018UnpackerTaskPsd.cxx
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 // ----- -----
3 // ----- CbmMcbm2018UnpackerTaskPsd -----
4 // ----- Created 09.10.2019 by N.Karpushkin -----
5 // ----- based on CbmMcbm2018UnpackerTaskTof by P.-A. Loizeau -----
6 // ----- -----
7 // -----------------------------------------------------------------------------
8 
10 
11 #include "CbmMcbm2018PsdPar.h"
13 
14 #include "FairLogger.h"
15 #include "FairParGenericSet.h"
16 #include "FairRootManager.h"
17 #include "FairRun.h"
18 #include "FairRunOnline.h"
19 #include "FairRuntimeDb.h"
20 
21 #include "TClonesArray.h"
22 #include "TH1.h"
23 #include "THttpServer.h"
24 #include "TROOT.h"
25 #include "TString.h"
26 #include <TFile.h>
27 
28 #include <chrono>
29 #include <fstream>
30 #include <iomanip>
31 #include <iostream>
32 #include <stdint.h>
33 
35 
37  : CbmMcbmUnpack()
38  , fbMonitorMode(kFALSE)
39  , fbDebugMonitorMode(kFALSE)
40  , fbWriteOutput(kTRUE)
41  , fuDigiMaskId(0x0001FFFF)
42  , fulTsCounter(0)
43  , fUnpackerAlgo(nullptr) {
45 }
46 
48  delete fUnpackerAlgo;
49 }
50 
52  LOG(info) << "CbmMcbm2018UnpackerTaskPsd::Init";
53  LOG(info) << "Initializing mCBM PSD 2018 Unpacker";
54 
55  FairRootManager* ioman = FairRootManager::Instance();
56  if (NULL == ioman) { LOG(fatal) << "No FairRootManager instance"; }
57 
60  ioman->RegisterAny("PsdDigi", fpvDigiPsd, fbWriteOutput);
61 
62  return kTRUE;
63 }
64 
66  LOG(info) << "Setting parameter containers for " << GetName();
67 
68  TList* fParCList = fUnpackerAlgo->GetParList();
69 
70  for (Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC) {
71  FairParGenericSet* tempObj = (FairParGenericSet*) (fParCList->At(iparC));
72  fParCList->Remove(tempObj);
73 
74  std::string sParamName {tempObj->GetName()};
75  FairParGenericSet* newObj = dynamic_cast<FairParGenericSet*>(
76  FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
77 
78  if (nullptr == newObj) {
79  LOG(error) << "Failed to obtain parameter container " << sParamName
80  << ", for parameter index " << iparC;
81  return;
82  } // if( nullptr == newObj )
83 
84  fParCList->AddAt(newObj, iparC);
85  // delete tempObj;
86  } // for( Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC )
87 }
88 
90  LOG(info) << "Init parameter containers for " << GetName();
91 
93  CbmMcbm2018PsdPar* pUnpackPar = dynamic_cast<CbmMcbm2018PsdPar*>(
94  FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018PsdPar"));
95  if (nullptr == pUnpackPar) {
96  LOG(error) << "Failed to obtain parameter container CbmMcbm2018PsdPar";
97  return kFALSE;
98  } // if( nullptr == pUnpackPar )
99  /*
100  fbMonitorMode = pUnpackPar->GetMonitorMode();
101  LOG(info) << "Monitor mode: "
102  << ( fbMonitorMode ? "ON" : "OFF" );
103 
104  fbDebugMonitorMode = pUnpackPar->GetDebugMonitorMode();
105  LOG(info) << "Debug Monitor mode: "
106  << ( fbDebugMonitorMode ? "ON" : "OFF" );
107 */
108  Bool_t initOK = fUnpackerAlgo->InitContainers();
109 
111  if (kTRUE == fbMonitorMode) {
113  initOK &= fUnpackerAlgo->CreateHistograms();
114 
115  fhArraySize =
116  new TH1I("fhArraySize",
117  "Size of the Array VS TS index; TS index; Size [bytes]",
118  10000,
119  0.,
120  10000.);
122  new TH1I("fhArrayCapacity",
123  "Size of the Array VS TS index; TS index; Size [bytes]",
124  10000,
125  0.,
126  10000.);
127 
129  std::vector<std::pair<TNamed*, std::string>> vHistos =
131 
133  THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
134  if (nullptr != server) {
135  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
136  server->Register(Form("/%s", vHistos[uHisto].second.data()),
137  vHistos[uHisto].first);
138  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
139 
140  server->RegisterCommand("/Reset_UnpPsd_Hist",
141  "bMcbm2018UnpackerTaskPsdResetHistos=kTRUE");
142  server->Restrict("/Reset_UnpPsd_Hist", "allow=admin");
143 
144  server->Register("/Array", fhArraySize);
145  server->Register("/Array", fhArrayCapacity);
146  } // if( nullptr != server )
147  } // if( kTRUE == fbMonitorMode )
148 
150 
151  return initOK;
152 }
153 
155  LOG(info) << "ReInit parameter containers for " << GetName();
156  Bool_t initOK = fUnpackerAlgo->ReInitContainers();
157 
158  return initOK;
159 }
160 
162  UShort_t usDetectorId) {
163  fUnpackerAlgo->AddMsComponentToList(component, usDetectorId);
164 }
165 
166 Bool_t CbmMcbm2018UnpackerTaskPsd::DoUnpack(const fles::Timeslice& ts,
167  size_t /*component*/) {
168 
170  LOG(info) << "Reset PSD unpacker histos ";
173  } // if( fbMonitorMode && bMcbm2018UnpackerTaskPsdResetHistos )
174 
175  if (kFALSE == fUnpackerAlgo->ProcessTs(ts)) {
176  LOG(error) << "Failed processing TS " << ts.index()
177  << " in unpacker algorithm class";
178  return kTRUE;
179  } // if( kFALSE == fUnpackerAlgo->ProcessTs( ts ) )
180 
181  /*
183  => Done in the algo!!!
184  sort(fpvDigiPsd->begin(), fpvDigiPsd->end(),
185  [](const CbmPsdDigi & a, const CbmPsdDigi & b) -> bool
186  {
187  return a.GetTime() < b.GetTime();
188  });
189 */
190 
191  /*
192  fhArraySize->Fill( fulTsCounter, fPsdDigiCloneArray->GetEntries() );
193  fhArrayCapacity->Fill( fulTsCounter, fPsdDigiCloneArray->Capacity() );
194 */
195  if (0 == fulTsCounter % 10000)
196  LOG(info) << "Processed " << fulTsCounter << "TS";
197  fulTsCounter++;
198 
199  return kTRUE;
200 }
201 
203 
204 
207  if (kTRUE == fbMonitorMode) {
209  std::vector<std::pair<TNamed*, std::string>> vHistos =
211 
213  TDirectory* oldDir = NULL;
214  TFile* histoFile = NULL;
215  // Store current directory position to allow restore later
216  oldDir = gDirectory;
217  // open separate histo file in recreate mode
218  histoFile = new TFile("data/HistosUnpackerPsd.root", "RECREATE");
219  histoFile->cd();
220 
222  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
224  TString sFolder = vHistos[uHisto].second.data();
225  if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
226  gDirectory->cd(sFolder);
227 
229  vHistos[uHisto].first->Write();
230 
231  histoFile->cd();
232  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
233 
234  fhArraySize->Write();
235  fhArrayCapacity->Write();
236  // Restore original directory position
237  oldDir->cd();
238  histoFile->Close();
239  } // if( kTRUE == fbMonitorMode )
240 }
241 
244 }
245 
247  fUnpackerAlgo->SetTimeOffsetNs(dOffsetIn);
248 }
251 }
252 
CbmMcbm2018UnpackerAlgoPsd::GetParList
TList * GetParList()
Definition: CbmMcbm2018UnpackerAlgoPsd.cxx:96
bMcbm2018UnpackerTaskPsdResetHistos
Bool_t bMcbm2018UnpackerTaskPsdResetHistos
Definition: CbmMcbm2018UnpackerTaskPsd.cxx:34
CbmMcbm2018UnpackerTaskPsd::Init
virtual Bool_t Init()
Definition: CbmMcbm2018UnpackerTaskPsd.cxx:51
CbmMcbm2018UnpackerAlgoPsd::ProcessTs
Bool_t ProcessTs(const fles::Timeslice &ts)
Definition: CbmMcbm2018UnpackerAlgoPsd.cxx:165
CbmStar2019Algo::GetHistoVector
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
Definition: CbmStar2019Algo.h:84
CbmMcbm2018UnpackerAlgoPsd.h
CbmStar2019Algo::GetVector
std::vector< T > & GetVector()
Definition: CbmStar2019Algo.h:97
CbmMcbm2018PsdPar.h
CbmMcbm2018UnpackerTaskPsd
Definition: CbmMcbm2018UnpackerTaskPsd.h:21
CbmMcbm2018UnpackerTaskPsd::SetParContainers
void SetParContainers()
Definition: CbmMcbm2018UnpackerTaskPsd.cxx:65
CbmMcbm2018UnpackerAlgoPsd::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018UnpackerAlgoPsd.cxx:85
CbmMcbm2018UnpackerTaskPsd::Finish
virtual void Finish()
Definition: CbmMcbm2018UnpackerTaskPsd.cxx:205
CbmMcbm2018UnpackerTaskPsd::fhArrayCapacity
TH1 * fhArrayCapacity
Definition: CbmMcbm2018UnpackerTaskPsd.h:78
CbmMcbm2018UnpackerAlgoPsd::SetDiamondDpbIdx
void SetDiamondDpbIdx(UInt_t uIdx=2)
Definition: CbmMcbm2018UnpackerAlgoPsd.h:63
CbmMcbm2018UnpackerTaskPsd::fUnpackerAlgo
CbmMcbm2018UnpackerAlgoPsd * fUnpackerAlgo
Processing algo.
Definition: CbmMcbm2018UnpackerTaskPsd.h:81
CbmMcbm2018UnpackerAlgoPsd
Definition: CbmMcbm2018UnpackerAlgoPsd.h:30
CbmMcbm2018UnpackerTaskPsd::DoUnpack
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
Definition: CbmMcbm2018UnpackerTaskPsd.cxx:166
CbmMcbm2018UnpackerTaskPsd::fulTsCounter
uint64_t fulTsCounter
Statistics & first TS rejection.
Definition: CbmMcbm2018UnpackerTaskPsd.h:71
CbmMcbm2018UnpackerTaskPsd.h
CbmMcbm2018UnpackerTaskPsd::fbWriteOutput
Bool_t fbWriteOutput
Switch ON the filling of a additional set of histograms.
Definition: CbmMcbm2018UnpackerTaskPsd.h:65
CbmMcbm2018UnpackerAlgoPsd::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018UnpackerAlgoPsd.cxx:79
CbmMcbm2018PsdPar
Definition: CbmMcbm2018PsdPar.h:19
CbmMcbm2018UnpackerTaskPsd::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018UnpackerTaskPsd.cxx:89
CbmMcbm2018UnpackerAlgoPsd::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Definition: CbmMcbm2018UnpackerAlgoPsd.cxx:150
CbmMcbm2018UnpackerTaskPsd::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
Definition: CbmMcbm2018UnpackerTaskPsd.cxx:161
CbmMcbm2018UnpackerAlgoPsd::SetMonitorMode
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018UnpackerAlgoPsd.h:57
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmMcbm2018UnpackerTaskPsd::fhArraySize
TH1 * fhArraySize
Histogrrams.
Definition: CbmMcbm2018UnpackerTaskPsd.h:77
CbmMcbm2018UnpackerTaskPsd::~CbmMcbm2018UnpackerTaskPsd
virtual ~CbmMcbm2018UnpackerTaskPsd()
Definition: CbmMcbm2018UnpackerTaskPsd.cxx:47
CbmMcbm2018UnpackerTaskPsd::CbmMcbm2018UnpackerTaskPsd
CbmMcbm2018UnpackerTaskPsd(UInt_t uNbSdpb=1)
Definition: CbmMcbm2018UnpackerTaskPsd.cxx:36
CbmMcbm2018UnpackerTaskPsd::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018UnpackerTaskPsd.cxx:154
CbmMcbm2018UnpackerTaskPsd::SetDiamondDpbIdx
void SetDiamondDpbIdx(UInt_t uIdx=2)
Definition: CbmMcbm2018UnpackerTaskPsd.cxx:249
CbmMcbm2018UnpackerAlgoPsd::CreateHistograms
Bool_t CreateHistograms()
Definition: CbmMcbm2018UnpackerAlgoPsd.cxx:388
CbmMcbm2018UnpackerTaskPsd::Reset
virtual void Reset()
Definition: CbmMcbm2018UnpackerTaskPsd.cxx:202
CbmMcbm2018UnpackerAlgoPsd::SetTimeOffsetNs
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerAlgoPsd.h:60
CbmMcbm2018UnpackerTaskPsd::SetTimeOffsetNs
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerTaskPsd.cxx:246
CbmMcbm2018UnpackerTaskPsd::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018UnpackerTaskPsd.cxx:242
CbmMcbm2018UnpackerAlgoPsd::ResetHistograms
Bool_t ResetHistograms()
Definition: CbmMcbm2018UnpackerAlgoPsd.cxx:390
CbmMcbm2018UnpackerTaskPsd::fbMonitorMode
Bool_t fbMonitorMode
Control flags.
Definition: CbmMcbm2018UnpackerTaskPsd.h:61
CbmMcbm2018UnpackerTaskPsd::fpvDigiPsd
std::vector< CbmPsdDigi > * fpvDigiPsd
Output vectors.
Definition: CbmMcbm2018UnpackerTaskPsd.h:74
CbmStar2019Algo::ClearVector
void ClearVector()
For unpacker algos.
Definition: CbmStar2019Algo.h:96
CbmMcbmUnpack
Definition: CbmMcbmUnpack.h:15
CbmStar2019Algo::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Control flags.
Definition: CbmStar2019Algo.h:102