12#ifndef CBMDEVICEUNPACK_H_
13#define CBMDEVICEUNPACK_H_
18#include "Timeslice.hpp"
20#include "FairMQDevice.h"
21#include "FairParGenericSet.h"
80 static constexpr std::uint16_t
fkFlesBmon =
static_cast<std::uint16_t
>(fles::Subsystem::BMON);
81 static constexpr std::uint16_t
fkFlesMvd =
static_cast<std::uint16_t
>(fles::Subsystem::MVD);
82 static constexpr std::uint16_t
fkFlesSts =
static_cast<std::uint16_t
>(fles::Subsystem::STS);
83 static constexpr std::uint16_t
fkFlesMuch =
static_cast<std::uint16_t
>(fles::Subsystem::MUCH);
84 static constexpr std::uint16_t
fkFlesTrd =
static_cast<std::uint16_t
>(fles::Subsystem::TRD);
85 static constexpr std::uint16_t
fkFlesTrd2D =
static_cast<std::uint16_t
>(fles::Subsystem::TRD2D);
86 static constexpr std::uint16_t
fkFlesTof =
static_cast<std::uint16_t
>(fles::Subsystem::TOF);
87 static constexpr std::uint16_t
fkFlesRich =
static_cast<std::uint16_t
>(fles::Subsystem::RICH);
88 static constexpr std::uint16_t
fkFlesPsd =
static_cast<std::uint16_t
>(fles::Subsystem::PSD);
126 Bool_t
InitParameters(std::vector<std::pair<std::string, std::shared_ptr<FairParGenericSet>>>* reqparvec);
133 std::map<std::uint16_t, std::pair<std::string, size_t>>
fNameMap = {};
135 std::map<std::uint16_t, std::pair<double, double>>
fTimeMap = {};
177 Bool_t
DoUnpack(
const fles::Timeslice& ts,
size_t component);
183 std::shared_ptr<CbmTrdSpadic>
GetTrdSpadic(
bool useAvgBaseline);
186 template<
typename TVecobj>
187 typename std::enable_if<std::is_same<TVecobj, std::nullptr_t>::value ==
true,
void>::type
190 LOG(debug) <<
"CbmDeviceUnpack::timesort() got an object that has no member function GetTime(). Hence, we can and "
191 "will not timesort it!";
194 template<
typename TVecobj>
195 typename std::enable_if<!std::is_member_function_pointer<
decltype(&TVecobj::GetTime)>::value,
void>::type
198 LOG(debug) <<
"CbmDeviceUnpack::timesort() " << TVecobj::Class_Name()
199 <<
"is an object that has no member function GetTime(). Hence, we can and "
200 "will not timesort it!";
203 template<
typename TVecobj>
204 typename std::enable_if<std::is_member_function_pointer<
decltype(&TVecobj::GetTime)>::value,
void>::type
207 if (vec ==
nullptr)
return;
208 std::sort(vec->begin(), vec->end(),
209 [](
const TVecobj& a,
const TVecobj& b) ->
bool { return a.GetTime() < b.GetTime(); });
225 template<
class TConfig,
class TOptOutA = std::
nullptr_t,
class TOptOutB = std::
nullptr_t>
226 size_t unpack(
const std::uint16_t subsysid,
const fles::Timeslice* ts, std::uint16_t icomp, TConfig config,
227 std::vector<TOptOutA>* optouttargetvecA =
nullptr, std::vector<TOptOutB>* optouttargetvecB =
nullptr)
230 auto wallstarttime = std::chrono::high_resolution_clock::now();
231 std::clock_t cpustarttime = std::clock();
233 auto algo = config->GetUnpacker();
234 std::vector<TOptOutA> optoutAvec = {};
235 std::vector<TOptOutB> optoutBvec = {};
236 if (optouttargetvecA) { algo->SetOptOutAVec(&optoutAvec); }
237 if (optouttargetvecB) { algo->SetOptOutBVec(&optoutBvec); }
240 algo->SetTsStartTime(ts->start_time());
243 auto digivec = algo->Unpack(ts, icomp);
246 if (config->GetOutputVec()) {
252 for (
auto digi : digivec)
253 config->GetOutputVec()->emplace_back(digi);
255 if (optouttargetvecA) {
259 for (
auto optoutA : optoutAvec)
260 optouttargetvecA->emplace_back(optoutA);
262 if (optouttargetvecB) {
267 for (
auto optoutB : optoutBvec)
268 optouttargetvecB->emplace_back(optoutB);
271 std::clock_t cpuendtime = std::clock();
272 auto wallendtime = std::chrono::high_resolution_clock::now();
275 auto cputime = 1e6 * (cpuendtime - cpustarttime) / CLOCKS_PER_SEC;
276 algo->AddCpuTime(cputime);
278 auto walltime = std::chrono::duration<double, std::micro>(wallendtime - wallstarttime).count();
279 algo->AddWallTime(walltime);
283 size_t nDigis = digivec.size();
284 LOG(debug) <<
"Component " << icomp <<
" connected to config " << config->GetName() <<
" n-Digis " << nDigis
285 <<
" processed in walltime(cputime) = " << walltime <<
"(" << cputime << cputime <<
") µs"
286 <<
"this timeslice.";
289 auto timeit =
fTimeMap.find(subsysid);
290 timeit->second.first += cputime;
291 timeit->second.second += walltime;
294 datait->second.first += ts->size_component(icomp) / 1.0e6;
295 datait->second.second += nDigis * algo->GetOutputObjSize() / 1.0e6;
297 fNameMap.find(subsysid)->second.second += nDigis;
bool fDoDebugPrints
Flag if extended debug output is to be printed or not.
std::string fsChannelNameDataInput
message queues
std::enable_if<!std::is_member_function_pointer< decltype(&TVecobj::GetTime)>::value, void >::type timesort(std::vector< TVecobj > *)
bool HandleCommand(FairMQMessagePtr &, int)
static constexpr std::uint16_t fkFlesMuch
static constexpr std::uint16_t fkFlesTrd
std::string fsChannelNameCommands
CbmTsEventHeader * fCbmTsEventHeader
Pointer to the Timeslice header conatining start time and index.
std::shared_ptr< CbmTofUnpackConfig > fTofConfig
std::shared_ptr< CbmBmonUnpackConfig > fBmonConfig
Configuration of the unpackers. Provides the configured algorithm.
std::enable_if< std::is_member_function_pointer< decltype(&TVecobj::GetTime)>::value, void >::type timesort(std::vector< TVecobj > *vec=nullptr)
static constexpr std::uint16_t fkFlesMvd
uint32_t fuPublishFreqTs
Histograms management.
static constexpr std::uint16_t fkFlesBmon
Constants.
std::chrono::system_clock::time_point fLastPublishTime
static constexpr std::uint16_t fkFlesTrd2D
void SetUnpackConfig(std::shared_ptr< CbmMuchUnpackConfig > config)
Set the Much Unpack Config.
std::vector< std::pair< std::string, std::string > > fvpsCanvasConfig
bool SendHistoConfAndData()
uint64_t fulNumMessages
Statistics & first TS rejection.
TObjArray fArrayHisto
Array of histograms to send to the histogram server.
void SetUnpackConfig(std::shared_ptr< CbmTofUnpackConfig > config)
Set the Tof Unpack Config.
std::shared_ptr< CbmPsdUnpackConfig > fPsdConfig
Bool_t fbIgnoreOverlapMs
Control flags.
Bool_t fbComponentsAddedToList
Ignore Overlap Ms: all fuOverlapMsNb MS at the end of timeslice.
void SetUnpackConfig(std::shared_ptr< CbmTrdUnpackConfig > config)
Set the Trd Unpack Config.
void SetUnpackConfig(std::shared_ptr< CbmBmonUnpackConfig > config)
Set the Bmon Unpack Config.
std::vector< std::pair< std::string, std::string > > fvpsHistosFolder
Vector of string pairs with ( HistoName, FolderPath ) to send to the histogram server.
size_t fuNbCoreMsPerTs
TS MetaData storage: stable so should be moved somehow to parameters handling (not transmitted with e...
static constexpr std::uint16_t fkFlesSts
bool fDoPerfProf
Flag if performance profiling should be activated or not.
std::map< std::uint16_t, std::pair< double, double > > fDataSizeMap
Map to store the in and out data amount, key = fkFlesId.
std::shared_ptr< CbmMuchUnpackConfig > fMuchConfig
static constexpr std::uint16_t fkFlesPsd
TimesliceMetaData * fTsMetaData
Total size of all MS in a TS, [nanoseconds].
Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
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()
void SetUnpackConfig(std::shared_ptr< CbmStsUnpackConfig > config)
Set the Sts Unpack Config.
std::shared_ptr< CbmTrdSpadic > GetTrdSpadic(bool useAvgBaseline)
Get the Trd Spadic.
std::vector< std::string > fvsSetTimeOffs
Time offsets.
std::shared_ptr< CbmTrdUnpackConfig > fTrd1DConfig
void SetUnpackConfig(std::shared_ptr< CbmPsdUnpackConfig > config)
Set the Psd Unpack Config.
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.
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.
static constexpr std::uint16_t fkFlesTof
bool fbConfigSent
Flag indicating whether the histograms and canvases configurations were already published.
Double_t fdTsOverSizeInNs
Total size of the core MS in a TS, [nanoseconds].
virtual ~CbmDeviceUnpack()
double_t fdMinPublishTime
std::shared_ptr< CbmStsUnpackConfig > fStsConfig
double_t fdMaxPublishTime
static constexpr std::uint16_t fkFlesRich
std::shared_ptr< CbmRichUnpackConfig > fRichConfig
std::string fsChannelNameDataOutput
std::string fsChannelNameHistosInput
Double_t fdTsCoreSizeInNs
Size of a single MS, [nanoseconds].
void SetUnpackConfig(std::shared_ptr< CbmTrdUnpackFaspConfig > config)
Set the Trd2D Unpack Config.
Bool_t InitParameters(std::vector< std::pair< std::string, std::shared_ptr< FairParGenericSet > > > *reqparvec)
Parameters management.
bool fbOutputFullTimeSorting
Flag to Enable/disable a full time sorting. If off, time sorting happens per link/FLIM source.
void SetUnpackConfig(std::shared_ptr< CbmRichUnpackConfig > config)
Set the Rich Unpack Config.
bool fbUnpBmon
---> for selective unpacking
std::map< std::uint16_t, std::pair< double, double > > fTimeMap
Map to store the cpu and wall time, key = fkFlesId.
std::shared_ptr< CbmTrdUnpackFaspConfig > fTrd2DConfig
std::string fsSetupName
User settings parameters.
Double_t fdTsFullSizeInNs
Total size of the overlap MS in a TS, [nanoseconds].