CbmRoot
CbmMcbm2018UnpackerTaskMuch.cxx
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 // ----- -----
3 // ----- CbmMcbm2018UnpackerTaskMuch -----
4 // ----- Created 02.02.2019 by P.-A. Loizeau -----
5 // ----- -----
6 // -----------------------------------------------------------------------------
7 
9 
10 #include "CbmMcbm2018MuchPar.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) << "CbmMcbm2018UnpackerTaskMuch::Init";
50  LOG(info) << "Initializing mCBM MUCH 2018 Unpacker";
51 
52  FairRootManager* ioman = FairRootManager::Instance();
53  if (NULL == ioman) { LOG(fatal) << "No FairRootManager instance"; }
54 
57  ioman->RegisterAny("MuchBeamTimeDigi", fpvDigiMuch, fbWriteOutput);
58 
61  ioman->RegisterAny("CbmMuchError", fpvErrorMuch, fbWriteOutput);
62 
63  return kTRUE;
64 }
65 
67  LOG(info) << "Setting parameter containers for " << GetName();
68 
69  TList* fParCList = fUnpackerAlgo->GetParList();
70 
71  for (Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC) {
72  FairParGenericSet* tempObj = (FairParGenericSet*) (fParCList->At(iparC));
73  fParCList->Remove(tempObj);
74 
75  std::string sParamName {tempObj->GetName()};
76  FairParGenericSet* newObj = dynamic_cast<FairParGenericSet*>(
77  FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
78 
79  if (nullptr == newObj) {
80  LOG(error) << "Failed to obtain parameter container " << sParamName
81  << ", for parameter index " << iparC;
82  return;
83  } // if( nullptr == newObj )
84 
85  fParCList->AddAt(newObj, iparC);
86  // delete tempObj;
87  } // for( Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC )
88 }
89 
91  LOG(info) << "Init parameter containers for " << GetName();
92 
94  CbmMcbm2018MuchPar* pUnpackPar = dynamic_cast<CbmMcbm2018MuchPar*>(
95  FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018MuchPar"));
96  if (nullptr == pUnpackPar) {
97  LOG(error) << "Failed to obtain parameter container CbmMcbm2018MuchPar";
98  return kFALSE;
99  } // if( nullptr == pUnpackPar )
100  /*
101  fbMonitorMode = pUnpackPar->GetMonitorMode();
102  LOG(info) << "Monitor mode: "
103  << ( fbMonitorMode ? "ON" : "OFF" );
104 
105  fbDebugMonitorMode = pUnpackPar->GetDebugMonitorMode();
106  LOG(info) << "Debug Monitor mode: "
107  << ( fbDebugMonitorMode ? "ON" : "OFF" );
108 */
109  Bool_t initOK = fUnpackerAlgo->InitContainers();
110 
112  if (kTRUE == fbMonitorMode) {
114  initOK &= fUnpackerAlgo->CreateHistograms();
115 
117  std::vector<std::pair<TNamed*, std::string>> vHistos =
119 
121  THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
122  if (nullptr != server) {
123  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
124  server->Register(Form("/%s", vHistos[uHisto].second.data()),
125  vHistos[uHisto].first);
126  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
127 
128  server->RegisterCommand("/Reset_UnpMuch_Hist",
129  "bMcbm2018UnpackerTaskMuchResetHistos=kTRUE");
130  server->Restrict("/Reset_UnpMuch_Hist", "allow=admin");
131  } // if( nullptr != server )
132 
133  } // if( kTRUE == fbMonitorMode )
134 
136 
137  for (std::vector<MuchFebChanMask>::iterator it = fvChanMasks.begin();
138  it < fvChanMasks.end();
139  ++it)
140  fUnpackerAlgo->MaskNoisyChannel((*it).uFeb, (*it).uChan, (*it).bMasked);
141 
142  return initOK;
143 }
144 
146  LOG(info) << "ReInit parameter containers for " << GetName();
147  Bool_t initOK = fUnpackerAlgo->ReInitContainers();
148 
149  return initOK;
150 }
151 
153  UShort_t usDetectorId) {
154  fUnpackerAlgo->AddMsComponentToList(component, usDetectorId);
155 }
156 
157 Bool_t CbmMcbm2018UnpackerTaskMuch::DoUnpack(const fles::Timeslice& ts,
158  size_t /*component*/) {
160  LOG(info) << "Reset MUCH unpacker histos ";
163  } // if( fbMonitorMode && bMcbm2018UnpackerTaskMuchResetHistos )
164 
165  if (kFALSE == fUnpackerAlgo->ProcessTs(ts)) {
166  LOG(error) << "Failed processing TS " << ts.index()
167  << " in unpacker algorithm class";
168  return kTRUE;
169  } // if( kFALSE == fUnpackerAlgo->ProcessTs( ts ) )
170 
171  /*
173  => Done in the algo!!!
174  sort(fpvDigiMuch->begin(), fpvDigiMuch->end(),
175  [](const CbmMuchBeamTimeDigi & a, const CbmMuchBeamTimeDigi & b) -> bool
176  {
177  return a.GetTime() < b.GetTime();
178  });
179 */
180 
181  if (0 == fulTsCounter % 10000)
182  LOG(info) << "Processed " << fulTsCounter << "TS";
183  fulTsCounter++;
184 
185  return kTRUE;
186 }
187 
191 }
192 
195  if (kTRUE == fbMonitorMode) {
197  std::vector<std::pair<TNamed*, std::string>> vHistos =
199 
201  TDirectory* oldDir = NULL;
202  TFile* histoFile = NULL;
203  // Store current directory position to allow restore later
204  oldDir = gDirectory;
205  // open separate histo file in recreate mode
206  histoFile = new TFile("data/HistosUnpackerMuch.root", "RECREATE");
207  histoFile->cd();
208 
210  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
212  TString sFolder = vHistos[uHisto].second.data();
213  if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
214  gDirectory->cd(sFolder);
215 
217  vHistos[uHisto].first->Write();
218 
219  histoFile->cd();
220  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
221 
222  // Restore original directory position
223  oldDir->cd();
224  histoFile->Close();
225  } // if( kTRUE == fbMonitorMode )
226 }
227 
230 }
231 
233  fUnpackerAlgo->SetTimeOffsetNs(dOffsetIn);
234 }
235 
237  Double_t dOffsetIn) {
238  return fUnpackerAlgo->SetTimeOffsetNsAsic(uAsicIdx, dOffsetIn);
239 }
240 
242  fUnpackerAlgo->EnableAsicType(fiFlag);
243 }
244 
247 }
248 
250  UInt_t uChan,
251  Bool_t bMasked) {
252 
253  fvChanMasks.push_back(MuchFebChanMask {uFeb, uChan, bMasked});
254 }
255 
257  fUnpackerAlgo->SetAdcCut(uAdc);
258 }
259 
260 
CbmMcbm2018UnpackerAlgoMuch::MaskNoisyChannel
void MaskNoisyChannel(UInt_t uFeb, UInt_t uChan, Bool_t bMasked=kTRUE)
Definition: CbmMcbm2018UnpackerAlgoMuch.cxx:1258
CbmMcbm2018UnpackerTaskMuch::fpvErrorMuch
std::vector< CbmErrorMessage > * fpvErrorMuch
Definition: CbmMcbm2018UnpackerTaskMuch.h:89
CbmMcbm2018UnpackerAlgoMuch::CreateHistograms
Bool_t CreateHistograms()
Definition: CbmMcbm2018UnpackerAlgoMuch.cxx:944
CbmMcbm2018UnpackerTaskMuch::SetParContainers
void SetParContainers()
Definition: CbmMcbm2018UnpackerTaskMuch.cxx:66
CbmMcbm2018UnpackerTaskMuch::Finish
virtual void Finish()
Definition: CbmMcbm2018UnpackerTaskMuch.cxx:193
CbmStar2019Algo::GetHistoVector
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
Definition: CbmStar2019Algo.h:84
CbmStar2019Algo::GetErrorVector
std::vector< CbmErrorMessage > & GetErrorVector()
Definition: CbmStar2019Algo.h:99
CbmMcbm2018UnpackerTaskMuch
Definition: CbmMcbm2018UnpackerTaskMuch.h:26
CbmMcbm2018MuchPar.h
CbmStar2019Algo::GetVector
std::vector< T > & GetVector()
Definition: CbmStar2019Algo.h:97
CbmMcbm2018UnpackerTaskMuch::Init
virtual Bool_t Init()
Definition: CbmMcbm2018UnpackerTaskMuch.cxx:48
CbmMcbm2018UnpackerTaskMuch::SetAdcCut
void SetAdcCut(UInt_t uAdc)
ADC cut.
Definition: CbmMcbm2018UnpackerTaskMuch.cxx:256
CbmMcbm2018UnpackerAlgoMuch::EnableAsicType
void EnableAsicType(Int_t flag=0)
Definition: CbmMcbm2018UnpackerAlgoMuch.h:72
CbmMcbm2018UnpackerTaskMuch::Reset
virtual void Reset()
Definition: CbmMcbm2018UnpackerTaskMuch.cxx:188
CbmMcbm2018UnpackerAlgoMuch::ProcessTs
Bool_t ProcessTs(const fles::Timeslice &ts)
Definition: CbmMcbm2018UnpackerAlgoMuch.cxx:242
CbmStar2019Algo::ClearErrorVector
void ClearErrorVector()
Definition: CbmStar2019Algo.h:98
CbmMcbm2018UnpackerTaskMuch::CbmMcbm2018UnpackerTaskMuch
CbmMcbm2018UnpackerTaskMuch(UInt_t uNbSdpb=1)
Definition: CbmMcbm2018UnpackerTaskMuch.cxx:34
CbmMcbm2018UnpackerAlgoMuch::GetParList
TList * GetParList()
Definition: CbmMcbm2018UnpackerAlgoMuch.cxx:126
CbmMcbm2018UnpackerTaskMuch.h
CbmMcbm2018UnpackerAlgoMuch::SetTimeOffsetNsAsic
void SetTimeOffsetNsAsic(UInt_t uAsicIdx, Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerAlgoMuch.cxx:1249
CbmMcbm2018UnpackerTaskMuch::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
Definition: CbmMcbm2018UnpackerTaskMuch.cxx:152
CbmMcbm2018UnpackerAlgoMuch::SetTimeOffsetNs
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerAlgoMuch.h:67
CbmMcbm2018UnpackerTaskMuch::SetTimeOffsetNsAsic
void SetTimeOffsetNsAsic(UInt_t uAsicIdx, Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerTaskMuch.cxx:236
CbmMcbm2018UnpackerTaskMuch::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018UnpackerTaskMuch.cxx:228
CbmMcbm2018UnpackerTaskMuch::fbMonitorMode
Bool_t fbMonitorMode
Control flags.
Definition: CbmMcbm2018UnpackerTaskMuch.h:75
CbmMcbm2018UnpackerTaskMuch::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018UnpackerTaskMuch.cxx:90
MuchFebChanMask
Definition: CbmMcbm2018UnpackerTaskMuch.h:20
CbmMcbm2018UnpackerAlgoMuch::SetAdcCut
void SetAdcCut(UInt_t uAdc)
Definition: CbmMcbm2018UnpackerAlgoMuch.h:81
CbmMcbm2018UnpackerAlgoMuch::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018UnpackerAlgoMuch.cxx:114
CbmMcbm2018UnpackerTaskMuch::fvChanMasks
std::vector< MuchFebChanMask > fvChanMasks
If ON the output TClonesArray of digi is written to disk.
Definition: CbmMcbm2018UnpackerTaskMuch.h:82
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmMcbm2018UnpackerTaskMuch::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018UnpackerTaskMuch.cxx:145
CbmMcbm2018UnpackerAlgoMuch::ResetHistograms
Bool_t ResetHistograms()
Definition: CbmMcbm2018UnpackerAlgoMuch.cxx:1212
CbmMcbm2018UnpackerTaskMuch::fUnpackerAlgo
CbmMcbm2018UnpackerAlgoMuch * fUnpackerAlgo
Processing algo.
Definition: CbmMcbm2018UnpackerTaskMuch.h:92
CbmMcbm2018UnpackerTaskMuch::SetBinningFwFlag
void SetBinningFwFlag(Bool_t bEnable=kTRUE)
=> Quick and dirty hack for binning FW!!!
Definition: CbmMcbm2018UnpackerTaskMuch.cxx:245
CbmMcbm2018UnpackerAlgoMuch::SetMonitorMode
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018UnpackerAlgoMuch.h:64
CbmMcbm2018UnpackerAlgoMuch
Definition: CbmMcbm2018UnpackerAlgoMuch.h:37
CbmMcbm2018MuchPar
Definition: CbmMcbm2018MuchPar.h:19
CbmMcbm2018UnpackerTaskMuch::SetTimeOffsetNs
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerTaskMuch.cxx:232
bMcbm2018UnpackerTaskMuchResetHistos
Bool_t bMcbm2018UnpackerTaskMuchResetHistos
Definition: CbmMcbm2018UnpackerTaskMuch.cxx:32
CbmMcbm2018UnpackerTaskMuch::fulTsCounter
uint64_t fulTsCounter
Statistics & first TS rejection.
Definition: CbmMcbm2018UnpackerTaskMuch.h:85
CbmMcbm2018UnpackerTaskMuch::fbWriteOutput
Bool_t fbWriteOutput
Switch ON the filling of a additional set of histograms.
Definition: CbmMcbm2018UnpackerTaskMuch.h:79
CbmMcbm2018UnpackerTaskMuch::~CbmMcbm2018UnpackerTaskMuch
virtual ~CbmMcbm2018UnpackerTaskMuch()
Definition: CbmMcbm2018UnpackerTaskMuch.cxx:44
CbmMcbm2018UnpackerTaskMuch::EnableAsicType
void EnableAsicType(Int_t fiFlag=0)
Definition: CbmMcbm2018UnpackerTaskMuch.cxx:241
CbmMcbm2018UnpackerAlgoMuch.h
CbmMcbm2018UnpackerAlgoMuch::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018UnpackerAlgoMuch.cxx:108
CbmMcbm2018UnpackerTaskMuch::MaskNoisyChannel
void MaskNoisyChannel(UInt_t uFeb, UInt_t uChan, Bool_t bMasked=kTRUE)
Definition: CbmMcbm2018UnpackerTaskMuch.cxx:249
CbmMcbm2018UnpackerTaskMuch::DoUnpack
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
Definition: CbmMcbm2018UnpackerTaskMuch.cxx:157
CbmStar2019Algo::ClearVector
void ClearVector()
For unpacker algos.
Definition: CbmStar2019Algo.h:96
CbmMcbmUnpack
Definition: CbmMcbmUnpack.h:15
CbmMcbm2018UnpackerTaskMuch::fpvDigiMuch
std::vector< CbmMuchBeamTimeDigi > * fpvDigiMuch
Output vectors.
Definition: CbmMcbm2018UnpackerTaskMuch.h:88
CbmMcbm2018UnpackerAlgoMuch::SetBinningFwFlag
void SetBinningFwFlag(Bool_t bEnable=kTRUE)
=> Quick and dirty hack for binning FW!!!
Definition: CbmMcbm2018UnpackerAlgoMuch.h:75
CbmMcbm2018UnpackerAlgoMuch::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Definition: CbmMcbm2018UnpackerAlgoMuch.cxx:227
CbmStar2019Algo::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Control flags.
Definition: CbmStar2019Algo.h:102