CbmRoot
CbmMcbm2018MonitorTaskTofPulser.cxx
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 // ----- -----
3 // ----- CbmMcbm2018MonitorTaskTofPulser -----
4 // ----- Created 27.11.2019 by P.-A. Loizeau -----
5 // ----- -----
6 // -----------------------------------------------------------------------------
7 
9 
11 #include "CbmMcbm2018TofPar.h"
12 
13 #include "FairLogger.h"
14 #include "FairParGenericSet.h"
15 #include "FairRootManager.h"
16 #include "FairRun.h"
17 #include "FairRunOnline.h"
18 #include "FairRuntimeDb.h"
19 
20 #include "TCanvas.h"
21 #include "THttpServer.h"
22 #include "TList.h"
23 #include "TROOT.h"
24 #include "TString.h"
25 #include <TFile.h>
26 
27 #include <chrono>
28 #include <fstream>
29 #include <iomanip>
30 #include <iostream>
31 #include <stdint.h>
32 
35 
37  : CbmMcbmUnpack()
38  , fsHistoFileName("data/HistosMonitorPulser.root")
39  , fuUpdateFreqTs(100)
40  , fuPulserMinTot(90)
41  , fuPulserMaxTot(110)
42  , fuPulserChannel(3)
43  , fiGdpbIndex(-1)
44  , fuHistoryHistoSize(1800)
45  , fulTsCounter(0)
46  , fMonitorPulserAlgo(nullptr) {
48 }
49 
51  delete fMonitorPulserAlgo;
52 }
53 
55  LOG(info) << "CbmMcbm2018MonitorTaskTofPulser::Init";
56  LOG(info) << "Initializing mCBM 2019 Monitor task";
57 
58  return kTRUE;
59 }
60 
62  LOG(info) << "Setting parameter containers for " << GetName();
63 
64  TList* parCList = fMonitorPulserAlgo->GetParList();
65 
66  for (Int_t iparC = 0; iparC < parCList->GetEntries(); ++iparC) {
67  FairParGenericSet* tempObj = (FairParGenericSet*) (parCList->At(iparC));
68  parCList->Remove(tempObj);
69 
70  std::string sParamName {tempObj->GetName()};
71  FairParGenericSet* newObj = dynamic_cast<FairParGenericSet*>(
72  FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
73 
74  if (nullptr == newObj) {
75  LOG(error) << "Failed to obtain parameter container " << sParamName
76  << ", for parameter index " << iparC;
77  return;
78  } // if( nullptr == newObj )
79 
80  parCList->AddAt(newObj, iparC);
81  // delete tempObj;
82  } // for( Int_t iparC = 0; iparC < parCList->GetEntries(); ++iparC )
83 }
84 
86  LOG(info) << "Init parameter containers for " << GetName();
87 
89  CbmMcbm2018TofPar* pUnpackPar = dynamic_cast<CbmMcbm2018TofPar*>(
90  FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018TofPar"));
91  if (nullptr == pUnpackPar) {
92  LOG(error) << "Failed to obtain parameter container CbmMcbm2018TofPar";
93  return kFALSE;
94  } // if( nullptr == pUnpackPar )
95 
101 
102  Bool_t initOK = fMonitorPulserAlgo->InitContainers();
103 
107 
109  std::vector<std::pair<TNamed*, std::string>> vHistos =
112  std::vector<std::pair<TCanvas*, std::string>> vCanvases =
114 
116  THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
117  if (nullptr != server) {
118  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
119  // LOG(info) << "Registering " << vHistos[ uHisto ].first->GetName()
120  // << " in " << vHistos[ uHisto ].second.data();
121  server->Register(Form("/%s", vHistos[uHisto].second.data()),
122  vHistos[uHisto].first);
123  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
124 
125  for (UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv) {
126  // LOG(info) << "Registering " << vCanvases[ uCanv ].first->GetName()
127  // << " in " << vCanvases[ uCanv ].second.data();
128  server->Register(Form("/%s", vCanvases[uCanv].second.data()),
129  gROOT->FindObject((vCanvases[uCanv].first)->GetName()));
130  } // for( UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv )
131 
132  server->RegisterCommand("/Reset_Pulser_Hist",
133  "bMcbm2018MonitorTaskTofPulserResetHistos=kTRUE");
134  server->RegisterCommand("/Save_Pulser_Hist",
135  "bMcbm2018MonitorTaskTofPulserSaveHistos=kTRUE");
136 
137  server->Restrict("/Reset_Moni_Hist", "allow=admin");
138  } // if( nullptr != server )
139 
140  return initOK;
141 }
142 
144  LOG(info) << "ReInit parameter containers for " << GetName();
145  Bool_t initOK = fMonitorPulserAlgo->ReInitContainers();
146 
147  return initOK;
148 }
149 
151  size_t component,
152  UShort_t usDetectorId) {
153  fMonitorPulserAlgo->AddMsComponentToList(component, usDetectorId);
154 }
155 
156 Bool_t CbmMcbm2018MonitorTaskTofPulser::DoUnpack(const fles::Timeslice& ts,
157  size_t /*component*/) {
159  LOG(info) << "Reset Monitor histos ";
162  } // if( bMcbm2018MonitorTaskTofPulserResetHistos )
163 
165  LOG(info) << "Save Monitor histos & canvases";
166  SaveHistograms();
168  } // if( bMcbm2018MonitorTaskTofPulserSaveHistos )
169 
170  if (kFALSE == fMonitorPulserAlgo->ProcessTs(ts)) {
171  LOG(error) << "Failed processing TS " << ts.index()
172  << " 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)
181  LOG(info) << "Processed " << fulTsCounter << "TS";
182  fulTsCounter++;
183 
184  return kTRUE;
185 }
186 
188 
191  SaveHistograms();
192 }
193 
196 }
197 
200  std::vector<std::pair<TNamed*, std::string>> vHistos =
202  std::vector<std::pair<TCanvas*, std::string>> vCanvas =
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 
216  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
218  TString sFolder = vHistos[uHisto].second.data();
219  if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
220  gDirectory->cd(sFolder);
221 
223  vHistos[uHisto].first->Write();
224 
225  histoFile->cd();
226  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
227 
228  for (UInt_t uCanvas = 0; uCanvas < vCanvas.size(); ++uCanvas) {
230  TString sFolder = vCanvas[uCanvas].second.data();
231  if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
232  gDirectory->cd(sFolder);
233 
235  vCanvas[uCanvas].first->Write();
236 
237  histoFile->cd();
238  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
239 
240  // Restore original directory position
241  oldDir->cd();
242  histoFile->Close();
243 
244  return kTRUE;
245 }
CbmMcbm2018MonitorAlgoTofPulser::ProcessTs
Bool_t ProcessTs(const fles::Timeslice &ts)
Definition: CbmMcbm2018MonitorAlgoTofPulser.cxx:208
CbmMcbm2018MonitorAlgoTofPulser::UpdateStats
Bool_t UpdateStats()
Definition: CbmMcbm2018MonitorAlgoTofPulser.cxx:774
CbmStar2019Algo::GetCanvasVector
std::vector< std::pair< TCanvas *, std::string > > GetCanvasVector()
Definition: CbmStar2019Algo.h:91
CbmStar2019Algo::GetHistoVector
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
Definition: CbmStar2019Algo.h:84
CbmMcbm2018MonitorAlgoTofPulser::SetUpdateFreqTs
void SetUpdateFreqTs(UInt_t uFreq=100)
Definition: CbmMcbm2018MonitorAlgoTofPulser.h:60
CbmStar2019Algo::GetVector
std::vector< T > & GetVector()
Definition: CbmStar2019Algo.h:97
CbmMcbm2018TofPar.h
CbmMcbm2018MonitorAlgoTofPulser::ResetHistograms
Bool_t ResetHistograms()
Definition: CbmMcbm2018MonitorAlgoTofPulser.cxx:851
CbmMcbm2018MonitorTaskTofPulser::fsHistoFileName
TString fsHistoFileName
Control flags.
Definition: CbmMcbm2018MonitorTaskTofPulser.h:64
CbmMcbm2018MonitorTaskTofPulser::fuUpdateFreqTs
UInt_t fuUpdateFreqTs
Definition: CbmMcbm2018MonitorTaskTofPulser.h:65
CbmMcbm2018MonitorTaskTofPulser::fuPulserMinTot
UInt_t fuPulserMinTot
Definition: CbmMcbm2018MonitorTaskTofPulser.h:66
CbmMcbm2018MonitorTaskTofPulser::~CbmMcbm2018MonitorTaskTofPulser
virtual ~CbmMcbm2018MonitorTaskTofPulser()
Definition: CbmMcbm2018MonitorTaskTofPulser.cxx:50
CbmMcbm2018MonitorAlgoTofPulser::SetPulserTotLimits
void SetPulserTotLimits(UInt_t uMin, UInt_t uMax)
Definition: CbmMcbm2018MonitorAlgoTofPulser.h:61
CbmMcbm2018MonitorAlgoTofPulser::SetGdpbIndex
void SetGdpbIndex(Int_t iGdpb=-1)
Definition: CbmMcbm2018MonitorAlgoTofPulser.h:59
CbmMcbm2018MonitorAlgoTofPulser.h
CbmMcbm2018MonitorTaskTofPulser::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
Definition: CbmMcbm2018MonitorTaskTofPulser.cxx:150
CbmMcbm2018MonitorTaskTofPulser::fuPulserMaxTot
UInt_t fuPulserMaxTot
Definition: CbmMcbm2018MonitorTaskTofPulser.h:67
CbmMcbm2018MonitorAlgoTofPulser::CreateHistograms
Bool_t CreateHistograms()
Definition: CbmMcbm2018MonitorAlgoTofPulser.cxx:527
CbmMcbm2018MonitorAlgoTofPulser::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018MonitorAlgoTofPulser.cxx:100
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmMcbm2018MonitorTaskTofPulser::DoUnpack
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
Definition: CbmMcbm2018MonitorTaskTofPulser.cxx:156
CbmMcbm2018MonitorAlgoTofPulser::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018MonitorAlgoTofPulser.cxx:106
CbmMcbm2018MonitorTaskTofPulser::fMonitorPulserAlgo
CbmMcbm2018MonitorAlgoTofPulser * fMonitorPulserAlgo
Processing algo.
Definition: CbmMcbm2018MonitorTaskTofPulser.h:76
CbmMcbm2018MonitorTaskTofPulser::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018MonitorTaskTofPulser.cxx:85
CbmMcbm2018MonitorAlgoTofPulser::GetParList
TList * GetParList()
Definition: CbmMcbm2018MonitorAlgoTofPulser.cxx:118
CbmMcbm2018MonitorTaskTofPulser::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Algo settings setters.
Definition: CbmMcbm2018MonitorTaskTofPulser.cxx:194
CbmMcbm2018MonitorAlgoTofPulser::SetPulserChannel
void SetPulserChannel(UInt_t uChan)
Definition: CbmMcbm2018MonitorAlgoTofPulser.h:65
CbmMcbm2018MonitorTaskTofPulser::fulTsCounter
uint64_t fulTsCounter
Statistics & first TS rejection.
Definition: CbmMcbm2018MonitorTaskTofPulser.h:73
CbmMcbm2018MonitorAlgoTofPulser::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Definition: CbmMcbm2018MonitorAlgoTofPulser.cxx:191
CbmMcbm2018TofPar
Definition: CbmMcbm2018TofPar.h:18
CbmMcbm2018MonitorTaskTofPulser::SaveHistograms
Bool_t SaveHistograms()
Definition: CbmMcbm2018MonitorTaskTofPulser.cxx:198
CbmMcbm2018MonitorTaskTofPulser::CbmMcbm2018MonitorTaskTofPulser
CbmMcbm2018MonitorTaskTofPulser()
Definition: CbmMcbm2018MonitorTaskTofPulser.cxx:36
CbmMcbm2018MonitorTaskTofPulser::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018MonitorTaskTofPulser.cxx:143
CbmMcbm2018MonitorTaskTofPulser::Finish
virtual void Finish()
Definition: CbmMcbm2018MonitorTaskTofPulser.cxx:189
CbmMcbm2018MonitorTaskTofPulser::Reset
virtual void Reset()
Definition: CbmMcbm2018MonitorTaskTofPulser.cxx:187
CbmMcbm2018MonitorAlgoTofPulser
Definition: CbmMcbm2018MonitorAlgoTofPulser.h:31
CbmMcbm2018MonitorTaskTofPulser::fuPulserChannel
UInt_t fuPulserChannel
Definition: CbmMcbm2018MonitorTaskTofPulser.h:68
bMcbm2018MonitorTaskTofPulserResetHistos
Bool_t bMcbm2018MonitorTaskTofPulserResetHistos
Definition: CbmMcbm2018MonitorTaskTofPulser.cxx:33
CbmMcbm2018MonitorTaskTofPulser::fiGdpbIndex
Int_t fiGdpbIndex
Definition: CbmMcbm2018MonitorTaskTofPulser.h:69
CbmMcbm2018MonitorTaskTofPulser::SetParContainers
void SetParContainers()
Definition: CbmMcbm2018MonitorTaskTofPulser.cxx:61
bMcbm2018MonitorTaskTofPulserSaveHistos
Bool_t bMcbm2018MonitorTaskTofPulserSaveHistos
Definition: CbmMcbm2018MonitorTaskTofPulser.cxx:34
CbmMcbm2018MonitorTaskTofPulser
Definition: CbmMcbm2018MonitorTaskTofPulser.h:19
CbmStar2019Algo::ClearVector
void ClearVector()
For unpacker algos.
Definition: CbmStar2019Algo.h:96
CbmMcbmUnpack
Definition: CbmMcbmUnpack.h:15
CbmMcbm2018MonitorTaskTofPulser::Init
virtual Bool_t Init()
Definition: CbmMcbm2018MonitorTaskTofPulser.cxx:54
CbmMcbm2018MonitorTaskTofPulser.h
CbmStar2019Algo::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Control flags.
Definition: CbmStar2019Algo.h:102