CbmRoot
Loading...
Searching...
No Matches
CbmDeviceBmonMonitor.h
Go to the documentation of this file.
1/* Copyright (C) 2022 Facility for Antiproton and Ion Research in Europe, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pierre-Alain Loizeau [committer] */
4
11
12#ifndef CBMDEVICEBMONMONI_H_
13#define CBMDEVICEBMONMONI_H_
14
15#include "CbmMqTMessage.h"
16#include "CbmTsEventHeader.h"
17
18#include "Timeslice.hpp"
19
20#include "FairMQDevice.h"
21#include "FairParGenericSet.h"
22
23#include "Rtypes.h"
24#include "TObjArray.h"
25
26#include <chrono>
27#include <map>
28#include <vector>
29
30class TList;
32
34
35class CbmTrdSpadic;
36
37class CbmDeviceBmonMonitor : public FairMQDevice {
38public:
40 virtual ~CbmDeviceBmonMonitor();
41
42protected:
43 virtual void InitTask();
44 bool ConditionalRun();
45 bool HandleCommand(FairMQMessagePtr&, int);
46
48 void SetUnpackConfig(std::shared_ptr<CbmBmonUnpackConfig> config) { fBmonConfig = config; }
49
50private:
52 static constexpr std::uint16_t fkFlesBmon = static_cast<std::uint16_t>(fles::Subsystem::BMON);
53
57 bool fbStartTimeSet = false;
58
60 bool fDoDebugPrints = false;
62 bool fDoPerfProf = false;
65
67 std::string fsSetupName = "mcbm_beam_2021_07_surveyed";
68 uint32_t fuRunId = 1588;
70 bool fbUnpBmon = true;
72 std::string fsChannelNameDataInput = "ts-request";
73 std::string fsChannelNameDataOutput = "unpts_0";
74 std::string fsChannelNameCommands = "commands";
75 std::string fsChannelNameHistosInput = "histogram-in";
77 uint32_t fuPublishFreqTs = 100;
78 double_t fdMinPublishTime = 0.5;
79 double_t fdMaxPublishTime = 5.0;
80
82 // TList* fParCList = nullptr;
83 Bool_t InitParameters(std::vector<std::pair<std::string, std::shared_ptr<FairParGenericSet>>>* reqparvec);
84
86 uint64_t fulNumMessages = 0;
87 uint64_t fulTsCounter = 0;
88 std::chrono::system_clock::time_point fLastPublishTime = std::chrono::system_clock::now();
90 std::map<uint16_t, std::pair<std::string, size_t>> fNameMap = {};
92 std::map<uint16_t, std::pair<double, double>> fTimeMap = {};
94 std::map<uint16_t, std::pair<double, double>> fDataSizeMap = {};
95
97 std::shared_ptr<CbmBmonUnpackConfig> fBmonConfig = nullptr;
98
101
103 std::vector<std::string> fvsSetTimeOffs = {};
104
106 size_t fuNbCoreMsPerTs = 0;
107 size_t fuNbOverMsPerTs = 0;
108 Double_t fdMsSizeInNs = 0;
109 Double_t fdTsCoreSizeInNs = -1.0;
110 Double_t fdTsOverSizeInNs = -1.0;
111 Double_t fdTsFullSizeInNs = -1.0;
113
115 TObjArray fArrayHisto = {};
117 std::vector<std::pair<std::string, std::string>> fvpsHistosFolder = {};
121 std::vector<std::pair<std::string, std::string>> fvpsCanvasConfig = {};
123 bool fbConfigSent = false;
124
126 bool InitHistograms();
127 Bool_t DoUnpack(const fles::Timeslice& ts, size_t component);
128 void Finish();
129 bool SendUnpData();
131 bool SendHistograms();
132
133 std::shared_ptr<CbmTrdSpadic> GetTrdSpadic(bool useAvgBaseline);
134
136 template<typename TVecobj>
137 typename std::enable_if<std::is_same<TVecobj, std::nullptr_t>::value == true, void>::type
138 timesort(std::vector<TVecobj>* /*vec = nullptr*/)
139 {
140 LOG(debug)
141 << "CbmDeviceBmonMonitor::timesort() got an object that has no member function GetTime(). Hence, we can and "
142 "will not timesort it!";
143 }
144
145 template<typename TVecobj>
146 typename std::enable_if<!std::is_member_function_pointer<decltype(&TVecobj::GetTime)>::value, void>::type
147 timesort(std::vector<TVecobj>* /*vec = nullptr*/)
148 {
149 LOG(debug) << "CbmDeviceBmonMonitor::timesort() " << TVecobj::Class_Name()
150 << "is an object that has no member function GetTime(). Hence, we can and "
151 "will not timesort it!";
152 }
153
154 template<typename TVecobj>
155 typename std::enable_if<std::is_member_function_pointer<decltype(&TVecobj::GetTime)>::value, void>::type
156 timesort(std::vector<TVecobj>* vec = nullptr)
157 {
158 if (vec == nullptr) return;
159 std::sort(vec->begin(), vec->end(),
160 [](const TVecobj& a, const TVecobj& b) -> bool { return a.GetTime() < b.GetTime(); });
161 }
162
176 template<class TConfig, class TOptOutA = std::nullptr_t, class TOptOutB = std::nullptr_t>
177 size_t unpack(const uint16_t subsysid, const fles::Timeslice* ts, uint16_t icomp, TConfig config,
178 std::vector<TOptOutA>* optouttargetvecA = nullptr, std::vector<TOptOutB>* optouttargetvecB = nullptr)
179 {
180
181 auto wallstarttime = std::chrono::high_resolution_clock::now();
182 std::clock_t cpustarttime = std::clock();
183
184 auto algo = config->GetUnpacker();
185 std::vector<TOptOutA> optoutAvec = {};
186 std::vector<TOptOutB> optoutBvec = {};
187 if (optouttargetvecA) { algo->SetOptOutAVec(&optoutAvec); }
188 if (optouttargetvecB) { algo->SetOptOutBVec(&optoutBvec); }
189
190 // Set the start time of the current TS for this algorithm
191 algo->SetTsStartTime(ts->start_time());
192
193 // Run the actual unpacking
194 auto digivec = algo->Unpack(ts, icomp);
195
196 // Check if we want to write the output to somewhere (in pure online monitoring mode for example this can/would/should be skipped)
197 if (config->GetOutputVec()) {
198 // Lets do some time-sorting if we are not doing it later
199 if (!fbOutputFullTimeSorting) timesort(&digivec);
200
201 // Transfer the data from the timeslice vector to the target branch vector
202 // Digis/default output retrieved as offered by the algorithm
203 for (auto digi : digivec)
204 config->GetOutputVec()->emplace_back(digi);
205 }
206 if (optouttargetvecA) {
207 // Lets do some timesorting
208 if (!fbOutputFullTimeSorting) timesort(&optoutAvec);
209 // Transfer the data from the timeslice vector to the target branch vector
210 for (auto optoutA : optoutAvec)
211 optouttargetvecA->emplace_back(optoutA);
212 }
213 if (optouttargetvecB) {
214 // Second opt output is not time sorted to allow non GetTime data container.
215 // Lets do some timesorting
216 timesort(&optoutAvec);
217 // Transfer the data from the timeslice vector to the target branch vector
218 for (auto optoutB : optoutBvec)
219 optouttargetvecB->emplace_back(optoutB);
220 }
221
222 std::clock_t cpuendtime = std::clock();
223 auto wallendtime = std::chrono::high_resolution_clock::now();
224
225 // Cpu time in [mus]
226 auto cputime = 1e6 * (cpuendtime - cpustarttime) / CLOCKS_PER_SEC;
227 algo->AddCpuTime(cputime);
228 // Real time in [mus]
229 auto walltime = std::chrono::duration<double, std::micro>(wallendtime - wallstarttime).count();
230 algo->AddWallTime(walltime);
231
232
233 // Check some numbers from this timeslice
234 size_t nDigis = digivec.size();
235 LOG(debug) << "Component " << icomp << " connected to config " << config->GetName() << " n-Digis " << nDigis
236 << " processed in walltime(cputime) = " << walltime << "(" << cputime << cputime << ") micro s"
237 << "this timeslice.";
238
239 if (fDoPerfProf) {
240 auto timeit = fTimeMap.find(subsysid);
241 timeit->second.first += cputime;
242 timeit->second.second += walltime;
243
244 auto datait = fDataSizeMap.find(subsysid);
245 datait->second.first += ts->size_component(icomp) / 1.0e6;
246 datait->second.second += nDigis * algo->GetOutputObjSize() / 1.0e6;
247
248 fNameMap.find(subsysid)->second.second += nDigis;
249 }
250
251 return nDigis;
252 }
253};
254
255#endif /* CBMDEVICEMCBMUNPACK_H_ */
bool Bool_t
std::chrono::system_clock::time_point fLastPublishTime
bool fDoDebugPrints
Flag if extended debug output is to be printed or not.
Double_t fdTsFullSizeInNs
Total size of the overlap MS in a TS, [nanoseconds].
Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
std::enable_if< std::is_member_function_pointer< decltype(&TVecobj::GetTime)>::value, void >::type timesort(std::vector< TVecobj > *vec=nullptr)
Bool_t InitParameters(std::vector< std::pair< std::string, std::shared_ptr< FairParGenericSet > > > *reqparvec)
Parameters management.
TObjArray fArrayHisto
Array of histograms to send to the histogram server.
uint32_t fuPublishFreqTs
Histograms management.
std::shared_ptr< CbmTrdSpadic > GetTrdSpadic(bool useAvgBaseline)
Get the Trd Spadic.
CbmTsEventHeader * fCbmTsEventHeader
Pointer to the Timeslice header conatining start time and index.
bool fbOutputFullTimeSorting
Flag to Enable/disable a full time sorting. If off, time sorting happens per link/FLIM source.
std::enable_if< std::is_same< TVecobj, std::nullptr_t >::value==true, void >::type timesort(std::vector< TVecobj > *)
Sort a vector timewise vector type has to provide GetTime()
Double_t fdTsCoreSizeInNs
Size of a single MS, [nanoseconds].
std::shared_ptr< CbmBmonUnpackConfig > fBmonConfig
Configuration of the unpackers. Provides the configured algorithm.
Bool_t fbComponentsAddedToList
Ignore Overlap Ms: all fuOverlapMsNb MS at the end of timeslice.
bool fDoPerfProf
Flag if performance profiling should be activated or not.
size_t unpack(const uint16_t subsysid, const fles::Timeslice *ts, uint16_t icomp, TConfig config, std::vector< TOptOutA > *optouttargetvecA=nullptr, std::vector< TOptOutB > *optouttargetvecB=nullptr)
Template for the unpacking call of a given algorithm.
std::vector< std::pair< std::string, std::string > > fvpsHistosFolder
Vector of string pairs with ( HistoName, FolderPath ) to send to the histogram server.
Double_t fdTsOverSizeInNs
Total size of the core MS in a TS, [nanoseconds].
std::map< uint16_t, std::pair< std::string, size_t > > fNameMap
Map to store a name for the unpackers and the processed amount of digis, key = fkFlesId.
std::vector< std::pair< std::string, std::string > > fvpsCanvasConfig
void SetUnpackConfig(std::shared_ptr< CbmBmonUnpackConfig > config)
Set the Bmon Unpack Config.
bool HandleCommand(FairMQMessagePtr &, int)
std::enable_if<!std::is_member_function_pointer< decltype(&TVecobj::GetTime)>::value, void >::type timesort(std::vector< TVecobj > *)
std::vector< std::string > fvsSetTimeOffs
Time offsets.
size_t fuNbCoreMsPerTs
TS MetaData storage: stable so should be moved somehow to parameters handling (not transmitted with e...
std::string fsSetupName
User settings parameters.
uint64_t fulNumMessages
Statistics & first TS rejection.
std::map< uint16_t, std::pair< double, double > > fDataSizeMap
Map to store the in and out data amount, key = fkFlesId.
static constexpr std::uint16_t fkFlesBmon
Constants.
std::string fsChannelNameDataInput
message queues
std::map< uint16_t, std::pair< double, double > > fTimeMap
Map to store the cpu and wall time, key = fkFlesId.
bool fbConfigSent
Flag indicating whether the histograms and canvases configurations were already published.
TimesliceMetaData * fTsMetaData
Total size of all MS in a TS, [nanoseconds].
bool fbUnpBmon
---> for selective unpacking
Bool_t fbIgnoreOverlapMs
Control flags.