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());
50 storable->BmonHits() = results.
bmonHits;
51 storable->StsHits() = results.
stsHits;
52 storable->TofHits() = results.
tofHits;
53 storable->TrdHits() = results.
trdHits;
55 storable->Tracks() = results.
tracks;
66 constexpr size_t DumpEventsPerTS = 10;
67 constexpr size_t DumpHitsPerSensor = 2;
68 constexpr size_t DumpTracksPerTS = 10;
76 auto desc = archive.descriptor();
77 L_(info) <<
"Archive descriptor: ";
78 L_(info) <<
" - time_created: " << desc.time_created();
79 L_(info) <<
" - hostname: " << desc.hostname();
80 L_(info) <<
" - username: " << desc.username();
82 for (
auto recoResults = archive.get(); !archive.eos(); recoResults = archive.get()) {
83 if (recoResults ==
nullptr) {
84 L_(error) <<
"Failed to read RecoResults from archive";
88 size_t nEvents = recoResults->DigiEvents().size();
89 L_(info) <<
"TS " << recoResults->TsIndex() <<
" start: " << recoResults->TsStartTime() <<
" events: " << nEvents
90 <<
", stsHits: " << recoResults->StsHits().NElements()
91 <<
", tofHits: " << recoResults->TofHits().NElements() <<
", tracks: " << recoResults->Tracks().size();
93 for (
size_t i = 0; i < std::min(DumpEventsPerTS, nEvents); i++) {
94 const auto& digiEvent = recoResults->DigiEvents().at(i);
95 L_(info) <<
" - Event " << i <<
" number: " << digiEvent.fNumber <<
"; time: " << digiEvent.fTime
100 if (nEvents > DumpEventsPerTS)
L_(info) <<
"...";
102 auto& bmonHits = recoResults->BmonHits();
103 for (
size_t m = 0; m < bmonHits.NPartitions(); m++) {
104 auto [
hits, address] = bmonHits.Partition(m);
105 for (
size_t i = 0; i < std::min(DumpHitsPerSensor,
hits.size()); i++) {
106 const auto& hit =
hits[i];
107 L_(info) <<
" - BMON Hit " << i <<
" sensor: " << address <<
"; time: " << hit.GetTime();
113 auto& stsHits = recoResults->StsHits();
114 for (
size_t m = 0; m < stsHits.NPartitions(); m++) {
115 auto [
hits, address] = stsHits.Partition(m);
116 for (
size_t i = 0; i < std::min(DumpHitsPerSensor,
hits.size()); i++) {
117 const auto& hit =
hits[i];
118 L_(info) <<
" - STS Hit " << i <<
" sensor: " << address <<
"; time: " << hit.fTime <<
", X: " << hit.fX
119 <<
", Y: " << hit.fY <<
", Z: " << hit.fZ;
125 auto tofHits = recoResults->TofHits();
126 for (
size_t m = 0; m < tofHits.NPartitions(); m++) {
127 auto [
hits, address] = tofHits.Partition(m);
128 for (
size_t i = 0; i < std::min(DumpHitsPerSensor,
hits.size()); i++) {
129 const auto& hit =
hits[i];
130 L_(info) <<
" - TOF Hit " << i <<
" sensor: " << address <<
"; time: " << hit.Time() <<
", X: " << hit.X()
131 <<
", Y: " << hit.Y() <<
", Z: " << hit.Z();
137 auto trdHits = recoResults->TrdHits();
138 for (
size_t m = 0; m < trdHits.NPartitions(); m++) {
139 auto [
hits, address] = trdHits.Partition(m);
140 for (
size_t i = 0; i < std::min(DumpHitsPerSensor,
hits.size()); i++) {
141 const auto& hit =
hits[i];
142 L_(info) <<
" - TRD Hit " << i <<
" sensor: " << address <<
"; time: " << hit.Time() <<
", X: " << hit.X()
143 <<
", Y: " << hit.Y() <<
", Z: " << hit.Z();
150 auto&
tracks = recoResults->Tracks();
151 for (
size_t t = 0; t < std::min(
tracks.size(), DumpTracksPerTS); t++) {
152 const auto& track =
tracks[t];
153 L_(info) <<
" - Track " << t <<
" nHits: " << track.fNofHits <<
", chi2: " << track.fParPV.ChiSq()
154 <<
", X: " << track.fParPV.X() <<
", Y: " << track.fParPV.Y() <<
", Z: " << track.fParPV.Z();
165 logging::add_console(opts.
LogLevel());
170 xpu::settings settings;
172 settings.device = opts.
Device();
174 settings.verbose =
true;
175 settings.logging_sink = [](std::string_view msg) {
L_(trace) << msg; };
177 xpu::initialize(settings);
178 xpu::preload<GPUReco>();
182 L_(debug) << *ompThreads <<
" OpenMP threads requested";
190 std::stringstream ss;
191 for (
int i = 0; i < argc; i++) {
192 ss << argv[i] <<
" ";
194 L_(info) << ss.str();
201 auto startProcessing = chron::high_resolution_clock::now();
208 std::optional<RecoResultsOutputArchiveSequence> archive;
210 L_(info) <<
"Writing results to file: " << opts.
OutputFile();
211 fles::ArchiveCompression compression = fles::ArchiveCompression::None;
213 compression = fles::ArchiveCompression::Zstd;
221 L_(debug) <<
"Starting to fetch timeslices from source...";
223 auto startFetchTS = chron::high_resolution_clock::now();
224 while (
auto timeslice = source.get()) {
230 std::unique_ptr<fles::Timeslice> ts;
232 ts = std::make_unique<fles::StorableTimeslice>(*timeslice);
236 ts = std::move(timeslice);
239 auto endFetchTS = chron::high_resolution_clock::now();
240 auto durationFetchTS = endFetchTS - startFetchTS;
241 extraMonitor.
timeIdle = chron::duration_cast<chron::duration<double, std::milli>>(durationFetchTS).count();
250 archive->put(storable);
255 L_(error) <<
"Caught ProcessingError while processing timeslice " << tsIdx <<
": " << e.what();
257 reco.QueueProcessingExtraMetrics(extraMonitor);
266 if (num_ts > 0 && tsIdx >= num_ts)
break;
268 startFetchTS = chron::high_resolution_clock::now();
271 if (archive) archive->end_stream();
274 auto endProcessing = chron::high_resolution_clock::now();
275 auto duration = chron::duration_cast<chron::milliseconds>(endProcessing - startProcessing);
276 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
std::size_t OutputMaxItems() const
std::size_t OutputMaxSize() const
severity_level LogLevel() const
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)
ca::Vector< std::vector< HitId_t > > trackTofHitIndices
PartitionedVector< trd::Hit > trdHits
PODVector< CbmMuchDigi > muchDigis
PartitionedVector< sts::Cluster > stsClusters
ca::Vector< ca::Track > tracks
PartitionedVector< tof::Hit > tofHits
ca::Vector< std::vector< HitId_t > > trackTrdHitIndices
std::vector< DigiEvent > events
PODVector< CbmTrdDigi > trd2dDigis
PartitionedVector< bmon::Hit > bmonHits
PODVector< CbmFsdDigi > fsdDigis
PODVector< CbmMvdRawDigi > mvdDigis
PartitionedSpan< sts::Hit > stsHits
PODVector< CbmTofDigi > tofDigis
ca::Vector< std::vector< HitId_t > > trackStsHitIndices
PODVector< CbmRichDigi > richDigis
PODVector< CbmStsDigi > stsDigis
PODVector< CbmTrdDigi > trdDigis
PODVector< CbmBmonDigi > bmonDigis