CbmRoot
Loading...
Searching...
No Matches
CbmMcbmSpillFindTask.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// ----- CbmMcbmSpillFindTask -----
8// ----- Created 10.02.2019 by P.-A. Loizeau -----
9// ----- -----
10// -----------------------------------------------------------------------------
11
13
14#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 , fulTsCounter(0)
50 , fMonitorAlgo(nullptr)
51{
53}
54
56
58{
59 LOG(info) << "CbmMcbmSpillFindTask::Init";
60 LOG(info) << "Initializing mCBM Bmon 2019 Monitor";
61
62 return kTRUE;
63}
64
66{
67 LOG(info) << "Setting parameter containers for " << GetName();
68
69 TList* parCList = fMonitorAlgo->GetParList();
70
71 for (Int_t iparC = 0; iparC < parCList->GetEntries(); ++iparC) {
72 FairParGenericSet* tempObj = (FairParGenericSet*) (parCList->At(iparC));
73 parCList->Remove(tempObj);
74
75 std::string sParamName {tempObj->GetName()};
76 FairParGenericSet* newObj =
77 dynamic_cast<FairParGenericSet*>(FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
78
79 if (nullptr == newObj) {
80 LOG(error) << "Failed to obtain parameter container " << sParamName << ", for parameter index " << iparC;
81 return;
82 } // if( nullptr == newObj )
83
84 parCList->AddAt(newObj, iparC);
85 // delete tempObj;
86 } // for( Int_t iparC = 0; iparC < parCList->GetEntries(); ++iparC )
87}
88
90{
91 LOG(info) << "Init parameter containers for " << GetName();
92
94 CbmMcbm2018TofPar* pUnpackPar =
95 dynamic_cast<CbmMcbm2018TofPar*>(FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018TofPar"));
96 if (nullptr == pUnpackPar) {
97 LOG(error) << "Failed to obtain parameter container CbmMcbm2018TofPar";
98 return kFALSE;
99 } // if( nullptr == pUnpackPar )
100
101 Bool_t initOK = fMonitorAlgo->InitContainers();
102
109
112 initOK &= fMonitorAlgo->CreateHistograms();
113
115 std::vector<std::pair<TNamed*, std::string>> vHistos = fMonitorAlgo->GetHistoVector();
117 std::vector<std::pair<TCanvas*, std::string>> vCanvases = fMonitorAlgo->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_MoniBmon_Hist", "bMcbmSpillFindResetHistos=kTRUE");
136 server->Restrict("/Reset_MoniBmon_Hist", "allow=admin");
137 } // if( nullptr != server )
138
139 return initOK;
140}
141
143{
144 LOG(info) << "ReInit parameter containers for " << GetName();
145 Bool_t initOK = fMonitorAlgo->ReInitContainers();
146
147 return initOK;
148}
149
150void CbmMcbmSpillFindTask::AddMsComponentToList(size_t component, UShort_t usDetectorId)
151{
152 fMonitorAlgo->AddMsComponentToList(component, usDetectorId);
153}
154
155Bool_t CbmMcbmSpillFindTask::DoUnpack(const fles::Timeslice& ts, size_t /*component*/)
156{
158 LOG(info) << "Reset Bmon Monitor histos ";
161 } // if( fbMonitorMode && bMcbmSpillFindResetHistos )
162
163 if (kFALSE == fMonitorAlgo->ProcessTs(ts)) {
164 LOG(error) << "Failed processing TS " << ts.index() << " in unpacker algorithm class";
165 return kTRUE;
166 } // if( kFALSE == fMonitorAlgo->ProcessTs( ts ) )
167
169 std::vector<CbmTofDigi> vDigi = fMonitorAlgo->GetVector();
171
172 if (0 == fulTsCounter % 1000) LOG(info) << "Processed " << fulTsCounter << "TS";
173 fulTsCounter++;
174
175 return kTRUE;
176}
177
179
181{
183
185 std::vector<std::pair<TNamed*, std::string>> vHistos = fMonitorAlgo->GetHistoVector();
186
188 TFile* oldFile = gFile;
189 TDirectory* oldDir = gDirectory;
190
191 TFile* histoFile = nullptr;
192
193 // open separate histo file in recreate mode
194 histoFile = new TFile(fsHistoFileName, "RECREATE");
195 histoFile->cd();
196
198 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
200 TString sFolder = vHistos[uHisto].second.data();
201 if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
202 gDirectory->cd(sFolder);
203
205 vHistos[uHisto].first->Write();
206
207 histoFile->cd();
208 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
209
211 gFile = oldFile;
212 gDirectory = oldDir;
213
214 histoFile->Close();
215}
216
218
219
ClassImp(CbmConverterManager)
Bool_t bMcbmSpillFindResetHistos
void SetSpillCheckIntervalSec(Double_t dInterval)
void SetPulserTotLimits(UInt_t uMin, UInt_t uMax)
Bool_t ProcessTs(const fles::Timeslice &ts)
void SetHistoryHistoSize(UInt_t inHistorySizeSec=1800)
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Bool_t ResetHistograms(Bool_t bResetTime=kTRUE)
void SetSpillThreshold(UInt_t uCntLimit)
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
uint64_t fulTsCounter
Statistics & first TS rejection.
Bool_t fbMonitorMode
Control flags.
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)
CbmMcbmSpillFindAlgo * fMonitorAlgo
Processing algo.
UInt_t fuHistoryHistoSize
Switch ON the filling of a additional set of histograms.
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
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.