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<uint16_t, std::pair<std::string, size_t>>
fNameMap = {};
135 std::map<uint16_t, std::pair<double, double>>
fTimeMap = {};
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!";
193 template<
typename TVecobj>
194 typename std::enable_if<!std::is_member_function_pointer<
decltype(&TVecobj::GetTime)>::value,
void>::type
197 LOG(debug) <<
"CbmDeviceUnpack::timesort() " << TVecobj::Class_Name()
198 <<
"is an object that has no member function GetTime(). Hence, we can and "
199 "will not timesort it!";
202 template<
typename TVecobj>
203 typename std::enable_if<std::is_member_function_pointer<
decltype(&TVecobj::GetTime)>::value,
void>::type
206 if (vec ==
nullptr)
return;
207 std::sort(vec->begin(), vec->end(),
208 [](
const TVecobj& a,
const TVecobj& b) ->
bool { return a.GetTime() < b.GetTime(); });
224 template<
class TConfig,
class TOptOutA = std::
nullptr_t,
class TOptOutB = std::
nullptr_t>
225 size_t unpack(
const uint16_t subsysid,
const fles::Timeslice* ts, uint16_t icomp, TConfig config,
226 std::vector<TOptOutA>* optouttargetvecA =
nullptr, std::vector<TOptOutB>* optouttargetvecB =
nullptr)
229 auto wallstarttime = std::chrono::high_resolution_clock::now();
230 std::clock_t cpustarttime = std::clock();
232 auto algo = config->GetUnpacker();
233 std::vector<TOptOutA> optoutAvec = {};
234 std::vector<TOptOutB> optoutBvec = {};
235 if (optouttargetvecA) { algo->SetOptOutAVec(&optoutAvec); }
236 if (optouttargetvecB) { algo->SetOptOutBVec(&optoutBvec); }
239 algo->SetTsStartTime(ts->start_time());
242 auto digivec = algo->Unpack(ts, icomp);
245 if (config->GetOutputVec()) {
251 for (
auto digi : digivec)
252 config->GetOutputVec()->emplace_back(digi);
254 if (optouttargetvecA) {
258 for (
auto optoutA : optoutAvec)
259 optouttargetvecA->emplace_back(optoutA);
261 if (optouttargetvecB) {
266 for (
auto optoutB : optoutBvec)
267 optouttargetvecB->emplace_back(optoutB);
270 std::clock_t cpuendtime = std::clock();
271 auto wallendtime = std::chrono::high_resolution_clock::now();
274 auto cputime = 1e6 * (cpuendtime - cpustarttime) / CLOCKS_PER_SEC;
275 algo->AddCpuTime(cputime);
277 auto walltime = std::chrono::duration<double, std::micro>(wallendtime - wallstarttime).count();
278 algo->AddWallTime(walltime);
282 size_t nDigis = digivec.size();
283 LOG(debug) <<
"Component " << icomp <<
" connected to config " << config->GetName() <<
" n-Digis " << nDigis
284 <<
" processed in walltime(cputime) = " << walltime <<
"(" << cputime << cputime <<
") micro s"
285 <<
"this timeslice.";
288 auto timeit =
fTimeMap.find(subsysid);
289 timeit->second.first += cputime;
290 timeit->second.second += walltime;
293 datait->second.first += ts->size_component(icomp) / 1.0e6;
294 datait->second.second += nDigis * algo->GetOutputObjSize() / 1.0e6;
296 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::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
std::map< uint16_t, std::pair< double, double > > fDataSizeMap
Map to store the in and out data amount, key = fkFlesId.
void SetUnpackConfig(std::shared_ptr< CbmPsdUnpackConfig > config)
Set the Psd Unpack Config.
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::map< uint16_t, std::pair< double, double > > fTimeMap
Map to store the cpu and wall time, key = fkFlesId.
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.
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.
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< 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::shared_ptr< CbmTrdUnpackFaspConfig > fTrd2DConfig
std::string fsSetupName
User settings parameters.
Double_t fdTsFullSizeInNs
Total size of the overlap MS in a TS, [nanoseconds].