46namespace chron = std::chrono;
55 bool hasOutputFile = !opts.
OutputFile().empty();
58 if (!hasOutputFile && hasOutputType) {
59 throw FatalError(
"Output types specified, but no output file given: -o <file> missing");
62 if (hasOutputFile && !hasOutputType) {
63 throw FatalError(
"Output file specified, but no output types given: -O <types> missing");
67 throw FatalError(
"Archive compression enabled but compiled without Zstd: Remove --archive-compression flag");
71 throw FatalError(
"Local reco can't run without unpacking: Add 'Unpack' to the reco steps");
75 throw FatalError(
"Tracking can't run without local reco: Add 'LocalReco' to the reco steps");
81 if (
fInitialized)
throw std::runtime_error(
"Chain already initialized");
88 if (
Opts().HistogramUri() !=
"") {
90 std::make_shared<HistogramSender>(
Opts().HistogramUri(),
Opts().HistogramHwm(),
Opts().CompressHistograms());
95 fRunStartTimeNs = chron::duration_cast<chron::nanoseconds>(chron::system_clock::now().time_since_epoch()).count();
99 xpu::device_prop props{xpu::device::active()};
101 <<
" OpenMP threads)";
105 L_(info) <<
"Monitoring enabled, sending to " << opts.
MonitorUri();
112 L_(info) <<
"Using parameter files for setup " << parFiles.
setup;
143 sts::Unpack::Config cfg{.readout = readout, .walkMap = walkMap, .bCollectAuxData = bCollectAux};
144 fStsUnpack = std::make_unique<sts::Unpack>(cfg);
148 fStsDigiQa->RegisterReadoutSetup(readoutSetup);
156 fTofUnpack = std::make_unique<tof::Unpack>(cfg);
161 fTrdUnpack = std::make_unique<trd::Unpack>(cfg);
170 auto pTrackingSetup = std::make_shared<TrackingSetup>();
171 pTrackingSetup->SetContext(&
fContext);
172 pTrackingSetup->Use(Subsystem::STS,
Opts().Has(Subsystem::STS));
173 pTrackingSetup->Use(Subsystem::TRD,
Opts().Has(Subsystem::TRD));
174 pTrackingSetup->Use(Subsystem::TOF,
Opts().Has(Subsystem::TOF));
175 pTrackingSetup->Init();
179 fs::path configFile = opts.
ParamsDir() /
"EventbuildConfig.yaml";
183 fEventBuild->RegisterTrackingSetup(pTrackingSetup);
192 hitFinderPars.
setup = std::move(hitFinderSetup);
206 fTofHitFinder = std::make_unique<tof::Hitfind>(hitfindSetup);
212 fTrdHitfind = std::make_unique<trd::Hitfind>(setup, setup2d);
218 fTracking->RegisterSetup(pTrackingSetup);
225 L_(debug) <<
"CBM Reco finished initialization";
232 throw std::runtime_error(
"Chain not initialized");
240 xpu::scoped_timer t_(fmt::format(
"TS {}", ts.index()), &procMon.
time);
243 L_(info) <<
">>> Processing TS " << ts.index();
244 xpu::set<cbm::algo::Params>(
Params());
250 xpu::scoped_timer timerU(
"Unpack", &procMon.
timeUnpack);
265 L_(info) <<
"TS contains Digis: STS=" << digis.
fSts.size() <<
" MUCH=" << digis.
fMuch.size()
266 <<
" TOF=" << digis.
fTof.size() <<
" BMON=" << digis.
fBmon.size() <<
" TRD=" << digis.
fTrd.size()
267 <<
" TRD2D=" << digis.
fTrd2d.size() <<
" RICH=" << digis.
fRich.size() <<
" PSD=" << digis.
fPsd.size()
268 <<
" FSD=" << digis.
fFsd.size();
270 if (
fSender !=
nullptr &&
Opts().Has(Subsystem::STS)) {
281 xpu::scoped_timer timerSTS(
"STS Reco", &procMon.
timeSTS);
284 auto stsResults = (*fStsHitFinder)(digis.
fSts, storeClusters);
285 stsHitfinderMonitor = std::move(stsResults.monitor);
286 recoData.
stsHits = stsResults.hits;
287 recoData.
stsClusters = std::move(stsResults.clusters);
293 xpu::scoped_timer timerTOF(
"TOF Reco", &procMon.
timeTOF);
295 auto [caldigis, calmonitor] = (*fTofCalibrator)(digis.
fTof);
296 auto nUnknownRPC = calmonitor.fDigiCalibUnknownRPC;
297 if (nUnknownRPC > 0) {
298 L_(error) <<
"TOF Digis with unknown RPCs: " << nUnknownRPC;
300 auto [
hits, hitmonitor, digiindices] = (*fTofHitFinder)(caldigis);
308 xpu::scoped_timer timerTRD(
"TRD Reco", &procMon.
timeTRD);
311 const auto& digis1d = digis.
fTrd;
312 const auto& digis2d = digis.
fTrd2d;
314 allDigis.reserve(digis1d.size() + digis2d.size());
315 std::copy(digis1d.begin(), digis1d.end(), std::back_inserter(allDigis));
316 std::copy(digis2d.begin(), digis2d.end(), std::back_inserter(allDigis));
317 auto trdResults = (*fTrdHitfind)(allDigis);
318 recoData.
trdHits = std::move(std::get<0>(trdResults));
322 L_(info) <<
"TS contains Hits: STS=" << recoData.
stsHits.NElements() <<
" TOF=" << recoData.
tofHits.NElements()
323 <<
" TRD=" << recoData.
trdHits.NElements();
329 xpu::scoped_timer timerCA(
"CA", &procMon.
timeCA);
339 recoData.
tracks = std::move(trackingOutput.tracks);
340 std::sort(recoData.
tracks.begin(), recoData.
tracks.end(),
342 return track1.fParPV.Time() < track2.fParPV.Time();
348 std::vector<DigiEvent> events;
351 auto [ev, mon] =
fEventBuild->Run(digis, recoData);
352 events = std::move(ev);
353 evbuildMonitor = mon;
408 if (
Opts().TimingsFile() !=
"") {
409 std::ofstream file(
Opts().TimingsFile().
string());
417 if (
Opts().CollectKernelTimes()) {
425 L_(info) <<
"TS Processing time (Wall): " << timings.wall() <<
" ms";
429template<
class Unpacker>
435 auto [digis, monitor, aux] = (*unpacker)(ts);
436 QueueUnpackerMetricsDet(monitor);
437 return std::make_tuple(digis, aux);
440template<
class MSMonitor>
449 auto MkKey = [&](std::string_view key) {
return fmt::format(
"{}{}", key,
Capitalize(det)); };
451 GetMonitor().QueueMetric(
"cbmreco", {{
"hostname", fles::system::current_hostname()}, {
"child",
Opts().
ChildId()}},
456 {MkKey(
"unpackNumMs"), monitor.
numMs},
466 GetMonitor().QueueMetric(
"cbmreco", {{
"hostname", fles::system::current_hostname()}, {
"child",
Opts().
ChildId()}},
468 {
"stsRecoNumClusters", (
unsigned long) monitor.
nClusterTotal},
469 {
"stsRecoNumHits", (
unsigned long) monitor.
nHitsTotal},
479 GetMonitor().QueueMetric(
"cbmreco", {{
"hostname", fles::system::current_hostname()}, {
"child",
Opts().
ChildId()}},
492 GetMonitor().QueueMetric(
"cbmreco", {{
"hostname", fles::system::current_hostname()}, {
"child",
Opts().
ChildId()}},
494 {
"trdRecoNumDigisIn", mon.
numDigis},
495 {
"trdRecoNumHits", mon.
numHits},
503 GetMonitor().QueueMetric(
"cbmreco", {{
"hostname", fles::system::current_hostname()}, {
"child",
Opts().
ChildId()}},
505 {
"tofCalibTimeTotal", mon.
fTime.wall()},
517 const MetricTagSet tags = {{
"hostname", fles::system::current_hostname()}, {
"child",
Opts().
ChildId()}};
519 size_t nDigisTotal = 0;
520 size_t nDigisInEventsTotal = 0;
522 auto queueDetMetrics = [&](std::string_view det,
auto& detMon) {
523 size_t nDigis = detMon.nDigis;
524 size_t nDigisInEvents = detMon.nDigisInEvents;
525 double selectionRatio = nDigis > 0 ? double(nDigisInEvents) / nDigis : 0;
527 nDigisTotal += nDigis;
528 nDigisInEventsTotal += nDigisInEvents;
531 {{fmt::format(
"{}NumDigisTotal", det), nDigis},
532 {fmt::format(
"{}NumDigisInEvents", det), nDigisInEvents},
533 {fmt::format(
"{}EvSelectionRatio", det), selectionRatio}});
544 double totalSelectionRatio = nDigisTotal > 0 ? double(nDigisInEventsTotal) / nDigisTotal : 0;
559 {
"totalEvSelectionRatio", totalSelectionRatio}});
568 GetMonitor().QueueMetric(
"cbmreco", {{
"hostname", fles::system::current_hostname()}, {
"child",
Opts().
ChildId()}},
583 MetricFieldSet fields = {
584 {
"processingTimeTotal", mon.
time.wall()}, {
"processingThroughput",
FilterNan(mon.
time.throughput())},
592 fields.emplace_back(
"tsDelta", *mon.
tsDelta);
595 GetMonitor().QueueMetric(
"cbmreco", {{
"hostname", fles::system::current_hostname()}, {
"child",
Opts().
ChildId()}},
610 GetMonitor().QueueMetric(
"cbmreco", {{
"hostname", fles::system::current_hostname()}, {
"child",
Opts().
ChildId()}},
Collection of auxiliary data from unpackers (header)
source file for the ca::Track class
static vector< vector< QAHit > > hits
This file contains the definition of the ParFiles class.
QA module for STS raw digis (source)
A chain class to execute CA tracking algorithm in online reconstruction (header)
A detector setup interface used for tracking input data initialization (source)
Data class for a single-channel message in the STS.
Data class for expanded digital TOF information.
const std::vector< RecoData > & OutputTypes() const
const std::string & MonitorUri() const
fs::path ParamsDir() const
uint64_t RunStart() const
bool CompressArchive() const
fs::path OutputFile() const
bool HasOutput(RecoData recoData) const
bool CollectAuxData() const
bool Has(fles::Subsystem detector) const
const std::string & ChildId() const
A vector that is partitioned into multiple subvectors.
std::unique_ptr< tof::Hitfind > fTofHitFinder
std::optional< u64 > prevTsId
void Init(const Options &)
std::unique_ptr< trd::Hitfind > fTrdHitfind
void QueueTofRecoMetrics(const tof::HitfindMonitorData &)
std::shared_ptr< HistogramSender > fSender
std::unique_ptr< bmon::Unpack > fBmonUnpack
std::unique_ptr< sts::Unpack > fStsUnpack
std::unique_ptr< rich::Unpack > fRichUnpack
void QueueTrdRecoMetrics(const trd::HitfindMonitorData &)
std::unique_ptr< much::Unpack > fMuchUnpack
auto RunUnpacker(const std::unique_ptr< Unpacker > &, const fles::Timeslice &) -> UnpackResult_t< Unpacker >
xpu::timings fTimesliceTimesAcc
std::unique_ptr< sts::DigiQa > fStsDigiQa
Raw STS-digis QA.
std::unique_ptr< tof::Unpack > fTofUnpack
void QueueProcessingMetrics(const ProcessingMonitor &)
static double FilterNan(double x)
void QueueStsRecoMetrics(const sts::HitfinderMon &)
std::unique_ptr< tof::Calibrate > fTofCalibrator
void QueueTofCalibMetrics(const tof::CalibrateMonitorData &)
std::unique_ptr< trd2d::Unpack > fTrd2dUnpack
std::unique_ptr< qa::RecoGeneralQa > fGeneralQa
QA of online processing itself.
std::unique_ptr< sts::HitfinderChain > fStsHitFinder
std::unique_ptr< TrackingChain > fTracking
void Validate(const Options &opts)
std::unique_ptr< trd::Unpack > fTrdUnpack
std::unique_ptr< evbuild::EventbuildChain > fEventBuild
RecoResults Run(const fles::Timeslice &)
void PrintTimings(xpu::timings &)
void QueueUnpackerMetricsDet(const UnpackMonitor< MSMonitor > &)
void QueueTrackingMetrics(const ca::TrackingMonitorData &)
void QueueEvbuildMetrics(const evbuild::EventbuildChainMonitorData &)
void QueueProcessingExtraMetrics(const ProcessingExtraMonitor &)
const RecoParams & Params() const
Monitor & GetMonitor() const
void SetContext(const ChainContext *ctx)
const Options & Opts() const
int GetCounterValue(ECounterKey key) const
Gets counter value.
const Timer & GetTimer(ETimerKey key) const
Gets timer.
double GetTotalMs() const
Gets total time [ms].
Class representing an output track in the CA tracking algorithm.
Configuration of digi event building.
Provides the hardware-to-software address mapping for the CBM-RICH.
Provides the hardware-to-software address mapping for the CBM-STS.
A light-weight TRD hit class for online reconstruction, based on CbmTrdHit. .
@ RecoHit
number of reconstructed hits
@ RecoTrack
number of reconstructed tracks
@ SubTS
number of sub time-slices
@ RecoHitUsed
number of used reconstructed hits
size_t SizeBytes(const fles::Timeslice &ts)
T ReadFromFile(fs::path path)
std::string_view ToString(T t)
std::tuple< algo_traits::Output_t< Unpacker >, algo_traits::Aux_t< Unpacker > > UnpackResult_t
std::string MakeReportSubtimers(std::string_view title, const xpu::timings &t, size_t align)
Print timings from subtimers.
std::string MakeReportYaml(const xpu::timings &t)
Print timings in YAML format.
std::vector< T, PODAllocator< T > > PODVector
PODVector is a std::vector that doesn't initialize its elements.
std::string MakeReportSummary(std::string_view title, const xpu::timings &t, size_t align)
Only print the top-level times (Elapsed time, total kernel time, memcpy and memset times)....
std::string Capitalize(std::string_view str)
Capitalize the first letter of a string. The rest of the string is made lowercase.
Collection of auxiliary digi objects from different module unpackers.
UnpackAux< bmon::UnpackAuxData > fBmon
UnpackAux< trd2d::UnpackAuxData > fTrd2d
UnpackAux< rich::UnpackAuxData > fRich
UnpackAux< sts::UnpackAuxData > fSts
UnpackAux< much::UnpackAuxData > fMuch
UnpackAux< tof::UnpackAuxData > fTof
UnpackAux< trd::UnpackAuxData > fTrd
std::unique_ptr< cbm::Monitor > monitor
Collection of digis from all detector systems.
PODVector< CbmRichDigi > fRich
Unpacked RICH digis.
PODVector< CbmTrdDigi > fTrd
Unpacked TRD digis.
PODVector< CbmStsDigi > fSts
Unpacked STS digis.
PODVector< CbmTrdDigi > fTrd2d
Unpacked TRD2D digis.
PODVector< CbmFsdDigi > fFsd
Unpacked FSD digis.
PODVector< CbmTofDigi > fTof
Unpacked TOF digis.
PODVector< CbmPsdDigi > fPsd
Unpacked PSD digis.
PODVector< CbmMuchDigi > fMuch
Unpacked MUCH digis.
PODVector< CbmBmonDigi > fBmon
Unpacked Bmon digis.
Indicates an unrecoverable error. Should tear down the process.
Class to hold the paths to the parameter files for the different detectors.
struct cbm::algo::ParFiles::@2 tof
struct cbm::algo::ParFiles::@0 bmon
struct cbm::algo::ParFiles::@1 sts
struct cbm::algo::ParFiles::@3 trd
std::optional< i64 > tsDelta
struct cbm::algo::RecoParams::STS::Memory memory
PartitionedVector< trd::Hit > trdHits
PODVector< CbmMuchDigi > muchDigis
PartitionedVector< sts::Cluster > stsClusters
ca::Vector< ca::Track > tracks
PartitionedVector< tof::Hit > tofHits
ca::Vector< std::vector< std::pair< uint32_t, uint32_t > > > trackStsHitIndices
std::vector< DigiEvent > events
PODVector< CbmTrdDigi > trd2dDigis
ca::Vector< std::vector< std::pair< uint32_t, uint32_t > > > trackTofHitIndices
PartitionedSpan< sts::Hit > stsHits
PODVector< CbmTofDigi > tofDigis
PODVector< CbmRichDigi > richDigis
PODVector< CbmStsDigi > stsDigis
PODVector< CbmTrdDigi > trdDigis
PODVector< CbmBmonDigi > bmonDigis
Output from the TrackingChain.
Readout setup / Hardware cabling for BMon Used to create the hardware mapping for the BMon unpacker.
double ExpansionFactor() const
size_t numTriggers
Number of input triggers.
EventBuilderDetectorMonitorData much
Monitoring data for MUCH.
EventBuilderDetectorMonitorData rich
Monitoring data for RICH.
size_t numEvents
Number of built and selected events.
EventBuilderDetectorMonitorData sts
Monitoring data for STS.
EventBuilderDetectorMonitorData tof
Monitoring data for TOF.
EventBuilderDetectorMonitorData bmon
Monitoring data for Bmon.
EventBuilderDetectorMonitorData trd2d
Monitoring data for TRD2D.
xpu::timings time
Time for event building.
EventBuilderDetectorMonitorData trd
Monitoring data for TRD.
TimeClusterTriggerMonitorData hitMultTrigger
EventBuilderMonitorData evbuild
TimeClusterTriggerMonitorData digiMultTrigger
V0TriggerMoniData v0Trigger
xpu::timings time
Time for trigger building.
xpu::timings time
Time for trigger building.
size_t numTrackPairsAfterTimeCut
RecoParams::STS::Memory memory
i32 nClusterBucketOverflow
static LandauTable FromFile(fs::path path)
Readout setup / Hardware cabling for STS Used to create the hardware mapping for the STS unpacker.
Monitoring data for calibration.
size_t fDigiCalibUnknownRPC
Monitoring data for hitfinding.
Readout setup / Hardware cabling for TOF Used to create the hardware mapping for the TOF unpacker.
Monitoring data for hitfinding.