12#ifndef CBMRECOUNPACK_H
13#define CBMRECOUNPACK_H 1
25#include <MicrosliceDescriptor.hpp>
26#include <Timeslice.hpp>
28#include <FairParAsciiFileIo.h>
29#include <FairRootManager.h>
31#include <RtypesCore.h>
115 std::string sJobId =
"local")
122 if (
"" != sUriMonitor) {
178 void Unpack(std::unique_ptr<fles::Timeslice> ts);
202 std::map<Subsystem, std::pair<std::string, size_t>>
fNameMap = {};
205 std::map<Subsystem, std::pair<double, double>>
fTimeMap = {};
250 template<
class TConfig>
274 config->RegisterOutput(ioman);
282 virtual Bool_t
initParContainers(std::vector<std::pair<std::string, std::shared_ptr<FairParGenericSet>>>* reqparvec)
284 LOG(debug) << GetName() <<
"::Init - initParContainers";
286 LOG(info) << GetName() <<
"::Init - initParContainers - empty requirements vector no parameters initialized.";
291 for (
auto& pair : *reqparvec) {
292 auto filepath = pair.first;
293 auto parset = pair.second;
294 FairParAsciiFileIo asciiInput;
295 if (!filepath.empty()) {
296 if (asciiInput.open(filepath.data())) {
297 parset->init(&asciiInput);
305 template<
typename TVecobj>
306 typename std::enable_if<std::is_same<TVecobj, std::nullptr_t>::value ==
true,
void>::type
309 LOG(debug) <<
"CbmRecoUnpack::timesort() got an object that has no member function GetTime(). Hence, we can and "
310 "will not timesort it!";
313 template<
typename TVecobj>
314 typename std::enable_if<!std::is_member_function_pointer<
decltype(&TVecobj::GetTime)>::value,
void>::type
317 LOG(debug) <<
"CbmRecoUnpack::timesort() " << TVecobj::Class_Name()
318 <<
"is an object that has no member function GetTime(). Hence, we can and "
319 "will not timesort it!";
322 template<
typename TVecobj>
323 typename std::enable_if<std::is_member_function_pointer<
decltype(&TVecobj::GetTime)>::value,
void>::type
326 if (vec ==
nullptr)
return;
327 std::sort(vec->begin(), vec->end(),
328 [](
const TVecobj& a,
const TVecobj& b) ->
bool { return a.GetTime() < b.GetTime(); });
345 template<
class TConfig,
class TOptOutA = std::
nullptr_t,
class TOptOutB = std::
nullptr_t>
346 size_t unpack(
const Subsystem subsystem,
const fles::Timeslice* ts, std::uint16_t icomp, TConfig config,
347 std::vector<TOptOutA>* optouttargetvecA =
nullptr, std::vector<TOptOutB>* optouttargetvecB =
nullptr)
350 auto wallstarttime = std::chrono::high_resolution_clock::now();
351 std::clock_t cpustarttime = std::clock();
353 auto algo = config->GetUnpacker();
354 std::vector<TOptOutA> optoutAvec = {};
355 std::vector<TOptOutB> optoutBvec = {};
356 if (optouttargetvecA) {
357 algo->SetOptOutAVec(&optoutAvec);
359 if (optouttargetvecB) {
360 algo->SetOptOutBVec(&optoutBvec);
364 algo->SetTsStartTime(ts->start_time());
367 auto digivec = algo->Unpack(ts, icomp);
371 if (config->GetOutputVec()) {
377 for (
auto digi : digivec)
378 config->GetOutputVec()->emplace_back(digi);
380 if (optouttargetvecA) {
384 for (
auto optoutA : optoutAvec)
385 optouttargetvecA->emplace_back(optoutA);
387 if (optouttargetvecB) {
392 for (
auto optoutB : optoutBvec)
393 optouttargetvecB->emplace_back(optoutB);
397 std::clock_t cpuendtime = std::clock();
398 auto wallendtime = std::chrono::high_resolution_clock::now();
401 auto cputime = 1e6 * (cpuendtime - cpustarttime) / CLOCKS_PER_SEC;
402 algo->AddCpuTime(cputime);
404 auto walltime = std::chrono::duration<double, std::micro>(wallendtime - wallstarttime).count();
405 algo->AddWallTime(walltime);
409 size_t nDigis = digivec.size();
410 LOG(debug) <<
"Component " << icomp <<
" connected to config " << config->GetName() <<
" n-Digis " << nDigis
411 <<
" processed in walltime(cputime) = " << walltime <<
"(" << cputime << cputime <<
") µs"
412 <<
"this timeslice.";
415 auto timeit =
fTimeMap.find(subsystem);
416 timeit->second.first += cputime;
417 timeit->second.second += walltime;
420 datait->second.first += ts->size_component(icomp) / 1.0e6;
421 datait->second.second += nDigis * algo->GetOutputObjSize() / 1.0e6;
423 fNameMap.find(subsystem)->second.second += nDigis;
428 timeit->second.first += cputime;
429 timeit->second.second += walltime;
432 datait->second.first += ts->size_component(icomp) / 1.0e6;
433 datait->second.second += nDigis * algo->GetOutputObjSize() / 1.0e6;
Configuration class for an unpacker algorithm.
Configuration class for an unpacker algorithm.
Configuration class for an unpacker algorithm.
Configuration class for an unpacker algorithm.
Configuration class for an unpacker algorithm.
Configuration class for an unpacker algorithm.
Configuration class for an unpacker algorithm.
Main steering class for unpacking in cbmroot.
void SetOutputFilename(std::string value)
Set the performance profiling Output Filename.
virtual Bool_t initParContainers(std::vector< std::pair< std::string, std::shared_ptr< FairParGenericSet > > > *reqparvec)
Initialise the parameter containers requested by the algorithm.
void Finish()
Actions at the end of the run.
void SetUnpackConfig(std::shared_ptr< CbmTofUnpackConfig > config)
Set the Tof Unpack Config.
void SetUnpackConfig(std::shared_ptr< CbmPsdUnpackConfig > config)
Set the Psd Unpack Config.
std::unique_ptr< cbm::Monitor > fMonitor
ratio of total unpacked size to input size vs TS in run
CbmTimeSlice * fTimeSlice
CbmTimeslice object, mostly redundant with the TsEventHeader, needed by L1 to switch timeslice mode.
std::string fUriPublishProfMoni
URI (type:hostname:port:db_name) for optional connection to monitoring DB.
CbmRecoUnpack()
Constructor.
std::map< Subsystem, TH1 * > fvhUnpRatioPerTs
ratio of system digi size in total output size vs TS in run
bool fPublishProfMoni
Flag if performance profiling data should be published to monitoring DB.
std::string fMoniCurrrentHostname
The application's monitoring object.
void SetTimeSorting(bool bIn=true)
Enable/disable a full time sorting. If off, time sorting happens per link/FLIM source.
std::map< Subsystem, std::pair< double, double > > fDataSizeMap
Map to store the in and out data amount, key = Subsystem.
TH1 * fhRealTimePerTsHist
Plotting time per TS.
std::enable_if<!std::is_member_function_pointer< decltype(&TVecobj::GetTime)>::value, void >::type timesort(std::vector< TVecobj > *)
void SetMonitoringOnly(bool bIn=true)
Enable/disable the data output. If On, data unpacked and monitored but neither sorted nor written to ...
TH1 * fhCpuTimePerTsHist
Processing time per TS.
std::map< Subsystem, std::pair< double, double > > fDataSizeMapCurrSec
void SetUnpackConfig(std::shared_ptr< CbmTrdUnpackFaspConfig > config)
Set the Trd2D Unpack Config.
void Reset()
Clear the output vectors as preparation of the next timeslice. Called via FairSource::Reset()
std::string fOutfilename
Name of the performance profiling output file.
std::shared_ptr< CbmStsUnpackConfig > fStsConfig
Configuration of the Sts unpacker. Provides the configured algorithm.
bool bOutputFullTimeSorting
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.
std::map< Subsystem, std::pair< std::string, size_t > > fNameMapPerTs
Map to store a name for the unpackers and the processed amount of digis for a single TS,...
std::shared_ptr< CbmBmonUnpackConfig > fBmonConfig
Configuration of the Bmon unpacker. Provides the configured algorithm.
CbmTsEventHeader * fCbmTsEventHeader
Pointer to the Timeslice start time used to write it to the output tree.
std::map< Subsystem, TH1 * > fvhOutRatioPerTs
ratio of system data in total input size vs TS in run
std::shared_ptr< CbmTrdUnpackFaspConfig > fTrd2DConfig
Configuration of the Trd unpacker. Provides the configured algorithm.
bool fPubMoniProcTime
Flag if perf data should be published to moni DB using data time (false) or processing time (true).
std::map< Subsystem, std::pair< double, double > > fTimeMap
Map to store the cpu and wall time, key = Subsystem.
fles::Subsystem Subsystem
bool bMonitoringOnly
Flag to Enable/disable the output completely.
void SetDebugPrintout(bool value=true)
Set the Debug Printout Flag.
ClassDef(CbmRecoUnpack, 3)
std::map< Subsystem, TH1 * > fvhInpRatioPerTs
Plotting time per TS.
void initPerformanceMaps(Subsystem subsystem, std::string name)
Init the performance profiling maps for a given unpacker.
std::shared_ptr< CbmTofUnpackConfig > fTofConfig
Configuration of the Tof unpacker. Provides the configured algorithm.
~CbmRecoUnpack()
Destructor.
std::map< Subsystem, std::pair< double, double > > fDataSizeMapPerTs
Map to store the in and out data amount for a single TS, key = Subsystem.
void performanceProfiling()
Run the performance profiling based on the fTimeMap and fDataSizeMap members.
bool fDoDebugPrints
Flag if extended debug output is to be printed or not.
std::map< Subsystem, std::pair< double, double > > fTimeMapPerTs
Map to store the cpu and wall time for a single TS, key = Subsystem.
void SetUnpackConfig(std::shared_ptr< CbmBmonUnpackConfig > config)
Set the Bmon Unpack Config.
TH1 * fhRealTimePerTs
Processing time per TS.
void Unpack(std::unique_ptr< fles::Timeslice > ts)
Trigger the unpacking procedure.
TH1 * fhUnpackingRatioPerTs
ratio of selected digi vs TS in run
CbmRecoUnpack & operator=(const CbmRecoUnpack &)=delete
Assignment operator - not implemented.
std::shared_ptr< CbmMuchUnpackConfig > fMuchConfig
Current time slice.
void SetUnpackConfig(std::shared_ptr< CbmStsUnpackConfig > config)
Set the Sts Unpack Config.
std::shared_ptr< CbmTrdUnpackConfig > fTrd1DConfig
Configuration of the Trd unpacker. Provides the configured algorithm.
CbmRecoUnpack(const CbmRecoUnpack &)=delete
Copy constructor - not implemented.
bool fDoPerfProfPerTs
Flag if performance profiling per TS should be activated or not.
void SetDoPerfProfiling(bool value=true)
(De)Activate the performance profiling based on histograms
void SetUnpackConfig(std::shared_ptr< CbmMuchUnpackConfig > config)
Set the Much Unpack Config.
void performanceProfilingPerTs()
Run the performance profiling for a single TS based on the fTimeMapPerTs and fDataSizeMapPerTs member...
std::enable_if< std::is_member_function_pointer< decltype(&TVecobj::GetTime)>::value, void >::type timesort(std::vector< TVecobj > *vec=nullptr)
std::chrono::system_clock::time_point fMonitorSecCurrentTs
std::shared_ptr< CbmRichUnpackConfig > fRichConfig
Configuration of the Rich unpacker. Provides the configured algorithm.
void SetDoPerfProfilingPerTs(bool value=true)
(De)Activate the performance profiling based on histograms for each TS
void SetPublishProfMoni(bool value=true, std::string sUriMonitor="", bool useProcTime=false, std::string sJobId="local")
(De)Activate the publication of performance profiling data to monitoring DB
void RegisterOutputs(FairRootManager *ioman, std::shared_ptr< TConfig > config)
Bool_t Init()
Initialisation.
std::map< Subsystem, std::pair< std::string, size_t > > fNameMap
Map to store a name for the unpackers and the processed amount of digis, key = Subsystem.
std::shared_ptr< CbmPsdUnpackConfig > fPsdConfig
Configuration of the Psd unpacker. Provides the configured algorithm.
size_t unpack(const Subsystem subsystem, 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::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< CbmTrdUnpackConfig > config)
Set the Trd Unpack Config.
bool fDoPerfProf
Flag if performance profiling should be activated or not.
Bookkeeping of time-slice content.