CbmRoot
Loading...
Searching...
No Matches
RecoSetup.cxx
Go to the documentation of this file.
1/* Copyright (C) 2025 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
11
12#include <boost/archive/binary_iarchive.hpp>
13#include <boost/archive/binary_oarchive.hpp>
14#include <boost/filesystem.hpp>
15#include <boost/serialization/vector.hpp>
16
17#include <fstream>
18#include <sstream>
19
21
22// ---------------------------------------------------------------------------------------------------------------------
23//
24RecoSetup::RecoSetup(const std::string& filename) : RecoSetup(std::move(RecoSetup::Load(filename))) {}
25
26// ---------------------------------------------------------------------------------------------------------------------
27//
28bool RecoSetup::Has(ECbmModuleId moduleId) const
29{
30 switch (moduleId) {
36 default: return false;
37 }
38}
39
40// ---------------------------------------------------------------------------------------------------------------------
41//
42RecoSetup RecoSetup::Load(const std::string& filename)
43{
44 RecoSetup setup{};
45
46 std::ifstream ifs(filename, std::ios::binary);
47 if (!ifs) {
48 std::stringstream msg;
49 msg << "RecoSetup::Load: input file \"" << filename << "\" was not found";
50 throw std::runtime_error(msg.str());
51 }
52
53 try {
54 boost::archive::binary_iarchive ia(ifs);
55 ia >> setup;
56 }
57 catch (const std::exception& err) {
58 std::stringstream msg;
59 msg << "RecoSetup::Load: input file \"" << filename
60 << "\" has inconsistent format or was corrupted. Details: " << err.what();
61 throw std::runtime_error(msg.str());
62 }
63
64 return setup;
65}
66
67// ---------------------------------------------------------------------------------------------------------------------
68//
69void RecoSetup::Store(const RecoSetup& setup, const std::string& filename)
70{
71 namespace fs = boost::filesystem;
72 auto path = fs::absolute(fs::weakly_canonical(filename));
73 fs::create_directories(path.parent_path());
74
75 std::ofstream ofs(path.string(), std::ios::binary);
76 if (!ofs) {
77 std::stringstream msg;
78 msg << "RecoSetup::Store: failed opening file \"" << filename << "\" to store a setup";
79 throw std::runtime_error(msg.str());
80 }
81 boost::archive::binary_oarchive oa(ofs);
82 oa << setup;
83}
84
85// ---------------------------------------------------------------------------------------------------------------------
86//
87std::string RecoSetup::ToString() const
88{
89 std::stringstream msg;
90 msg << "======== CBM Reconstruction Setup ============================================";
91 ForEachUnit([&](const auto& unit) { msg << '\n' << unit.TableOfTrackingStations(); });
92 msg << "==============================================================================";
93 return msg.str();
94}
ECbmModuleId
Enumerator for module Identifiers.
Definition CbmDefs.h:45
@ kMvd
Micro-Vertex Detector.
Definition CbmDefs.h:47
@ kTrd
Transition Radiation Detector.
Definition CbmDefs.h:51
@ kTof
Time-of-flight Detector.
Definition CbmDefs.h:52
@ kSts
Silicon Tracking System.
Definition CbmDefs.h:48
@ kMuch
Muon detection system.
Definition CbmDefs.h:50
A collection of reconstruction setup unit interfaces for different CBM subsystems.
RecoSetup()=default
Default constructor.
An instance of reconstruction setup unit interfaces for online/offline data reconstruction.
Definition RecoSetup.h:62
void ForEachUnit(Visitor &&visitor) const
A for-each method, which is applied to each unit, if it has a value (constant access)
Definition RecoSetup.h:95
std::string ToString() const
Dumps contents to string.
Definition RecoSetup.cxx:87
static RecoSetup Load(const std::string &filename)
Loads setup from a file.
Definition RecoSetup.cxx:42
static void Store(const RecoSetup &setup, const std::string &filename)
Stores setup in a file.
Definition RecoSetup.cxx:69
bool Has() const
Checks, if a setup unit is available (compile-time)
Definition RecoSetup.h:153
RecoSetup()=default
Default constructor.
Hash for CbmL1LinkKey.