CbmRoot
Loading...
Searching...
No Matches
CbmMcbm2018MonitorTaskBmon.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// ----- CbmMcbm2018MonitorTaskBmon -----
8// ----- Created 10.02.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
39
42 , fbMonitorMode(kTRUE)
43 , fbDebugMonitorMode(kFALSE)
44 , fuHistoryHistoSize(3600)
45 , fsHistoFileName("data/HistosMonitorBmon.root")
46 , fuMinTotPulser(90)
47 , fuMaxTotPulser(100)
48 , fuOffSpillCountLimit(200)
49 , fuOffSpillCountLimitNonPulser(80)
50 , fdSpillCheckInterval(1.0)
51 , fulTsCounter(0)
52 , fMonitorAlgo(nullptr)
53{
55}
56
58
60{
61 LOG(info) << "CbmMcbm2018MonitorTaskBmon::Init";
62 LOG(info) << "Initializing mCBM Bmon 2019 Monitor";
63
64 return kTRUE;
65}
66
68{
69 LOG(info) << "Setting parameter containers for " << GetName();
70
71 TList* parCList = fMonitorAlgo->GetParList();
72
73 for (Int_t iparC = 0; iparC < parCList->GetEntries(); ++iparC) {
74 FairParGenericSet* tempObj = (FairParGenericSet*) (parCList->At(iparC));
75 parCList->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 parCList->AddAt(newObj, iparC);
87 // delete tempObj;
88 } // for( Int_t iparC = 0; iparC < parCList->GetEntries(); ++iparC )
89}
90
92{
93 LOG(info) << "Init parameter containers for " << GetName();
94
96 CbmMcbm2018TofPar* pUnpackPar =
97 dynamic_cast<CbmMcbm2018TofPar*>(FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018TofPar"));
98 if (nullptr == pUnpackPar) {
99 LOG(error) << "Failed to obtain parameter container CbmMcbm2018TofPar";
100 return kFALSE;
101 } // if( nullptr == pUnpackPar )
102 /*
103 fbMonitorMode = pUnpackPar->GetMonitorMode();
104 LOG(info) << "Monitor mode: "
105 << ( fbMonitorMode ? "ON" : "OFF" );
106
107 fbDebugMonitorMode = pUnpackPar->GetDebugMonitorMode();
108 LOG(info) << "Debug Monitor mode: "
109 << ( fbDebugMonitorMode ? "ON" : "OFF" );
110*/
111 Bool_t initOK = fMonitorAlgo->InitContainers();
112
120
123 initOK &= fMonitorAlgo->CreateHistograms();
124
126 std::vector<std::pair<TNamed*, std::string>> vHistos = fMonitorAlgo->GetHistoVector();
128 std::vector<std::pair<TCanvas*, std::string>> vCanvases = fMonitorAlgo->GetCanvasVector();
129
131 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
132 if (nullptr != server) {
133 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
134 // LOG(info) << "Registering " << vHistos[ uHisto ].first->GetName()
135 // << " in " << vHistos[ uHisto ].second.data();
136 server->Register(Form("/%s", vHistos[uHisto].second.data()), vHistos[uHisto].first);
137 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
138
139 for (UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv) {
140 // LOG(info) << "Registering " << vCanvases[ uCanv ].first->GetName()
141 // << " in " << vCanvases[ uCanv ].second.data();
142 server->Register(Form("/%s", vCanvases[uCanv].second.data()),
143 gROOT->FindObject((vCanvases[uCanv].first)->GetName()));
144 } // for( UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv )
145
146 server->RegisterCommand("/Reset_MoniBmon_Hist", "bMcbm2018MonitorTaskBmonResetHistos=kTRUE");
147 server->Restrict("/Reset_MoniBmon_Hist", "allow=admin");
148 } // if( nullptr != server )
149
150 return initOK;
151}
152
154{
155 LOG(info) << "ReInit parameter containers for " << GetName();
156 Bool_t initOK = fMonitorAlgo->ReInitContainers();
157
158 return initOK;
159}
160
161void CbmMcbm2018MonitorTaskBmon::AddMsComponentToList(size_t component, UShort_t usDetectorId)
162{
163 fMonitorAlgo->AddMsComponentToList(component, usDetectorId);
164}
165
166Bool_t CbmMcbm2018MonitorTaskBmon::DoUnpack(const fles::Timeslice& ts, size_t /*component*/)
167{
169 LOG(info) << "Reset Bmon Monitor histos ";
172 } // if( fbMonitorMode && bMcbm2018MonitorTaskBmonResetHistos )
173
174 if (kFALSE == fMonitorAlgo->ProcessTs(ts)) {
175 LOG(error) << "Failed processing TS " << ts.index() << " in unpacker algorithm class";
176 return kTRUE;
177 } // if( kFALSE == fMonitorAlgo->ProcessTs( ts ) )
178
180 std::vector<CbmTofDigi> vDigi = fMonitorAlgo->GetVector();
182
183 if (0 == fulTsCounter % 10000) LOG(info) << "Processed " << fulTsCounter << "TS";
184 fulTsCounter++;
185
186 return kTRUE;
187}
188
190
192{
194 std::vector<std::pair<TNamed*, std::string>> vHistos = fMonitorAlgo->GetHistoVector();
195
197 TFile* oldFile = gFile;
198 TDirectory* oldDir = gDirectory;
199
200 TFile* histoFile = nullptr;
201
202 // open separate histo file in recreate mode
203 histoFile = new TFile(fsHistoFileName, "RECREATE");
204 histoFile->cd();
205
207 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
209 TString sFolder = vHistos[uHisto].second.data();
210 if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
211 gDirectory->cd(sFolder);
212
214 vHistos[uHisto].first->Write();
215
216 histoFile->cd();
217 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
218
220 gFile = oldFile;
221 gDirectory = oldDir;
222
223 histoFile->Close();
224}
225
227
228void CbmMcbm2018MonitorTaskBmon::SetChannelMap(UInt_t uChan0, UInt_t uChan1, UInt_t uChan2, UInt_t uChan3,
229 UInt_t uChan4, UInt_t uChan5, UInt_t uChan6, UInt_t uChan7)
230{
231 fMonitorAlgo->SetChannelMap(uChan0, uChan1, uChan2, uChan3, uChan4, uChan5, uChan6, uChan7);
232}
233
ClassImp(CbmConverterManager)
Bool_t bMcbm2018MonitorTaskBmonResetHistos
Bool_t ResetHistograms(Bool_t bResetTime=kTRUE)
void SetSpillThreshold(UInt_t uCntLimit)
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Bool_t ProcessTs(const fles::Timeslice &ts)
void SetChannelMap(UInt_t uChan0, UInt_t uChan1, UInt_t uChan2, UInt_t uChan3, UInt_t uChan4, UInt_t uChan5, UInt_t uChan6, UInt_t uChan7)
void SetSpillCheckInterval(Double_t dIntervalSec)
void SetHistoryHistoSize(UInt_t inHistorySizeSec=1800)
void SetPulserTotLimits(UInt_t uMin, UInt_t uMax)
void SetSpillThresholdNonPulser(UInt_t uCntLimit)
CbmMcbm2018MonitorAlgoBmon * fMonitorAlgo
Processing algo.
UInt_t fuHistoryHistoSize
Switch ON the filling of a additional set of histograms.
void SetChannelMap(UInt_t uChan0, UInt_t uChan1, UInt_t uChan2, UInt_t uChan3, UInt_t uChan4, UInt_t uChan5, UInt_t uChan6, UInt_t uChan7)
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
uint64_t fulTsCounter
Statistics & first TS rejection.
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
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.