MARLEY (Model of Argon Reaction Low Energy Yields) v2.0.0
A Monte Carlo event generator for tens-of-MeV neutrino interactions
Loading...
Searching...
No Matches
GenRunInfo.h
1// -*- C++ -*-
2//
3// This file is part of HepMC
4// Copyright (C) 2014-2023 The HepMC collaboration (see AUTHORS for details)
5//
10#ifndef HEPMC3_GENRUNINFO_H
11#define HEPMC3_GENRUNINFO_H
12
13#if !defined(__CINT__)
14#include "HepMC3/Units.h"
15#include "HepMC3/Attribute.h"
16#include <mutex>
17#endif // __CINT__
18
19#ifdef HEPMC3_ROOTIO
20class TBuffer;
21#endif
22
23namespace HepMC3 {
25using namespace std;
26
27struct GenRunInfoData;
28
34
35public:
36
38 struct ToolInfo {
39
41 std::string name;
42
44 std::string version;
45
48 std::string description;
49 };
50
51public:
52
56 GenRunInfo(const GenRunInfo& r);
59
60#if !defined(__CINT__)
61
63 const std::vector<ToolInfo> & tools() const {
64 return m_tools;
65 }
66
67 std::vector<ToolInfo> & tools() {
68 return m_tools;
69 }
70
72 bool has_weight(const std::string& name) const {
73 return m_weight_indices.find(name) != m_weight_indices.end();
74 }
75
77 std::map<std::string, int> weight_indices() const {
78 return m_weight_indices;
79 }
80
83 int weight_index(const std::string& name) const {
84 std::map<std::string, int>::const_iterator it = m_weight_indices.find(name);
85 return it == m_weight_indices.end()? -1: it->second;
86 }
87
89 const std::vector<std::string> & weight_names() const {
90 return m_weight_names;
91 }
92
97 void set_weight_names(const std::vector<std::string> & names);
98
102 void add_attribute(const std::string &name,
103 const std::shared_ptr<Attribute> &att) {
104 std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
105 if ( att ) m_attributes[name] = att;
106 }
107
109 void remove_attribute(const std::string &name) {
110 std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
111 m_attributes.erase(name);
112 }
113
115 template<class T>
116 std::shared_ptr<T> attribute(const std::string &name) const;
117
119 std::string attribute_as_string(const std::string &name) const;
120
122 std::vector<std::string> attribute_names() const;
123
126 std::map< std::string, std::shared_ptr<Attribute> > attributes() const {
127 return m_attributes;
128 }
129
130
131#endif // __CINT__
132
135
137 void write_data(GenRunInfoData &data) const;
138
140 void read_data(const GenRunInfoData &data);
141
142#ifdef HEPMC3_ROOTIO
144 void Streamer(TBuffer &b);
146#endif
147
148private:
149
152
153#if !defined(__CINT__)
154
156 std::vector<ToolInfo> m_tools;
157
159 std::map<std::string, int> m_weight_indices;
160
162 std::vector<std::string> m_weight_names;
163
165 mutable std::map< std::string, std::shared_ptr<Attribute> > m_attributes;
166
168 mutable std::recursive_mutex m_lock_attributes;
170
171#endif // __CINT__
172};
173
174#if !defined(__CINT__)
175
176//
177// Template methods
178//
179
180template<class T>
181std::shared_ptr<T> GenRunInfo::attribute(const std::string &name) const {
182 std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
183 std::map< std::string, std::shared_ptr<Attribute> >::iterator i =
184 m_attributes.find(name);
185 if ( i == m_attributes.end() ) return std::shared_ptr<T>();
186
187 if ( !i->second->is_parsed() ) {
188
189 std::shared_ptr<T> att = std::make_shared<T>();
190 if ( att->from_string(i->second->unparsed_string()) &&
191 att->init(*this) ) {
192 // update map with new pointer
193 i->second = att;
194
195 return att;
196 }
197 else
198 return std::shared_ptr<T>();
199 }
200 else return std::dynamic_pointer_cast<T>(i->second);
201}
202
203/*
205template<typename T> std::map<std::string, T> weight_indices() const {
206 std::map<std::string, T> ret;
207 ret.insert(m_weight_indices.begin(),m_weight_indices.end());
208 return ret;
209}
210*/
211
212#endif // __CINT__
213
214} // namespace HepMC3
215
216#endif
Stores run-related information.
Definition GenRunInfo.h:33
std::map< std::string, int > weight_indices() const
Returns a copy of indices map.
Definition GenRunInfo.h:77
int weight_index(const std::string &name) const
Return the index corresponding to a weight name.
Definition GenRunInfo.h:83
void remove_attribute(const std::string &name)
Remove attribute.
Definition GenRunInfo.h:109
std::string version
The version of the tool.
Definition GenRunInfo.h:44
void add_attribute(const std::string &name, const std::shared_ptr< Attribute > &att)
add an attribute This will overwrite existing attribute if an attribute with the same name is present
Definition GenRunInfo.h:102
void read_data(const GenRunInfoData &data)
Fill GenRunInfo based on GenRunInfoData.
std::vector< ToolInfo > & tools()
The vector of tools used to produce this run.
Definition GenRunInfo.h:67
bool has_weight(const std::string &name) const
Check if a weight name is present.
Definition GenRunInfo.h:72
void set_weight_names(const std::vector< std::string > &names)
Set the names of the weights in this run.
GenRunInfo & operator=(const GenRunInfo &r)
Assignmet.
const std::vector< std::string > & weight_names() const
Get the vector of weight names.
Definition GenRunInfo.h:89
std::map< std::string, std::shared_ptr< Attribute > > attributes() const
Get a copy of the list of attributes.
Definition GenRunInfo.h:126
std::string description
Other information about how the tool was used in the run.
Definition GenRunInfo.h:48
const std::vector< ToolInfo > & tools() const
The vector of tools used to produce this run.
Definition GenRunInfo.h:63
GenRunInfo()
Default constructor.
Definition GenRunInfo.h:54
std::string attribute_as_string(const std::string &name) const
Get attribute of any type as string.
std::string name
The name of the tool.
Definition GenRunInfo.h:41
std::shared_ptr< T > attribute(const std::string &name) const
Get attribute of type T.
Definition GenRunInfo.h:181
void write_data(GenRunInfoData &data) const
Fill GenRunInfoData object.
std::vector< std::string > attribute_names() const
Get list of attribute names.
Interrnal struct for keeping track of tools.
Definition GenRunInfo.h:38
Stores serializable run information.