13#include "CbmRecoUnpackConfig.tmpl"
21#include <FairRootManager.h>
24#include <RtypesCore.h>
26#include <TStopwatch.h>
48 LOG(debug) <<
"CbmRecoUnpack::~CbmRecoUnpack!";
56 LOG(info) <<
"CbmRecoUnpack::Finish() I do let the unpackers talk first :\n";
70 double dTotalDataSizeIn = 0.0;
71 double dTotalDataSizeOut = 0.0;
73 dTotalDataSizeIn += datait.second.first;
74 dTotalDataSizeOut += datait.second.second;
77 double dUnpRatio = 0 < datait.second.first ? datait.second.second / datait.second.first : 0.0;
78 double dShareIn = 0 < dTotalDataSizeIn ? datait.second.first / dTotalDataSizeIn : 0.0;
79 double dShareOut = 0 < dTotalDataSizeOut ? datait.second.second / dTotalDataSizeOut : 0.0;
83 {{
"dataIn", datait.second.first},
84 {
"dataOut", datait.second.second},
85 {
"unpRatio", dUnpRatio},
86 {
"shareIn", dShareIn},
87 {
"shareOut", dShareOut}},
99 FairRootManager* ioman = FairRootManager::Instance();
102 auto eh = FairRun::Instance()->GetEventHeader();
103 if (eh->IsA() == CbmTsEventHeader::Class())
107 <<
"CbmRecoUnpack::Init() no CbmTsEventHeader was added to the run. Without it, we can not store the UTC of the "
108 "Timeslices correctly. Hence, this causes a fatal. Please add it in the steering macro to the Run.";
111 ioman->Register(
"TimeSlice.",
"DAQ",
fTimeSlice, kTRUE);
175 LOG(info) <<
fTrd2DConfig->GetName() <<
"::Init() ---------------------------------";
208 fhCpuTimePerTs =
new TH1D(
"hCpuTimePerTs",
"CPU Processing time of TS vs TS; Ts; CPU time [ms]", 6000, 0, 6000);
209 fhRealTimePerTs =
new TH1D(
"hRealTimePerTs",
"Real Processing time of TS vs TS; Ts; Real time [ms]", 6000, 0, 6000);
212 new TH1D(
"hCpuTimePerTsHist",
"CPU Histo filling time of TS vs TS; Ts; CPU time [ms]", 6000, 0, 6000);
214 new TH1D(
"hRealTimePerTsHist",
"Real Histo filling time of TS vs TS; Ts; Real time [ms]", 6000, 0, 6000);
217 new TH1D(
"hUnpackingRatioPerTs",
"ratio of tot. unp. digi size to tot. input raw size vs TS; TS; Size Ratio []",
224 LOG(info) <<
"Unpack: Publishing monitoring metrics to time-series DB at " <<
fUriPublishProfMoni <<
" as "
237 fNameMap.emplace(std::make_pair(subsystem, std::make_pair(name, 0)));
238 fTimeMap.emplace(std::make_pair(subsystem, std::make_pair(0, 0)));
239 fDataSizeMap.emplace(std::make_pair(subsystem, std::make_pair(0, 0)));
242 fNameMapPerTs.emplace(std::make_pair(subsystem, std::make_pair(name, 0)));
243 fTimeMapPerTs.emplace(std::make_pair(subsystem, std::make_pair(0, 0)));
251 new TH1D(Form(
"hInpRatioPerTs%s", name.c_str()),
252 Form(
"ratio of input data size in total input data size vs TS for %s; TS; Size Ratio []", name.c_str()),
256 new TH1D(Form(
"hOutRatioPerTs%s", name.c_str()),
257 Form(
"ratio of unpacked digi size in total output size vs TS for %s; TS; Size Ratio []", name.c_str()),
261 new TH1D(Form(
"hUnpRatioPerTs%s", name.c_str()),
262 Form(
"ratio of unpacked digi size to raw data size vs TS for %s; TS; O/I Size Ratio []", name.c_str()),
272 std::unique_ptr<TH1D> hProducedDigis =
273 std::unique_ptr<TH1D>(
new TH1D(
"ProducedDigis",
"ProducedDigis",
fNameMap.size(), -0.5,
fNameMap.size() - 0.5));
274 hProducedDigis->SetXTitle(
"Subsystem");
275 hProducedDigis->SetYTitle(
"N-Digis");
276 std::unique_ptr<TH1D> hSpeedPerf = std::unique_ptr<TH1D>(
277 new TH1D(
"SpeedPerformance",
"SpeedPerformance",
fNameMap.size() * 2, -0.5,
fNameMap.size() * 2 - 0.5));
278 hSpeedPerf->SetXTitle(
"Subsystem");
279 hSpeedPerf->SetYTitle(
"Unpacking performance [#mus/Digi]");
280 std::unique_ptr<TH1D> hDataPerf = std::unique_ptr<TH1D>(
281 new TH1D(
"DataPerformance",
"DataPerformance",
fNameMap.size() * 2, -0.5,
fNameMap.size() * 2 - 0.5));
282 hDataPerf->SetXTitle(
"Subsystem");
283 hDataPerf->SetYTitle(
"Data [MB]");
284 size_t iunpackerbin = 1;
288 auto timeit =
fTimeMap.find(namepair.first);
289 double cpu = 0 < namepair.second.second ? timeit->second.first / namepair.second.second : 0.0;
290 double wall = 0 < namepair.second.second ? timeit->second.second / namepair.second.second : 0.0;
294 double indata = datait->second.first;
295 double outdata = datait->second.second;
299 std::string label = namepair.second.first;
300 hProducedDigis->GetXaxis()->SetBinLabel(iunpackerbin, label.data());
301 hProducedDigis->SetBinContent(iunpackerbin, namepair.second.second);
304 label = namepair.second.first;
306 hSpeedPerf->GetXaxis()->SetBinLabel(iunpackerbin * 2 - 1, label.data());
307 hSpeedPerf->SetBinContent(iunpackerbin * 2 - 1, cpu);
309 label = namepair.second.first;
311 hSpeedPerf->GetXaxis()->SetBinLabel(iunpackerbin * 2, label.data());
312 hSpeedPerf->SetBinContent(iunpackerbin * 2, wall);
315 label = namepair.second.first;
317 hDataPerf->GetXaxis()->SetBinLabel(iunpackerbin * 2 - 1, label.data());
318 hDataPerf->SetBinContent(iunpackerbin * 2 - 1, indata);
321 label = namepair.second.first;
323 hDataPerf->GetXaxis()->SetBinLabel(iunpackerbin * 2, label.data());
324 hDataPerf->SetBinContent(iunpackerbin * 2, outdata);
330 TFile* oldFile = gFile;
331 TDirectory* oldDir = gDirectory;
337 hProducedDigis->Write();
364 double dTotalCpuTime =
fTimerTs->CpuTime() * 1000.;
365 double dTotalRealTime =
fTimerTs->RealTime() * 1000.;
376 double dTotalDataSizeIn = 0.0;
377 double dTotalDataSizeOut = 0.0;
379 using sctp = std::chrono::system_clock::time_point;
386 dTotalDataSizeIn += datait.second.first;
387 dTotalDataSizeOut += datait.second.second;
390 double dUnpRatio = 0 < datait.second.first ? datait.second.second / datait.second.first : 0.0;
391 double dShareIn = 0 < dTotalDataSizeIn ? datait.second.first / dTotalDataSizeIn : 0.0;
392 double dShareOut = 0 < dTotalDataSizeOut ? datait.second.second / dTotalDataSizeOut : 0.0;
396 {{
"dataIn", datait.second.first},
397 {
"dataOut", datait.second.second},
398 {
"unpRatio", dUnpRatio},
399 {
"shareIn", dShareIn},
400 {
"shareOut", dShareOut}},
405 datait->second.first = 0.0;
406 datait->second.second = 0.0;
408 dTotalDataSizeIn = 0.0;
409 dTotalDataSizeOut = 0.0;
414 dTotalDataSizeIn += datait.second.first;
415 dTotalDataSizeOut += datait.second.second;
425 if (datait.second.first) {
435 timeit->second.first = 0.0;
436 timeit->second.second = 0.0;
439 datait->second.first = 0.0;
440 datait->second.second = 0.0;
487 const fles::Timeslice& timeslice = *ts;
494 uint64_t nComponents = ts->num_components();
496 LOG(info) <<
"Unpack: TS index " << ts->index() <<
" components " << nComponents;
499 for (uint64_t component = 0; component < nComponents; component++) {
501 auto subsystem =
static_cast<Subsystem>(ts->descriptor(component, 0).sys_id);
504 case Subsystem::MUCH: {
512 case Subsystem::PSD: {
519 case Subsystem::RICH: {
526 case Subsystem::STS: {
533 case Subsystem::TOF: {
540 case Subsystem::TRD: {
547 case Subsystem::TRD2D: {
554 case Subsystem::BMON: {
563 LOG(error) <<
"Unpack: Unknown subsystem " << fles::to_string(subsystem) <<
" for component " << component;
624 fBmonConfig->GetMonitor()->FinalizeTsBmonMicroSpillHistos();
ClassImp(CbmConverterManager)
Main steering class for unpacking in cbmroot.
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.
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.
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.
TH1 * fhCpuTimePerTsHist
Processing time per TS.
std::map< Subsystem, std::pair< double, double > > fDataSizeMapCurrSec
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.
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.
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.
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
std::shared_ptr< CbmMuchUnpackConfig > fMuchConfig
Current time slice.
std::shared_ptr< CbmTrdUnpackConfig > fTrd1DConfig
Configuration of the Trd unpacker. Provides the configured algorithm.
bool fDoPerfProfPerTs
Flag if performance profiling per TS should be activated or not.
void performanceProfilingPerTs()
Run the performance profiling for a single TS based on the fTimeMapPerTs and fDataSizeMapPerTs member...
std::chrono::system_clock::time_point fMonitorSecCurrentTs
std::shared_ptr< CbmRichUnpackConfig > fRichConfig
Configuration of the Rich unpacker. Provides the configured algorithm.
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()
bool fDoPerfProf
Flag if performance profiling should be activated or not.
Bookkeeping of time-slice content.
void SetStartTime(double time)
Set start time.
void Reset()
Reset the time slice.
std::chrono::time_point< std::chrono::system_clock > sctp