CbmRoot
Loading...
Searching...
No Matches
CbmTrdUnpackMonitor.h
Go to the documentation of this file.
1/* Copyright (C) 2021 Goethe-University Frankfurt, Frankfurt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pascal Raisig [committer] */
4
20
21#ifndef CbmTrdUnpackMonitor_H
22#define CbmTrdUnpackMonitor_H
23
24#include "CbmTrdDigi.h"
25#include "CbmTrdParSetAsic.h"
26#include "CbmTrdParSetDigi.h"
28#include "CbmTrdSpadic.h"
29
30#include <MicrosliceDescriptor.hpp>
31#include <Timeslice.hpp>
32
33#include <FairRunOnline.h>
34#include <FairTask.h>
35#include <Logger.h>
36
37#include <Rtypes.h> // for types
38#include <RtypesCore.h>
39#include <TFile.h>
40#include <TH1.h>
41#include <THttpServer.h> // for histogram server
42
43#include <cmath>
44#include <cstdint>
45#include <map>
46#include <memory>
47#include <string>
48#include <vector>
49
51 public:
68
84
94
96 static const uint32_t kTimeplotLenghtSeconds = 600; // 10 minuntes
97
99 CbmTrdUnpackMonitor(/* args */);
100
102 virtual ~CbmTrdUnpackMonitor();
103
106
109
111 void FillHistos(CbmTrdDigi* digi, CbmTrdRawMessageSpadic* raw = nullptr);
112
118 void FillHisto(Spadic::MsInfoType type, uint32_t moduleid);
119
125 void FillHisto(fles::MicrosliceFlags flag, uint32_t moduleid);
126
128 void Finish();
129
130 // Runtime functions
132 Bool_t Init(CbmTrdParSetDigi* digiParSet, CbmTrdParSetAsic* asicParSet = nullptr);
133
135 void SetActiveHistos(std::vector<eDigiHistos> vec) { fActiveDigiHistos.swap(vec); }
136
138 void SetActiveHistos(std::vector<eRawHistos> vec) { fActiveRawHistos.swap(vec); }
139
141 void SetActiveHistos(std::vector<eOtherHistos> vec) { fActiveOtherHistos.swap(vec); }
142
144 void SetSpadicObject(std::shared_ptr<CbmTrdSpadic> value) { fSpadic = value; }
145
147 void SetWriteToFile(std::string filename)
148 {
149 fOutfilename = filename;
150 fDoWriteToFile = true;
151 }
152
154 void SetDigiOutputVec(std::vector<CbmTrdDigi>* digiOutputVec) { fDigiOutputVec = digiOutputVec; }
155
158
159
160 protected:
161 template<class histotype>
162 void addHistoToMap(std::shared_ptr<TH1> histo,
163 std::map<histotype, std::map<uint32_t, std::shared_ptr<TH1>>>* histomap, uint32_t moduleid,
164 histotype kHisto)
165 {
166 // If the histogram already exists we stop here
167 if (checkIfHistoExists(kHisto, histomap, moduleid)) return;
168
169 // Create a histo module pair
170 auto histopair = std::make_pair(moduleid, histo);
171
172 // Check if already have a histo map for the histo category
173 auto histomapIt = histomap->find(kHisto);
174 if (histomapIt == histomap->end()) {
175 // There is no map yet for the given histogram category
176 std::map<uint32_t, std::shared_ptr<TH1>> newmap = {};
177 newmap.emplace(histopair);
178 // Create a pair with the map and the histogram category
179 auto pair = std::make_pair(kHisto, newmap);
180 // And put it to the digi histo map
181 histomap->emplace(pair);
182 }
183 else {
184 // We found a map where we can put the histopair into
185 histomapIt->second.emplace(histopair);
186 }
187 // And finally if we have HttpServer we pass the histogram pointer to it
188 if (fHistoServer) {
189
190 std::string directory = std::to_string(moduleid) + "/" + getHistoType(histo) + "/";
191 fHistoServer->Register(directory.data(), histo.get());
192 }
193 }
194
195 template<typename THistotype>
196 bool checkIfHistoExists(THistotype etype, std::map<THistotype, std::map<uint32_t, std::shared_ptr<TH1>>>* histomap,
197 uint32_t moduleid)
198 {
199 // First check if the map knows about the type, if not the histo does not exist yet.
200 auto histotypemapIt = histomap->find(etype);
201 if (histotypemapIt == histomap->end()) return false;
202
203 // Check if at the moduleId position we find something
204 auto histopair = histotypemapIt->second.find(moduleid);
205 if (histopair == histotypemapIt->second.end()) return false;
206
207 // Check if there is a pointer to the histo which not null
208 if (histopair->second != nullptr) return true;
209
210 return false;
211 }
212
214 virtual void createHistos();
215
217 virtual void createHisto(eDigiHistos kHisto);
218
220 virtual void createHisto(eRawHistos kHisto);
221
223 virtual void createHisto(eOtherHistos kHisto);
224
233 virtual void fillHisto(CbmTrdDigi* digi, eDigiHistos kHisto, uint32_t moduleid, std::shared_ptr<TH1> histo);
234
242 void fillHisto(CbmTrdRawMessageSpadic* raw, eRawHistos kHisto, std::shared_ptr<TH1> histo, CbmTrdDigi* digi);
243
250 void fillSamplesHisto(std::shared_ptr<TH1> histo, CbmTrdRawMessageSpadic* raw);
251
253 std::double_t getDeltaT(CbmTrdDigi* digi);
254
256 std::string getHistoName(eDigiHistos kHisto);
257
259 std::string getHistoName(eRawHistos kHisto);
260
262 std::string getHistoName(eOtherHistos kHisto);
263
265 static std::string getTypeName(eDigiHistos kHisto)
266 {
267 (void) kHisto;
268 return "Digi";
269 };
270
272 static std::string getTypeName(eRawHistos kHisto)
273 {
274 (void) kHisto;
275 return "Raw";
276 };
277
279 static std::string getTypeName(eOtherHistos kHisto)
280 {
281 (void) kHisto;
282 return "Other";
283 };
284
286 std::string getHistoType(std::shared_ptr<TH1> histo);
287
295 std::pair<uint32_t, uint32_t> getRowAndCol(uint32_t moduleid, uint32_t channelid);
296
298 std::float_t getSamplesStdDev(CbmTrdRawMessageSpadic* raw);
299
300 template<class histotype>
301 size_t writeHistosToFile(std::map<histotype, std::map<uint32_t, std::shared_ptr<TH1>>>* histomap, TFile* file)
302 {
303 // Counter of written histos
304 size_t nhistos = 0;
305
306 // Make sure we are in the file to which we want to write our histos
307 file->cd();
308 for (auto typemappair : *histomap) {
309 for (auto histopair : typemappair.second) {
310
311 // Make sure we end up in chosen folder
312 std::string moduleidname = std::to_string(histopair.first);
313 if (nullptr == gDirectory->Get(moduleidname.data())) gDirectory->mkdir(moduleidname.data());
314 gDirectory->cd(moduleidname.data());
315
316 // Now move(create) to the histotype folder (digi, raw or other histo)
317 std::string histotypename = getTypeName(typemappair.first);
318 // (Create and) Move to the directory of the type
319 if (nullptr == gDirectory->Get(histotypename.data())) gDirectory->mkdir(histotypename.data());
320 gDirectory->cd(histotypename.data());
321
322 // Write histogram
323 LOG(debug) << Class_Name() << "::Finish() Write histo " << histopair.second->GetName() << " to file "
324 << file->GetName() << " in folder " << moduleidname.data() << "/" << histotypename.data();
325 histopair.second->Write();
326 nhistos++;
327 // Move back to root directory of the output file
328 file->cd();
329 }
330 }
331 return nhistos;
332 }
333
335 void fillNtCorrHisto(std::shared_ptr<TH1> histo, CbmTrdDigi* digi);
336
338 void resetTimeplots();
339
341 void adjustTimeplots(uint64_t newtime);
342
343 // Member variables
345 std::map<eDigiHistos, std::map<uint32_t, std::shared_ptr<TH1>>> fDigiHistoMap = {};
346
348 std::map<eRawHistos, std::map<uint32_t, std::shared_ptr<TH1>>> fRawHistoMap = {};
349
351 std::map<eOtherHistos, std::map<uint32_t, std::shared_ptr<TH1>>> fOtherHistoMap = {};
352
354 std::vector<eDigiHistos> fActiveDigiHistos = {};
355
357 std::vector<eRawHistos> fActiveRawHistos = {};
358
360 std::vector<eOtherHistos> fActiveOtherHistos = {};
361
363 THttpServer* fHistoServer = nullptr;
364
366 bool fDoWriteToFile = false;
367
369 std::string fOutfilename = "";
370
371 // ---- TRD parameters ----
373 std::vector<uint32_t> fModuleIdsVec = {};
374
376 std::map<uint32_t, uint8_t> fModuleOrientation = {};
377
379 std::map<uint32_t, uint8_t> fModuleNrRows = {};
380
382 std::map<uint32_t, uint8_t> fModuleNrColumns = {};
383
385 std::map<uint32_t, std::vector<size_t>> fLastDigiTimeMap = {};
386
388 std::vector<CbmTrdDigi>* fDigiOutputVec = {};
389
390 // All other parameters and containers
391 std::shared_ptr<CbmTrdSpadic> fSpadic = nullptr;
392
395
398
400 uint64_t fLastRawTime = 0;
401
402 private:
403 ClassDef(CbmTrdUnpackMonitor, 2)
404};
405
406#endif // CbmTrdUnpackMonitor_H
Software representation of the SPADIC v2.2+.
bool Bool_t
Describe TRD module ASIC settings (electronic gain, delays, etc)
Base class for storing raw information which comes from the Spadic v2.2 trough flib or from a tsa fil...
std::pair< uint32_t, uint32_t > getRowAndCol(uint32_t moduleid, uint32_t channelid)
Get the row and column ids (potentially rotated chambers are adjusted to humand readable rotations)
void Finish()
Actions at the end of the run, e.g. write histos to file if flag is set.
bool checkIfHistoExists(THistotype etype, std::map< THistotype, std::map< uint32_t, std::shared_ptr< TH1 > > > *histomap, uint32_t moduleid)
static std::string getTypeName(eDigiHistos kHisto)
Get the Type Name for the given histo.
virtual ~CbmTrdUnpackMonitor()
Destroy the Cbm Trd Unpack Task object.
void SetCurrentTimesliceStartTime(uint64_t time)
Set the start time of the current timeslice in ns.
CbmTrdUnpackMonitor()
Create the Cbm Trd Unpack AlgoBase object.
void fillSamplesHisto(std::shared_ptr< TH1 > histo, CbmTrdRawMessageSpadic *raw)
Fill the passed histo with the samples as function of time.
std::vector< eDigiHistos > fActiveDigiHistos
Enums of Digi histos to be activated.
std::map< uint32_t, uint8_t > fModuleNrColumns
Map with the number of columns of the modules. Performance helper to not go through the extraction fr...
std::string getHistoName(eDigiHistos kHisto)
Get the Histo Name for the given histo.
void adjustTimeplots(uint64_t newtime)
Adjust the boundaries of all timeplots to contain newtime.
virtual void fillHisto(CbmTrdDigi *digi, eDigiHistos kHisto, uint32_t moduleid, std::shared_ptr< TH1 > histo)
Fill the given histo with the information from the digi.
void fillNtCorrHisto(std::shared_ptr< TH1 > histo, CbmTrdDigi *digi)
Fill the NeighborTrigger Checking Histogram.
eDigiHistos
Enum for the predefined digi histograms.
CbmTrdUnpackMonitor(const CbmTrdUnpackMonitor &)=delete
Copy constructor - not implemented.
virtual void createHisto(eDigiHistos kHisto)
Create the actual TH1 shared_ptrs of the Digi histos.
std::vector< eRawHistos > fActiveRawHistos
Enums of Raw histos to be activated.
std::map< uint32_t, std::vector< size_t > > fLastDigiTimeMap
Map with the last digi time for each channel of a given module.
std::string getHistoType(std::shared_ptr< TH1 > histo)
Get the Histo Type, i.e. "Digi/Raw/Other", deduced from the histo name.
void SetDigiOutputVec(std::vector< CbmTrdDigi > *digiOutputVec)
Set digi outpout vector (to make it usable for correlations)
std::vector< uint32_t > fModuleIdsVec
Vector with the unique module Ids.
static std::string getTypeName(eOtherHistos kHisto)
Get the Type Name for the given histo.
void SetActiveHistos(std::vector< eOtherHistos > vec)
transfer the enums for the histos to be activated to the member vector
Bool_t Init(CbmTrdParSetDigi *digiParSet, CbmTrdParSetAsic *asicParSet=nullptr)
Init all required parameter informations.
uint64_t fCurrentTimesliceStartTimeNs
Variable which holds the start time in ns of the current timeslice.
static const uint32_t kTimeplotLenghtSeconds
Constant which defines the lenght of the time axis in seconds of plots which display a quantity over ...
static std::string getTypeName(eRawHistos kHisto)
Get the Type Name for the given histo.
std::shared_ptr< CbmTrdSpadic > fSpadic
void SetActiveHistos(std::vector< eDigiHistos > vec)
transfer the enums for the histos to be activated to the member vector
std::vector< eOtherHistos > fActiveOtherHistos
Enums of Raw histos to be activated.
std::vector< CbmTrdDigi > * fDigiOutputVec
Variable which holds a reference to the TRD digi output vector (for correlations)
uint64_t fCurrentTimeplotStartNs
Variable which holds the start time in ns of the current time axis of plots which display a quantity ...
std::map< eDigiHistos, std::map< uint32_t, std::shared_ptr< TH1 > > > fDigiHistoMap
Digi histogram pointers stored in a map together with the module id.
void SetActiveHistos(std::vector< eRawHistos > vec)
transfer the enums for the histos to be activated to the member vector
void FillHisto(Spadic::MsInfoType type, uint32_t moduleid)
Fill the given histo with the information on the info type.
std::map< uint32_t, uint8_t > fModuleNrRows
Map with the number of rows of the modules. Performance helper to not go through the extraction from ...
bool fDoWriteToFile
Flag whether to write histos to file or not, gets activated if a output filename gets set.
std::double_t getDeltaT(CbmTrdDigi *digi)
Get the time difference between this digi and the previous one from the channel of this digi.
std::map< uint32_t, uint8_t > fModuleOrientation
Map with the orientations of the modules. Performance helper to not go through the extraction from Pa...
void FillHistos(CbmTrdDigi *digi, CbmTrdRawMessageSpadic *raw=nullptr)
fill the stored digi histograms
eOtherHistos
Enum for the predefined other histograms.
std::map< eRawHistos, std::map< uint32_t, std::shared_ptr< TH1 > > > fRawHistoMap
Raw histogram pointers stored in a map together with the module id.
eRawHistos
Enum for the predefined raw histograms.
THttpServer * fHistoServer
Pointer to the histogram server, in case we run the online monitoring, the pointer is automatically d...
std::float_t getSamplesStdDev(CbmTrdRawMessageSpadic *raw)
Extract the std deviation of all samples in the message.
void SetWriteToFile(std::string filename)
Set the output filename, automatically also sets the flag to create an output file.
uint64_t fLastRawTime
Variable which holds the time in ns of the last processed raw message.
void resetTimeplots()
Reset the contents of all timeplots.
std::string fOutfilename
File name for the output file.
void addHistoToMap(std::shared_ptr< TH1 > histo, std::map< histotype, std::map< uint32_t, std::shared_ptr< TH1 > > > *histomap, uint32_t moduleid, histotype kHisto)
std::map< eOtherHistos, std::map< uint32_t, std::shared_ptr< TH1 > > > fOtherHistoMap
Other histogram pointers stored in a map together with the module id.
CbmTrdUnpackMonitor & operator=(const CbmTrdUnpackMonitor &)=delete
Assignment operator - not implemented.
void SetSpadicObject(std::shared_ptr< CbmTrdSpadic > value)
Set the Spadic Object.
virtual void createHistos()
Create the actual TH1 shared_ptrs.
size_t writeHistosToFile(std::map< histotype, std::map< uint32_t, std::shared_ptr< TH1 > > > *histomap, TFile *file)