CbmRoot
Loading...
Searching...
No Matches
CbmCosy2019MonitorTaskHodo.cxx
Go to the documentation of this file.
1/* Copyright (C) 2019-2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pierre-Alain Loizeau, Florian Uhlig [committer] */
4
5// -----------------------------------------------------------------------------
6// ----- -----
7// ----- CbmCosy2019MonitorTaskHodo -----
8// ----- Created 03.07.2019 by P.-A. Loizeau -----
9// ----- -----
10// -----------------------------------------------------------------------------
11
13
15//#include "CbmCosy2019HodoPar.h"
16//#include "CbmHodoDigi.h"
17
18#include "FairParGenericSet.h"
19#include "FairRootManager.h"
20#include "FairRun.h"
21#include "FairRunOnline.h"
22#include "FairRuntimeDb.h"
23#include <Logger.h>
24
25#include "TCanvas.h"
26#include "THttpServer.h"
27#include "TList.h"
28#include "TROOT.h"
29#include "TString.h"
30#include <TFile.h>
31
32#include <chrono>
33#include <fstream>
34#include <iomanip>
35#include <iostream>
36
37#include <stdint.h>
38
40
43 , fbMonitorMode(kFALSE)
44 , fbWriteOutput(kTRUE)
45 , fulTsCounter(0)
46 ,
47 // fHodoDigiCloneArray(),
48 fMonitorAlgo(nullptr)
49{
51}
52
54
56{
57 LOG(info) << "CbmCosy2019MonitorTaskHodo::Init";
58 LOG(info) << "Initializing mCBM Hodoscopes Monitor";
59 /*
60 FairRootManager* ioman = FairRootManager::Instance();
61 if( NULL == ioman )
62 {
63 LOG(fatal) << "No FairRootManager instance";
64 }
65
66 fHodoDigiCloneArray= new TClonesArray("CbmHodoDigi", 10);
67 if( NULL == fHodoDigiCloneArray )
68 {
69 LOG(fatal) << "Failed creating the STS Digi TClonesarray ";
70 }
71 ioman->Register("CbmHodoDigi", "STS raw Digi", fHodoDigiCloneArray, fbWriteOutput);
72*/
73 return kTRUE;
74}
75
77{
78 LOG(info) << "Setting parameter containers for " << GetName();
79
80 TList* parCList = fMonitorAlgo->GetParList();
81
82 for (Int_t iparC = 0; iparC < parCList->GetEntries(); ++iparC) {
83 FairParGenericSet* tempObj = (FairParGenericSet*) (parCList->At(iparC));
84 parCList->Remove(tempObj);
85
86 std::string sParamName {tempObj->GetName()};
87 FairParGenericSet* newObj =
88 dynamic_cast<FairParGenericSet*>(FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
89
90 if (nullptr == newObj) {
91 LOG(error) << "Failed to obtain parameter container " << sParamName << ", for parameter index " << iparC;
92 return;
93 } // if( nullptr == newObj )
94
95 parCList->AddAt(newObj, iparC);
96 // delete tempObj;
97 } // for( Int_t iparC = 0; iparC < parCList->GetEntries(); ++iparC )
98}
99
101{
102 LOG(info) << "Init parameter containers for " << GetName();
103
105 /*
106 CbmCosy2019HodoPar * pUnpackPar = dynamic_cast<CbmCosy2019HodoPar*>( FairRun::Instance()->GetRuntimeDb()->getContainer( "CbmCosy2019HodoPar" ) );
107 if( nullptr == pUnpackPar )
108 {
109 LOG(error) << "Failed to obtain parameter container CbmCosy2019HodoPar";
110 return kFALSE;
111 } // if( nullptr == pUnpackPar )
112*/
113 /*
114 fbMonitorMode = pUnpackPar->GetMonitorMode();
115 LOG(info) << "Monitor mode: "
116 << ( fbMonitorMode ? "ON" : "OFF" );
117
118 fbDebugMonitorMode = pUnpackPar->GetDebugMonitorMode();
119 LOG(info) << "Debug Monitor mode: "
120 << ( fbDebugMonitorMode ? "ON" : "OFF" );
121*/
122 Bool_t initOK = fMonitorAlgo->InitContainers();
123
124
126 initOK &= fMonitorAlgo->CreateHistograms();
127
129 std::vector<std::pair<TNamed*, std::string>> vHistos = fMonitorAlgo->GetHistoVector();
130 std::vector<std::pair<TCanvas*, std::string>> vCanvas = fMonitorAlgo->GetCanvasVector();
131
133 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
134 if (nullptr != server) {
135 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
136 if (nullptr != vHistos[uHisto].first)
137 server->Register(Form("/%s", vHistos[uHisto].second.data()), vHistos[uHisto].first);
138 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
139
140 for (UInt_t uCanvas = 0; uCanvas < vCanvas.size(); ++uCanvas) {
141 if (nullptr != vCanvas[uCanvas].first)
142 server->Register(Form("/%s", vCanvas[uCanvas].second.data()), vCanvas[uCanvas].first);
143 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
144
145 server->RegisterCommand("/Reset_MoniHodo_Hist", "bCosy2019MonitorTaskHodoResetHistos=kTRUE");
146 server->Restrict("/Reset_MoniHodo_Hist", "allow=admin");
147 } // if( nullptr != server )
148
150
151 return initOK;
152}
153
155{
156 LOG(info) << "ReInit parameter containers for " << GetName();
157 Bool_t initOK = fMonitorAlgo->ReInitContainers();
158
159 return initOK;
160}
161
162void CbmCosy2019MonitorTaskHodo::AddMsComponentToList(size_t component, UShort_t usDetectorId)
163{
164 fMonitorAlgo->AddMsComponentToList(component, usDetectorId);
165}
166
167Bool_t CbmCosy2019MonitorTaskHodo::DoUnpack(const fles::Timeslice& ts, size_t /*component*/)
168{
170 LOG(info) << "Reset Hodoscopes monitor histos ";
173 } // if( fbMonitorMode && bCosy2019MonitorTaskHodoResetHistos )
174
175 if (kFALSE == fMonitorAlgo->ProcessTs(ts)) {
176 LOG(error) << "Failed processing TS " << ts.index() << " in monitor algorithm class";
177 return kTRUE;
178 } // if( kFALSE == fMonitorAlgo->ProcessTs( ts ) )
179 /*
181 std::vector< CbmHodoDigi > vDigi = fMonitorAlgo->GetVector();
182
183 for( auto digi: vDigi) {
185 LOG(debug) << "Fill digi TClonesarray with "
186 << Form("0x%08x", digi.GetAddress())
187 << " at " << static_cast<Int_t>( fHodoDigiCloneArray->GetEntriesFast() );
188
189 new( (*fHodoDigiCloneArray)[ fHodoDigiCloneArray->GetEntriesFast() ] )
190 CbmHodoDigi( digi) ;
191 }
192
193 vDigi.clear();
194 fMonitorAlgo->ClearVector();
195*/
196 if (0 == fulTsCounter % 10000) LOG(info) << "Processed " << fulTsCounter << "TS";
197 fulTsCounter++;
198
199 if (0 == fulTsCounter % 6000 && 0 < fulTsCounter) SaveHistograms();
200
201 return kTRUE;
202}
203
205{
206 // fHodoDigiCloneArray->Clear();
207}
208
210{
212 if (kTRUE == fbMonitorMode) { SaveHistograms(); } // if( kTRUE == fbMonitorMode )
213}
214
216{
218 std::vector<std::pair<TNamed*, std::string>> vHistos = fMonitorAlgo->GetHistoVector();
219 std::vector<std::pair<TCanvas*, std::string>> vCanvas = fMonitorAlgo->GetCanvasVector();
220
222 TFile* oldFile = gFile;
223 TDirectory* oldDir = gDirectory;
224
225 TFile* histoFile = nullptr;
226
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
260 gFile = oldFile;
261 gDirectory = oldDir;
262
263 histoFile->Close();
264
265 return kTRUE;
266}
267
269
272void CbmCosy2019MonitorTaskHodo::SetHodoElinkIdx(UInt_t uElinkHodoA, UInt_t uElinkHodoB)
273{
274 fMonitorAlgo->SetHodoElinkIdx(uElinkHodoA, uElinkHodoB);
275}
276void CbmCosy2019MonitorTaskHodo::SetHodoSwapXY(Bool_t bSwapHodoA, Bool_t bSwapHodoB)
277{
278 fMonitorAlgo->SetHodoSwapXY(bSwapHodoA, bSwapHodoB);
279}
280void CbmCosy2019MonitorTaskHodo::SetHodoInvertX(Bool_t bInvHodoA, Bool_t bInvHodoB)
281{
282 fMonitorAlgo->SetHodoInvertX(bInvHodoA, bInvHodoB);
283}
284void CbmCosy2019MonitorTaskHodo::SetHodoInvertY(Bool_t bInvHodoA, Bool_t bInvHodoB)
285{
286 fMonitorAlgo->SetHodoInvertY(bInvHodoA, bInvHodoB);
287}
288
289
ClassImp(CbmConverterManager)
Bool_t bCosy2019MonitorTaskHodoResetHistos
bool first
void SetDpbId(UInt_t uDpbId=0x5b75)
void SetHodoElinkIdx(UInt_t uElinkHodoA=5, UInt_t uElinkHodoB=10)
void SetHodoInvertY(Bool_t bInvHodoA=kFALSE, Bool_t bInvHodoB=kTRUE)
Default set closest cosmic setup stack.
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
void SetHodoSwapXY(Bool_t bSwapHodoA=kFALSE, Bool_t bSwapHodoB=kTRUE)
Default set for mMUCH FMC slots 8 and 9.
void SetHodoInvertX(Bool_t bInvHodoA=kFALSE, Bool_t bInvHodoB=kTRUE)
Default set closest cosmic setup stack.
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
Bool_t ProcessTs(const fles::Timeslice &ts)
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
void SetHodoInvertX(Bool_t bInvHodoA=kFALSE, Bool_t bInvHodoB=kTRUE)
void SetHodoSwapXY(Bool_t bSwapHodoA=kFALSE, Bool_t bSwapHodoB=kTRUE)
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
void SetHodoInvertY(Bool_t bInvHodoA=kFALSE, Bool_t bInvHodoB=kTRUE)
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
void SetHodoElinkIdx(UInt_t uElinkHodoA=5, UInt_t uElinkHodoB=10)
CbmCosy2019MonitorAlgoHodo * fMonitorAlgo
Processing algo.
uint64_t fulTsCounter
If ON the output TClonesArray of digi is written to disk.
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Control flags.
std::vector< std::pair< TCanvas *, std::string > > GetCanvasVector()