CbmRoot
CbmMcbm2018MonitorTaskTof.cxx
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 // ----- -----
3 // ----- CbmMcbm2018MonitorTaskTof -----
4 // ----- Created 27.11.2019 by P.-A. Loizeau -----
5 // ----- -----
6 // -----------------------------------------------------------------------------
7 
9 
11 #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 "TCanvas.h"
21 #include "THttpServer.h"
22 #include "TList.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 
35 
37  : CbmMcbmUnpack()
38  , fbDebugMonitorMode(kFALSE)
39  , fbIgnoreCriticalErrors(kFALSE)
40  , fuHistoryHistoSize(3600)
41  , fsHistoFileName("data/HistosMonitor.root")
42  , fuMinTotPulser(90)
43  , fuMaxTotPulser(100)
44  , fiGdpbIndex(-1)
45  , fulTsCounter(0)
46  , fMonitorAlgo(nullptr) {
48 }
49 
51 
53  LOG(info) << "CbmMcbm2018MonitorTaskTof::Init";
54  LOG(info) << "Initializing eTOF 2019 Monitor task";
55 
56  return kTRUE;
57 }
58 
60  LOG(info) << "Setting parameter containers for " << GetName();
61 
62  TList* parCList = fMonitorAlgo->GetParList();
63 
64  for (Int_t iparC = 0; iparC < parCList->GetEntries(); ++iparC) {
65  FairParGenericSet* tempObj = (FairParGenericSet*) (parCList->At(iparC));
66  parCList->Remove(tempObj);
67 
68  std::string sParamName {tempObj->GetName()};
69  FairParGenericSet* newObj = dynamic_cast<FairParGenericSet*>(
70  FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
71 
72  if (nullptr == newObj) {
73  LOG(error) << "Failed to obtain parameter container " << sParamName
74  << ", for parameter index " << iparC;
75  return;
76  } // if( nullptr == newObj )
77 
78  parCList->AddAt(newObj, iparC);
79  // delete tempObj;
80  } // for( Int_t iparC = 0; iparC < parCList->GetEntries(); ++iparC )
81 }
82 
84  LOG(info) << "Init parameter containers for " << GetName();
85 
87  CbmMcbm2018TofPar* pUnpackPar = dynamic_cast<CbmMcbm2018TofPar*>(
88  FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018TofPar"));
89  if (nullptr == pUnpackPar) {
90  LOG(error) << "Failed to obtain parameter container CbmMcbm2018TofPar";
91  return kFALSE;
92  } // if( nullptr == pUnpackPar )
93 
100 
101  Bool_t initOK = fMonitorAlgo->InitContainers();
102 
105  initOK &= fMonitorAlgo->CreateHistograms();
106 
108  std::vector<std::pair<TNamed*, std::string>> vHistos =
111  std::vector<std::pair<TCanvas*, std::string>> vCanvases =
113 
115  THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
116  if (nullptr != server) {
117  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
118  // LOG(info) << "Registering " << vHistos[ uHisto ].first->GetName()
119  // << " in " << vHistos[ uHisto ].second.data();
120  server->Register(Form("/%s", vHistos[uHisto].second.data()),
121  vHistos[uHisto].first);
122  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
123 
124  for (UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv) {
125  // LOG(info) << "Registering " << vCanvases[ uCanv ].first->GetName()
126  // << " in " << vCanvases[ uCanv ].second.data();
127  server->Register(Form("/%s", vCanvases[uCanv].second.data()),
128  gROOT->FindObject((vCanvases[uCanv].first)->GetName()));
129  } // for( UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv )
130 
131  server->RegisterCommand("/Reset_Moni_Hist",
132  "bMcbm2018MonitorTaskTofResetHistos=kTRUE");
133  server->RegisterCommand("/Save_Moni_Hist",
134  "bMcbm2018MonitorTaskTofSaveHistos=kTRUE");
135 
136  server->Restrict("/Reset_Moni_Hist", "allow=admin");
137  } // if( nullptr != server )
138 
139  return initOK;
140 }
141 
143  LOG(info) << "ReInit parameter containers for " << GetName();
144  Bool_t initOK = fMonitorAlgo->ReInitContainers();
145 
146  return initOK;
147 }
148 
150  UShort_t usDetectorId) {
151  fMonitorAlgo->AddMsComponentToList(component, usDetectorId);
152 }
153 
154 Bool_t CbmMcbm2018MonitorTaskTof::DoUnpack(const fles::Timeslice& ts,
155  size_t /*component*/) {
157  LOG(info) << "Reset Monitor histos ";
160  } // if( bMcbm2018MonitorTaskTofResetHistos )
161 
163  LOG(info) << "Save Monitor histos & canvases";
164  SaveHistograms();
166  } // if( bMcbm2018MonitorTaskTofSaveHistos )
167 
168  if (kFALSE == fMonitorAlgo->ProcessTs(ts)) {
169  LOG(error) << "Failed processing TS " << ts.index()
170  << " in unpacker algorithm class";
171  return kTRUE;
172  } // if( kFALSE == fMonitorAlgo->ProcessTs( ts ) )
173 
175  std::vector<CbmTofDigi> vDigi = fMonitorAlgo->GetVector();
177 
178  if (0 == fulTsCounter % 10000)
179  LOG(info) << "Processed " << fulTsCounter << "TS";
180  fulTsCounter++;
181 
182  return kTRUE;
183 }
184 
186 
188 
191 }
192 
195  std::vector<std::pair<TNamed*, std::string>> vHistos =
197  std::vector<std::pair<TCanvas*, std::string>> vCanvas =
199 
201  TDirectory* oldDir = NULL;
202  TFile* histoFile = NULL;
203  // Store current directory position to allow restore later
204  oldDir = gDirectory;
205  // open separate histo file in recreate mode
206  histoFile = new TFile(fsHistoFileName, "RECREATE");
207 
208  if (nullptr == histoFile) return kFALSE;
209 
211  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
213  TString sFolder = vHistos[uHisto].second.data();
214  if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
215  gDirectory->cd(sFolder);
216 
218  vHistos[uHisto].first->Write();
219 
220  histoFile->cd();
221  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
222 
223  for (UInt_t uCanvas = 0; uCanvas < vCanvas.size(); ++uCanvas) {
225  TString sFolder = vCanvas[uCanvas].second.data();
226  if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
227  gDirectory->cd(sFolder);
228 
230  vCanvas[uCanvas].first->Write();
231 
232  histoFile->cd();
233  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
234 
235  // Restore original directory position
236  oldDir->cd();
237  histoFile->Close();
238 
239  return kTRUE;
240 }
CbmMcbm2018MonitorTaskTof::fulTsCounter
uint64_t fulTsCounter
Statistics & first TS rejection.
Definition: CbmMcbm2018MonitorTaskTof.h:78
CbmMcbm2018MonitorTaskTof::fMonitorAlgo
CbmMcbm2018MonitorAlgoTof * fMonitorAlgo
Processing algo.
Definition: CbmMcbm2018MonitorTaskTof.h:81
CbmMcbm2018MonitorAlgoTof::CreateHistograms
Bool_t CreateHistograms()
Definition: CbmMcbm2018MonitorAlgoTof.cxx:1348
CbmMcbm2018MonitorTaskTof::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018MonitorTaskTof.cxx:189
CbmMcbm2018MonitorTaskTof::DoUnpack
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
Definition: CbmMcbm2018MonitorTaskTof.cxx:154
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
bMcbm2018MonitorTaskTofSaveHistos
Bool_t bMcbm2018MonitorTaskTofSaveHistos
Definition: CbmMcbm2018MonitorTaskTof.cxx:34
CbmMcbm2018MonitorAlgoTof::SetIgnoreCriticalErrors
void SetIgnoreCriticalErrors(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018MonitorAlgoTof.h:63
CbmMcbm2018MonitorTaskTof::fuMaxTotPulser
UInt_t fuMaxTotPulser
Definition: CbmMcbm2018MonitorTaskTof.h:74
CbmStar2019Algo::GetVector
std::vector< T > & GetVector()
Definition: CbmStar2019Algo.h:97
CbmMcbm2018TofPar.h
CbmMcbm2018MonitorTaskTof::CbmMcbm2018MonitorTaskTof
CbmMcbm2018MonitorTaskTof()
Definition: CbmMcbm2018MonitorTaskTof.cxx:36
CbmMcbm2018MonitorTaskTof::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018MonitorTaskTof.cxx:142
CbmMcbm2018MonitorTaskTof::~CbmMcbm2018MonitorTaskTof
virtual ~CbmMcbm2018MonitorTaskTof()
Definition: CbmMcbm2018MonitorTaskTof.cxx:50
CbmMcbm2018MonitorTaskTof::fuMinTotPulser
UInt_t fuMinTotPulser
Definition: CbmMcbm2018MonitorTaskTof.h:73
CbmMcbm2018MonitorAlgoTof
Definition: CbmMcbm2018MonitorAlgoTof.h:32
CbmMcbm2018MonitorTaskTof::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
Definition: CbmMcbm2018MonitorTaskTof.cxx:149
CbmMcbm2018MonitorTaskTof::fbDebugMonitorMode
Bool_t fbDebugMonitorMode
Control flags.
Definition: CbmMcbm2018MonitorTaskTof.h:66
CbmMcbm2018MonitorTaskTof::SaveHistograms
Bool_t SaveHistograms()
Definition: CbmMcbm2018MonitorTaskTof.cxx:193
CbmMcbm2018MonitorAlgoTof::ProcessTs
Bool_t ProcessTs(const fles::Timeslice &ts)
Definition: CbmMcbm2018MonitorAlgoTof.cxx:317
CbmMcbm2018MonitorTaskTof::fsHistoFileName
TString fsHistoFileName
Definition: CbmMcbm2018MonitorTaskTof.h:72
CbmMcbm2018MonitorTaskTof::Finish
virtual void Finish()
Definition: CbmMcbm2018MonitorTaskTof.cxx:187
CbmMcbm2018MonitorTaskTof::Init
virtual Bool_t Init()
Definition: CbmMcbm2018MonitorTaskTof.cxx:52
CbmMcbm2018MonitorTaskTof
Definition: CbmMcbm2018MonitorTaskTof.h:19
CbmMcbm2018MonitorAlgoTof::SetPulserTotLimits
void SetPulserTotLimits(UInt_t uMin, UInt_t uMax)
Definition: CbmMcbm2018MonitorAlgoTof.h:69
bMcbm2018MonitorTaskTofResetHistos
Bool_t bMcbm2018MonitorTaskTofResetHistos
Definition: CbmMcbm2018MonitorTaskTof.cxx:33
CbmMcbm2018MonitorTaskTof::fbIgnoreCriticalErrors
Bool_t fbIgnoreCriticalErrors
Switch ON the filling of a additional set of histograms.
Definition: CbmMcbm2018MonitorTaskTof.h:68
CbmMcbm2018MonitorAlgoTof::ResetHistograms
Bool_t ResetHistograms(Bool_t bResetTime=kTRUE)
Definition: CbmMcbm2018MonitorAlgoTof.cxx:2461
CbmMcbm2018MonitorAlgoTof::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018MonitorAlgoTof.cxx:185
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmMcbm2018MonitorAlgoTof::SetDebugMonitorMode
void SetDebugMonitorMode(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018MonitorAlgoTof.h:60
CbmMcbm2018MonitorTaskTof::fuHistoryHistoSize
UInt_t fuHistoryHistoSize
If ON not printout at all for critical errors.
Definition: CbmMcbm2018MonitorTaskTof.h:71
CbmMcbm2018MonitorAlgoTof.h
CbmMcbm2018MonitorAlgoTof::SetGdpbIndex
void SetGdpbIndex(Int_t iGdpb=-1)
Definition: CbmMcbm2018MonitorAlgoTof.h:74
CbmMcbm2018MonitorAlgoTof::SetHistoryHistoSize
void SetHistoryHistoSize(UInt_t inHistorySizeSec=1800)
Definition: CbmMcbm2018MonitorAlgoTof.h:66
CbmMcbm2018TofPar
Definition: CbmMcbm2018TofPar.h:18
CbmMcbm2018MonitorAlgoTof::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Definition: CbmMcbm2018MonitorAlgoTof.cxx:302
CbmMcbm2018MonitorTaskTof::SetParContainers
void SetParContainers()
Definition: CbmMcbm2018MonitorTaskTof.cxx:59
CbmMcbm2018MonitorTaskTof::fiGdpbIndex
Int_t fiGdpbIndex
Definition: CbmMcbm2018MonitorTaskTof.h:75
CbmMcbm2018MonitorTaskTof::Reset
virtual void Reset()
Definition: CbmMcbm2018MonitorTaskTof.cxx:185
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
CbmMcbm2018MonitorTaskTof.h
CbmMcbm2018MonitorTaskTof::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018MonitorTaskTof.cxx:83
CbmMcbm2018MonitorAlgoTof::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018MonitorAlgoTof.cxx:179
CbmMcbm2018MonitorAlgoTof::GetParList
TList * GetParList()
Definition: CbmMcbm2018MonitorAlgoTof.cxx:196