diff --git a/algo/CMakeLists.txt b/algo/CMakeLists.txt index ab468ea286c9460ca47e3fc4833eec8783f218ca..e816a0cdd1a81b329d8f819f503f8f0c6ebeaea8 100644 --- a/algo/CMakeLists.txt +++ b/algo/CMakeLists.txt @@ -37,6 +37,8 @@ set(SRCS detectors/trd2d/UnpackTrd2d.cxx detectors/rich/RichReadoutConfig.cxx detectors/rich/UnpackRich.cxx + global/Archive.cxx + global/RecoIO.cxx global/Reco.cxx qa/DigiEventQa.cxx qa/Histo1D.cxx diff --git a/algo/global/Archive.cxx b/algo/global/Archive.cxx new file mode 100644 index 0000000000000000000000000000000000000000..6084543697fe69f33dce124dc78b9df3a27b25af --- /dev/null +++ b/algo/global/Archive.cxx @@ -0,0 +1,34 @@ +/* Copyright (C) 2023 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main + SPDX-License-Identifier: GPL-3.0-only + Authors: Felix Weiglhofer [committer] */ +#include "Archive.h" + +#include "CbmStsDigi.h" + +#include <boost/archive/binary_iarchive.hpp> +#include <boost/archive/binary_oarchive.hpp> +#include <boost/serialization/vector.hpp> + +#include <fstream> + +#include "log.hpp" + +using namespace cbm::algo; + +namespace ba = boost::archive; + +Archive::Archive(fs::path file) +{ + L_(info) << "Reading archive from " << file; + std::ifstream ifs(file.string(), std::ios::binary); + ba::binary_iarchive ia(ifs); + ia >> *this; +} + +void Archive::Store(fs::path file) const +{ + L_(info) << "Writing archive to " << file; + std::ofstream ofs(file.string(), std::ios::binary); + ba::binary_oarchive oa(ofs); + oa << *this; +} diff --git a/algo/global/Archive.h b/algo/global/Archive.h new file mode 100644 index 0000000000000000000000000000000000000000..4f97dc3ac92ac2f42e32c56ea0586fa836761dc1 --- /dev/null +++ b/algo/global/Archive.h @@ -0,0 +1,59 @@ +/* Copyright (C) 2023 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main + SPDX-License-Identifier: GPL-3.0-only + Authors: Felix Weiglhofer [committer] */ +#ifndef CBM_ALGO_GLOBAL_ARCHIVE_H +#define CBM_ALGO_GLOBAL_ARCHIVE_H + +#include "MicrosliceDescriptor.hpp" + +#include <boost/serialization/access.hpp> +#include <boost/serialization/version.hpp> + +#include <vector> + +#include "RecoIO.h" +#include "compat/Filesystem.h" + +namespace cbm::algo +{ + class Archive { + public: + /** + * @brief Read Archive object from file. + */ + Archive(fs::path file); + + /** + * @brief Construct empty archive. + */ + Archive(const std::vector<fles::SubsystemIdentifier>& detectors) : fDetectors(detectors) {} + ~Archive() = default; + + /** + * @brief Store Archive object to file. + */ + void Store(fs::path file) const; + + const std::vector<fles::SubsystemIdentifier>& Detectors() const { return fDetectors; } + + std::vector<RecoIO>& TimesliceResults() { return fTimesliceResults; } + const std::vector<RecoIO>& TimesliceResults() const { return fTimesliceResults; } + + private: + std::vector<fles::SubsystemIdentifier> fDetectors; + + std::vector<RecoIO> fTimesliceResults; + + friend class boost::serialization::access; + template<class Archive> + void serialize(Archive& ar, const unsigned int /*version*/) + { + ar& fDetectors; + ar& fTimesliceResults; + } + }; +} // namespace cbm::algo + +BOOST_CLASS_VERSION(cbm::algo::Archive, 1) + +#endif diff --git a/algo/global/Reco.cxx b/algo/global/Reco.cxx index aee8e12cef94bf9cc5788464d0ec56666c3b1fcb..637ed89fa3721af78bd5ff518bd3a49bd9f01e7b 100644 --- a/algo/global/Reco.cxx +++ b/algo/global/Reco.cxx @@ -72,7 +72,8 @@ void Reco::Init(const Options& opts) xpu::push_timer("Reco"); } -void Reco::Run(const fles::Timeslice& ts) + +RecoIO Reco::Run(const fles::Timeslice& ts) { if (!fInitialized) { throw std::runtime_error("Chain not initialized"); } @@ -108,6 +109,11 @@ void Reco::Run(const fles::Timeslice& ts) PrintTimings(ts_times); + + RecoIO results; + results.StsDigis() = std::move(digis); + + return results; } void Reco::Finalize() diff --git a/algo/global/Reco.h b/algo/global/Reco.h index 662e3e762f4a1ac9e3472995e91767fd72d4d071..276bc591fb546de7faeafb6aeddcc05a0413c760 100644 --- a/algo/global/Reco.h +++ b/algo/global/Reco.h @@ -6,6 +6,7 @@ #include <xpu/host.h> +#include "RecoIO.h" #include "SubChain.h" #include "UnpackChain.h" #include "sts/StsHitfinderChain.h" @@ -24,13 +25,13 @@ namespace cbm::algo Reco(); ~Reco(); - Reco(const Reco&) = delete; + Reco(const Reco&) = delete; Reco& operator=(const Reco&) = delete; Reco(Reco&&) = delete; - Reco& operator=(Reco&&) = delete; + Reco& operator=(Reco&&) = delete; void Init(const Options&); - void Run(const fles::Timeslice&); + RecoIO Run(const fles::Timeslice&); void Finalize(); void PrintTimings(xpu::timings&); diff --git a/algo/global/RecoIO.cxx b/algo/global/RecoIO.cxx new file mode 100644 index 0000000000000000000000000000000000000000..aae34693010200443f7ef99e6b4b281448790e2c --- /dev/null +++ b/algo/global/RecoIO.cxx @@ -0,0 +1,11 @@ +/* Copyright (C) 2023 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main + SPDX-License-Identifier: GPL-3.0-only + Authors: Felix Weiglhofer [committer] */ +#include "RecoIO.h" + +#include "CbmStsDigi.h" + +using namespace cbm::algo; + +RecoIO::RecoIO() {} +RecoIO::~RecoIO() {} diff --git a/algo/global/RecoIO.h b/algo/global/RecoIO.h new file mode 100644 index 0000000000000000000000000000000000000000..fab2837b3041737cd0942db9dd8b2476c36efe6c --- /dev/null +++ b/algo/global/RecoIO.h @@ -0,0 +1,41 @@ +/* Copyright (C) 2023 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main + SPDX-License-Identifier: GPL-3.0-only + Authors: Felix Weiglhofer [committer] */ +#ifndef CBM_ALGO_GLOBAL_RECOIO_H +#define CBM_ALGO_GLOBAL_RECOIO_H + +#include <boost/serialization/access.hpp> + +#include <vector> + +class CbmStsDigi; +namespace cbm::algo::sts +{ + using Digi = CbmStsDigi; +} + +namespace cbm::algo +{ + class RecoIO { + + public: + // Place ctor / dtor in cxx, so that we can forward-declare the data classes and keep this header small. + RecoIO(); + ~RecoIO(); + + std::vector<sts::Digi>& StsDigis() { return fStsDigis; } + const std::vector<sts::Digi>& StsDigis() const { return fStsDigis; } + + private: + std::vector<sts::Digi> fStsDigis; + + friend class boost::serialization::access; + template<class Archive> + void serialize(Archive& ar, const unsigned int /*version*/) + { + ar& fStsDigis; + } + }; +} // namespace cbm::algo + +#endif diff --git a/reco/app/cbmreco/main.cxx b/reco/app/cbmreco/main.cxx index 32f2b08078824cd6e54da55671eb0cd1638774de..63aea0df5e418786a826034122aa1a673a59368c 100644 --- a/reco/app/cbmreco/main.cxx +++ b/reco/app/cbmreco/main.cxx @@ -8,6 +8,7 @@ #include <xpu/host.h> +#include "Archive.h" #include "BuildInfo.h" #include "Options.h" #include "Reco.h" @@ -44,6 +45,8 @@ int main(int argc, char** argv) Reco reco; reco.Init(opts); + + Archive archive(opts.Detectors()); fles::TimesliceAutoSource source {opts.InputLocator()}; int tsIdx = 0; int num_ts = opts.NumTimeslices(); @@ -53,7 +56,8 @@ int main(int argc, char** argv) tsIdx++; continue; } - reco.Run(*ts); + auto result = reco.Run(*ts); + archive.TimesliceResults().push_back(result); tsIdx++; if (num_ts > 0 && tsIdx >= num_ts) { break; }