CbmRoot
Loading...
Searching...
No Matches
CbmMcbm2018UnpackerTaskTrdR.cxx
Go to the documentation of this file.
1/* Copyright (C) 2020-2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Florian Uhlig [committer] */
4
6
8
9#include "FairRootManager.h"
10#include "FairRun.h"
11#include "FairRunOnline.h"
12#include "FairRuntimeDb.h"
13#include <Logger.h>
14
15#include <TFile.h>
16#include <THttpServer.h>
17
18/* Default Constructor */
21 , fbMonitorMode(kFALSE)
22 , fbDebugMonitorMode(kFALSE)
23 , fbWriteOutput(kTRUE)
24 , fbDebugWriteOutput(kFALSE)
25 , fbBaselineAvg(kFALSE)
26 , fSystemIdentifier((std::uint8_t) fles::Subsystem::TRD)
27 , fdMsSizeInNs(1.28e6) // default value corresponds to mCbm 2020 value
28 , fMonitorHistoFileName("")
29 , fIsActiveHistoVec(CbmMcbm2018UnpackerAlgoTrdR::kEndDefinedHistos, false)
30 , fTrdDigiVector(nullptr)
31 , fTrdRawMessageVector(nullptr)
32 , fSpadicInfoMsgVector(nullptr)
33 , fUnpackerAlgo(nullptr)
34{
36}
37
38/* Default Destructor */
40
42{
43 LOG(info) << "Initializing CbmMcbm2018UnpackerTaskTrdR...";
44 Bool_t initOK = 1;
45
46 FairRootManager* ioman = nullptr;
47 ioman = FairRootManager::Instance();
48 if (ioman == nullptr) { LOG(fatal) << "No FairRootManager instance"; }
49
51 fTrdDigiVector = new std::vector<CbmTrdDigi>();
52 if (fTrdDigiVector) {
53 ioman->RegisterAny("TrdDigi", fTrdDigiVector, fbWriteOutput);
55 }
56 else {
57 LOG(fatal) << "fTrdDigiVector could not be registered at FairRootManager.";
58 }
59
62 fTrdRawMessageVector = new std::vector<CbmTrdRawMessageSpadic>();
63 fSpadicInfoMsgVector = new std::vector<std::pair<size_t, size_t>>();
65 ioman->RegisterAny("CbmTrdSpadicRawMessages", fTrdRawMessageVector, kTRUE);
66 ioman->RegisterAny("CbmTrdSpadicInfoMessages", fSpadicInfoMsgVector, kTRUE);
68 }
69 else {
70 LOG(fatal) << "[CbmMcbm2018UnpackerTaskTrdR::Init] Raw output could not "
71 "be registered at FairRootManager.";
72 }
73 }
74
75 fUnpackerAlgo->SetMsSizeInNs(fdMsSizeInNs); // TODO handle this with asic parameter files
77 initOK &= fUnpackerAlgo->Init();
78
79 if (initOK) {
80 LOG(info) << "Initialization of CbmMcbm2018UnpackerTaskTrdR and "
81 "CbmMcbm2018UnpackerAlgoTrdR successfull!";
82 }
83 else {
84 LOG(fatal) << "Init of CbmMcbm2018UnpackerAlgoTrdR failed!";
85 }
86
87 return initOK;
88}
89
90Bool_t CbmMcbm2018UnpackerTaskTrdR::DoUnpack(const fles::Timeslice& ts, size_t /*component*/)
91{
93 if (kFALSE == fUnpackerAlgo->ProcessTs(ts)) {
94 LOG(error) << "CbmMcbm2018UnpackerTaskTrdR: Failed processing TS " << ts.index() << " in unpacker algorithm class.";
95 return kFALSE;
96 }
97
98
99 // sts does a time sorting of fTrdDigiVector here. but this could also be done in the algo?!
100
101
102 return kTRUE;
103}
104
112
114{
115 LOG(info) << "Finish of CbmMcbm2018UnpackerTaskTrdR";
117
118 if ((fbMonitorMode == kTRUE || fbDebugMonitorMode == kTRUE) && fMonitorHistoFileName != "") {
120 std::vector<std::pair<TNamed*, std::string>> vHistos = fUnpackerAlgo->GetHistoVector();
121
123 TFile* oldFile = gFile;
124 TDirectory* oldDir = gDirectory;
125
127 TFile* histoFile = nullptr;
128
129 // open separate histo file in recreate mode
130 TString histoFileName = fMonitorHistoFileName;
131 histoFile = new TFile(histoFileName.Data(), "RECREATE");
132 histoFile->cd();
134 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
135 // Make sure we end up in chosen folder
136 TString sFolder = vHistos[uHisto].second.data();
137 if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
138 gDirectory->cd(sFolder);
139 // Write histogram
140 vHistos[uHisto].first->Write();
141 histoFile->cd();
142 }
143
145 gFile = oldFile;
146 gDirectory = oldDir;
147
148 histoFile->Close();
149 }
150}
151
153{
154 LOG(info) << "Setting parameter containers for " << GetName();
155
156 TList* fParContList = fUnpackerAlgo->GetParList();
157
158 Int_t iParCont(0);
159 for (auto parSetIt : *fParContList) {
160 CbmTrdParSet* tempObj = (CbmTrdParSet*) (parSetIt);
161 fParContList->Remove(tempObj);
162 std::string sParamName {tempObj->GetName()};
163 delete tempObj;
164 CbmTrdParSet* updatedParSet = nullptr;
165 updatedParSet = dynamic_cast<CbmTrdParSet*>(FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
166
167 if (!updatedParSet) {
168 LOG(error) << "Failed to obtain parameter container " << sParamName << ", for parameter index " << iParCont;
169 return;
170 }
171 fParContList->AddAt(updatedParSet, iParCont);
172 }
173
174 // Get timeshift parameters
175 fTimeshiftPar = dynamic_cast<CbmMcbm2020TrdTshiftPar*>(
176 FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2020TrdTshiftPar"));
177}
178
180{
181 if (fUnpackerAlgo == nullptr) {
182 LOG(error) << "CbmMcbm2018UnpackerTaskTrdR::InitContainers failed! No "
183 "Unpacker Algo.";
184 return kFALSE;
185 }
186 LOG(info) << "Init containers for CbmMcbm2018UnpackerTaskTrdR";
187
195 // Activate histograms in unpacker
197
198 Bool_t initOK = fUnpackerAlgo->InitContainers();
199
200 if (fTimeshiftPar) {
201 auto maptimeshifts = fTimeshiftPar->GetTimeshiftsMap();
202 fUnpackerAlgo->SetTimeshiftsMap(maptimeshifts);
203 LOG(info) << "CbmMcbm2018UnpackerTaskTrdR::SetParContainers() - Parsing "
204 "timeshift correction map to unpacker algo";
205 }
206
209 if (fbMonitorMode == kTRUE || fbDebugMonitorMode == kTRUE) {
211 initOK &= fUnpackerAlgo->CreateHistograms();
212
214 std::vector<std::pair<TNamed*, std::string>> vHistos = fUnpackerAlgo->GetHistoVector();
215
217 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
218 if (nullptr != server) {
219 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
220 server->Register(Form("/%s", vHistos[uHisto].second.data()), vHistos[uHisto].first);
221 }
222 // FIXME: register the correct command
223 //server->RegisterCommand("/Reset_UnpSts_Hist", "bMcbm2018UnpackerTaskStsResetHistos=kTRUE");
224 //server->Restrict("/Reset_UnpSts_Hist", "allow=admin");
225 }
226 else {
227 // initOK &= 0;
230 LOG(warning) << "The histograms from CbmMcbm2018UnpackerTaskTrdR will "
231 "not be available online as no server present";
232 } // end if( nullptr != server )
233 } // end if (fbMonitorMode == kTRUE || fbDebugMonitorMode == kTRUE)
234
235 return initOK;
236}
237
239{
240 if (fUnpackerAlgo == nullptr) return kFALSE;
241
242 LOG(info) << "ReInit parameter containers for CbmMcbm2018UnpackerTaskTrdR";
243
244 Bool_t initOK = fUnpackerAlgo->ReInitContainers();
245 return initOK;
246}
247
248void CbmMcbm2018UnpackerTaskTrdR::AddMsComponentToList(size_t component, UShort_t usDetectorId)
249{
250 if (usDetectorId != (UShort_t) fSystemIdentifier) {
251 LOG(error) << "CbmMcbm2018UnpackerTaskTrdR::AddMsComponentToList : Wrong "
252 "Detector ID!";
253 return;
254 }
255 if (fUnpackerAlgo != nullptr) fUnpackerAlgo->AddMsComponentToList(component, usDetectorId);
256}
257
258void CbmMcbm2018UnpackerTaskTrdR::SetNbMsInTs(size_t uCoreMsNb, size_t uOverlapMsNb)
259{
260 if (fUnpackerAlgo != nullptr) fUnpackerAlgo->SetNbMsInTs(uCoreMsNb, uOverlapMsNb);
261}
262
264{
265 fMonitorHistoFileName = filename;
266 SetMonitorMode(kTRUE);
267}
268
270{
271 if (fUnpackerAlgo != nullptr) fUnpackerAlgo->SetTimeOffsetNs(dOffsetIn);
272}
273
ClassImp(CbmConverterManager)
Timeslice unpacker algorithm for Spadic v.2.2 .
void SetActiveHistograms(std::vector< bool > isActiveHistoVec)
Bool_t ProcessTs(const fles::Timeslice &ts)
void SetDebugSortOutput(Bool_t bFlagIn=kTRUE)
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
Bool_t CreateHistograms()
Goes through fIsActiveHistoVec and creates the activated histograms.
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
void SetMsSizeInNs(Double_t msSizeInNs)
void SetTimeshiftsMap(std::map< size_t, std::vector< Int_t > > *setvalue)
In the mCbm 2020 beamtime timeshifts changing during the run of the correlation time to the Bmon have...
Bool_t SetDigiOutputPointer(std::vector< CbmTrdDigi > *const pVector)
Set fTrdDigiVector to the address of pVector.
void SetBaselineAvg(Bool_t bFlagIn=kTRUE)
Call this when Spadic Average-Baseline feature is enabled.
void SetWriteOutput(Bool_t bFlagIn=kTRUE)
void SetNbMsInTs(size_t uCoreMsNb, size_t uOverlapMsNb)
Bool_t SetRawOutputPointer(std::vector< CbmTrdRawMessageSpadic > *const pVector, std::vector< std::pair< size_t, size_t > > *const qVector=nullptr)
Set fTrdRawMessageVector to the address of pVector.
void SetDebugMonitorMode(Bool_t bFlagIn=kTRUE)
void SetDebugWriteOutput(Bool_t bFlagIn=kTRUE)
Timeslice unpacker FairTask for Spadic v.2.2 .
Bool_t fbDebugSortOutput
If ON the output vector of raw messages is sorted in time.
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
Bool_t fbWriteOutput
If ON the output Vector of digis is written to disk.
std::vector< std::pair< size_t, size_t > > * fSpadicInfoMsgVector
vector< pair< fulltime, word > >
Bool_t fbDebugMonitorMode
Switch ON the filling of a additional set of histograms.
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
virtual Bool_t Init()
Registers output-data containers at the FairRootManager.
Double_t fdMsSizeInNs
microslice size in ns to be passed to the unpacker // TODO handle this with asic parameter files
Bool_t fbBaselineAvg
Set to true if Baseline Averaging is activated in Spadic.
virtual void SetNbMsInTs(size_t uCoreMsNb, size_t uOverlapMsNb)
Sets numbers of Core Microslices and overlap Microslices per Timeslice.
std::uint8_t fSystemIdentifier
by default set to: fles::Subsystem::TRD, changable via setter
Bool_t fbDebugWriteOutput
If ON the output vector of raw messages is filled and written to disk.
CbmMcbm2020TrdTshiftPar * fTimeshiftPar
mCbm2020 timeshift correction parameters
std::vector< CbmTrdRawMessageSpadic > * fTrdRawMessageVector
Output Spadic raw messages for debugging.
std::vector< CbmTrdDigi > * fTrdDigiVector
Output Digi vector.
Bool_t fbMonitorMode
< Set wether channels 00..15 are on the even (true) or the odd (false and default) elink
virtual void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Adds an input component to the list of active components for this unpacker.
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
CbmMcbm2018UnpackerAlgoTrdR * fUnpackerAlgo
Processing algo.
bool fIsFirstChannelsElinkEven
define if the first 16 channels (00..15) are found on the even (set true) or odd (false) eLinkId,...
std::map< size_t, std::vector< Int_t > > * GetTimeshiftsMap()
Return the timeshift map.
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
void SetIgnoreOverlapMs(Bool_t bFlagIn=kTRUE)
Control flags.
Definition Reco.h:14
Hash for CbmL1LinkKey.