CbmRoot
Loading...
Searching...
No Matches
CbmMcbm2018UnpackerTaskSts.cxx
Go to the documentation of this file.
1/* Copyright (C) 2019-2021 Facility for Antiproton and Ion Research in Europe, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pierre-Alain Loizeau [committer] */
4
5// -----------------------------------------------------------------------------
6// ----- -----
7// ----- CbmMcbm2018UnpackerTaskSts -----
8// ----- Created 26.01.2019 by P.-A. Loizeau -----
9// ----- -----
10// -----------------------------------------------------------------------------
11
13
14#include "CbmMcbm2018StsPar.h"
16
17#include "FairParGenericSet.h"
18#include "FairRootManager.h"
19#include "FairRun.h"
20#include "FairRunOnline.h"
21#include "FairRuntimeDb.h"
22#include <Logger.h>
23
24#include "TClonesArray.h"
25#include "THttpServer.h"
26#include "TROOT.h"
27#include "TString.h"
28#include <TFile.h>
29
30#include <chrono>
31#include <fstream>
32#include <iomanip>
33#include <iostream>
34
35#include <stdint.h>
36
38
41 , fbMonitorMode(kFALSE)
42 , fbWriteOutput(kTRUE)
43 , fvChanMasks()
44 , fulTsCounter(0)
45 , fUnpackerAlgo(nullptr)
46{
48}
49
51
53{
54 LOG(info) << "CbmMcbm2018UnpackerTaskSts::Init";
55 LOG(info) << "Initializing mCBM STS 2018 Unpacker";
56
57 FairRootManager* ioman = FairRootManager::Instance();
58 if (NULL == ioman) { LOG(fatal) << "No FairRootManager instance"; }
59
61 if (nullptr != ioman->InitObjectAs<std::vector<CbmStsDigi> const*>("StsDigi"))
62 LOG(fatal) << "CbmMcbm2018UnpackerTaskSts::Init => output vector already registered,"
63 << " probably by CbmMcbm2018UnpackerTaskHodo" << std::endl
64 << " THESE TWO CLASSES ARE INCOMPATIBLE!";
65
68 ioman->RegisterAny("StsDigi", fpvDigiSts, fbWriteOutput);
69
70 if (fbPulserOutput) {
73 ioman->RegisterAny("StsDigiPulser", fpvPulserDigiSts, fbWriteOutput);
74 }
75
78 ioman->RegisterAny("CbmStsError", fpvErrorSts, fbWriteOutput);
79
80 return kTRUE;
81}
82
84{
85 LOG(info) << "Setting parameter containers for " << GetName();
86
87 TList* fParCList = fUnpackerAlgo->GetParList();
88
89 for (Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC) {
90 FairParGenericSet* tempObj = (FairParGenericSet*) (fParCList->At(iparC));
91 fParCList->Remove(tempObj);
92
93 std::string sParamName {tempObj->GetName()};
94 FairParGenericSet* newObj =
95 dynamic_cast<FairParGenericSet*>(FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
96
97 if (nullptr == newObj) {
98 LOG(error) << "Failed to obtain parameter container " << sParamName << ", for parameter index " << iparC;
99 return;
100 } // if( nullptr == newObj )
101
102 fParCList->AddAt(newObj, iparC);
103 // delete tempObj;
104 } // for( Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC )
105}
106
108{
109 LOG(info) << "Init parameter containers for " << GetName();
110
112 CbmMcbm2018StsPar* pUnpackPar =
113 dynamic_cast<CbmMcbm2018StsPar*>(FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018StsPar"));
114 if (nullptr == pUnpackPar) {
115 LOG(error) << "Failed to obtain parameter container CbmMcbm2018StsPar";
116 return kFALSE;
117 } // if( nullptr == pUnpackPar )
118 /*
119 fbMonitorMode = pUnpackPar->GetMonitorMode();
120 LOG(info) << "Monitor mode: "
121 << ( fbMonitorMode ? "ON" : "OFF" );
122
123 fbDebugMonitorMode = pUnpackPar->GetDebugMonitorMode();
124 LOG(info) << "Debug Monitor mode: "
125 << ( fbDebugMonitorMode ? "ON" : "OFF" );
126*/
127 Bool_t initOK = fUnpackerAlgo->InitContainers();
128
130 if (kTRUE == fbMonitorMode) {
132 initOK &= fUnpackerAlgo->CreateHistograms();
133
135 std::vector<std::pair<TNamed*, std::string>> vHistos = fUnpackerAlgo->GetHistoVector();
136
138 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
139 if (nullptr != server) {
140 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
141 server->Register(Form("/%s", vHistos[uHisto].second.data()), vHistos[uHisto].first);
142 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
143
144 server->RegisterCommand("/Reset_UnpSts_Hist", "bMcbm2018UnpackerTaskStsResetHistos=kTRUE");
145 server->Restrict("/Reset_UnpSts_Hist", "allow=admin");
146 } // if( nullptr != server )
147
148 } // if( kTRUE == fbMonitorMode )
149
151 for (std::vector<FebChanMask>::iterator it = fvChanMasks.begin(); it < fvChanMasks.end(); ++it)
152 fUnpackerAlgo->MaskNoisyChannel((*it).uFeb, (*it).uChan, (*it).bMasked);
153
154 return initOK;
155}
156
158{
159 LOG(info) << "ReInit parameter containers for " << GetName();
160 Bool_t initOK = fUnpackerAlgo->ReInitContainers();
161
162 return initOK;
163}
164
165void CbmMcbm2018UnpackerTaskSts::AddMsComponentToList(size_t component, UShort_t usDetectorId)
166{
167 fUnpackerAlgo->AddMsComponentToList(component, usDetectorId);
168}
169
170Bool_t CbmMcbm2018UnpackerTaskSts::DoUnpack(const fles::Timeslice& ts, size_t /*component*/)
171{
173 LOG(info) << "Reset STS unpacker histos ";
176 } // if( fbMonitorMode && bMcbm2018UnpackerTaskStsResetHistos )
177
178 if (kFALSE == fUnpackerAlgo->ProcessTs(ts)) {
179 LOG(error) << "Failed processing TS " << ts.index() << " in unpacker algorithm class";
180 return kTRUE;
181 } // if( kFALSE == fUnpackerAlgo->ProcessTs( ts ) )
182
183 /*
185 => Done in the algo!!!
186 sort(fpvDigiSts->begin(), fpvDigiSts->end(),
187 [](const CbmStsDigi & a, const CbmStsDigi & b) -> bool
188 {
189 return a.GetTime() < b.GetTime();
190 });
191*/
192
193 if (0 == fulTsCounter % 10000) LOG(info) << "Processed " << fulTsCounter << "TS";
194 fulTsCounter++;
195
196 return kTRUE;
197}
198
205
207{
209 if (kTRUE == fbMonitorMode) {
211 std::vector<std::pair<TNamed*, std::string>> vHistos = fUnpackerAlgo->GetHistoVector();
212
214 TFile* oldFile = gFile;
215 TDirectory* oldDir = gDirectory;
216
217 TFile* histoFile = nullptr;
218
219 // open separate histo file in recreate mode
220 histoFile = new TFile("data/HistosUnpackerSts.root", "RECREATE");
221 histoFile->cd();
222
224 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
226 TString sFolder = vHistos[uHisto].second.data();
227 if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
228 gDirectory->cd(sFolder);
229
231 vHistos[uHisto].first->Write();
232
233 histoFile->cd();
234 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
235
237 gFile = oldFile;
238 gDirectory = oldDir;
239
240 histoFile->Close();
241 } // if( kTRUE == fbMonitorMode )
242}
243
245
247
248void CbmMcbm2018UnpackerTaskSts::SetTimeOffsetNsAsic(UInt_t uAsicIdx, Double_t dOffsetIn)
249{
250 fUnpackerAlgo->SetTimeOffsetNsAsic(uAsicIdx, dOffsetIn);
251}
252
253void CbmMcbm2018UnpackerTaskSts::MaskNoisyChannel(UInt_t uFeb, UInt_t uChan, Bool_t bMasked)
254{
255 fvChanMasks.push_back(FebChanMask {uFeb, uChan, bMasked});
256}
257
259
261
267
ClassImp(CbmConverterManager)
Bool_t bMcbm2018UnpackerTaskStsResetHistos
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
std::vector< CbmStsDigi > & GetPulserVector()
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
void SetBinningFwFlag(Bool_t bEnable=kTRUE)
=> Quick and dirty hack for binning FW!!!
void SetTimeOffsetNsAsic(UInt_t uAsicIdx, Double_t dOffsetIn=0.0)
Bool_t ProcessTs(const fles::Timeslice &ts)
void MaskNoisyChannel(UInt_t uFeb, UInt_t uChan, Bool_t bMasked=kTRUE)
Bool_t fbWriteOutput
Switch ON the filling of a additional set of histograms.
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
void MaskNoisyChannel(UInt_t uFeb, UInt_t uChan, Bool_t bMasked=kTRUE)
uint64_t fulTsCounter
Statistics & first TS rejection.
Bool_t fbPulserOutput
If ON the output TClonesArray of digi is written to disk.
void SetBinningFwFlag(Bool_t bEnable=kTRUE)
=> Quick and dirty hack for binning FW!!!
CbmMcbm2018UnpackerAlgoSts * fUnpackerAlgo
Processing algo.
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
std::vector< CbmStsDigi > * fpvDigiSts
Output vectors.
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
std::vector< CbmStsDigi > * fpvPulserDigiSts
std::vector< CbmErrorMessage > * fpvErrorSts
std::vector< FebChanMask > fvChanMasks
If ON a separate output vector of digi is used for the pulser.
void SetTimeOffsetNsAsic(UInt_t uAsicIdx, Double_t dOffsetIn=0.0)
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
std::vector< T > & GetVector()
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Control flags.
std::vector< CbmErrorMessage > & GetErrorVector()
void ClearVector()
For unpacker algos.