fire v0.19.0
Framework for sImulation and Reconstruction of Events
EventHeader.h
1#ifndef FIRE_EVENTHEADER_H
2#define FIRE_EVENTHEADER_H
3
4// STL
5#include <ctime>
6#include <iostream>
7#include <map>
8#include <string>
9#include <variant>
10
11#include "fire/version/Version.h"
12#include "fire/io/Constants.h"
13#include "fire/io/Data.h"
14#include "fire/io/ParameterStorage.h"
15
16#ifdef fire_USE_ROOT
17#include "TObject.h"
18#include "TTimeStamp.h"
19namespace ldmx {
20#else
21namespace fire {
22#endif
23
28 public:
35 static const std::string NAME;
36
49 std::string_view label{eh.isRealData_ ? "DATA" : "MC"};
50 std::time_t t = eh.time_;
51 return s << "EventHeader {"
52 << " number: " << eh.eventNumber_
53 << ", run: " << eh.run_
54 << ", weight: " << eh.weight_
55 << ", " << label
56 << ", timestamp: " << std::asctime(std::localtime(&t))
57 << " }";
58 }
59
64 int getEventNumber() const { return eventNumber_; }
65
70 int number() const { return eventNumber_; }
71
76 int getRun() const { return run_; }
77
82 int run() const { return run_; }
83
88 double getWeight() const { return weight_; }
89
94 double weight() const { return weight_; }
95
100 bool isRealData() const { return isRealData_; }
101
106 void setEventNumber(int number) { this->eventNumber_ = number; }
107
112 void setRun(int run) { this->run_ = run; }
113
119 this->time_ = std::time(nullptr);
120 }
121
126 void setWeight(double weight) { this->weight_ = weight; }
127
129 void clear() {
130 weight_ = 1.;
131 isRealData_ = false;
132 time_ = 0.;
133 run_ = -1;
134 eventNumber_ = -1;
135 parameters_.clear();
136 }
137
145 template<typename ParameterType>
146 const ParameterType& get(const std::string& name) const {
147 return parameters_.get<ParameterType>(name);
148 }
149
157 template<typename ParameterType>
158 void set(const std::string& name, const ParameterType& val) {
159 parameters_.set(name,val);
160 }
161
162 private:
164 friend class fire::io::access;
165
175 template<typename DataSet>
176 void attach(DataSet& d) {
177 // make sure we use the name for this variable that the reader expects
178 d.attach(fire::io::constants::NUMBER_NAME,eventNumber_);
179 d.attach("run",run_);
180 d.attach("timestamp",time_);
181 d.attach("weight",weight_);
182 d.attach("isRealData",isRealData_);
183 d.attach("parameters",parameters_);
184 }
185
189 int eventNumber_{-1};
190
194 int run_{-1};
195
199 long int time_;
200
204 double weight_{1.0};
205
209 bool isRealData_{false};
210
216
217#ifdef fire_USE_ROOT
219 friend class fire::io::Data<ldmx::EventHeader>;
220
224 TTimeStamp timestamp_;
225
229 std::map<std::string,int> intParameters_;
230
234 std::map<std::string,float> floatParameters_;
235
239 std::map<std::string,std::string> stringParameters_;
240
246 ClassDef(EventHeader, 4);
247#endif
248};
249
250} // namespace fire
251
252#ifdef fire_USE_ROOT
253namespace fire {
254
256using EventHeader = ldmx::EventHeader;
257
258namespace io {
259
276template<>
277class Data<ldmx::EventHeader> : public AbstractData<ldmx::EventHeader> {
278 public:
288 explicit Data(const std::string& path, Reader* input_file, ldmx::EventHeader* eh);
289
295 void load(h5::Reader& r) final override;
296
306 void load(root::Reader& r) final override;
307
313 void save(Writer& w) final override;
314
319 void structure(Writer& w) final override;
320
331 template <typename MemberType>
332 void attach(const std::string& name, MemberType& m) {
333 members_.push_back(
334 std::make_unique<Data<MemberType>>(this->path_ + "/" + name, input_file_, &m));
335 }
336
337 private:
341 Reader* input_file_;
342}; // Data<ldmx::EventHeader>
343
344} // namespace fire
345} // namespace io
346#endif // fire_USE_ROOT
347#endif // FIRE_EVENTHEADER_H
Definitions for names of structures required by serialization methods.
T asctime(T... args)
Header information of an event such as event number and timestamp.
Definition: EventHeader.h:27
int run_
The run number.
Definition: EventHeader.h:194
double weight_
The event weight.
Definition: EventHeader.h:204
int number() const
Return the event number.
Definition: EventHeader.h:70
int run() const
Return the run number.
Definition: EventHeader.h:82
void setWeight(double weight)
Set the event weight.
Definition: EventHeader.h:126
long int time_
The event timestamp.
Definition: EventHeader.h:199
static const std::string NAME
Name of EventHeader branch.
Definition: EventHeader.h:35
void set(const std::string &name, const ParameterType &val)
set a parameter in storage
Definition: EventHeader.h:158
fire::io::ParameterStorage parameters_
Event parameters three types of parameters are allowed: int, float, string.
Definition: EventHeader.h:215
bool isRealData() const
Is this a real data event?
Definition: EventHeader.h:100
void setEventNumber(int number)
Set the event number.
Definition: EventHeader.h:106
bool isRealData_
Is this event real data?
Definition: EventHeader.h:209
void clear()
clear the event header, required by serialization technique
Definition: EventHeader.h:129
void setRun(int run)
Set the run number.
Definition: EventHeader.h:112
friend std::ostream & operator<<(std::ostream &s, const EventHeader &eh)
Stream an event header.
Definition: EventHeader.h:48
int getRun() const
Return the run number.
Definition: EventHeader.h:76
double weight() const
Get the event weight (default of 1.0).
Definition: EventHeader.h:94
int eventNumber_
The event number.
Definition: EventHeader.h:189
void attach(DataSet &d)
attach to the serializing h5::Data wrapper
Definition: EventHeader.h:176
int getEventNumber() const
Return the event number.
Definition: EventHeader.h:64
const ParameterType & get(const std::string &name) const
get a parameter from storage
Definition: EventHeader.h:146
void setTimestamp()
Set the timestamp.
Definition: EventHeader.h:118
double getWeight() const
Get the event weight (default of 1.0).
Definition: EventHeader.h:88
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
T localtime(T... args)
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)