12#ifndef CBMRECOUNPACK_H
13#define CBMRECOUNPACK_H 1
26#include <MicrosliceDescriptor.hpp>
27#include <Timeslice.hpp>
29#include <FairParAsciiFileIo.h>
30#include <FairRootManager.h>
32#include <RtypesCore.h>
116 std::string sJobId =
"local")
123 if (
"" != sUriMonitor) {
158 void AddSpillFilter(std::string sAccEvtTimingFileIn, double_t dWinStart = -1000.0, double_t dWinStop = 4500.0,
159 int32_t iSpillStartDelay = 28400, uint64_t ulTsDurationNs = 128000000,
bool bMoniFindPeak =
false)
203 void Unpack(std::unique_ptr<fles::Timeslice> ts);
227 std::map<Subsystem, std::pair<std::string, size_t>>
fNameMap = {};
230 std::map<Subsystem, std::pair<double, double>>
fTimeMap = {};
281 template<
class TConfig>
305 config->RegisterOutput(ioman);
315 LOG(debug) << GetName() <<
"::Init - initParContainers";
317 LOG(info) << GetName() <<
"::Init - initParContainers - empty requirements vector no parameters initialized.";
322 for (
auto& pair : *reqparvec) {
323 auto filepath = pair.first;
324 auto parset = pair.second;
325 FairParAsciiFileIo asciiInput;
326 if (!filepath.empty()) {
327 if (asciiInput.open(filepath.data())) {
328 parset->init(&asciiInput);
336 template<
typename TVecobj>
337 typename std::enable_if<std::is_same<TVecobj, std::nullptr_t>::value ==
true,
void>::type
340 LOG(debug) <<
"CbmRecoUnpack::timesort() got an object that has no member function GetTime(). Hence, we can and "
341 "will not timesort it!";
344 template<
typename TVecobj>
345 typename std::enable_if<!std::is_member_function_pointer<
decltype(&TVecobj::GetTime)>::value,
void>::type
348 LOG(debug) <<
"CbmRecoUnpack::timesort() " << TVecobj::Class_Name()
349 <<
"is an object that has no member function GetTime(). Hence, we can and "
350 "will not timesort it!";
353 template<
typename TVecobj>
354 typename std::enable_if<std::is_member_function_pointer<
decltype(&TVecobj::GetTime)>::value,
void>::type
357 if (vec ==
nullptr)
return;
358 std::sort(vec->begin(), vec->end(),
359 [](
const TVecobj& a,
const TVecobj& b) ->
bool { return a.GetTime() < b.GetTime(); });
376 template<
class TConfig,
class TOptOutA = std::
nullptr_t,
class TOptOutB = std::
nullptr_t>
377 size_t unpack(
const Subsystem subsystem,
const fles::Timeslice* ts, uint16_t icomp, TConfig config,
378 std::vector<TOptOutA>* optouttargetvecA =
nullptr, std::vector<TOptOutB>* optouttargetvecB =
nullptr)
381 auto wallstarttime = std::chrono::high_resolution_clock::now();
382 std::clock_t cpustarttime = std::clock();
384 auto algo = config->GetUnpacker();
385 std::vector<TOptOutA> optoutAvec = {};
386 std::vector<TOptOutB> optoutBvec = {};
387 if (optouttargetvecA) {
388 algo->SetOptOutAVec(&optoutAvec);
390 if (optouttargetvecB) {
391 algo->SetOptOutBVec(&optoutBvec);
395 algo->SetTsStartTime(ts->start_time());
398 auto digivec = algo->Unpack(ts, icomp);
402 if (config->GetOutputVec()) {
408 for (
auto digi : digivec)
409 config->GetOutputVec()->emplace_back(digi);
411 if (optouttargetvecA) {
415 for (
auto optoutA : optoutAvec)
416 optouttargetvecA->emplace_back(optoutA);
418 if (optouttargetvecB) {
423 for (
auto optoutB : optoutBvec)
424 optouttargetvecB->emplace_back(optoutB);
428 std::clock_t cpuendtime = std::clock();
429 auto wallendtime = std::chrono::high_resolution_clock::now();
432 auto cputime = 1e6 * (cpuendtime - cpustarttime) / CLOCKS_PER_SEC;
433 algo->AddCpuTime(cputime);
435 auto walltime = std::chrono::duration<double, std::micro>(wallendtime - wallstarttime).count();
436 algo->AddWallTime(walltime);
440 size_t nDigis = digivec.size();
441 LOG(debug) <<
"Component " << icomp <<
" connected to config " << config->GetName() <<
" n-Digis " << nDigis
442 <<
" processed in walltime(cputime) = " << walltime <<
"(" << cputime << cputime <<
") micro s"
443 <<
"this timeslice.";
446 auto timeit =
fTimeMap.find(subsystem);
447 timeit->second.first += cputime;
448 timeit->second.second += walltime;
451 datait->second.first += ts->size_component(icomp) / 1.0e6;
452 datait->second.second += nDigis * algo->GetOutputObjSize() / 1.0e6;
454 fNameMap.find(subsystem)->second.second += nDigis;
459 timeit->second.first += cputime;
460 timeit->second.second += walltime;
463 datait->second.first += ts->size_component(icomp) / 1.0e6;
464 datait->second.second += nDigis * algo->GetOutputObjSize() / 1.0e6;
578 template<
typename TVecobj>
579 typename std::enable_if<std::is_same<TVecobj, std::nullptr_t>::value ==
true,
void>::type
582 LOG(debug) <<
"CbmRecoUnpack::SpillFilter() got an object that has no member function GetTime(). Hence, we can and "
583 "will not filter it!";
586 template<
typename TVecobj>
587 typename std::enable_if<!std::is_member_function_pointer<
decltype(&TVecobj::GetTime)>::value,
void>::type
590 LOG(debug) <<
"CbmRecoUnpack::SpillFilter() " << TVecobj::Class_Name()
591 <<
"is an object that has no member function GetTime(). Hence, we can and "
592 "will not filter it!";
595 template<
typename TVecobj>
596 typename std::enable_if<std::is_member_function_pointer<
decltype(&TVecobj::GetTime)>::value,
void>::type
599 size_t originalSize = vec->size();
603 bool bStartInTs =
false;
604 double_t dStartTimeInTs = 0.0;
605 if (ulTsStartNs <= itSpillStart->GetTime() &&
itSpillStart->GetTime() <= ulTsStopNs) {
609 bool bStopInTs =
false;
610 double_t dStopTimeInTs = 0.0;
611 if (ulTsStartNs <= itSpillStop->GetTime() &&
itSpillStop->GetTime() <= ulTsStopNs) {
613 dStopTimeInTs =
itSpillStop->GetTime() - ulTsStartNs;
615 if (bStartInTs || bStopInTs) {
616 auto itWinStart = vec->begin();
617 auto itWinStop = vec->end();
618 bool bFoundStart =
false;
619 bool bFoundStop =
false;
620 for (
auto itDigi = vec->begin(); itDigi != vec->end(); ++itDigi) {
621 double_t dTimeToStart = itDigi->GetTime() - dStartTimeInTs;
622 double_t dTimeToStop = itDigi->GetTime() - dStopTimeInTs;
654 vec->erase(itWinStop, vec->end());
660 vec->erase(vec->begin(), itWinStart);
667 LOG(debug2) <<
"Filtered " << fles::to_string(subsystem) <<
" digi vector from " << originalSize <<
" to "
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.
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.
double_t dSpillFilterWinStart
Start of time window for digi filtering relative to spill start event.
TH1 * fhDigiSpillStartDist
Monitoring histograms for the spill digi filter.
std::string fUriPublishProfMoni
URI (type:hostname:port:db_name) for optional connection to monitoring DB.
TH2 * fhDigiSpillFilterStop
Digi time relative to spill start.
std::map< Subsystem, TH2 * > fhDigiSpillFilterStartPerDet
Digi time relative to spill stop, per detector.
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.
size_t unpack(const Subsystem subsystem, 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.
double_t dSpillFilterWinStop
End of time window for digi filtering relative to spill start event.
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.
void WriteHistograms()
Open special output file and save eventual performance monitoring histograms into it.
std::enable_if<!std::is_member_function_pointer< decltype(&TVecobj::GetTime)>::value, void >::type SpillFilter(uint64_t ulTsStartNs, const Subsystem subsystem, std::vector< TVecobj > *)
std::map< Subsystem, std::pair< double, double > > fDataSizeMap
Map to store the in and out data amount, key = Subsystem.
std::string sAccEvtTimingFile
Full path to a text file containing the raw Accelerator Event timings.
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::map< Subsystem, TH2 * > fhDigiSpillFilterStopPerDet
Digi time relative to spill start, per detector.
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::vector< AccTimingEvent >::iterator itSpillStart
Current spill start Event.
std::map< Subsystem, TH1 * > fvhOutRatioPerTs
ratio of system data in total input size vs TS in run
void initSpillFilterMonitoring(Subsystem subsystem, std::string name)
Init the Spill filter monitoring histograms for a given system.
void InitSpillFilter()
Digi time relative to spill stop, per detector.
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).
TH1 * fhDigiSpillStopDist
Digi time relative to spill start.
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, 4)
std::map< Subsystem, TH1 * > fhDigiSpillStartDistPerDet
Digi time relative to spill stop.
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.
uint32_t uSpillIndex
Index of the current spill in current run.
std::enable_if< std::is_member_function_pointer< decltype(&TVecobj::GetTime)>::value, void >::type SpillFilter(uint64_t ulTsStartNs, const Subsystem subsystem, std::vector< TVecobj > *vec=nullptr)
bool fDoDebugPrints
Flag if extended debug output is to be printed or not.
std::vector< AccTimingEvent > vAccEvtsSpillStart
Storage of spill start accelerator events (Either KickerStart or ExtractionStartSlow)
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.
bool bSpillFilterMoniFindPeak
Flag to Enable/disable monitoring histos with long range for digi filtering relative to spill start e...
TH2 * fhDigiSpillFilterStart
Digi time relative to spill stop.
int32_t iSpillFilterStartDelay
Delay of the real start of the spill relative to Spill Start Event (negative if Event is late one)
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.
std::map< Subsystem, TH1 * > fhDigiSpillStopDistPerDet
Digi time relative to spill start, per detector.
void performanceProfilingPerTs()
Run the performance profiling for a single TS based on the fTimeMapPerTs and fDataSizeMapPerTs member...
bool bSpillFilter
Flag to Enable/disable digi filtering relative to spill start event.
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
uint64_t ulSpillFilterTsDurationNs
Duration of TS in nanoseconds (mCBM default = 128 ms = 128 000 000 ns)
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::vector< AccTimingEvent >::iterator itSpillStop
Current spill stop Event.
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.
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 AddSpillFilter(std::string sAccEvtTimingFileIn, double_t dWinStart=-1000.0, double_t dWinStop=4500.0, int32_t iSpillStartDelay=28400, uint64_t ulTsDurationNs=128000000, bool bMoniFindPeak=false)
Enable filtering of the digis using a user define window around the spill start. Requires a full time...
void SetUnpackConfig(std::shared_ptr< CbmTrdUnpackConfig > config)
Set the Trd Unpack Config.
std::enable_if< std::is_same< TVecobj, std::nullptr_t >::value==true, void >::type SpillFilter(uint64_t ulTsStartNs, const Subsystem subsystem, std::vector< TVecobj > *)
Filter a vector timewise relative to spill start. Vector type has to provide GetTime()
bool fDoPerfProf
Flag if performance profiling should be activated or not.
std::vector< AccTimingEvent > vAccEvtsSpillEnd
Storage of spill end accelerator events (ExtractionEnd or ExtractionSlowStop)
Bookkeeping of time-slice content.