CbmRoot
CbmMcbm2018UnpackerTaskSts.cxx
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 // ----- -----
3 // ----- CbmMcbm2018UnpackerTaskSts -----
4 // ----- Created 26.01.2019 by P.-A. Loizeau -----
5 // ----- -----
6 // -----------------------------------------------------------------------------
7 
9 
10 #include "CbmMcbm2018StsPar.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 "TClonesArray.h"
21 #include "THttpServer.h"
22 #include "TROOT.h"
23 #include "TString.h"
24 #include <TFile.h>
25 
26 #include <chrono>
27 #include <fstream>
28 #include <iomanip>
29 #include <iostream>
30 #include <stdint.h>
31 
33 
35  : CbmMcbmUnpack()
36  , fbMonitorMode(kFALSE)
37  , fbWriteOutput(kTRUE)
38  , fvChanMasks()
39  , fulTsCounter(0)
40  , fUnpackerAlgo(nullptr) {
42 }
43 
45  delete fUnpackerAlgo;
46 }
47 
49  LOG(info) << "CbmMcbm2018UnpackerTaskSts::Init";
50  LOG(info) << "Initializing mCBM STS 2018 Unpacker";
51 
52  FairRootManager* ioman = FairRootManager::Instance();
53  if (NULL == ioman) { LOG(fatal) << "No FairRootManager instance"; }
54 
56  if (nullptr != ioman->InitObjectAs<std::vector<CbmStsDigi> const*>("StsDigi"))
57  LOG(fatal)
58  << "CbmMcbm2018UnpackerTaskSts::Init => output vector already registered,"
59  << " probably by CbmMcbm2018UnpackerTaskHodo" << std::endl
60  << " THESE TWO CLASSES ARE INCOMPATIBLE!";
61 
64  ioman->RegisterAny("StsDigi", fpvDigiSts, fbWriteOutput);
65 
68  ioman->RegisterAny("CbmStsError", fpvErrorSts, fbWriteOutput);
69 
70  return kTRUE;
71 }
72 
74  LOG(info) << "Setting parameter containers for " << GetName();
75 
76  TList* fParCList = fUnpackerAlgo->GetParList();
77 
78  for (Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC) {
79  FairParGenericSet* tempObj = (FairParGenericSet*) (fParCList->At(iparC));
80  fParCList->Remove(tempObj);
81 
82  std::string sParamName {tempObj->GetName()};
83  FairParGenericSet* newObj = dynamic_cast<FairParGenericSet*>(
84  FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
85 
86  if (nullptr == newObj) {
87  LOG(error) << "Failed to obtain parameter container " << sParamName
88  << ", for parameter index " << iparC;
89  return;
90  } // if( nullptr == newObj )
91 
92  fParCList->AddAt(newObj, iparC);
93  // delete tempObj;
94  } // for( Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC )
95 }
96 
98  LOG(info) << "Init parameter containers for " << GetName();
99 
101  CbmMcbm2018StsPar* pUnpackPar = dynamic_cast<CbmMcbm2018StsPar*>(
102  FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018StsPar"));
103  if (nullptr == pUnpackPar) {
104  LOG(error) << "Failed to obtain parameter container CbmMcbm2018StsPar";
105  return kFALSE;
106  } // if( nullptr == pUnpackPar )
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 = fUnpackerAlgo->InitContainers();
117 
119  if (kTRUE == fbMonitorMode) {
121  initOK &= fUnpackerAlgo->CreateHistograms();
122 
124  std::vector<std::pair<TNamed*, std::string>> vHistos =
126 
128  THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
129  if (nullptr != server) {
130  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
131  server->Register(Form("/%s", vHistos[uHisto].second.data()),
132  vHistos[uHisto].first);
133  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
134 
135  server->RegisterCommand("/Reset_UnpSts_Hist",
136  "bMcbm2018UnpackerTaskStsResetHistos=kTRUE");
137  server->Restrict("/Reset_UnpSts_Hist", "allow=admin");
138  } // if( nullptr != server )
139 
140  } // if( kTRUE == fbMonitorMode )
141 
143  for (std::vector<FebChanMask>::iterator it = fvChanMasks.begin();
144  it < fvChanMasks.end();
145  ++it)
146  fUnpackerAlgo->MaskNoisyChannel((*it).uFeb, (*it).uChan, (*it).bMasked);
147 
148  return initOK;
149 }
150 
152  LOG(info) << "ReInit parameter containers for " << GetName();
153  Bool_t initOK = fUnpackerAlgo->ReInitContainers();
154 
155  return initOK;
156 }
157 
159  UShort_t usDetectorId) {
160  fUnpackerAlgo->AddMsComponentToList(component, usDetectorId);
161 }
162 
163 Bool_t CbmMcbm2018UnpackerTaskSts::DoUnpack(const fles::Timeslice& ts,
164  size_t /*component*/) {
166  LOG(info) << "Reset STS unpacker histos ";
169  } // if( fbMonitorMode && bMcbm2018UnpackerTaskStsResetHistos )
170 
171  if (kFALSE == fUnpackerAlgo->ProcessTs(ts)) {
172  LOG(error) << "Failed processing TS " << ts.index()
173  << " in unpacker algorithm class";
174  return kTRUE;
175  } // if( kFALSE == fUnpackerAlgo->ProcessTs( ts ) )
176 
177  /*
179  => Done in the algo!!!
180  sort(fpvDigiSts->begin(), fpvDigiSts->end(),
181  [](const CbmStsDigi & a, const CbmStsDigi & b) -> bool
182  {
183  return a.GetTime() < b.GetTime();
184  });
185 */
186 
187  if (0 == fulTsCounter % 10000)
188  LOG(info) << "Processed " << fulTsCounter << "TS";
189  fulTsCounter++;
190 
191  return kTRUE;
192 }
193 
197 }
198 
201  if (kTRUE == fbMonitorMode) {
203  std::vector<std::pair<TNamed*, std::string>> vHistos =
205 
207  TDirectory* oldDir = NULL;
208  TFile* histoFile = NULL;
209  // Store current directory position to allow restore later
210  oldDir = gDirectory;
211  // open separate histo file in recreate mode
212  histoFile = new TFile("data/HistosUnpackerSts.root", "RECREATE");
213  histoFile->cd();
214 
216  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
218  TString sFolder = vHistos[uHisto].second.data();
219  if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
220  gDirectory->cd(sFolder);
221 
223  vHistos[uHisto].first->Write();
224 
225  histoFile->cd();
226  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
227 
228  // Restore original directory position
229  oldDir->cd();
230  histoFile->Close();
231  } // if( kTRUE == fbMonitorMode )
232 }
233 
236 }
237 
239  fUnpackerAlgo->SetTimeOffsetNs(dOffsetIn);
240 }
241 
243  Double_t dOffsetIn) {
244  fUnpackerAlgo->SetTimeOffsetNsAsic(uAsicIdx, dOffsetIn);
245 }
246 
248  UInt_t uChan,
249  Bool_t bMasked) {
250  fvChanMasks.push_back(FebChanMask {uFeb, uChan, bMasked});
251 }
252 
254  fUnpackerAlgo->SetAdcCut(uAdc);
255 }
256 
259 }
260 
261 
CbmMcbm2018UnpackerAlgoSts::CreateHistograms
Bool_t CreateHistograms()
Definition: CbmMcbm2018UnpackerAlgoSts.cxx:1061
CbmMcbm2018UnpackerTaskSts::fpvDigiSts
std::vector< CbmStsDigi > * fpvDigiSts
Output vectors.
Definition: CbmMcbm2018UnpackerTaskSts.h:84
CbmMcbm2018UnpackerTaskSts::SetAdcCut
void SetAdcCut(UInt_t uAdc)
Definition: CbmMcbm2018UnpackerTaskSts.cxx:253
CbmStar2019Algo::GetHistoVector
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
Definition: CbmStar2019Algo.h:84
CbmMcbm2018UnpackerTaskSts::~CbmMcbm2018UnpackerTaskSts
virtual ~CbmMcbm2018UnpackerTaskSts()
Definition: CbmMcbm2018UnpackerTaskSts.cxx:44
CbmStar2019Algo::GetErrorVector
std::vector< CbmErrorMessage > & GetErrorVector()
Definition: CbmStar2019Algo.h:99
CbmStar2019Algo::GetVector
std::vector< T > & GetVector()
Definition: CbmStar2019Algo.h:97
CbmMcbm2018UnpackerTaskSts::SetBinningFwFlag
void SetBinningFwFlag(Bool_t bEnable=kTRUE)
=> Quick and dirty hack for binning FW!!!
Definition: CbmMcbm2018UnpackerTaskSts.cxx:257
CbmMcbm2018UnpackerTaskSts::fbMonitorMode
Bool_t fbMonitorMode
Control flags.
Definition: CbmMcbm2018UnpackerTaskSts.h:71
CbmMcbm2018UnpackerTaskSts::SetParContainers
void SetParContainers()
Definition: CbmMcbm2018UnpackerTaskSts.cxx:73
CbmStar2019Algo::ClearErrorVector
void ClearErrorVector()
Definition: CbmStar2019Algo.h:98
CbmMcbm2018UnpackerTaskSts::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018UnpackerTaskSts.cxx:151
CbmMcbm2018UnpackerAlgoSts::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Definition: CbmMcbm2018UnpackerAlgoSts.cxx:351
bMcbm2018UnpackerTaskStsResetHistos
Bool_t bMcbm2018UnpackerTaskStsResetHistos
Definition: CbmMcbm2018UnpackerTaskSts.cxx:32
FebChanMask
Definition: CbmMcbm2018UnpackerTaskSts.h:20
CbmMcbm2018UnpackerTaskSts::CbmMcbm2018UnpackerTaskSts
CbmMcbm2018UnpackerTaskSts(UInt_t uNbSdpb=1)
Definition: CbmMcbm2018UnpackerTaskSts.cxx:34
CbmMcbm2018UnpackerTaskSts::fUnpackerAlgo
CbmMcbm2018UnpackerAlgoSts * fUnpackerAlgo
Processing algo.
Definition: CbmMcbm2018UnpackerTaskSts.h:88
CbmMcbm2018UnpackerAlgoSts::SetTimeOffsetNsAsic
void SetTimeOffsetNsAsic(UInt_t uAsicIdx, Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerAlgoSts.cxx:1387
CbmMcbm2018UnpackerTaskSts
Definition: CbmMcbm2018UnpackerTaskSts.h:26
CbmMcbm2018UnpackerAlgoSts::ResetHistograms
Bool_t ResetHistograms()
Definition: CbmMcbm2018UnpackerAlgoSts.cxx:1350
CbmMcbm2018UnpackerTaskSts::SetTimeOffsetNsAsic
void SetTimeOffsetNsAsic(UInt_t uAsicIdx, Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerTaskSts.cxx:242
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmMcbm2018UnpackerTaskSts::MaskNoisyChannel
void MaskNoisyChannel(UInt_t uFeb, UInt_t uChan, Bool_t bMasked=kTRUE)
Definition: CbmMcbm2018UnpackerTaskSts.cxx:247
CbmMcbm2018UnpackerAlgoSts.h
CbmMcbm2018UnpackerTaskSts::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
Definition: CbmMcbm2018UnpackerTaskSts.cxx:158
CbmMcbm2018UnpackerAlgoSts
Definition: CbmMcbm2018UnpackerAlgoSts.h:37
CbmMcbm2018UnpackerTaskSts::Init
virtual Bool_t Init()
Definition: CbmMcbm2018UnpackerTaskSts.cxx:48
CbmMcbm2018StsPar
Definition: CbmMcbm2018StsPar.h:18
CbmMcbm2018UnpackerTaskSts::fbWriteOutput
Bool_t fbWriteOutput
Switch ON the filling of a additional set of histograms.
Definition: CbmMcbm2018UnpackerTaskSts.h:75
CbmMcbm2018UnpackerAlgoSts::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018UnpackerAlgoSts.cxx:113
CbmMcbm2018UnpackerTaskSts.h
CbmMcbm2018UnpackerAlgoSts::SetTimeOffsetNs
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerAlgoSts.h:67
CbmMcbm2018UnpackerTaskSts::SetTimeOffsetNs
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerTaskSts.cxx:238
CbmMcbm2018UnpackerAlgoSts::MaskNoisyChannel
void MaskNoisyChannel(UInt_t uFeb, UInt_t uChan, Bool_t bMasked=kTRUE)
Definition: CbmMcbm2018UnpackerAlgoSts.cxx:1396
CbmMcbm2018UnpackerTaskSts::fulTsCounter
uint64_t fulTsCounter
Statistics & first TS rejection.
Definition: CbmMcbm2018UnpackerTaskSts.h:81
CbmMcbm2018UnpackerAlgoSts::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018UnpackerAlgoSts.cxx:119
CbmMcbm2018UnpackerTaskSts::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018UnpackerTaskSts.cxx:234
CbmMcbm2018UnpackerAlgoSts::SetMonitorMode
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018UnpackerAlgoSts.h:64
CbmMcbm2018UnpackerAlgoSts::GetParList
TList * GetParList()
Definition: CbmMcbm2018UnpackerAlgoSts.cxx:130
CbmMcbm2018StsPar.h
CbmMcbm2018UnpackerTaskSts::fpvErrorSts
std::vector< CbmErrorMessage > * fpvErrorSts
Definition: CbmMcbm2018UnpackerTaskSts.h:85
CbmMcbm2018UnpackerAlgoSts::SetAdcCut
void SetAdcCut(UInt_t uAdc)
Definition: CbmMcbm2018UnpackerAlgoSts.h:72
CbmMcbm2018UnpackerTaskSts::DoUnpack
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
Definition: CbmMcbm2018UnpackerTaskSts.cxx:163
CbmStar2019Algo::ClearVector
void ClearVector()
For unpacker algos.
Definition: CbmStar2019Algo.h:96
CbmMcbm2018UnpackerTaskSts::Finish
virtual void Finish()
Definition: CbmMcbm2018UnpackerTaskSts.cxx:199
CbmMcbm2018UnpackerTaskSts::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018UnpackerTaskSts.cxx:97
CbmMcbmUnpack
Definition: CbmMcbmUnpack.h:15
CbmMcbm2018UnpackerTaskSts::fvChanMasks
std::vector< FebChanMask > fvChanMasks
If ON the output TClonesArray of digi is written to disk.
Definition: CbmMcbm2018UnpackerTaskSts.h:78
CbmMcbm2018UnpackerAlgoSts::ProcessTs
Bool_t ProcessTs(const fles::Timeslice &ts)
Definition: CbmMcbm2018UnpackerAlgoSts.cxx:366
CbmMcbm2018UnpackerTaskSts::Reset
virtual void Reset()
Definition: CbmMcbm2018UnpackerTaskSts.cxx:194
CbmStar2019Algo::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Control flags.
Definition: CbmStar2019Algo.h:102
CbmMcbm2018UnpackerAlgoSts::SetBinningFwFlag
void SetBinningFwFlag(Bool_t bEnable=kTRUE)
=> Quick and dirty hack for binning FW!!!
Definition: CbmMcbm2018UnpackerAlgoSts.h:75