CbmRoot
Loading...
Searching...
No Matches
CbmMcbm2018MonitorTaskTofPulser.cxx
Go to the documentation of this file.
1/* Copyright (C) 2019-2021 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// ----- CbmMcbm2018MonitorTaskTofPulser -----
8// ----- Created 27.11.2019 by P.-A. Loizeau -----
9// ----- -----
10// -----------------------------------------------------------------------------
11
13
15#include "CbmMcbm2018TofPar.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 "THttpServer.h"
26#include "TList.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 , fsHistoFileName("data/HistosMonitorPulser.root")
44 , fuUpdateFreqTs(100)
45 , fuPulserMinTot(90)
46 , fuPulserMaxTot(110)
47 , fuPulserChannel(3)
48 , fiGdpbIndex(-1)
49 , fuHistoryHistoSize(1800)
50 , fulTsCounter(0)
51 , fMonitorPulserAlgo(nullptr)
52{
54}
55
57
59{
60 LOG(info) << "CbmMcbm2018MonitorTaskTofPulser::Init";
61 LOG(info) << "Initializing mCBM 2019 Monitor task";
62
63 return kTRUE;
64}
65
67{
68 LOG(info) << "Setting parameter containers for " << GetName();
69
70 TList* parCList = fMonitorPulserAlgo->GetParList();
71
72 for (Int_t iparC = 0; iparC < parCList->GetEntries(); ++iparC) {
73 FairParGenericSet* tempObj = (FairParGenericSet*) (parCList->At(iparC));
74 parCList->Remove(tempObj);
75
76 std::string sParamName {tempObj->GetName()};
77 FairParGenericSet* newObj =
78 dynamic_cast<FairParGenericSet*>(FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
79
80 if (nullptr == newObj) {
81 LOG(error) << "Failed to obtain parameter container " << sParamName << ", for parameter index " << iparC;
82 return;
83 } // if( nullptr == newObj )
84
85 parCList->AddAt(newObj, iparC);
86 // delete tempObj;
87 } // for( Int_t iparC = 0; iparC < parCList->GetEntries(); ++iparC )
88}
89
91{
92 LOG(info) << "Init parameter containers for " << GetName();
93
95 CbmMcbm2018TofPar* pUnpackPar =
96 dynamic_cast<CbmMcbm2018TofPar*>(FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018TofPar"));
97 if (nullptr == pUnpackPar) {
98 LOG(error) << "Failed to obtain parameter container CbmMcbm2018TofPar";
99 return kFALSE;
100 } // if( nullptr == pUnpackPar )
101
107
108 Bool_t initOK = fMonitorPulserAlgo->InitContainers();
109
113
115 std::vector<std::pair<TNamed*, std::string>> vHistos = fMonitorPulserAlgo->GetHistoVector();
117 std::vector<std::pair<TCanvas*, std::string>> vCanvases = fMonitorPulserAlgo->GetCanvasVector();
118
120 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
121 if (nullptr != server) {
122 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
123 // LOG(info) << "Registering " << vHistos[ uHisto ].first->GetName()
124 // << " in " << vHistos[ uHisto ].second.data();
125 server->Register(Form("/%s", vHistos[uHisto].second.data()), vHistos[uHisto].first);
126 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
127
128 for (UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv) {
129 // LOG(info) << "Registering " << vCanvases[ uCanv ].first->GetName()
130 // << " in " << vCanvases[ uCanv ].second.data();
131 server->Register(Form("/%s", vCanvases[uCanv].second.data()),
132 gROOT->FindObject((vCanvases[uCanv].first)->GetName()));
133 } // for( UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv )
134
135 server->RegisterCommand("/Reset_Pulser_Hist", "bMcbm2018MonitorTaskTofPulserResetHistos=kTRUE");
136 server->RegisterCommand("/Save_Pulser_Hist", "bMcbm2018MonitorTaskTofPulserSaveHistos=kTRUE");
137
138 server->Restrict("/Reset_Moni_Hist", "allow=admin");
139 } // if( nullptr != server )
140
141 return initOK;
142}
143
145{
146 LOG(info) << "ReInit parameter containers for " << GetName();
147 Bool_t initOK = fMonitorPulserAlgo->ReInitContainers();
148
149 return initOK;
150}
151
152void CbmMcbm2018MonitorTaskTofPulser::AddMsComponentToList(size_t component, UShort_t usDetectorId)
153{
154 fMonitorPulserAlgo->AddMsComponentToList(component, usDetectorId);
155}
156
157Bool_t CbmMcbm2018MonitorTaskTofPulser::DoUnpack(const fles::Timeslice& ts, size_t /*component*/)
158{
160 LOG(info) << "Reset Monitor histos ";
163 } // if( bMcbm2018MonitorTaskTofPulserResetHistos )
164
166 LOG(info) << "Save Monitor histos & canvases";
169 } // if( bMcbm2018MonitorTaskTofPulserSaveHistos )
170
171 if (kFALSE == fMonitorPulserAlgo->ProcessTs(ts)) {
172 LOG(error) << "Failed processing TS " << ts.index() << " in unpacker algorithm class";
173 return kTRUE;
174 } // if( kFALSE == fMonitorPulserAlgo->ProcessTs( ts ) )
175
177 std::vector<CbmTofDigi> vDigi = fMonitorPulserAlgo->GetVector();
179
180 if (0 == fulTsCounter % 10000) LOG(info) << "Processed " << fulTsCounter << "TS";
181 fulTsCounter++;
182
183 return kTRUE;
184}
185
187
193
198
200{
202 std::vector<std::pair<TNamed*, std::string>> vHistos = fMonitorPulserAlgo->GetHistoVector();
203 std::vector<std::pair<TCanvas*, std::string>> vCanvas = fMonitorPulserAlgo->GetCanvasVector();
204
206 TFile* oldFile = gFile;
207 TDirectory* oldDir = gDirectory;
208
209 TFile* histoFile = nullptr;
210
211 // open separate histo file in recreate mode
212 histoFile = new TFile(fsHistoFileName, "RECREATE");
213
214 if (nullptr == histoFile) return kFALSE;
215
217 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
219 TString sFolder = vHistos[uHisto].second.data();
220 if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
221 gDirectory->cd(sFolder);
222
224 vHistos[uHisto].first->Write();
225
226 histoFile->cd();
227 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
228
229 for (UInt_t uCanvas = 0; uCanvas < vCanvas.size(); ++uCanvas) {
231 TString sFolder = vCanvas[uCanvas].second.data();
232 if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
233 gDirectory->cd(sFolder);
234
236 vCanvas[uCanvas].first->Write();
237
238 histoFile->cd();
239 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
240
242 gFile = oldFile;
243 gDirectory = oldDir;
244
245 histoFile->Close();
246
247 return kTRUE;
248}
ClassImp(CbmConverterManager)
Bool_t bMcbm2018MonitorTaskTofPulserSaveHistos
Bool_t bMcbm2018MonitorTaskTofPulserResetHistos
Bool_t ProcessTs(const fles::Timeslice &ts)
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
void SetPulserTotLimits(UInt_t uMin, UInt_t uMax)
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Algo settings setters.
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
CbmMcbm2018MonitorAlgoTofPulser * fMonitorPulserAlgo
Processing algo.
uint64_t fulTsCounter
Statistics & first TS rejection.
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.