17#include <StorableTimeslice.hpp>
18#include <TimesliceAutoSource.hpp>
27namespace chron = std::chrono;
31 auto storable = std::make_shared<StorableRecoResults>(ts.index(), ts.start_time());
33 storable->DigiEvents().reserve(results.
events.size());
34 for (
const auto& digiEvent : results.
events) {
35 storable->DigiEvents().emplace_back(digiEvent.ToStorable());
48 storable->StsHits() = results.
stsHits;
49 storable->TofHits() = results.
tofHits;
50 storable->TrdHits() = results.
trdHits;
52 storable->Tracks() = results.
tracks;
62 constexpr size_t DumpEventsPerTS = 10;
63 constexpr size_t DumpHitsPerSensor = 2;
64 constexpr size_t DumpTracksPerTS = 10;
72 auto desc = archive.descriptor();
73 L_(info) <<
"Archive descriptor: ";
74 L_(info) <<
" - time_created: " << desc.time_created();
75 L_(info) <<
" - hostname: " << desc.hostname();
76 L_(info) <<
" - username: " << desc.username();
78 for (
auto recoResults = archive.get(); !archive.eos(); recoResults = archive.get()) {
79 if (recoResults ==
nullptr) {
80 L_(error) <<
"Failed to read RecoResults from archive";
84 size_t nEvents = recoResults->DigiEvents().size();
85 L_(info) <<
"TS " << recoResults->TsIndex() <<
" start: " << recoResults->TsStartTime() <<
" events: " << nEvents
86 <<
", stsHits: " << recoResults->StsHits().NElements()
87 <<
", tofHits: " << recoResults->TofHits().NElements() <<
", tracks: " << recoResults->Tracks().size();
89 for (
size_t i = 0; i < std::min(DumpEventsPerTS, nEvents); i++) {
90 const auto& digiEvent = recoResults->DigiEvents().at(i);
91 L_(info) <<
" - Event " << i <<
" number: " << digiEvent.fNumber <<
"; time: " << digiEvent.fTime
96 if (nEvents > DumpEventsPerTS)
L_(info) <<
"...";
98 auto& stsHits = recoResults->StsHits();
99 for (
size_t m = 0; m < stsHits.NPartitions(); m++) {
100 auto [
hits, address] = stsHits.Partition(m);
101 for (
size_t i = 0; i < std::min(DumpHitsPerSensor,
hits.size()); i++) {
102 const auto& hit =
hits[i];
103 L_(info) <<
" - STS Hit " << i <<
" sensor: " << address <<
"; time: " << hit.fTime <<
", X: " << hit.fX
104 <<
", Y: " << hit.fY <<
", Z: " << hit.fZ;
110 auto tofHits = recoResults->TofHits();
111 for (
size_t m = 0; m < tofHits.NPartitions(); m++) {
112 auto [
hits, address] = tofHits.Partition(m);
113 for (
size_t i = 0; i < std::min(DumpHitsPerSensor,
hits.size()); i++) {
114 const auto& hit =
hits[i];
115 L_(info) <<
" - TOF Hit " << i <<
" sensor: " << address <<
"; time: " << hit.Time() <<
", X: " << hit.X()
116 <<
", Y: " << hit.Y() <<
", Z: " << hit.Z();
122 auto&
tracks = recoResults->Tracks();
123 for (
size_t t = 0; t < std::min(
tracks.size(), DumpTracksPerTS); t++) {
124 const auto& track =
tracks[t];
125 L_(info) <<
" - Track " << t <<
" nHits: " << track.fNofHits <<
", chi2: " << track.fParPV.ChiSq()
126 <<
", X: " << track.fParPV.X() <<
", Y: " << track.fParPV.Y() <<
", Z: " << track.fParPV.Z();
137 logging::add_console(opts.
LogLevel());
142 xpu::settings settings;
144 settings.device = opts.
Device();
146 settings.verbose =
true;
147 settings.logging_sink = [](std::string_view msg) {
L_(trace) << msg; };
149 xpu::initialize(settings);
150 xpu::preload<GPUReco>();
154 L_(debug) << *ompThreads <<
" OpenMP threads requested";
162 std::stringstream ss;
163 for (
int i = 0; i < argc; i++) {
164 ss << argv[i] <<
" ";
166 L_(info) << ss.str();
173 auto startProcessing = chron::high_resolution_clock::now();
180 std::optional<RecoResultsOutputArchive> archive;
182 L_(info) <<
"Writing results to file: " << opts.
OutputFile();
183 fles::ArchiveCompression compression = fles::ArchiveCompression::None;
185 compression = fles::ArchiveCompression::Zstd;
187 archive.emplace(opts.
OutputFile().string(), compression);
193 L_(debug) <<
"Starting to fetch timeslices from source...";
195 auto startFetchTS = chron::high_resolution_clock::now();
196 while (
auto timeslice = source.get()) {
202 std::unique_ptr<fles::Timeslice> ts;
204 ts = std::make_unique<fles::StorableTimeslice>(*timeslice);
208 ts = std::move(timeslice);
211 auto endFetchTS = chron::high_resolution_clock::now();
212 auto durationFetchTS = endFetchTS - startFetchTS;
213 extraMonitor.
timeIdle = chron::duration_cast<chron::duration<double, std::milli>>(durationFetchTS).count();
222 archive->put(storable);
227 L_(error) <<
"Caught ProcessingError while processing timeslice " << tsIdx <<
": " << e.what();
238 if (num_ts > 0 && tsIdx >= num_ts)
break;
240 startFetchTS = chron::high_resolution_clock::now();
243 if (archive) archive->end_stream();
246 auto endProcessing = chron::high_resolution_clock::now();
247 auto duration = chron::duration_cast<chron::milliseconds>(endProcessing - startProcessing);
248 L_(info) <<
"Total Processing time (Wall): " << duration.count() <<
" ms";
@ kTof
Time-of-flight Detector.
@ kSts
Silicon Tracking System.
static vector< vector< QAHit > > hits
Track the memory usage of the process and write it to the log.
void Log()
Log the current memory usage.
const std::string & Device() const
bool CompressArchive() const
int SkipTimeslices() const
std::optional< int > NumOMPThreads() const
int NumTimeslices() const
bool CollectKernelTimes() const
fs::path OutputFile() const
const std::string & InputLocator() const
severity_level LogLevel() const
void Init(const Options &)
RecoResults Run(const fles::Timeslice &)
void QueueProcessingExtraMetrics(const ProcessingExtraMonitor &)
const std::string GIT_HASH
constexpr bool WITH_PARALLEL_STL
const std::string BUILD_TYPE
fles::InputArchive< StorableRecoResults, StorableRecoResults, fles::ArchiveType::RecoResultsArchive > RecoResultsInputArchive
task_thread_pool::task_thread_pool & GetGlobalSTLThreadPool()
Get the global thread pool for parallel stl algorithms.
std::vector< T > ToStdVector(const PODVector< T > &vec)
bool dumpArchive(const Options &opts)
int main(int argc, char **argv)
std::shared_ptr< StorableRecoResults > makeStorableRecoResults(const fles::Timeslice &ts, const RecoResults &results)
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