CbmRoot
Loading...
Searching...
No Matches
CbmStar2019MonitorTask.cxx
Go to the documentation of this file.
1/* Copyright (C) 2019-2020 Facility for Antiproton and Ion Research in Europe, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pierre-Alain Loizeau [committer] */
4
5// -----------------------------------------------------------------------------
6// ----- -----
7// ----- CbmStar2019MonitorTask -----
8// ----- Created 12.10.2019 by P.-A. Loizeau -----
9// ----- -----
10// -----------------------------------------------------------------------------
11
13
15#include "CbmStar2019TofPar.h"
16
17#include "FairParGenericSet.h"
18#include "FairRootManager.h"
19#include "FairRun.h"
20#include "FairRunOnline.h"
21#include "FairRuntimeDb.h"
22#include <Logger.h>
23
24#include "TCanvas.h"
25#include "TClonesArray.h"
26#include "THttpServer.h"
27#include "TROOT.h"
28#include "TString.h"
29#include <TFile.h>
30
31#include <chrono>
32#include <fstream>
33#include <iomanip>
34#include <iostream>
35
36#include <stdint.h>
37
40
43 , fbDebugMonitorMode(kFALSE)
44 , fbIgnoreCriticalErrors(kFALSE)
45 , fuHistoryHistoSize(3600)
46 , fsHistoFileName("data/HistosMonitor.root")
47 , fuMinTotPulser(90)
48 , fuMaxTotPulser(100)
49 , fiSectorIndex(-1)
50 , fParCList(nullptr)
51 , fulTsCounter(0)
52 , fMonitorAlgo(nullptr)
53{
55}
56
58
60{
61 LOG(info) << "CbmStar2019MonitorTask::Init";
62 LOG(info) << "Initializing eTOF 2019 Monitor task";
63
64 return kTRUE;
65}
66
68{
69 LOG(info) << "Setting parameter containers for " << GetName();
70
72
73 for (Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC) {
74 FairParGenericSet* tempObj = (FairParGenericSet*) (fParCList->At(iparC));
75 fParCList->Remove(tempObj);
76
77 std::string sParamName {tempObj->GetName()};
78 FairParGenericSet* newObj =
79 dynamic_cast<FairParGenericSet*>(FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
80
81 if (nullptr == newObj) {
82 LOG(error) << "Failed to obtain parameter container " << sParamName << ", for parameter index " << iparC;
83 return;
84 } // if( nullptr == newObj )
85
86 fParCList->AddAt(newObj, iparC);
87 // delete tempObj;
88 } // for( Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC )
89}
90
92{
93 LOG(info) << "Init parameter containers for " << GetName();
94
96 CbmStar2019TofPar* pUnpackPar =
97 dynamic_cast<CbmStar2019TofPar*>(FairRun::Instance()->GetRuntimeDb()->getContainer("CbmStar2019TofPar"));
98 if (nullptr == pUnpackPar) {
99 LOG(error) << "Failed to obtain parameter container CbmStar2019TofPar";
100 return kFALSE;
101 } // if( nullptr == pUnpackPar )
102
109
110 Bool_t initOK = fMonitorAlgo->InitContainers();
111
114 initOK &= fMonitorAlgo->CreateHistograms();
115
117 std::vector<std::pair<TNamed*, std::string>> vHistos = fMonitorAlgo->GetHistoVector();
119 std::vector<std::pair<TCanvas*, std::string>> vCanvases = fMonitorAlgo->GetCanvasVector();
120
122 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
123 if (nullptr != server) {
124 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
125 // LOG(info) << "Registering " << vHistos[ uHisto ].first->GetName()
126 // << " in " << vHistos[ uHisto ].second.data();
127 server->Register(Form("/%s", vHistos[uHisto].second.data()), vHistos[uHisto].first);
128 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
129
130 for (UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv) {
131 // LOG(info) << "Registering " << vCanvases[ uCanv ].first->GetName()
132 // << " in " << vCanvases[ uCanv ].second.data();
133 server->Register(Form("/%s", vCanvases[uCanv].second.data()),
134 gROOT->FindObject((vCanvases[uCanv].first)->GetName()));
135 } // for( UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv )
136
137 server->RegisterCommand("/Reset_Moni_Hist", "bStar2019MonitorTaskResetHistos=kTRUE");
138 server->RegisterCommand("/Save_Moni_Hist", "bStar2019MonitorTaskSaveHistos=kTRUE");
139
140 server->Restrict("/Reset_Moni_Hist", "allow=admin");
141 } // if( nullptr != server )
142
143 return initOK;
144}
145
147{
148 LOG(info) << "ReInit parameter containers for " << GetName();
149 Bool_t initOK = fMonitorAlgo->ReInitContainers();
150
151 return initOK;
152}
153
154void CbmStar2019MonitorTask::AddMsComponentToList(size_t component, UShort_t usDetectorId)
155{
156 fMonitorAlgo->AddMsComponentToList(component, usDetectorId);
157}
158
159Bool_t CbmStar2019MonitorTask::DoUnpack(const fles::Timeslice& ts, size_t /*component*/)
160{
162 LOG(info) << "Reset Monitor histos ";
165 } // if( bStar2019MonitorTaskResetHistos )
166
168 LOG(info) << "Save Monitor histos & canvases";
171 } // if( bStar2019MonitorTaskSaveHistos )
172
173 if (kFALSE == fMonitorAlgo->ProcessTs(ts)) {
174 LOG(error) << "Failed processing TS " << ts.index() << " in unpacker algorithm class";
175 return kTRUE;
176 } // if( kFALSE == fMonitorAlgo->ProcessTs( ts ) )
177
179 std::vector<CbmTofDigi> vDigi = fMonitorAlgo->GetVector();
181
182 if (0 == fulTsCounter % 10000) LOG(info) << "Processed " << fulTsCounter << "TS";
183 fulTsCounter++;
184
185 return kTRUE;
186}
187
189
191
193
195{
196 return fMonitorAlgo->SaveLatencyHistograms(sFilename);
197}
198
200{
202 std::vector<std::pair<TNamed*, std::string>> vHistos = fMonitorAlgo->GetHistoVector();
203 std::vector<std::pair<TCanvas*, std::string>> vCanvas = fMonitorAlgo->GetCanvasVector();
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}
ClassImp(CbmConverterManager)
Bool_t bStar2019MonitorTaskSaveHistos
Bool_t bStar2019MonitorTaskResetHistos
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
std::vector< T > & GetVector()
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Control flags.
std::vector< std::pair< TCanvas *, std::string > > GetCanvasVector()
void ClearVector()
For unpacker algos.
void SetIgnoreCriticalErrors(Bool_t bFlagIn=kTRUE)
Bool_t ProcessTs(const fles::Timeslice &ts)
void SetHistoryHistoSize(UInt_t inHistorySizeSec=1800)
void SetPulserTotLimits(UInt_t uMin, UInt_t uMax)
Bool_t SaveLatencyHistograms(TString fsHistoFileName)
void SetSectorIndex(Int_t iSector=-1)
void SetDebugMonitorMode(Bool_t bFlagIn=kTRUE)
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
UInt_t fuHistoryHistoSize
If ON not printout at all for critical errors.
CbmStar2019MonitorAlgo * fMonitorAlgo
Processing algo.
uint64_t fulTsCounter
Statistics & first TS rejection.
Bool_t SaveLatencyHistograms(TString sFilename)
Bool_t fbDebugMonitorMode
Control flags.
Bool_t fbIgnoreCriticalErrors
Switch ON the filling of a additional set of histograms.
TList * fParCList
Parameters management.