CbmRoot
CbmMcbm2018UnpackerTaskTrdR.cxx
Go to the documentation of this file.
3 
4 #include "FairLogger.h"
5 #include "FairRootManager.h"
6 #include "FairRun.h"
7 #include "FairRunOnline.h"
8 #include "FairRuntimeDb.h"
9 
10 #include <TFile.h>
11 #include <THttpServer.h>
12 
13 /* Default Constructor */
15  : CbmMcbmUnpack()
16  , fbMonitorMode(kFALSE)
17  , fbDebugMonitorMode(kFALSE)
18  , fbWriteOutput(kTRUE)
19  , fbDebugWriteOutput(kFALSE)
20  , fbBaselineAvg(kFALSE)
21  , fSystemIdentifier((std::uint8_t) fles::SubsystemIdentifier::TRD)
22  , fdMsSizeInNs(1.28e6) // default value corresponds to mCbm 2020 value
23  , fMonitorHistoFileName("")
24  , fIsActiveHistoVec(CbmMcbm2018UnpackerAlgoTrdR::kEndDefinedHistos, false)
25  , fTrdDigiVector(nullptr)
26  , fTrdRawMessageVector(nullptr)
27  , fSpadicInfoMsgVector(nullptr)
28  , fUnpackerAlgo(nullptr) {
30 }
31 
32 /* Default Destructor */
34  delete fUnpackerAlgo;
35 }
36 
38  LOG(info) << "Initializing CbmMcbm2018UnpackerTaskTrdR...";
39  Bool_t initOK = 1;
40 
41  FairRootManager* ioman = nullptr;
42  ioman = FairRootManager::Instance();
43  if (ioman == nullptr) { LOG(fatal) << "No FairRootManager instance"; }
44 
46  fTrdDigiVector = new std::vector<CbmTrdDigi>();
47  if (fTrdDigiVector) {
48  ioman->RegisterAny("TrdDigi", fTrdDigiVector, fbWriteOutput);
50  } else {
51  LOG(fatal) << "fTrdDigiVector could not be registered at FairRootManager.";
52  }
53 
55  if (fbDebugWriteOutput) {
56  fTrdRawMessageVector = new std::vector<CbmTrdRawMessageSpadic>();
58  new std::vector<std::pair<std::uint64_t, std::uint64_t>>();
60  ioman->RegisterAny(
61  "CbmTrdSpadicRawMessages", fTrdRawMessageVector, kTRUE);
62  ioman->RegisterAny(
63  "CbmTrdSpadicInfoMessages", fSpadicInfoMsgVector, kTRUE);
66  } else {
67  LOG(fatal) << "[CbmMcbm2018UnpackerTaskTrdR::Init] Raw output could not "
68  "be registered at FairRootManager.";
69  }
70  }
71 
73  fdMsSizeInNs); // TODO handle this with asic parameter files
75  initOK &= fUnpackerAlgo->Init();
76 
77  if (initOK) {
78  LOG(info) << "Initialization of CbmMcbm2018UnpackerTaskTrdR and "
79  "CbmMcbm2018UnpackerAlgoTrdR successfull!";
80  } else {
81  LOG(fatal) << "Init of CbmMcbm2018UnpackerAlgoTrdR failed!";
82  }
83 
84  return initOK;
85 }
86 
87 Bool_t CbmMcbm2018UnpackerTaskTrdR::DoUnpack(const fles::Timeslice& ts,
88  size_t /*component*/) {
90  if (kFALSE == fUnpackerAlgo->ProcessTs(ts)) {
91  LOG(error) << "CbmMcbm2018UnpackerTaskTrdR: Failed processing TS "
92  << ts.index() << " in unpacker algorithm class.";
93  return kFALSE;
94  }
95 
96 
97  // sts does a time sorting of fTrdDigiVector here. but this could also be done in the algo?!
98 
99 
100  return kTRUE;
101 }
102 
104  if (fTrdDigiVector) fTrdDigiVector->clear();
108 }
109 
111  LOG(info) << "Finish of CbmMcbm2018UnpackerTaskTrdR";
113 
114  if ((fbMonitorMode == kTRUE || fbDebugMonitorMode == kTRUE)
115  && fMonitorHistoFileName != "") {
117  std::vector<std::pair<TNamed*, std::string>> vHistos =
119 
121  TDirectory* oldDir = nullptr;
122  TFile* histoFile = nullptr;
123  // Store current directory position to allow restore later
124  oldDir = gDirectory;
125  // open separate histo file in recreate mode
126  TString histoFileName = fMonitorHistoFileName;
127  histoFile = new TFile(histoFileName.Data(), "RECREATE");
128  histoFile->cd();
130  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
131  // Make sure we end up in chosen folder
132  TString sFolder = vHistos[uHisto].second.data();
133  if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
134  gDirectory->cd(sFolder);
135  // Write histogram
136  vHistos[uHisto].first->Write();
137  histoFile->cd();
138  }
139  // Restore original directory position
140  oldDir->cd();
141  histoFile->Close();
142  }
143 }
144 
146  LOG(info) << "Setting parameter containers for " << GetName();
147 
148  TList* fParContList = fUnpackerAlgo->GetParList();
149 
150  Int_t iParCont(0);
151  for (auto parSetIt : *fParContList) {
152  CbmTrdParSet* tempObj = (CbmTrdParSet*) (parSetIt);
153  fParContList->Remove(tempObj);
154  std::string sParamName {tempObj->GetName()};
155  delete tempObj;
156  CbmTrdParSet* updatedParSet = nullptr;
157  updatedParSet = dynamic_cast<CbmTrdParSet*>(
158  FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
159 
160  if (!updatedParSet) {
161  LOG(error) << "Failed to obtain parameter container " << sParamName
162  << ", for parameter index " << iParCont;
163  return;
164  }
165  fParContList->AddAt(updatedParSet, iParCont);
166  }
167 }
168 
170  if (fUnpackerAlgo == nullptr) {
171  LOG(error) << "CbmMcbm2018UnpackerTaskTrdR::InitContainers failed! No "
172  "Unpacker Algo.";
173  return kFALSE;
174  }
175  LOG(info) << "Init containers for CbmMcbm2018UnpackerTaskTrdR";
176 
184  // Activate histograms in unpacker
186 
187  Bool_t initOK = fUnpackerAlgo->InitContainers();
188 
191  if (fbMonitorMode == kTRUE || fbDebugMonitorMode == kTRUE) {
193  initOK &= fUnpackerAlgo->CreateHistograms();
194 
196  std::vector<std::pair<TNamed*, std::string>> vHistos =
198 
200  THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
201  if (nullptr != server) {
202  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
203  server->Register(Form("/%s", vHistos[uHisto].second.data()),
204  vHistos[uHisto].first);
205  }
206  // FIXME: register the correct command
207  //server->RegisterCommand("/Reset_UnpSts_Hist", "bMcbm2018UnpackerTaskStsResetHistos=kTRUE");
208  //server->Restrict("/Reset_UnpSts_Hist", "allow=admin");
209  } else {
210  // initOK &= 0;
213  LOG(warning) << "The histograms from CbmMcbm2018UnpackerTaskTrdR will "
214  "not be available online as no server present";
215  } // end if( nullptr != server )
216  } // end if (fbMonitorMode == kTRUE || fbDebugMonitorMode == kTRUE)
217 
218  return initOK;
219 }
220 
222  if (fUnpackerAlgo == nullptr) return kFALSE;
223 
224  LOG(info) << "ReInit parameter containers for CbmMcbm2018UnpackerTaskTrdR";
225 
226  Bool_t initOK = fUnpackerAlgo->ReInitContainers();
227  return initOK;
228 }
229 
231  UShort_t usDetectorId) {
232  if (usDetectorId != (UShort_t) fSystemIdentifier) {
233  LOG(error) << "CbmMcbm2018UnpackerTaskTrdR::AddMsComponentToList : Wrong "
234  "Detector ID!";
235  return;
236  }
237  if (fUnpackerAlgo != nullptr)
238  fUnpackerAlgo->AddMsComponentToList(component, usDetectorId);
239 }
240 
242  size_t uOverlapMsNb) {
243  if (fUnpackerAlgo != nullptr)
244  fUnpackerAlgo->SetNbMsInTs(uCoreMsNb, uOverlapMsNb);
245 }
246 
248  fMonitorHistoFileName = filename;
249  SetMonitorMode(kTRUE);
250 }
251 
253  if (fUnpackerAlgo != nullptr) fUnpackerAlgo->SetTimeOffsetNs(dOffsetIn);
254 }
255 
258 }
CbmMcbm2018UnpackerAlgoTrdR::Finish
virtual void Finish()
Definition: CbmMcbm2018UnpackerAlgoTrdR.cxx:83
CbmMcbm2018UnpackerTaskTrdR::fbDebugWriteOutput
Bool_t fbDebugWriteOutput
If ON the output vector of raw messages is filled and written to disk.
Definition: CbmMcbm2018UnpackerTaskTrdR.h:113
CbmMcbm2018UnpackerTaskTrdR::fIsActiveHistoVec
std::vector< bool > fIsActiveHistoVec
Definition: CbmMcbm2018UnpackerTaskTrdR.h:128
CbmMcbm2018UnpackerTaskTrdR::SetParContainers
virtual void SetParContainers()
Definition: CbmMcbm2018UnpackerTaskTrdR.cxx:145
CbmMcbm2018UnpackerTaskTrdR
Timeslice unpacker FairTask for Spadic v.2.2 .
Definition: CbmMcbm2018UnpackerTaskTrdR.h:24
CbmMcbm2018UnpackerTaskTrdR.h
CbmMcbm2018UnpackerTaskTrdR::fMonitorHistoFileName
TString fMonitorHistoFileName
Definition: CbmMcbm2018UnpackerTaskTrdR.h:127
CbmStar2019Algo::GetHistoVector
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
Definition: CbmStar2019Algo.h:84
CbmMcbm2018UnpackerTaskTrdR::fbBaselineAvg
Bool_t fbBaselineAvg
Set to true if Baseline Averaging is activated in Spadic.
Definition: CbmMcbm2018UnpackerTaskTrdR.h:117
CbmMcbm2018UnpackerAlgoTrdR::SetDebugSortOutput
void SetDebugSortOutput(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018UnpackerAlgoTrdR.h:129
CbmMcbm2018UnpackerTaskTrdR::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018UnpackerTaskTrdR.cxx:256
CbmMcbm2018UnpackerAlgoTrdR::SetDebugWriteOutput
void SetDebugWriteOutput(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018UnpackerAlgoTrdR.h:126
CbmMcbm2018UnpackerTaskTrdR::fbWriteOutput
Bool_t fbWriteOutput
If ON the output Vector of digis is written to disk.
Definition: CbmMcbm2018UnpackerTaskTrdR.h:111
CbmMcbm2018UnpackerAlgoTrdR::SetRawOutputPointer
Bool_t SetRawOutputPointer(std::vector< CbmTrdRawMessageSpadic > *const pVector, std::vector< std::pair< std::uint64_t, std::uint64_t >> *const qVector=nullptr)
Set fTrdRawMessageVector to the address of pVector.
Definition: CbmMcbm2018UnpackerAlgoTrdR.cxx:839
CbmMcbm2018UnpackerTaskTrdR::fbDebugSortOutput
Bool_t fbDebugSortOutput
If ON the output vector of raw messages is sorted in time.
Definition: CbmMcbm2018UnpackerTaskTrdR.h:114
CbmMcbm2018UnpackerAlgoTrdR::Init
virtual Bool_t Init()
Definition: CbmMcbm2018UnpackerAlgoTrdR.cxx:68
CbmMcbm2018UnpackerTaskTrdR::ReInitContainers
virtual Bool_t ReInitContainers()
Definition: CbmMcbm2018UnpackerTaskTrdR.cxx:221
CbmMcbm2018UnpackerTaskTrdR::SetMonitorMode
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018UnpackerTaskTrdR.h:70
CbmMcbm2018UnpackerTaskTrdR::fSystemIdentifier
std::uint8_t fSystemIdentifier
by default set to: fles::SubsystemIdentifier::TRD, changable via setter
Definition: CbmMcbm2018UnpackerTaskTrdR.h:119
CbmMcbm2018UnpackerTaskTrdR::SetTimeOffsetNs
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerTaskTrdR.cxx:252
CbmMcbm2018UnpackerAlgoTrdR::ProcessTs
Bool_t ProcessTs(const fles::Timeslice &ts)
Definition: CbmMcbm2018UnpackerAlgoTrdR.cxx:174
CbmMcbm2018UnpackerAlgoTrdR::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Definition: CbmMcbm2018UnpackerAlgoTrdR.cxx:366
CbmMcbm2018UnpackerAlgoTrdR::SetDebugMonitorMode
void SetDebugMonitorMode(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018UnpackerAlgoTrdR.h:122
CbmTrdParSet
Definition: CbmTrdParSet.h:19
CbmMcbm2018UnpackerTaskTrdR::SetNbMsInTs
virtual void SetNbMsInTs(size_t uCoreMsNb, size_t uOverlapMsNb)
Sets numbers of Core Microslices and overlap Microslices per Timeslice.
Definition: CbmMcbm2018UnpackerTaskTrdR.cxx:241
CbmMcbm2018UnpackerTaskTrdR::Init
virtual Bool_t Init()
Registers output-data containers at the FairRootManager.
Definition: CbmMcbm2018UnpackerTaskTrdR.cxx:37
CbmMcbm2018UnpackerTaskTrdR::fdMsSizeInNs
Double_t fdMsSizeInNs
microslice size in ns to be passed to the unpacker // TODO handle this with asic parameter files
Definition: CbmMcbm2018UnpackerTaskTrdR.h:121
CbmMcbm2018UnpackerAlgoTrdR::SetDigiOutputPointer
Bool_t SetDigiOutputPointer(std::vector< CbmTrdDigi > *const pVector)
Set fTrdDigiVector to the address of pVector.
Definition: CbmMcbm2018UnpackerAlgoTrdR.cxx:829
CbmMcbm2018UnpackerAlgoTrdR::SetWriteOutput
void SetWriteOutput(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018UnpackerAlgoTrdR.h:125
CbmMcbm2018UnpackerAlgoTrdR::SetMsSizeInNs
void SetMsSizeInNs(Double_t msSizeInNs)
Definition: CbmMcbm2018UnpackerAlgoTrdR.h:162
CbmMcbm2018UnpackerTaskTrdR::Reset
virtual void Reset()
Definition: CbmMcbm2018UnpackerTaskTrdR.cxx:103
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmMcbm2018UnpackerTaskTrdR::~CbmMcbm2018UnpackerTaskTrdR
virtual ~CbmMcbm2018UnpackerTaskTrdR()
Definition: CbmMcbm2018UnpackerTaskTrdR.cxx:33
CbmMcbm2018UnpackerTaskTrdR::SetHistoFileName
void SetHistoFileName(TString filename)
Definition: CbmMcbm2018UnpackerTaskTrdR.cxx:247
CbmMcbm2018UnpackerAlgoTrdR::SetBaselineAvg
void SetBaselineAvg(Bool_t bFlagIn=kTRUE)
Call this when Spadic Average-Baseline feature is enabled.
Definition: CbmMcbm2018UnpackerAlgoTrdR.h:139
CbmMcbm2018UnpackerTaskTrdR::fbMonitorMode
Bool_t fbMonitorMode
< Set wether channels 00..15 are on the even (true) or the odd (false and default) elink
Definition: CbmMcbm2018UnpackerTaskTrdR.h:107
CbmMcbm2018UnpackerAlgoTrdR.h
CbmMcbm2018UnpackerTaskTrdR::InitContainers
virtual Bool_t InitContainers()
Definition: CbmMcbm2018UnpackerTaskTrdR.cxx:169
CbmMcbm2018UnpackerAlgoTrdR::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018UnpackerAlgoTrdR.cxx:103
CbmMcbm2018UnpackerTaskTrdR::fTrdDigiVector
std::vector< CbmTrdDigi > * fTrdDigiVector
Output Digi vector.
Definition: CbmMcbm2018UnpackerTaskTrdR.h:131
CbmMcbm2018UnpackerAlgoTrdR::CreateHistograms
Bool_t CreateHistograms()
Goes through fIsActiveHistoVec and creates the activated histograms.
Definition: CbmMcbm2018UnpackerAlgoTrdR.cxx:388
CbmMcbm2018UnpackerAlgoTrdR::GetParList
TList * GetParList()
Definition: CbmMcbm2018UnpackerAlgoTrdR.cxx:135
CbmMcbm2018UnpackerAlgoTrdR::SetTimeOffsetNs
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
Definition: CbmMcbm2018UnpackerAlgoTrdR.h:132
CbmMcbm2018UnpackerTaskTrdR::fbDebugMonitorMode
Bool_t fbDebugMonitorMode
Switch ON the filling of a additional set of histograms.
Definition: CbmMcbm2018UnpackerTaskTrdR.h:109
CbmMcbm2018UnpackerTaskTrdR::fIsFirstChannelsElinkEven
bool fIsFirstChannelsElinkEven
define if the first 16 channels (00..15) are found on the even (set true) or odd (false) eLinkId,...
Definition: CbmMcbm2018UnpackerTaskTrdR.h:123
CbmMcbm2018UnpackerTaskTrdR::fSpadicInfoMsgVector
std::vector< std::pair< std::uint64_t, std::uint64_t > > * fSpadicInfoMsgVector
vector< pair< fulltime, word > >
Definition: CbmMcbm2018UnpackerTaskTrdR.h:137
CbmMcbm2018UnpackerAlgoTrdR::Reset
virtual void Reset()
Definition: CbmMcbm2018UnpackerAlgoTrdR.cxx:78
CbmMcbm2018UnpackerAlgoTrdR::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018UnpackerAlgoTrdR.cxx:94
CbmMcbm2018UnpackerAlgoTrdR::SetMonitorMode
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
Definition: CbmMcbm2018UnpackerAlgoTrdR.h:121
CbmMcbm2018UnpackerTaskTrdR::Finish
virtual void Finish()
Definition: CbmMcbm2018UnpackerTaskTrdR.cxx:110
CbmMcbm2018UnpackerAlgoTrdR::SetNbMsInTs
void SetNbMsInTs(size_t uCoreMsNb, size_t uOverlapMsNb)
Definition: CbmMcbm2018UnpackerAlgoTrdR.cxx:380
CbmMcbm2018UnpackerTaskTrdR::fTrdRawMessageVector
std::vector< CbmTrdRawMessageSpadic > * fTrdRawMessageVector
Output Spadic raw messages for debugging.
Definition: CbmMcbm2018UnpackerTaskTrdR.h:134
CbmMcbm2018UnpackerTaskTrdR::fUnpackerAlgo
CbmMcbm2018UnpackerAlgoTrdR * fUnpackerAlgo
Processing algo.
Definition: CbmMcbm2018UnpackerTaskTrdR.h:140
CbmMcbm2018UnpackerTaskTrdR::AddMsComponentToList
virtual void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Adds an input component to the list of active components for this unpacker.
Definition: CbmMcbm2018UnpackerTaskTrdR.cxx:230
CbmMcbm2018UnpackerTaskTrdR::DoUnpack
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
Definition: CbmMcbm2018UnpackerTaskTrdR.cxx:87
CbmMcbm2018UnpackerAlgoTrdR::SetFirstChannelsElinkEven
void SetFirstChannelsElinkEven(bool isEven)
Definition: CbmMcbm2018UnpackerAlgoTrdR.h:159
CbmMcbmUnpack
Definition: CbmMcbmUnpack.h:15
CbmMcbm2018UnpackerTaskTrdR::CbmMcbm2018UnpackerTaskTrdR
CbmMcbm2018UnpackerTaskTrdR()
Definition: CbmMcbm2018UnpackerTaskTrdR.cxx:14
CbmMcbm2018UnpackerAlgoTrdR::SetActiveHistograms
void SetActiveHistograms(std::vector< bool > isActiveHistoVec)
Definition: CbmMcbm2018UnpackerAlgoTrdR.h:101
CbmStar2019Algo::SetIgnoreOverlapMs
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Control flags.
Definition: CbmStar2019Algo.h:102
CbmMcbm2018UnpackerAlgoTrdR
Timeslice unpacker algorithm for Spadic v.2.2 .
Definition: CbmMcbm2018UnpackerAlgoTrdR.h:34