CbmRoot
CbmMcbm2018MonitorTaskHodo.cxx
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 // ----- -----
3 // ----- CbmMcbm2018MonitorTaskHodo -----
4 // ----- Created 03.07.2019 by P.-A. Loizeau -----
5 // ----- -----
6 // -----------------------------------------------------------------------------
7 
9 
11 //#include "CbmMcbm2018HodoPar.h"
12 //#include "CbmHodoDigi.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(kFALSE)
39  , fbWriteOutput(kTRUE)
40  , fulTsCounter(0)
41  ,
42  // fHodoDigiCloneArray(),
43  fMonitorAlgo(nullptr) {
45 }
46 
48  delete fMonitorAlgo;
49 }
50 
52  LOG(info) << "CbmMcbm2018MonitorTaskHodo::Init";
53  LOG(info) << "Initializing mCBM Hodoscopes Monitor";
54  /*
55  FairRootManager* ioman = FairRootManager::Instance();
56  if( NULL == ioman )
57  {
58  LOG(fatal) << "No FairRootManager instance";
59  }
60 
61  fHodoDigiCloneArray= new TClonesArray("CbmHodoDigi", 10);
62  if( NULL == fHodoDigiCloneArray )
63  {
64  LOG(fatal) << "Failed creating the STS Digi TClonesarray ";
65  }
66  ioman->Register("CbmHodoDigi", "STS raw Digi", fHodoDigiCloneArray, fbWriteOutput);
67 */
68  return kTRUE;
69 }
70 
72  LOG(info) << "Setting parameter containers for " << GetName();
73 
74  TList* parCList = fMonitorAlgo->GetParList();
75 
76  for (Int_t iparC = 0; iparC < parCList->GetEntries(); ++iparC) {
77  FairParGenericSet* tempObj = (FairParGenericSet*) (parCList->At(iparC));
78  parCList->Remove(tempObj);
79 
80  std::string sParamName {tempObj->GetName()};
81  FairParGenericSet* newObj = dynamic_cast<FairParGenericSet*>(
82  FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
83 
84  if (nullptr == newObj) {
85  LOG(error) << "Failed to obtain parameter container " << sParamName
86  << ", for parameter index " << iparC;
87  return;
88  } // if( nullptr == newObj )
89 
90  parCList->AddAt(newObj, iparC);
91  // delete tempObj;
92  } // for( Int_t iparC = 0; iparC < parCList->GetEntries(); ++iparC )
93 }
94 
96  LOG(info) << "Init parameter containers for " << GetName();
97 
99  /*
100  CbmMcbm2018HodoPar * pUnpackPar = dynamic_cast<CbmMcbm2018HodoPar*>( FairRun::Instance()->GetRuntimeDb()->getContainer( "CbmMcbm2018HodoPar" ) );
101  if( nullptr == pUnpackPar )
102  {
103  LOG(error) << "Failed to obtain parameter container CbmMcbm2018HodoPar";
104  return kFALSE;
105  } // if( nullptr == pUnpackPar )
106 */
107  /*
108  fbMonitorMode = pUnpackPar->GetMonitorMode();
109  LOG(info) << "Monitor mode: "
110  << ( fbMonitorMode ? "ON" : "OFF" );
111 
112  fbDebugMonitorMode = pUnpackPar->GetDebugMonitorMode();
113  LOG(info) << "Debug Monitor mode: "
114  << ( fbDebugMonitorMode ? "ON" : "OFF" );
115 */
116  Bool_t initOK = fMonitorAlgo->InitContainers();
117 
118 
120  initOK &= fMonitorAlgo->CreateHistograms();
121 
123  std::vector<std::pair<TNamed*, std::string>> vHistos =
125  std::vector<std::pair<TCanvas*, std::string>> vCanvas =
127 
129  THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
130  if (nullptr != server) {
131  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
132  if (nullptr != vHistos[uHisto].first)
133  server->Register(Form("/%s", vHistos[uHisto].second.data()),
134  vHistos[uHisto].first);
135  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
136 
137  for (UInt_t uCanvas = 0; uCanvas < vCanvas.size(); ++uCanvas) {
138  if (nullptr != vCanvas[uCanvas].first)
139  server->Register(Form("/%s", vCanvas[uCanvas].second.data()),
140  vCanvas[uCanvas].first);
141  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
142 
143  server->RegisterCommand("/Reset_MoniHodo_Hist",
144  "bMcbm2018MonitorTaskHodoResetHistos=kTRUE");
145  server->Restrict("/Reset_MoniHodo_Hist", "allow=admin");
146  } // if( nullptr != server )
147 
149 
150  return initOK;
151 }
152 
154  LOG(info) << "ReInit parameter containers for " << GetName();
155  Bool_t initOK = fMonitorAlgo->ReInitContainers();
156 
157  return initOK;
158 }
159 
161  UShort_t usDetectorId) {
162  fMonitorAlgo->AddMsComponentToList(component, usDetectorId);
163 }
164 
165 Bool_t CbmMcbm2018MonitorTaskHodo::DoUnpack(const fles::Timeslice& ts,
166  size_t /*component*/) {
168  LOG(info) << "Reset Hodoscopes monitor histos ";
171  } // if( fbMonitorMode && bMcbm2018MonitorTaskHodoResetHistos )
172 
173  if (kFALSE == fMonitorAlgo->ProcessTs(ts)) {
174  LOG(error) << "Failed processing TS " << ts.index()
175  << " in monitor algorithm class";
176  return kTRUE;
177  } // if( kFALSE == fMonitorAlgo->ProcessTs( ts ) )
178  /*
180  std::vector< CbmHodoDigi > vDigi = fMonitorAlgo->GetVector();
181 
182  for( auto digi: vDigi) {
184  LOG(debug) << "Fill digi TClonesarray with "
185  << Form("0x%08x", digi.GetAddress())
186  << " at " << static_cast<Int_t>( fHodoDigiCloneArray->GetEntriesFast() );
187 
188  new( (*fHodoDigiCloneArray)[ fHodoDigiCloneArray->GetEntriesFast() ] )
189  CbmHodoDigi( digi) ;
190  }
191 
192  vDigi.clear();
193  fMonitorAlgo->ClearVector();
194 */
195  if (0 == fulTsCounter % 10000)
196  LOG(info) << "Processed " << fulTsCounter << "TS";
197  fulTsCounter++;
198 
199  if (0 == fulTsCounter % 6000 && 0 < fulTsCounter) SaveHistograms();
200 
201  return kTRUE;
202 }
203 
205  // fHodoDigiCloneArray->Clear();
206 }
207 
210  if (kTRUE == fbMonitorMode) {
211  SaveHistograms();
212  } // if( kTRUE == fbMonitorMode )
213 }
214 
217  std::vector<std::pair<TNamed*, std::string>> vHistos =
219  std::vector<std::pair<TCanvas*, std::string>> vCanvas =
221 
223  TDirectory* oldDir = NULL;
224  TFile* histoFile = NULL;
225  // Store current directory position to allow restore later
226  oldDir = gDirectory;
227  // open separate histo file in recreate mode
228  histoFile = new TFile("data/HistosMonitorHodo.root", "RECREATE");
229 
230  if (nullptr == histoFile) return kFALSE;
231 
232  histoFile->cd();
233 
235  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
237  TString sFolder = vHistos[uHisto].second.data();
238  if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
239  gDirectory->cd(sFolder);
240 
242  vHistos[uHisto].first->Write();
243 
244  histoFile->cd();
245  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
246 
247  for (UInt_t uCanvas = 0; uCanvas < vCanvas.size(); ++uCanvas) {
249  TString sFolder = vCanvas[uCanvas].second.data();
250  if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
251  gDirectory->cd(sFolder);
252 
254  vCanvas[uCanvas].first->Write();
255 
256  histoFile->cd();
257  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
258 
259  // Restore original directory position
260  oldDir->cd();
261  histoFile->Close();
262 
263  return kTRUE;
264 }
265 
268 }
269 
271  fMonitorAlgo->SetTimeOffsetNs(dOffsetIn);
272 }
274  fMonitorAlgo->SetDpbId(uDpbId);
275 }
277  UInt_t uElinkHodoB) {
278  fMonitorAlgo->SetHodoElinkIdx(uElinkHodoA, uElinkHodoB);
279 }
281  Bool_t bSwapHodoB) {
282  fMonitorAlgo->SetHodoSwapXY(bSwapHodoA, bSwapHodoB);
283 }
285  Bool_t bInvHodoB) {
286  fMonitorAlgo->SetHodoInvertX(bInvHodoA, bInvHodoB);
287 }
289  Bool_t bInvHodoB) {
290  fMonitorAlgo->SetHodoInvertY(bInvHodoA, bInvHodoB);
291 }
292 
293 
CbmMcbm2018MonitorTaskHodo::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
Definition: CbmMcbm2018MonitorTaskHodo.cxx:160
CbmMcbm2018MonitorTaskHodo::Reset
virtual void Reset()
Definition: CbmMcbm2018MonitorTaskHodo.cxx:204
CbmMcbm2018MonitorTaskHodo::SetDpbId
void SetDpbId(UInt_t uDpbId=0x5b75)
Definition: CbmMcbm2018MonitorTaskHodo.cxx:273
CbmMcbm2018MonitorAlgoHodo::SetTimeOffsetNs
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018MonitorAlgoHodo.h:66
CbmMcbm2018MonitorAlgoHodo.h
CbmMcbm2018MonitorTaskHodo::DoUnpack
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
Definition: CbmMcbm2018MonitorTaskHodo.cxx:165
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
CbmMcbm2018MonitorAlgoHodo::ProcessTs
Bool_t ProcessTs(const fles::Timeslice &ts)
Definition: CbmMcbm2018MonitorAlgoHodo.cxx:387
CbmMcbm2018MonitorTaskHodo::SetParContainers
void SetParContainers()
Definition: CbmMcbm2018MonitorTaskHodo.cxx:71
CbmMcbm2018MonitorAlgoHodo::SetHodoInvertY
void SetHodoInvertY(Bool_t bInvHodoA=kFALSE, Bool_t bInvHodoB=kTRUE)
Default set closest cosmic setup stack.
Definition: CbmMcbm2018MonitorAlgoHodo.h:85
CbmMcbm2018MonitorAlgoHodo
Definition: CbmMcbm2018MonitorAlgoHodo.h:36
CbmMcbm2018MonitorTaskHodo::SetHodoElinkIdx
void SetHodoElinkIdx(UInt_t uElinkHodoA=5, UInt_t uElinkHodoB=10)
Definition: CbmMcbm2018MonitorTaskHodo.cxx:276
CbmMcbm2018MonitorAlgoHodo::SetHodoElinkIdx
void SetHodoElinkIdx(UInt_t uElinkHodoA=5, UInt_t uElinkHodoB=10)
Definition: CbmMcbm2018MonitorAlgoHodo.h:71
CbmMcbm2018MonitorTaskHodo::SetTimeOffsetNs
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018MonitorTaskHodo.cxx:270
CbmMcbm2018MonitorTaskHodo::fulTsCounter
uint64_t fulTsCounter
If ON the output TClonesArray of digi is written to disk.
Definition: CbmMcbm2018MonitorTaskHodo.h:68
CbmMcbm2018MonitorTaskHodo::SetHodoSwapXY
void SetHodoSwapXY(Bool_t bSwapHodoA=kFALSE, Bool_t bSwapHodoB=kTRUE)
Definition: CbmMcbm2018MonitorTaskHodo.cxx:280
CbmMcbm2018MonitorTaskHodo::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018MonitorTaskHodo.cxx:266
CbmMcbm2018MonitorAlgoHodo::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018MonitorAlgoHodo.cxx:160
CbmMcbm2018MonitorAlgoHodo::SetHodoSwapXY
void SetHodoSwapXY(Bool_t bSwapHodoA=kFALSE, Bool_t bSwapHodoB=kTRUE)
Default set for mMUCH FMC slots 8 and 9.
Definition: CbmMcbm2018MonitorAlgoHodo.h:75
CbmMcbm2018MonitorTaskHodo
Definition: CbmMcbm2018MonitorTaskHodo.h:17
CbmMcbm2018MonitorAlgoHodo::SetDpbId
void SetDpbId(UInt_t uDpbId=0x5b75)
Definition: CbmMcbm2018MonitorAlgoHodo.h:70
CbmMcbm2018MonitorAlgoHodo::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Definition: CbmMcbm2018MonitorAlgoHodo.cxx:372
bMcbm2018MonitorTaskHodoResetHistos
Bool_t bMcbm2018MonitorTaskHodoResetHistos
Definition: CbmMcbm2018MonitorTaskHodo.cxx:34
CbmMcbm2018MonitorAlgoHodo::CreateHistograms
Bool_t CreateHistograms()
Definition: CbmMcbm2018MonitorAlgoHodo.cxx:799
CbmMcbm2018MonitorAlgoHodo::ResetHistograms
Bool_t ResetHistograms()
Definition: CbmMcbm2018MonitorAlgoHodo.cxx:1856
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
first
bool first
Definition: LKFMinuit.cxx:143
CbmMcbm2018MonitorTaskHodo::fMonitorAlgo
CbmMcbm2018MonitorAlgoHodo * fMonitorAlgo
Processing algo.
Definition: CbmMcbm2018MonitorTaskHodo.h:71
CbmMcbm2018MonitorTaskHodo::SaveHistograms
Bool_t SaveHistograms()
Definition: CbmMcbm2018MonitorTaskHodo.cxx:215
CbmMcbm2018MonitorTaskHodo::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018MonitorTaskHodo.cxx:153
CbmMcbm2018MonitorTaskHodo::SetHodoInvertY
void SetHodoInvertY(Bool_t bInvHodoA=kFALSE, Bool_t bInvHodoB=kTRUE)
Definition: CbmMcbm2018MonitorTaskHodo.cxx:288
CbmMcbm2018MonitorTaskHodo.h
CbmMcbm2018MonitorTaskHodo::SetHodoInvertX
void SetHodoInvertX(Bool_t bInvHodoA=kFALSE, Bool_t bInvHodoB=kTRUE)
Definition: CbmMcbm2018MonitorTaskHodo.cxx:284
CbmMcbm2018MonitorAlgoHodo::SetMonitorMode
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018MonitorAlgoHodo.h:63
CbmMcbm2018MonitorAlgoHodo::SetHodoInvertX
void SetHodoInvertX(Bool_t bInvHodoA=kFALSE, Bool_t bInvHodoB=kTRUE)
Default set closest cosmic setup stack.
Definition: CbmMcbm2018MonitorAlgoHodo.h:80
CbmMcbm2018MonitorTaskHodo::Finish
virtual void Finish()
Definition: CbmMcbm2018MonitorTaskHodo.cxx:208
CbmMcbm2018MonitorTaskHodo::Init
virtual Bool_t Init()
Definition: CbmMcbm2018MonitorTaskHodo.cxx:51
CbmMcbm2018MonitorAlgoHodo::GetParList
TList * GetParList()
Definition: CbmMcbm2018MonitorAlgoHodo.cxx:178
CbmMcbm2018MonitorTaskHodo::fbMonitorMode
Bool_t fbMonitorMode
Control flags.
Definition: CbmMcbm2018MonitorTaskHodo.h:61
CbmMcbm2018MonitorAlgoHodo::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018MonitorAlgoHodo.cxx:166
CbmMcbm2018MonitorTaskHodo::CbmMcbm2018MonitorTaskHodo
CbmMcbm2018MonitorTaskHodo(UInt_t uNbSdpb=1)
Definition: CbmMcbm2018MonitorTaskHodo.cxx:36
CbmMcbmUnpack
Definition: CbmMcbmUnpack.h:15
CbmMcbm2018MonitorTaskHodo::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018MonitorTaskHodo.cxx:95
CbmMcbm2018MonitorTaskHodo::~CbmMcbm2018MonitorTaskHodo
virtual ~CbmMcbm2018MonitorTaskHodo()
Definition: CbmMcbm2018MonitorTaskHodo.cxx:47
CbmStar2019Algo::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Control flags.
Definition: CbmStar2019Algo.h:102