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
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
54
56 Bool_t fbIgnoreOverlapMs = false;
57 Bool_t fbComponentsAddedToList = kFALSE;
58 bool fbStartTimeSet = false;
59
61 bool fDoDebugPrints = false;
63 bool fDoPerfProf = false;
66
68 std::string fsSetupName = "mcbm_beam_2021_07_surveyed";
69 uint32_t fuRunId = 1588;
71 bool fbUnpBmon = true;
73 std::string fsChannelNameDataInput = "ts-request";
74 std::string fsChannelNameDataOutput = "unpts_0";
75 std::string fsChannelNameCommands = "commands";
76 std::string fsChannelNameHistosInput = "histogram-in";
78 uint32_t fuPublishFreqTs = 100;
79 double_t fdMinPublishTime = 0.5;
80 double_t fdMaxPublishTime = 5.0;
81
83 // TList* fParCList = nullptr;
84 Bool_t InitParameters(std::vector<std::pair<std::string, std::shared_ptr<FairParGenericSet>>>* reqparvec);
85
87 uint64_t fulNumMessages = 0;
88 uint64_t fulTsCounter = 0;
89 std::chrono::system_clock::time_point fLastPublishTime = std::chrono::system_clock::now();
91 std::map<std::uint16_t, std::pair<std::string, size_t>> fNameMap = {};
93 std::map<std::uint16_t, std::pair<double, double>> fTimeMap = {};
95 std::map<std::uint16_t, std::pair<double, double>> fDataSizeMap = {};
96
98 std::shared_ptr<CbmBmonUnpackConfig> fBmonConfig = nullptr;
99
102
104 std::vector<std::string> fvsSetTimeOffs = {};
105
107 size_t fuNbCoreMsPerTs = 0;
108 size_t fuNbOverMsPerTs = 0;
109 Double_t fdMsSizeInNs = 0;
110 Double_t fdTsCoreSizeInNs = -1.0;
111 Double_t fdTsOverSizeInNs = -1.0;
112 Double_t fdTsFullSizeInNs = -1.0;
114
116 TObjArray fArrayHisto = {};
118 std::vector<std::pair<std::string, std::string>> fvpsHistosFolder = {};
122 std::vector<std::pair<std::string, std::string>> fvpsCanvasConfig = {};
124 bool fbConfigSent = false;
125
126 Bool_t InitContainers();
127 bool InitHistograms();
128 Bool_t DoUnpack(const fles::Timeslice& ts, size_t component);
129 void Finish();
130 bool SendUnpData();
132 bool SendHistograms();
133
134 std::shared_ptr<CbmTrdSpadic> GetTrdSpadic(bool useAvgBaseline);
135
137 template<typename TVecobj>
138 typename std::enable_if<std::is_same<TVecobj, std::nullptr_t>::value == true, void>::type
139 timesort(std::vector<TVecobj>* /*vec = nullptr*/)
140 {
141 LOG(debug)
142 << "CbmDeviceBmonMonitor::timesort() got an object that has no member function GetTime(). Hence, we can and "
143 "will not timesort it!";
144 }
145
146 template<typename TVecobj>
147 typename std::enable_if<!std::is_member_function_pointer<decltype(&TVecobj::GetTime)>::value, void>::type
148 timesort(std::vector<TVecobj>* /*vec = nullptr*/)
149 {
150 LOG(debug) << "CbmDeviceBmonMonitor::timesort() " << TVecobj::Class_Name()
151 << "is an object that has no member function GetTime(). Hence, we can and "
152 "will not timesort it!";
153 }
154
155 template<typename TVecobj>
156 typename std::enable_if<std::is_member_function_pointer<decltype(&TVecobj::GetTime)>::value, void>::type
157 timesort(std::vector<TVecobj>* vec = nullptr)
158 {
159 if (vec == nullptr) return;
160 std::sort(vec->begin(), vec->end(),
161 [](const TVecobj& a, const TVecobj& b) -> bool { return a.GetTime() < b.GetTime(); });
162 }
163
177 template<class TConfig, class TOptOutA = std::nullptr_t, class TOptOutB = std::nullptr_t>
178 size_t unpack(const std::uint16_t subsysid, const fles::Timeslice* ts, std::uint16_t icomp, TConfig config,
179 std::vector<TOptOutA>* optouttargetvecA = nullptr, std::vector<TOptOutB>* optouttargetvecB = nullptr)
180 {
181
182 auto wallstarttime = std::chrono::high_resolution_clock::now();
183 std::clock_t cpustarttime = std::clock();
184
185 auto algo = config->GetUnpacker();
186 std::vector<TOptOutA> optoutAvec = {};
187 std::vector<TOptOutB> optoutBvec = {};
188 if (optouttargetvecA) { algo->SetOptOutAVec(&optoutAvec); }
189 if (optouttargetvecB) { algo->SetOptOutBVec(&optoutBvec); }
190
191 // Set the start time of the current TS for this algorithm
192 algo->SetTsStartTime(ts->start_time());
193
194 // Run the actual unpacking
195 auto digivec = algo->Unpack(ts, icomp);
196
197 // Check if we want to write the output to somewhere (in pure online monitoring mode for example this can/would/should be skipped)
198 if (config->GetOutputVec()) {
199 // Lets do some time-sorting if we are not doing it later
200 if (!fbOutputFullTimeSorting) timesort(&digivec);
201
202 // Transfer the data from the timeslice vector to the target branch vector
203 // Digis/default output retrieved as offered by the algorithm
204 for (auto digi : digivec)
205 config->GetOutputVec()->emplace_back(digi);
206 }
207 if (optouttargetvecA) {
208 // Lets do some timesorting
209 if (!fbOutputFullTimeSorting) timesort(&optoutAvec);
210 // Transfer the data from the timeslice vector to the target branch vector
211 for (auto optoutA : optoutAvec)
212 optouttargetvecA->emplace_back(optoutA);
213 }
214 if (optouttargetvecB) {
215 // Second opt output is not time sorted to allow non GetTime data container.
216 // Lets do some timesorting
217 timesort(&optoutAvec);
218 // Transfer the data from the timeslice vector to the target branch vector
219 for (auto optoutB : optoutBvec)
220 optouttargetvecB->emplace_back(optoutB);
221 }
222
223 std::clock_t cpuendtime = std::clock();
224 auto wallendtime = std::chrono::high_resolution_clock::now();
225
226 // Cpu time in [µs]
227 auto cputime = 1e6 * (cpuendtime - cpustarttime) / CLOCKS_PER_SEC;
228 algo->AddCpuTime(cputime);
229 // Real time in [µs]
230 auto walltime = std::chrono::duration<double, std::micro>(wallendtime - wallstarttime).count();
231 algo->AddWallTime(walltime);
232
233
234 // Check some numbers from this timeslice
235 size_t nDigis = digivec.size();
236 LOG(debug) << "Component " << icomp << " connected to config " << config->GetName() << " n-Digis " << nDigis
237 << " processed in walltime(cputime) = " << walltime << "(" << cputime << cputime << ") µs"
238 << "this timeslice.";
239
240 if (fDoPerfProf) {
241 auto timeit = fTimeMap.find(subsysid);
242 timeit->second.first += cputime;
243 timeit->second.second += walltime;
244
245 auto datait = fDataSizeMap.find(subsysid);
246 datait->second.first += ts->size_component(icomp) / 1.0e6;
247 datait->second.second += nDigis * algo->GetOutputObjSize() / 1.0e6;
248
249 fNameMap.find(subsysid)->second.second += nDigis;
250 }
251
252 return nDigis;
253 }
254};
255
256#endif /* CBMDEVICEMCBMUNPACK_H_ */
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.
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< std::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.
static constexpr std::uint16_t fkFlesBmon
Constants.
std::string fsChannelNameDataInput
message queues
std::map< std::uint16_t, std::pair< double, double > > fDataSizeMap
Map to store the in and out data amount, key = fkFlesId.
size_t unpack(const std::uint16_t subsysid, const fles::Timeslice *ts, std::uint16_t icomp, TConfig config, std::vector< TOptOutA > *optouttargetvecA=nullptr, std::vector< TOptOutB > *optouttargetvecB=nullptr)
Template for the unpacking call of a given algorithm.
bool fbConfigSent
Flag indicating whether the histograms and canvases configurations were already published.
TimesliceMetaData * fTsMetaData
Total size of all MS in a TS, [nanoseconds].
std::map< std::uint16_t, std::pair< double, double > > fTimeMap
Map to store the cpu and wall time, key = fkFlesId.
bool fbUnpBmon
---> for selective unpacking
Bool_t fbIgnoreOverlapMs
Control flags.