CbmRoot
CbmMcbm2018MonitorTaskT0.cxx
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 // ----- -----
3 // ----- CbmMcbm2018MonitorTaskT0 -----
4 // ----- Created 10.02.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 
34 
36  : CbmMcbmUnpack()
37  , fbMonitorMode(kTRUE)
38  , fbDebugMonitorMode(kFALSE)
39  , fuHistoryHistoSize(3600)
40  , fsHistoFileName("data/HistosMonitorT0.root")
41  , fuMinTotPulser(90)
42  , fuMaxTotPulser(100)
43  , fuOffSpillCountLimit(200)
44  , fulTsCounter(0)
45  , fMonitorAlgo(nullptr) {
47 }
48 
50 
52  LOG(info) << "CbmMcbm2018MonitorTaskT0::Init";
53  LOG(info) << "Initializing mCBM T0 2019 Monitor";
54 
55  return kTRUE;
56 }
57 
59  LOG(info) << "Setting parameter containers for " << GetName();
60 
61  TList* parCList = fMonitorAlgo->GetParList();
62 
63  for (Int_t iparC = 0; iparC < parCList->GetEntries(); ++iparC) {
64  FairParGenericSet* tempObj = (FairParGenericSet*) (parCList->At(iparC));
65  parCList->Remove(tempObj);
66 
67  std::string sParamName {tempObj->GetName()};
68  FairParGenericSet* newObj = dynamic_cast<FairParGenericSet*>(
69  FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
70 
71  if (nullptr == newObj) {
72  LOG(error) << "Failed to obtain parameter container " << sParamName
73  << ", 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 
83  LOG(info) << "Init parameter containers for " << GetName();
84 
86  CbmMcbm2018TofPar* pUnpackPar = dynamic_cast<CbmMcbm2018TofPar*>(
87  FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018TofPar"));
88  if (nullptr == pUnpackPar) {
89  LOG(error) << "Failed to obtain parameter container CbmMcbm2018TofPar";
90  return kFALSE;
91  } // if( nullptr == pUnpackPar )
92  /*
93  fbMonitorMode = pUnpackPar->GetMonitorMode();
94  LOG(info) << "Monitor mode: "
95  << ( fbMonitorMode ? "ON" : "OFF" );
96 
97  fbDebugMonitorMode = pUnpackPar->GetDebugMonitorMode();
98  LOG(info) << "Debug Monitor mode: "
99  << ( fbDebugMonitorMode ? "ON" : "OFF" );
100 */
101  Bool_t initOK = fMonitorAlgo->InitContainers();
102 
108 
111  initOK &= fMonitorAlgo->CreateHistograms();
112 
114  std::vector<std::pair<TNamed*, std::string>> vHistos =
117  std::vector<std::pair<TCanvas*, std::string>> vCanvases =
119 
121  THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
122  if (nullptr != server) {
123  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
124  // LOG(info) << "Registering " << vHistos[ uHisto ].first->GetName()
125  // << " in " << vHistos[ uHisto ].second.data();
126  server->Register(Form("/%s", vHistos[uHisto].second.data()),
127  vHistos[uHisto].first);
128  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
129 
130  for (UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv) {
131  // LOG(info) << "Registering " << vCanvases[ uCanv ].first->GetName()
132  // << " in " << vCanvases[ uCanv ].second.data();
133  server->Register(Form("/%s", vCanvases[uCanv].second.data()),
134  gROOT->FindObject((vCanvases[uCanv].first)->GetName()));
135  } // for( UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv )
136 
137  server->RegisterCommand("/Reset_MoniT0_Hist",
138  "bMcbm2018MonitorTaskT0ResetHistos=kTRUE");
139  server->Restrict("/Reset_MoniT0_Hist", "allow=admin");
140  } // if( nullptr != server )
141 
142  return initOK;
143 }
144 
146  LOG(info) << "ReInit parameter containers for " << GetName();
147  Bool_t initOK = fMonitorAlgo->ReInitContainers();
148 
149  return initOK;
150 }
151 
153  UShort_t usDetectorId) {
154  fMonitorAlgo->AddMsComponentToList(component, usDetectorId);
155 }
156 
157 Bool_t CbmMcbm2018MonitorTaskT0::DoUnpack(const fles::Timeslice& ts,
158  size_t /*component*/) {
160  LOG(info) << "Reset T0 Monitor histos ";
163  } // if( fbMonitorMode && bMcbm2018MonitorTaskT0ResetHistos )
164 
165  if (kFALSE == fMonitorAlgo->ProcessTs(ts)) {
166  LOG(error) << "Failed processing TS " << ts.index()
167  << " in unpacker algorithm class";
168  return kTRUE;
169  } // if( kFALSE == fMonitorAlgo->ProcessTs( ts ) )
170 
172  std::vector<CbmTofDigi> vDigi = fMonitorAlgo->GetVector();
174 
175  if (0 == fulTsCounter % 10000)
176  LOG(info) << "Processed " << fulTsCounter << "TS";
177  fulTsCounter++;
178 
179  return kTRUE;
180 }
181 
183 
186  std::vector<std::pair<TNamed*, std::string>> vHistos =
188 
190  TDirectory* oldDir = NULL;
191  TFile* histoFile = NULL;
192  // Store current directory position to allow restore later
193  oldDir = gDirectory;
194  // open separate histo file in recreate mode
195  histoFile = new TFile(fsHistoFileName, "RECREATE");
196  histoFile->cd();
197 
199  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
201  TString sFolder = vHistos[uHisto].second.data();
202  if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
203  gDirectory->cd(sFolder);
204 
206  vHistos[uHisto].first->Write();
207 
208  histoFile->cd();
209  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
210 
211  // Restore original directory position
212  oldDir->cd();
213  histoFile->Close();
214 }
215 
218 }
219 
221  UInt_t uChan1,
222  UInt_t uChan2,
223  UInt_t uChan3,
224  UInt_t uChan4,
225  UInt_t uChan5,
226  UInt_t uChan6,
227  UInt_t uChan7) {
229  uChan0, uChan1, uChan2, uChan3, uChan4, uChan5, uChan6, uChan7);
230 }
231 
CbmMcbm2018MonitorTaskT0::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018MonitorTaskT0.cxx:145
CbmMcbm2018MonitorTaskT0::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018MonitorTaskT0.cxx:82
bMcbm2018MonitorTaskT0ResetHistos
Bool_t bMcbm2018MonitorTaskT0ResetHistos
Definition: CbmMcbm2018MonitorTaskT0.cxx:33
CbmMcbm2018MonitorTaskT0::Finish
virtual void Finish()
Definition: CbmMcbm2018MonitorTaskT0.cxx:184
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
CbmMcbm2018MonitorTaskT0::Reset
virtual void Reset()
Definition: CbmMcbm2018MonitorTaskT0.cxx:182
CbmMcbm2018MonitorTaskT0
Definition: CbmMcbm2018MonitorTaskT0.h:18
CbmStar2019Algo::GetVector
std::vector< T > & GetVector()
Definition: CbmStar2019Algo.h:97
CbmMcbm2018TofPar.h
CbmMcbm2018MonitorAlgoT0::SetChannelMap
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)
Definition: CbmMcbm2018MonitorAlgoT0.h:75
CbmMcbm2018MonitorAlgoT0::SetSpillThreshold
void SetSpillThreshold(UInt_t uCntLimit)
Definition: CbmMcbm2018MonitorAlgoT0.h:72
CbmMcbm2018MonitorAlgoT0::ResetHistograms
Bool_t ResetHistograms(Bool_t bResetTime=kTRUE)
Definition: CbmMcbm2018MonitorAlgoT0.cxx:1339
CbmMcbm2018MonitorAlgoT0::SetHistoryHistoSize
void SetHistoryHistoSize(UInt_t inHistorySizeSec=1800)
Definition: CbmMcbm2018MonitorAlgoT0.h:65
CbmMcbm2018MonitorTaskT0::fuMaxTotPulser
UInt_t fuMaxTotPulser
Definition: CbmMcbm2018MonitorTaskT0.h:78
CbmMcbm2018MonitorTaskT0::fMonitorAlgo
CbmMcbm2018MonitorAlgoT0 * fMonitorAlgo
Processing algo.
Definition: CbmMcbm2018MonitorTaskT0.h:85
CbmMcbm2018MonitorTaskT0::Init
virtual Bool_t Init()
Definition: CbmMcbm2018MonitorTaskT0.cxx:51
CbmMcbm2018MonitorAlgoT0::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018MonitorAlgoT0.cxx:61
CbmMcbm2018MonitorAlgoT0
Definition: CbmMcbm2018MonitorAlgoT0.h:35
CbmMcbm2018MonitorTaskT0::fuMinTotPulser
UInt_t fuMinTotPulser
Definition: CbmMcbm2018MonitorTaskT0.h:77
CbmMcbm2018MonitorTaskT0::~CbmMcbm2018MonitorTaskT0
virtual ~CbmMcbm2018MonitorTaskT0()
Definition: CbmMcbm2018MonitorTaskT0.cxx:49
CbmMcbm2018MonitorTaskT0.h
CbmMcbm2018MonitorAlgoT0::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Definition: CbmMcbm2018MonitorAlgoT0.cxx:130
CbmMcbm2018MonitorAlgoT0::ProcessTs
Bool_t ProcessTs(const fles::Timeslice &ts)
Definition: CbmMcbm2018MonitorAlgoT0.cxx:145
CbmMcbm2018MonitorTaskT0::CbmMcbm2018MonitorTaskT0
CbmMcbm2018MonitorTaskT0()
Definition: CbmMcbm2018MonitorTaskT0.cxx:35
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmMcbm2018MonitorTaskT0::fulTsCounter
uint64_t fulTsCounter
Statistics & first TS rejection.
Definition: CbmMcbm2018MonitorTaskT0.h:82
CbmMcbm2018MonitorTaskT0::SetChannelMap
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)
Definition: CbmMcbm2018MonitorTaskT0.cxx:220
CbmMcbm2018MonitorTaskT0::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
Definition: CbmMcbm2018MonitorTaskT0.cxx:152
CbmMcbm2018MonitorTaskT0::fuOffSpillCountLimit
UInt_t fuOffSpillCountLimit
Definition: CbmMcbm2018MonitorTaskT0.h:79
CbmMcbm2018MonitorAlgoT0::SetPulserTotLimits
void SetPulserTotLimits(UInt_t uMin, UInt_t uMax)
Definition: CbmMcbm2018MonitorAlgoT0.h:68
CbmMcbm2018MonitorTaskT0::DoUnpack
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
Definition: CbmMcbm2018MonitorTaskT0.cxx:157
CbmMcbm2018TofPar
Definition: CbmMcbm2018TofPar.h:18
CbmMcbm2018MonitorTaskT0::fuHistoryHistoSize
UInt_t fuHistoryHistoSize
Switch ON the filling of a additional set of histograms.
Definition: CbmMcbm2018MonitorTaskT0.h:75
CbmMcbm2018MonitorTaskT0::fbMonitorMode
Bool_t fbMonitorMode
Control flags.
Definition: CbmMcbm2018MonitorTaskT0.h:70
CbmMcbm2018MonitorTaskT0::fsHistoFileName
TString fsHistoFileName
Definition: CbmMcbm2018MonitorTaskT0.h:76
CbmMcbm2018MonitorAlgoT0::SetMonitorMode
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018MonitorAlgoT0.h:62
CbmStar2019Algo::ClearVector
void ClearVector()
For unpacker algos.
Definition: CbmStar2019Algo.h:96
CbmMcbm2018MonitorTaskT0::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018MonitorTaskT0.cxx:216
CbmMcbmUnpack
Definition: CbmMcbmUnpack.h:15
CbmMcbm2018MonitorAlgoT0::GetParList
TList * GetParList()
Definition: CbmMcbm2018MonitorAlgoT0.cxx:78
CbmMcbm2018MonitorAlgoT0::CreateHistograms
Bool_t CreateHistograms()
Definition: CbmMcbm2018MonitorAlgoT0.cxx:753
CbmMcbm2018MonitorTaskT0::SetParContainers
void SetParContainers()
Definition: CbmMcbm2018MonitorTaskT0.cxx:58
CbmMcbm2018MonitorAlgoT0::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018MonitorAlgoT0.cxx:67
CbmStar2019Algo::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Control flags.
Definition: CbmStar2019Algo.h:102
CbmMcbm2018MonitorAlgoT0.h