CbmRoot
CbmMcbm2018MonitorTaskPsd.cxx
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 // ----- -----
3 // ----- CbmMcbm2018MonitorTaskPsd -----
4 // ----- Created 26.09.2019 by N.Karpushkin -----
5 // ----- based on CbmMcbm2018MonitorTaskT0 by P.-A. Loizeau -----
6 // ----- -----
7 // -----------------------------------------------------------------------------
8 
10 
12 #include "CbmMcbm2018PsdPar.h"
13 
14 #include "FairLogger.h"
15 #include "FairParGenericSet.h"
16 #include "FairRootManager.h"
17 #include "FairRun.h"
18 #include "FairRunOnline.h"
19 #include "FairRuntimeDb.h"
20 
21 #include "TCanvas.h"
22 #include "THttpServer.h"
23 #include "TList.h"
24 #include "TROOT.h"
25 #include "TString.h"
26 #include <TFile.h>
27 
28 #include <chrono>
29 #include <fstream>
30 #include <iomanip>
31 #include <iostream>
32 #include <stdint.h>
33 
35 
37  : CbmMcbmUnpack()
38  , fbMonitorMode(kTRUE)
39  , fbDebugMonitorMode(kFALSE)
40  , fuHistoryHistoSize(1800)
41  , fviHistoChargeArgs(3, 0)
42  , fviHistoAmplArgs(3, 0)
43  , fviHistoZLArgs(3, 0)
44  , fsHistoFileName("data/HistosMonitorPsd.root")
45  , fulTsCounter(0)
46  , fMonitorAlgo(nullptr) {
48 }
49 
51 
53  LOG(info) << "CbmMcbm2018MonitorTaskPsd::Init";
54  LOG(info) << "Initializing mCBM Psd 2019 Monitor";
55 
56  return kTRUE;
57 }
58 
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 = dynamic_cast<FairParGenericSet*>(
70  FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
71 
72  if (nullptr == newObj) {
73  LOG(error) << "Failed to obtain parameter container " << sParamName
74  << ", for parameter index " << iparC;
75  return;
76  } // if( nullptr == newObj )
77 
78  parCList->AddAt(newObj, iparC);
79  // delete tempObj;
80  } // for( Int_t iparC = 0; iparC < parCList->GetEntries(); ++iparC )
81 }
82 
84  LOG(info) << "Init parameter containers for " << GetName();
85 
87  CbmMcbm2018PsdPar* pUnpackPar = dynamic_cast<CbmMcbm2018PsdPar*>(
88  FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018PsdPar"));
89  if (nullptr == pUnpackPar) {
90  LOG(error) << "Failed to obtain parameter container CbmMcbm2018PsdPar";
91  return kFALSE;
92  } // if( nullptr == pUnpackPar )
93  /*
94  fbMonitorMode = pUnpackPar->GetMonitorMode();
95  LOG(info) << "Monitor mode: "
96  << ( fbMonitorMode ? "ON" : "OFF" );
97 
98  fbDebugMonitorMode = pUnpackPar->GetDebugMonitorMode();
99  LOG(info) << "Debug Monitor mode: "
100  << ( fbDebugMonitorMode ? "ON" : "OFF" );
101 */
102  Bool_t initOK = fMonitorAlgo->InitContainers();
103 
110 
113  initOK &= fMonitorAlgo->CreateHistograms();
114 
116  std::vector<std::pair<TNamed*, std::string>> vHistos =
119  std::vector<std::pair<TCanvas*, std::string>> vCanvases =
121 
123  THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
124  if (nullptr != server) {
125  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
126  // LOG(info) << "Registering " << vHistos[ uHisto ].first->GetName()
127  // << " in " << vHistos[ uHisto ].second.data();
128  server->Register(Form("/%s", vHistos[uHisto].second.data()),
129  vHistos[uHisto].first);
130  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
131 
132  for (UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv) {
133  // LOG(info) << "Registering " << vCanvases[ uCanv ].first->GetName()
134  // << " in " << vCanvases[ uCanv ].second.data();
135  server->Register(Form("/%s", vCanvases[uCanv].second.data()),
136  gROOT->FindObject((vCanvases[uCanv].first)->GetName()));
137  } // for( UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv )
138 
139  server->RegisterCommand("/Reset_MoniPsd_Hist",
140  "bMcbm2018MonitorTaskPsdResetHistos=kTRUE");
141  // server->Restrict("/Reset_MoniPsd_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 = fMonitorAlgo->ReInitContainers();
150 
151  return initOK;
152 }
153 
155  UShort_t usDetectorId) {
156  fMonitorAlgo->AddMsComponentToList(component, usDetectorId);
157 }
158 
159 Bool_t CbmMcbm2018MonitorTaskPsd::DoUnpack(const fles::Timeslice& ts,
160  size_t /*component*/) {
162  LOG(info) << "Reset Psd Monitor histos ";
165  } // if( fbMonitorMode && bMcbm2018MonitorTaskPsdResetHistos )
166 
167  if (kFALSE == fMonitorAlgo->ProcessTs(ts)) {
168  LOG(error) << "Failed processing TS " << ts.index()
169  << " in unpacker algorithm class";
170  return kTRUE;
171  } // if( kFALSE == fMonitorAlgo->ProcessTs( ts ) )
172 
174  std::vector<CbmPsdDigi> vDigi = fMonitorAlgo->GetVector();
176 
177  if (0 == fulTsCounter % 10000)
178  LOG(info) << "Processed " << fulTsCounter << "TS";
179  fulTsCounter++;
180 
181  return kTRUE;
182 }
183 
185 
188  std::vector<std::pair<TNamed*, std::string>> vHistos =
190 
192  TDirectory* oldDir = NULL;
193  TFile* histoFile = NULL;
194  // Store current directory position to allow restore later
195  oldDir = gDirectory;
196  // open separate histo file in recreate mode
197  histoFile = new TFile(fsHistoFileName, "RECREATE");
198  histoFile->cd();
199 
201  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
203  TString sFolder = vHistos[uHisto].second.data();
204  if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
205  gDirectory->cd(sFolder);
206 
208  vHistos[uHisto].first->Write();
209 
210  histoFile->cd();
211  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
212 
213  // Restore original directory position
214  oldDir->cd();
215  histoFile->Close();
216 }
217 
220 }
221 
CbmMcbm2018MonitorTaskPsd::Reset
virtual void Reset()
Definition: CbmMcbm2018MonitorTaskPsd.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
CbmMcbm2018MonitorAlgoPsd::ResetHistograms
Bool_t ResetHistograms()
Definition: CbmMcbm2018MonitorAlgoPsd.cxx:1184
CbmMcbm2018MonitorTaskPsd::DoUnpack
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
Definition: CbmMcbm2018MonitorTaskPsd.cxx:159
CbmMcbm2018MonitorAlgoPsd::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Definition: CbmMcbm2018MonitorAlgoPsd.cxx:200
CbmMcbm2018MonitorTaskPsd::~CbmMcbm2018MonitorTaskPsd
virtual ~CbmMcbm2018MonitorTaskPsd()
Definition: CbmMcbm2018MonitorTaskPsd.cxx:50
CbmStar2019Algo::GetVector
std::vector< T > & GetVector()
Definition: CbmStar2019Algo.h:97
CbmMcbm2018MonitorTaskPsd::fulTsCounter
uint64_t fulTsCounter
Statistics & first TS rejection.
Definition: CbmMcbm2018MonitorTaskPsd.h:78
CbmMcbm2018PsdPar.h
CbmMcbm2018MonitorTaskPsd::fuHistoryHistoSize
UInt_t fuHistoryHistoSize
Switch ON the filling of a additional set of histograms.
Definition: CbmMcbm2018MonitorTaskPsd.h:68
CbmMcbm2018MonitorTaskPsd.h
CbmMcbm2018MonitorTaskPsd::fviHistoChargeArgs
std::vector< Int_t > fviHistoChargeArgs
Definition: CbmMcbm2018MonitorTaskPsd.h:70
CbmMcbm2018MonitorTaskPsd::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018MonitorTaskPsd.cxx:83
CbmMcbm2018MonitorAlgoPsd::ProcessTs
Bool_t ProcessTs(const fles::Timeslice &ts)
Definition: CbmMcbm2018MonitorAlgoPsd.cxx:215
CbmMcbm2018MonitorTaskPsd::Init
virtual Bool_t Init()
Definition: CbmMcbm2018MonitorTaskPsd.cxx:52
CbmMcbm2018MonitorAlgoPsd::SetChargeHistoArgs
void SetChargeHistoArgs(std::vector< Int_t > inVec)
Definition: CbmMcbm2018MonitorAlgoPsd.h:67
CbmMcbm2018MonitorAlgoPsd::SetAmplHistoArgs
void SetAmplHistoArgs(std::vector< Int_t > inVec)
Definition: CbmMcbm2018MonitorAlgoPsd.h:70
CbmMcbm2018MonitorAlgoPsd
Definition: CbmMcbm2018MonitorAlgoPsd.h:34
CbmMcbm2018PsdPar
Definition: CbmMcbm2018PsdPar.h:19
CbmMcbm2018MonitorTaskPsd::fviHistoZLArgs
std::vector< Int_t > fviHistoZLArgs
Definition: CbmMcbm2018MonitorTaskPsd.h:74
CbmMcbm2018MonitorAlgoPsd::CreateHistograms
Bool_t CreateHistograms()
Definition: CbmMcbm2018MonitorAlgoPsd.cxx:608
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmMcbm2018MonitorAlgoPsd::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018MonitorAlgoPsd.cxx:147
CbmMcbm2018MonitorTaskPsd::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018MonitorTaskPsd.cxx:218
CbmMcbm2018MonitorAlgoPsd::SetZLHistoArgs
void SetZLHistoArgs(std::vector< Int_t > inVec)
Definition: CbmMcbm2018MonitorAlgoPsd.h:73
CbmMcbm2018MonitorTaskPsd::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
Definition: CbmMcbm2018MonitorTaskPsd.cxx:154
CbmMcbm2018MonitorAlgoPsd::GetParList
TList * GetParList()
Definition: CbmMcbm2018MonitorAlgoPsd.cxx:164
bMcbm2018MonitorTaskPsdResetHistos
Bool_t bMcbm2018MonitorTaskPsdResetHistos
Definition: CbmMcbm2018MonitorTaskPsd.cxx:34
CbmMcbm2018MonitorTaskPsd::SetParContainers
void SetParContainers()
Definition: CbmMcbm2018MonitorTaskPsd.cxx:59
CbmMcbm2018MonitorTaskPsd::fbMonitorMode
Bool_t fbMonitorMode
Control flags.
Definition: CbmMcbm2018MonitorTaskPsd.h:63
CbmMcbm2018MonitorAlgoPsd::SetHistoryHistoSize
void SetHistoryHistoSize(UInt_t inHistorySizeSec=1800)
Definition: CbmMcbm2018MonitorAlgoPsd.h:64
CbmMcbm2018MonitorTaskPsd::fsHistoFileName
TString fsHistoFileName
Definition: CbmMcbm2018MonitorTaskPsd.h:75
CbmMcbm2018MonitorAlgoPsd::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018MonitorAlgoPsd.cxx:153
CbmMcbm2018MonitorTaskPsd::CbmMcbm2018MonitorTaskPsd
CbmMcbm2018MonitorTaskPsd()
Definition: CbmMcbm2018MonitorTaskPsd.cxx:36
CbmMcbm2018MonitorTaskPsd::Finish
virtual void Finish()
Definition: CbmMcbm2018MonitorTaskPsd.cxx:186
CbmMcbm2018MonitorTaskPsd::fviHistoAmplArgs
std::vector< Int_t > fviHistoAmplArgs
Definition: CbmMcbm2018MonitorTaskPsd.h:72
CbmMcbm2018MonitorTaskPsd
Definition: CbmMcbm2018MonitorTaskPsd.h:20
CbmMcbm2018MonitorTaskPsd::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018MonitorTaskPsd.cxx:147
CbmStar2019Algo::ClearVector
void ClearVector()
For unpacker algos.
Definition: CbmStar2019Algo.h:96
CbmMcbm2018MonitorAlgoPsd.h
CbmMcbmUnpack
Definition: CbmMcbmUnpack.h:15
CbmMcbm2018MonitorTaskPsd::fMonitorAlgo
CbmMcbm2018MonitorAlgoPsd * fMonitorAlgo
Processing algo.
Definition: CbmMcbm2018MonitorTaskPsd.h:81
CbmMcbm2018MonitorAlgoPsd::SetMonitorMode
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018MonitorAlgoPsd.h:61
CbmStar2019Algo::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Control flags.
Definition: CbmStar2019Algo.h:102