CbmRoot
Loading...
Searching...
No Matches
CbmMcbm2018MonitorTaskMuchLite.cxx
Go to the documentation of this file.
1/* Copyright (C) 2021 Variable Energy Cyclotron Centre, Kolkata
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Vikas Singhal [committer] */
4
6
9
10#include "FairParGenericSet.h"
11#include "FairRootManager.h"
12#include "FairRun.h"
13#include "FairRunOnline.h"
14#include "FairRuntimeDb.h"
15#include "Logger.h"
16
17#include "TCanvas.h"
18#include "THttpServer.h"
19#include "TList.h"
20#include "TROOT.h"
21#include "TString.h"
22#include <TFile.h>
23
24#include <chrono>
25#include <fstream>
26#include <iomanip>
27#include <iostream>
28
29#include <stdint.h>
30
34
37 , fbMonitorMode(kTRUE)
38 , fbDebugMonitorMode(kFALSE)
39 , fuHistoryHistoSize(3600)
40 , fsHistoFilename("data/HistosMonitorMuch.root")
41 , fuOffSpillCountLimit(200)
42 , fulTsCounter(0)
43 , fMonitorAlgo(nullptr)
44{
46}
47
49
51{
52 LOG(info) << "CbmMcbm2018MonitorTaskMuchLite::Init";
53 LOG(info) << "Initializing Much 2019 Monitor";
54
55 return kTRUE;
56}
57
59{
60 LOG(info) << "Setting parameter containers for " << GetName();
61
62 TList* parCList = fMonitorAlgo->GetParList();
63
64 for (Int_t iparC = 0; iparC < parCList->GetEntries(); ++iparC) {
65 FairParGenericSet* tempObj = (FairParGenericSet*) (parCList->At(iparC));
66 parCList->Remove(tempObj);
67
68 std::string sParamName {tempObj->GetName()};
69 FairParGenericSet* newObj =
70 dynamic_cast<FairParGenericSet*>(FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
71
72 if (nullptr == newObj) {
73 LOG(error) << "Failed to obtain parameter container " << sParamName << ", for parameter index " << iparC;
74 return;
75 } // if( nullptr == newObj )
76
77 parCList->AddAt(newObj, iparC);
78 // delete tempObj;
79 } // for( Int_t iparC = 0; iparC < parCList->GetEntries(); ++iparC )
80
81 /*fUnpackParMuch =
82 (CbmMcbm2018MuchPar*) (FairRun::Instance()->GetRuntimeDb()->getContainer(
83 "CbmMcbm2018MuchPar")); */
84}
85
87{
88 LOG(info) << "Init parameter containers for " << GetName();
89
91 CbmMcbm2018MuchPar* pUnpackPar =
92 dynamic_cast<CbmMcbm2018MuchPar*>(FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018MuchPar"));
93 if (nullptr == pUnpackPar) {
94 LOG(error) << "Failed to obtain parameter container CbmMcbm2018MuchPar";
95 return kFALSE;
96 } // if( nullptr == pUnpackPar )
97 /*
98 fbMonitorMode = pUnpackPar->GetMonitorMode();
99 LOG(info) << "Monitor mode: "
100 << ( fbMonitorMode ? "ON" : "OFF" );
101
102 fbDebugMonitorMode = pUnpackPar->GetDebugMonitorMode();
103 LOG(info) << "Debug Monitor mode: "
104 << ( fbDebugMonitorMode ? "ON" : "OFF" );
105*/
106
107 Bool_t initOK = fMonitorAlgo->InitContainers();
108 LOG(info) << "after initOK";
109
113 //fMonitorAlgo->SetPulserTotLimits(fuMinTotPulser, fuMaxTotPulser);
115
118 LOG(info) << "before creating histogram";
119 initOK &= fMonitorAlgo->CreateHistograms();
120 LOG(info) << "created histograms";
122 std::vector<std::pair<TNamed*, std::string>> vHistos = fMonitorAlgo->GetHistoVector();
124 std::vector<std::pair<TCanvas*, std::string>> vCanvases = fMonitorAlgo->GetCanvasVector();
125
127 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
128 if (nullptr != server) {
129 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
130 // LOG(info) << "Registering " << vHistos[ uHisto ].first->GetName()
131 // << " in " << vHistos[ uHisto ].second.data();
132 server->Register(Form("/%s", vHistos[uHisto].second.data()), vHistos[uHisto].first);
133 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
134
135 for (UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv) {
136 // LOG(info) << "Registering " << vCanvases[ uCanv ].first->GetName()
137 // << " in " << vCanvases[ uCanv ].second.data();
138 server->Register(Form("/%s", vCanvases[uCanv].second.data()),
139 gROOT->FindObject((vCanvases[uCanv].first)->GetName()));
140 } // for( UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv )
141
142 server->RegisterCommand("/Reset_All", "bMcbm2018ResetTaskMuchLite=kTRUE");
143 server->RegisterCommand("/Write_All", "bMcbm2018WriteTaskMuchLite=kTRUE");
144 server->RegisterCommand("/ScanNoisyCh", "bMcbm2018ScanNoisyTaskMuchLite=kTRUE");
145 server->Restrict("/Reset_All", "allow=admin");
146 server->Restrict("/Write_All", "allow=admin");
147 server->Restrict("/ScanNoisyCh", "allow=admin");
148
149 } // if( nullptr != server )
150
151 return initOK;
152}
153
155{
156 LOG(info) << "ReInit parameter containers for " << GetName();
157 Bool_t initOK = fMonitorAlgo->ReInitContainers();
158
159 return initOK;
160}
161
162/* Bool_t CbmMcbm2018MonitorTaskMuchLite::InitMuchParameters() {
163
164 fuNrOfDpbs = fUnpackParMuch->GetNrOfDpbs();
165 LOG(info) << "Nr. of MUCH DPBs: " << fuNrOfDpbs;
166
167 fDpbIdIndexMap.clear();
168 for (UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb) {
169 fDpbIdIndexMap[fUnpackParMuch->GetDpbId(uDpb)] = uDpb;
170 LOG(info) << "Eq. ID for DPB #" << std::setw(2) << uDpb << " = 0x"
171 << std::setw(4) << std::hex << fUnpackParMuch->GetDpbId(uDpb)
172 << std::dec << " => "
173 << fDpbIdIndexMap[fUnpackParMuch->GetDpbId(uDpb)];
174 } // for( UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb )
175
176 fuNbFebs = fUnpackParMuch->GetNrOfFebs();
177 LOG(info) << "Nr. of FEBs: " << fuNbFebs;
178
179 fuNbStsXyters = fUnpackParMuch->GetNrOfAsics();
180 LOG(info) << "Nr. of StsXyter ASICs: " << fuNbStsXyters;
181
182 fvbCrobActiveFlag.resize(fuNrOfDpbs);
183 //fvdFebAdcGain.resize( fuNrOfDpbs );
184 //fvdFebAdcOffs.resize( fuNrOfDpbs );
185 for (UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb) {
186 fvbCrobActiveFlag[uDpb].resize(fUnpackParMuch->GetNbCrobsPerDpb());
187 //fvdFebAdcGain[ uDpb ].resize( fUnpackParMuch->GetNbCrobsPerDpb() );
188 //fvdFebAdcOffs[ uDpb ].resize( fUnpackParMuch->GetNbCrobsPerDpb() );
189 for (UInt_t uCrobIdx = 0; uCrobIdx < fUnpackParMuch->GetNbCrobsPerDpb();
190 ++uCrobIdx) {
191 fvbCrobActiveFlag[uDpb][uCrobIdx] =
192 fUnpackParMuch->IsCrobActive(uDpb, uCrobIdx);
193 // fvdFebAdcGain[ uDpb ][ uCrobIdx ].resize( fUnpackParMuch->GetNbFebsPerCrob(), 0.0 );
194 //fvdFebAdcOffs[ uDpb ][ uCrobIdx ].resize( fUnpackParMuch->GetNbFebsPerCrob(), 0.0 );
195 } // for( UInt_t uCrobIdx = 0; uCrobIdx < fUnpackParMuch->GetNbCrobsPerDpb(); ++uCrobIdx )
196 } // for( UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb )
197
198 for (UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb) {
199 for (UInt_t uCrobIdx = 0; uCrobIdx < fUnpackParMuch->GetNbCrobsPerDpb();
200 ++uCrobIdx) {
201 LOG(info) << Form("DPB #%02u CROB #%02u Active: ", uDpb, uCrobIdx)
202 << fvbCrobActiveFlag[uDpb][uCrobIdx];
203 } // for( UInt_t uCrobIdx = 0; uCrobIdx < fUnpackParMuch->GetNbCrobsPerDpb(); ++uCrobIdx )
204 } // for( UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb )
205
206 if (fbBinningFw)
207 LOG(info) << "Unpacking data in bin sorter FW mode";
208 else
209 LOG(info) << "Unpacking data in full time sorter FW mode (legacy)";
210
211 // Internal status initialization
212 fvulCurrentTsMsb.resize(fuNrOfDpbs);
213 fvuCurrentTsMsbCycle.resize(fuNrOfDpbs);
214 fvuInitialHeaderDone.resize(fuNrOfDpbs);
215 fvuInitialTsMsbCycleHeader.resize(fuNrOfDpbs);
216 fvuElinkLastTsHit.resize(fuNrOfDpbs);
217 for (UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb) {
218 fvulCurrentTsMsb[uDpb] = 0;
219 fvuCurrentTsMsbCycle[uDpb] = 0;
220 fvuInitialHeaderDone[uDpb] = kFALSE;
221 fvuInitialTsMsbCycleHeader[uDpb] = 0;
222 } // for( UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb )
223
224 fvdPrevMsTime.resize(kiMaxNbFlibLinks);
225 fvulChanLastHitTime.resize(fuNbStsXyters);
226 fvdChanLastHitTime.resize(fuNbStsXyters);
227 fvdMsTime.resize(fuMaxNbMicroslices);
228 fvuChanNbHitsInMs.resize(fuNbFebs);
229 fvdChanLastHitTimeInMs.resize(fuNbFebs);
230 fvusChanLastHitAdcInMs.resize(fuNbFebs);
231 fvmAsicHitsInMs.resize(fuNbFebs);
232
233 //fvdMsTime.resize( fuMaxNbMicroslices );
234 //fvuChanNbHitsInMs.resize( fuNbStsXyters );
235 //fvdChanLastHitTimeInMs.resize( fuNbStsXyters );
236 //fvusChanLastHitAdcInMs.resize( fuNbStsXyters );
237 //fvmAsicHitsInMs.resize( fuNbStsXyters );
238
239 for (UInt_t uXyterIdx = 0; uXyterIdx < fuNbFebs; ++uXyterIdx) {
240 fvulChanLastHitTime[uXyterIdx].resize(fUnpackParMuch->GetNbChanPerAsic());
241 fvdChanLastHitTime[uXyterIdx].resize(fUnpackParMuch->GetNbChanPerAsic());
242 fvuChanNbHitsInMs[uXyterIdx].resize(fUnpackParMuch->GetNbChanPerAsic());
243 fvdChanLastHitTimeInMs[uXyterIdx].resize(
244 fUnpackParMuch->GetNbChanPerAsic());
245 fvusChanLastHitAdcInMs[uXyterIdx].resize(
246 fUnpackParMuch->GetNbChanPerAsic());
247 fvmAsicHitsInMs[uXyterIdx].clear();
248
249 for (UInt_t uChan = 0; uChan < fUnpackParMuch->GetNbChanPerAsic();
250 ++uChan) {
251 fvulChanLastHitTime[uXyterIdx][uChan] = 0;
252 fvdChanLastHitTime[uXyterIdx][uChan] = -1.0;
253
254 fvuChanNbHitsInMs[uXyterIdx][uChan].resize(fuMaxNbMicroslices);
255 fvdChanLastHitTimeInMs[uXyterIdx][uChan].resize(fuMaxNbMicroslices);
256 fvusChanLastHitAdcInMs[uXyterIdx][uChan].resize(fuMaxNbMicroslices);
257 for (UInt_t uMsIdx = 0; uMsIdx < fuMaxNbMicroslices; ++uMsIdx) {
258 fvuChanNbHitsInMs[uXyterIdx][uChan][uMsIdx] = 0;
259 fvdChanLastHitTimeInMs[uXyterIdx][uChan][uMsIdx] = -1.0;
260 fvusChanLastHitAdcInMs[uXyterIdx][uChan][uMsIdx] = 0;
261 } // for( UInt_t uMsIdx = 0; uMsIdx < fuMaxNbMicroslices; ++uMsIdx )
262 } // for( UInt_t uChan = 0; uChan < fUnpackParMuch->GetNbChanPerAsic(); ++uChan )
263 } // for( UInt_t uXyterIdx = 0; uXyterIdx < fuNbStsXyters; ++uXyterIdx )
264
265 LOG(info) << "CbmMcbm2018MonitorTaskMuchLite::ReInitContainers => Changed "
266 "fvuChanNbHitsInMs size "
267 << fvuChanNbHitsInMs.size() << " VS " << fuNbFebs;
268 LOG(info) << "CbmMcbm2018MonitorTaskMuchLite::ReInitContainers => Changed "
269 "fvuChanNbHitsInMs size "
270 << fvuChanNbHitsInMs[0].size() << " VS "
271 << fUnpackParMuch->GetNbChanPerAsic();
272 LOG(info) << "CbmMcbm2018MonitorTaskMuchLite::ReInitContainers => Changed "
273 "fvuChanNbHitsInMs size "
274 << fvuChanNbHitsInMs[0][0].size() << " VS " << fuMaxNbMicroslices;
275
276 fvmFebHitsInMs.resize(fuNbFebs);
277 fviFebTimeSecLastRateUpdate.resize(fuNbFebs, -1);
278 fviFebCountsSinceLastRateUpdate.resize(fuNbFebs, -1);
279 fvdFebChanCountsSinceLastRateUpdate.resize(fuNbFebs);
280 fdMuchFebChanLastTimeForDist.resize(fuNbFebs);
281 for (UInt_t uFebIdx = 0; uFebIdx < fuNbFebs; ++uFebIdx) {
282 fvmFebHitsInMs[uFebIdx].clear();
283 fvdFebChanCountsSinceLastRateUpdate[uFebIdx].resize(
284 fUnpackParMuch->GetNbChanPerFeb(), 0.0);
285 fdMuchFebChanLastTimeForDist[uFebIdx].resize(
286 fUnpackParMuch->GetNbChanPerFeb(), -1.0);
287 } // for( UInt_t uFebIdx = 0; uFebIdx < fuNbFebs; ++uFebIdx )
288
290 // SmxErrInitializeVariables();
292
293 return kTRUE;
294} */
295
296void CbmMcbm2018MonitorTaskMuchLite::AddMsComponentToList(size_t component, UShort_t usDetectorId)
297{
298 fMonitorAlgo->AddMsComponentToList(component, usDetectorId);
299}
300
301Bool_t CbmMcbm2018MonitorTaskMuchLite::DoUnpack(const fles::Timeslice& ts, size_t /*component*/)
302{
306 } // if( bMcbm2018ResetMuchLite )
310 } // if( bMcbm2018WriteMuchLite )
314 } // if( bMcbm2018WriteMuchLite )
315
316
317 /* if (fbMonitorMode && bMcbm2018MonitorTaskMuchResetHistos) {
318 LOG(info) << "Reset Much Monitor histos ";
319 fMonitorAlgo->ResetAllHistos();
320 bMcbm2018MonitorTaskMuchResetHistos = kFALSE;
321 } // if( fbMonitorMode && bMcbm2018MonitorTaskBmonResetHistos ) */ //closed by me
322
323 if (kFALSE == fMonitorAlgo->ProcessTs(ts)) {
324 //if (kFALSE == fMonitorAlgo->ProcessMuchMs(ts)) {
325 LOG(error) << "Failed processing TS " << ts.index() << " in unpacker algorithm class";
326 return kTRUE;
327 } // if( kFALSE == fMonitorAlgo->ProcessTs( ts ) )
328
330 std::vector<CbmMuchBeamTimeDigi> vDigi = fMonitorAlgo->GetVector();
332
333 if (0 == fulTsCounter % 10000) LOG(info) << "Processed " << fulTsCounter << "TS";
334 fulTsCounter++;
335
336 return kTRUE;
337}
338
339
341
343{
346 std::vector<std::pair<TNamed*, std::string>> vHistos = fMonitorAlgo->GetHistoVector();
347
349 TFile* oldFile = gFile;
350 TDirectory* oldDir = gDirectory;
351
352 TFile* histoFile = nullptr;
353
354 // open separate histo file in recreate mode
355 histoFile = new TFile(fsHistoFilename, "RECREATE");
356 histoFile->cd();
357
359 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
361 TString sFolder = vHistos[uHisto].second.data();
362 if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
363 gDirectory->cd(sFolder);
364
366 vHistos[uHisto].first->Write();
367
368 histoFile->cd();
369 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
370
372 gFile = oldFile;
373 gDirectory = oldDir;
374
375 histoFile->Close();
376}
377
379
380/*void CbmMcbm2018MonitorTaskMuchLite::SetChannelMap(UInt_t uChan0,
381 UInt_t uChan1,
382 UInt_t uChan2,
383 UInt_t uChan3,
384 UInt_t uChan4,
385 UInt_t uChan5,
386 UInt_t uChan6,
387 UInt_t uChan7) {
388 fMonitorAlgo->SetChannelMap(
389 uChan0, uChan1, uChan2, uChan3, uChan4, uChan5, uChan6, uChan7);
390} */
391
ClassImp(CbmConverterManager)
Bool_t bMcbm2018ResetTaskMuchLite
Bool_t bMcbm2018WriteTaskMuchLite
Bool_t bMcbm2018ScanNoisyTaskMuchLite
Bool_t ProcessTs(const fles::Timeslice &ts)
Bool_t ScanForNoisyChannels(Double_t dNoiseThreshold=1e3)
---------------------------------------------------------------—///
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
void SetHistoryHistoSize(UInt_t inHistorySizeSec=1800)
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
UInt_t fuHistoryHistoSize
Histograms related variables.
CbmMcbm2018MonitorAlgoMuchLite * fMonitorAlgo
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
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.