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