CbmRoot
CbmStar2019MonitorPulserTask.cxx
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 // ----- -----
3 // ----- CbmStar2019MonitorPulserTask -----
4 // ----- Created 12.10.2019 by P.-A. Loizeau -----
5 // ----- -----
6 // -----------------------------------------------------------------------------
7 
9 
11 #include "CbmStar2019TofPar.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 "TClonesArray.h"
22 #include "THttpServer.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  , fbEtofFeeIndexing(kTRUE)
39  , fsHistoFileName("data/HistosMonitorPulser.root")
40  , fuUpdateFreqTs(100)
41  , fuPulserMinTot(90)
42  , fuPulserMaxTot(110)
43  , fuPulserChannel(3)
44  , fiSectorIndex(-1)
45  , fuHistoryHistoSize(1800)
46  , fParCList(nullptr)
47  , fulTsCounter(0)
48  , fMonitorPulserAlgo(nullptr) {
50 }
51 
53  delete fMonitorPulserAlgo;
54 }
55 
57  LOG(info) << "CbmStar2019MonitorPulserTask::Init";
58  LOG(info) << "Initializing eTOF 2019 Monitor task";
59 
60  return kTRUE;
61 }
62 
64  LOG(info) << "Setting parameter containers for " << GetName();
65 
67 
68  for (Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC) {
69  FairParGenericSet* tempObj = (FairParGenericSet*) (fParCList->At(iparC));
70  fParCList->Remove(tempObj);
71 
72  std::string sParamName {tempObj->GetName()};
73  FairParGenericSet* newObj = dynamic_cast<FairParGenericSet*>(
74  FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
75 
76  if (nullptr == newObj) {
77  LOG(error) << "Failed to obtain parameter container " << sParamName
78  << ", for parameter index " << iparC;
79  return;
80  } // if( nullptr == newObj )
81 
82  fParCList->AddAt(newObj, iparC);
83  // delete tempObj;
84  } // for( Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC )
85 }
86 
88  LOG(info) << "Init parameter containers for " << GetName();
89 
91  CbmStar2019TofPar* pUnpackPar = dynamic_cast<CbmStar2019TofPar*>(
92  FairRun::Instance()->GetRuntimeDb()->getContainer("CbmStar2019TofPar"));
93  if (nullptr == pUnpackPar) {
94  LOG(error) << "Failed to obtain parameter container CbmStar2019TofPar";
95  return kFALSE;
96  } // if( nullptr == pUnpackPar )
97 
104 
105  Bool_t initOK = fMonitorPulserAlgo->InitContainers();
106 
110 
112  std::vector<std::pair<TNamed*, std::string>> vHistos =
115  std::vector<std::pair<TCanvas*, std::string>> vCanvases =
117 
119  THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
120  if (nullptr != server) {
121  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
122  // LOG(info) << "Registering " << vHistos[ uHisto ].first->GetName()
123  // << " in " << vHistos[ uHisto ].second.data();
124  server->Register(Form("/%s", vHistos[uHisto].second.data()),
125  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",
136  "bStar2019MonitorPulserTaskResetHistos=kTRUE");
137  server->RegisterCommand("/Save_Pulser_Hist",
138  "bStar2019MonitorPulserTaskSaveHistos=kTRUE");
139 
140  server->Restrict("/Reset_Moni_Hist", "allow=admin");
141  server->Restrict("/Save_Pulser_Hist", "allow=admin");
142  } // if( nullptr != server )
143 
144  return initOK;
145 }
146 
148  LOG(info) << "ReInit parameter containers for " << GetName();
149  Bool_t initOK = fMonitorPulserAlgo->ReInitContainers();
150 
151  return initOK;
152 }
153 
155  UShort_t usDetectorId) {
156  fMonitorPulserAlgo->AddMsComponentToList(component, usDetectorId);
157 }
158 
159 Bool_t CbmStar2019MonitorPulserTask::DoUnpack(const fles::Timeslice& ts,
160  size_t /*component*/) {
162  LOG(info) << "Reset Monitor histos ";
165  } // if( bStar2019MonitorPulserTaskResetHistos )
166 
168  LOG(info) << "Save Monitor histos & canvases";
169  SaveHistograms();
171  } // if( bStar2019MonitorPulserTaskSaveHistos )
172 
173  if (kFALSE == fMonitorPulserAlgo->ProcessTs(ts)) {
174  LOG(error) << "Failed processing TS " << ts.index()
175  << " in unpacker algorithm class";
176  return kTRUE;
177  } // if( kFALSE == fMonitorPulserAlgo->ProcessTs( ts ) )
178 
180  std::vector<CbmTofDigi> vDigi = fMonitorPulserAlgo->GetVector();
182 
183  if (0 == fulTsCounter % 10000)
184  LOG(info) << "Processed " << fulTsCounter << "TS";
185  fulTsCounter++;
186 
187  return kTRUE;
188 }
189 
191 
194  SaveHistograms();
195 }
196 
199 }
200 
203  std::vector<std::pair<TNamed*, std::string>> vHistos =
205  std::vector<std::pair<TCanvas*, std::string>> vCanvas =
207 
209  TDirectory* oldDir = NULL;
210  TFile* histoFile = NULL;
211  // Store current directory position to allow restore later
212  oldDir = gDirectory;
213  // open separate histo file in recreate mode
214  histoFile = new TFile(fsHistoFileName, "RECREATE");
215 
216  if (nullptr == histoFile) return kFALSE;
217 
219  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
221  TString sFolder = vHistos[uHisto].second.data();
222  if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
223  gDirectory->cd(sFolder);
224 
226  vHistos[uHisto].first->Write();
227 
228  histoFile->cd();
229  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
230 
231  for (UInt_t uCanvas = 0; uCanvas < vCanvas.size(); ++uCanvas) {
233  TString sFolder = vCanvas[uCanvas].second.data();
234  if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
235  gDirectory->cd(sFolder);
236 
238  vCanvas[uCanvas].first->Write();
239 
240  histoFile->cd();
241  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
242 
243  // Restore original directory position
244  oldDir->cd();
245  histoFile->Close();
246 
247  return kTRUE;
248 }
CbmStar2019MonitorPulserAlgo::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Definition: CbmStar2019MonitorPulserAlgo.cxx:196
CbmStar2019MonitorPulserAlgo::SetUpdateFreqTs
void SetUpdateFreqTs(UInt_t uFreq=100)
Definition: CbmStar2019MonitorPulserAlgo.h:63
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
CbmStar2019MonitorPulserTask::fParCList
TList * fParCList
Parameters management.
Definition: CbmStar2019MonitorPulserTask.h:75
CbmStar2019Algo::GetVector
std::vector< T > & GetVector()
Definition: CbmStar2019Algo.h:97
CbmStar2019MonitorPulserTask::InitContainers
Bool_t InitContainers()
Definition: CbmStar2019MonitorPulserTask.cxx:87
CbmStar2019MonitorPulserTask::fulTsCounter
uint64_t fulTsCounter
Statistics & first TS rejection.
Definition: CbmStar2019MonitorPulserTask.h:78
CbmStar2019MonitorPulserAlgo::GetParList
TList * GetParList()
Definition: CbmStar2019MonitorPulserAlgo.cxx:118
CbmStar2019MonitorPulserTask.h
CbmStar2019MonitorPulserAlgo::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmStar2019MonitorPulserAlgo.cxx:107
CbmStar2019MonitorPulserTask::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmStar2019MonitorPulserTask.cxx:147
CbmStar2019MonitorPulserTask::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Algo settings setters.
Definition: CbmStar2019MonitorPulserTask.cxx:197
bStar2019MonitorPulserTaskSaveHistos
Bool_t bStar2019MonitorPulserTaskSaveHistos
Definition: CbmStar2019MonitorPulserTask.cxx:34
CbmStar2019MonitorPulserTask::fuPulserMaxTot
UInt_t fuPulserMaxTot
Definition: CbmStar2019MonitorPulserTask.h:69
CbmStar2019MonitorPulserTask::fuPulserMinTot
UInt_t fuPulserMinTot
Definition: CbmStar2019MonitorPulserTask.h:68
CbmStar2019MonitorPulserAlgo::ResetHistograms
Bool_t ResetHistograms()
Definition: CbmStar2019MonitorPulserAlgo.cxx:935
CbmStar2019MonitorPulserTask::~CbmStar2019MonitorPulserTask
virtual ~CbmStar2019MonitorPulserTask()
Definition: CbmStar2019MonitorPulserTask.cxx:52
CbmStar2019MonitorPulserTask::fsHistoFileName
TString fsHistoFileName
User settings parameters.
Definition: CbmStar2019MonitorPulserTask.h:66
CbmStar2019MonitorPulserAlgo::SetPulserTotLimits
void SetPulserTotLimits(UInt_t uMin, UInt_t uMax)
Definition: CbmStar2019MonitorPulserAlgo.h:64
CbmStar2019MonitorPulserTask::fiSectorIndex
Int_t fiSectorIndex
Definition: CbmStar2019MonitorPulserTask.h:71
CbmStar2019MonitorPulserTask::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
Definition: CbmStar2019MonitorPulserTask.cxx:154
CbmStar2019MonitorPulserAlgo::ProcessTs
Bool_t ProcessTs(const fles::Timeslice &ts)
Definition: CbmStar2019MonitorPulserAlgo.cxx:212
CbmStar2019MonitorPulserTask::fuUpdateFreqTs
UInt_t fuUpdateFreqTs
Definition: CbmStar2019MonitorPulserTask.h:67
CbmStar2019MonitorPulserAlgo::InitContainers
Bool_t InitContainers()
Definition: CbmStar2019MonitorPulserAlgo.cxx:101
CbmStar2019MonitorPulserTask::DoUnpack
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
Definition: CbmStar2019MonitorPulserTask.cxx:159
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmStar2019MonitorPulserAlgo.h
CbmStar2019TofPar.h
CbmStar2019TofPar
Definition: CbmStar2019TofPar.h:18
CbmStar2019MonitorPulserAlgo::UpdateStats
Bool_t UpdateStats()
Definition: CbmStar2019MonitorPulserAlgo.cxx:853
CbmStar2019MonitorPulserTask::fuPulserChannel
UInt_t fuPulserChannel
Definition: CbmStar2019MonitorPulserTask.h:70
CbmStar2019MonitorPulserTask::Init
virtual Bool_t Init()
Definition: CbmStar2019MonitorPulserTask.cxx:56
CbmStar2019MonitorPulserAlgo::CreateHistograms
Bool_t CreateHistograms()
Definition: CbmStar2019MonitorPulserAlgo.cxx:525
CbmStar2019MonitorPulserAlgo::SetSectorIndex
void SetSectorIndex(Int_t iSector=-1)
Definition: CbmStar2019MonitorPulserAlgo.h:62
CbmStar2019MonitorPulserTask::CbmStar2019MonitorPulserTask
CbmStar2019MonitorPulserTask()
Definition: CbmStar2019MonitorPulserTask.cxx:36
CbmStar2019MonitorPulserAlgo::SetPulserChannel
void SetPulserChannel(UInt_t uChan)
Definition: CbmStar2019MonitorPulserAlgo.h:68
CbmStar2019MonitorPulserTask
Definition: CbmStar2019MonitorPulserTask.h:21
CbmStar2019MonitorPulserTask::SetParContainers
void SetParContainers()
Definition: CbmStar2019MonitorPulserTask.cxx:63
CbmStar2019MonitorPulserTask::SaveHistograms
Bool_t SaveHistograms()
Definition: CbmStar2019MonitorPulserTask.cxx:201
CbmStar2019MonitorPulserTask::Reset
virtual void Reset()
Definition: CbmStar2019MonitorPulserTask.cxx:190
CbmStar2019MonitorPulserTask::fbEtofFeeIndexing
Bool_t fbEtofFeeIndexing
Control flags.
Definition: CbmStar2019MonitorPulserTask.h:63
bStar2019MonitorPulserTaskResetHistos
Bool_t bStar2019MonitorPulserTaskResetHistos
Definition: CbmStar2019MonitorPulserTask.cxx:33
CbmStar2019Algo::ClearVector
void ClearVector()
For unpacker algos.
Definition: CbmStar2019Algo.h:96
CbmMcbmUnpack
Definition: CbmMcbmUnpack.h:15
CbmStar2019MonitorPulserTask::fMonitorPulserAlgo
CbmStar2019MonitorPulserAlgo * fMonitorPulserAlgo
Processing algo.
Definition: CbmStar2019MonitorPulserTask.h:81
CbmStar2019MonitorPulserTask::Finish
virtual void Finish()
Definition: CbmStar2019MonitorPulserTask.cxx:192
CbmStar2019MonitorPulserAlgo
Definition: CbmStar2019MonitorPulserAlgo.h:31
CbmStar2019MonitorPulserAlgo::SetEtofFeeIndexing
void SetEtofFeeIndexing(Bool_t bFlagIn=kTRUE)
Definition: CbmStar2019MonitorPulserAlgo.h:59
CbmStar2019Algo::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Control flags.
Definition: CbmStar2019Algo.h:102