fire v0.19.0
Framework for sImulation and Reconstruction of Events
RunHeader.h
1#ifndef FIRE_RUNHEADER_H
2#define FIRE_RUNHEADER_H
3
4#include <map>
5#include <string>
6
7#include "fire/version/Version.h"
8#include "fire/io/Constants.h"
9#include "fire/io/Data.h"
10#include "fire/io/ParameterStorage.h"
11
12#ifdef fire_USE_ROOT
13#include "TObject.h"
14namespace ldmx {
15#else
16namespace fire {
17#endif
18
27class RunHeader {
28 public:
30 static const std::string NAME;
31
33 int getRunNumber() const { return runNumber_; }
34
36 const std::string &getDetectorName() const { return detectorName_; }
37
39 void setDetectorName(const std::string &det) { detectorName_ = det; }
40
45 const std::string &getSoftwareTag() const { return softwareTag_; }
46
48 const std::string &getDescription() const { return description_; }
49
51 void setDescription(const std::string &des) { description_ = des; }
52
59 int getRunStart() const { return runStart_; }
60
66 void runStart(const int run) {
67 runStart_ = std::time(nullptr);
68 runNumber_ = run;
69 }
70
76 int getRunEnd() const { return runEnd_; }
77
81 void runEnd() {
82 runEnd_ = std::time(nullptr);
83 }
84
92 template <typename ParameterType>
93 const ParameterType& get(const std::string& name) const {
94 return parameters_.get<ParameterType>(name);
95 }
96
104 template <typename ParameterType>
105 void set(const std::string& name, const ParameterType& val) {
106 parameters_.set(name,val);
107 }
108
116 void stream(std::ostream &s) const;
117
119 void Print() const;
120
124 void clear() {
125 runNumber_ = -1;
126 runStart_ = 0;
127 runEnd_ = 0;
128 detectorName_.clear();
129 description_.clear();
130 softwareTag_.clear();
131 parameters_.clear();
132 }
133
146 h.stream(s);
147 return s;
148 }
149
150 private:
152 friend class fire::io::access;
153
161 template<typename DataSet>
162 void attach(DataSet& d) {
163 d.attach(fire::io::constants::NUMBER_NAME,runNumber_);
164 d.attach("start",runStart_);
165 d.attach("end",runEnd_);
166 d.attach("detectorName",detectorName_);
167 d.attach("description",description_);
168 d.attach("softwareTag",softwareTag_);
169 d.attach("parameters",parameters_);
170 }
171
172 private:
174 int runNumber_{0};
175
177 std::string detectorName_{""};
178
180 std::string description_{""};
181
183 long int runStart_{0};
184
186 long int runEnd_{0};
187
193
196
197#ifdef fire_USE_ROOT
199 friend class fire::io::Data<ldmx::RunHeader>;
200
204 std::map<std::string,int> intParameters_;
205
209 std::map<std::string,float> floatParameters_;
210
214 std::map<std::string,std::string> stringParameters_;
220 ClassDef(RunHeader, 5);
221#endif
222}; // RunHeader
223} // namespace fire/ldmx
224
225#ifdef fire_USE_ROOT
226namespace fire {
227
229using RunHeader = ldmx::RunHeader;
230
231namespace io {
232
249template<>
250class Data<ldmx::RunHeader> : public AbstractData<ldmx::RunHeader> {
251 public:
258 explicit Data(const std::string& path, Reader* input_file = nullptr, ldmx::RunHeader* rh = nullptr);
259
265 void load(h5::Reader& r) final override;
266
276 void load(root::Reader& r) final override;
277
283 void save(Writer& w) final override;
284
290 void structure(Writer& w) final override;
291
302 template <typename MemberType>
303 void attach(const std::string& name, MemberType& m) {
304 members_.push_back(
305 std::make_unique<Data<MemberType>>(this->path_ + "/" + name, input_file_, &m));
306 }
307
308 private:
312 Reader* input_file_;
313}; // Data<ldmx::RunHeader>
314
315} // namespace io
316} // namespace fire
317#endif // fire_USE_ROOT
318#endif // FIRE_RUNHEADER_H
Definitions for names of structures required by serialization methods.
Container for run parameters.
Definition: RunHeader.h:27
void stream(std::ostream &s) const
Stream this object into the input ostream.
Definition: RunHeader.cxx:17
const std::string & getDescription() const
Definition: RunHeader.h:48
void attach(DataSet &d)
Attach to our fire::io::Data.
Definition: RunHeader.h:162
void clear()
clear the run header
Definition: RunHeader.h:124
void setDetectorName(const std::string &det)
Set the name of the detector that was used in this run.
Definition: RunHeader.h:39
static const std::string NAME
the name of the data holding the run headers
Definition: RunHeader.h:30
void runStart(const int run)
Start the run.
Definition: RunHeader.h:66
void setDescription(const std::string &des)
Set the description of this run.
Definition: RunHeader.h:51
const std::string & getDetectorName() const
Definition: RunHeader.h:36
friend std::ostream & operator<<(std::ostream &s, const RunHeader &h)
Stream this object to an output stream.
Definition: RunHeader.h:145
void set(const std::string &name, const ParameterType &val)
Set a run parameter.
Definition: RunHeader.h:105
int getRunEnd() const
Get the end time of the run in seconds since epoch.
Definition: RunHeader.h:76
const ParameterType & get(const std::string &name) const
Get a run parameter.
Definition: RunHeader.h:93
fire::io::ParameterStorage parameters_
run parameteres
Definition: RunHeader.h:195
void runEnd()
Set the end time of the run in seconds since epoch.
Definition: RunHeader.h:81
const std::string & getSoftwareTag() const
Definition: RunHeader.h:45
int getRunStart() const
Get the start time of the run in seconds since epoch.
Definition: RunHeader.h:59
int getRunNumber() const
Definition: RunHeader.h:33
General data set.
Definition: Data.h:90
Provides dynamic parameter storage by interfacing between a map to variants storing parameters and a ...
Definition: ParameterStorage.h:40
constexpr std::string_view GIT_SHA1
The git commit sha for this installation of fire.
Definition: Version.h.in:35
empty struct for connecting a instance of Data and the type it wraps
Definition: Access.h:22
static const std::string NUMBER_NAME
the name of the variable in event and run headers corresponding to their ID
Definition: Constants.h:20
T time(T... args)