12#ifndef CBMDEVICEBMONMONI_H_
13#define CBMDEVICEBMONMONI_H_
18#include "Timeslice.hpp"
20#include "FairMQDevice.h"
21#include "FairParGenericSet.h"
52 static constexpr std::uint16_t
fkFlesBmon =
static_cast<std::uint16_t
>(fles::Subsystem::BMON);
84 Bool_t
InitParameters(std::vector<std::pair<std::string, std::shared_ptr<FairParGenericSet>>>* reqparvec);
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 = {};
128 Bool_t
DoUnpack(
const fles::Timeslice& ts,
size_t component);
134 std::shared_ptr<CbmTrdSpadic>
GetTrdSpadic(
bool useAvgBaseline);
137 template<
typename TVecobj>
138 typename std::enable_if<std::is_same<TVecobj, std::nullptr_t>::value ==
true,
void>::type
142 <<
"CbmDeviceBmonMonitor::timesort() got an object that has no member function GetTime(). Hence, we can and "
143 "will not timesort it!";
146 template<
typename TVecobj>
147 typename std::enable_if<!std::is_member_function_pointer<
decltype(&TVecobj::GetTime)>::value,
void>::type
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!";
155 template<
typename TVecobj>
156 typename std::enable_if<std::is_member_function_pointer<
decltype(&TVecobj::GetTime)>::value,
void>::type
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(); });
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)
182 auto wallstarttime = std::chrono::high_resolution_clock::now();
183 std::clock_t cpustarttime = std::clock();
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); }
192 algo->SetTsStartTime(ts->start_time());
195 auto digivec = algo->Unpack(ts, icomp);
198 if (config->GetOutputVec()) {
204 for (
auto digi : digivec)
205 config->GetOutputVec()->emplace_back(digi);
207 if (optouttargetvecA) {
211 for (
auto optoutA : optoutAvec)
212 optouttargetvecA->emplace_back(optoutA);
214 if (optouttargetvecB) {
219 for (
auto optoutB : optoutBvec)
220 optouttargetvecB->emplace_back(optoutB);
223 std::clock_t cpuendtime = std::clock();
224 auto wallendtime = std::chrono::high_resolution_clock::now();
227 auto cputime = 1e6 * (cpuendtime - cpustarttime) / CLOCKS_PER_SEC;
228 algo->AddCpuTime(cputime);
230 auto walltime = std::chrono::duration<double, std::micro>(wallendtime - wallstarttime).count();
231 algo->AddWallTime(walltime);
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.";
241 auto timeit =
fTimeMap.find(subsysid);
242 timeit->second.first += cputime;
243 timeit->second.second += walltime;
246 datait->second.first += ts->size_component(icomp) / 1.0e6;
247 datait->second.second += nDigis * algo->GetOutputObjSize() / 1.0e6;
249 fNameMap.find(subsysid)->second.second += nDigis;
std::chrono::system_clock::time_point fLastPublishTime
bool fDoDebugPrints
Flag if extended debug output is to be printed or not.
virtual ~CbmDeviceBmonMonitor()
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.
double_t fdMinPublishTime
std::string fsChannelNameHistosInput
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 SendHistoConfAndData()
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 fsChannelNameDataOutput
double_t fdMaxPublishTime
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.
std::string fsChannelNameCommands
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.