File indexing completed on 2025-01-18 10:01:12
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef HEPMC3_GENRUNINFO_H
0011 #define HEPMC3_GENRUNINFO_H
0012
0013 #if !defined(__CINT__)
0014 #include "HepMC3/Units.h"
0015 #include "HepMC3/Attribute.h"
0016 #include <mutex>
0017 #endif
0018
0019 #ifdef HEPMC3_ROOTIO
0020 class TBuffer;
0021 #endif
0022
0023 namespace HepMC3 {
0024
0025 using namespace std;
0026
0027 struct GenRunInfoData;
0028
0029
0030
0031
0032
0033 class GenRunInfo {
0034
0035 public:
0036
0037
0038 struct ToolInfo {
0039
0040
0041 std::string name;
0042
0043
0044 std::string version;
0045
0046
0047
0048 std::string description;
0049 };
0050
0051 public:
0052
0053
0054 GenRunInfo() {}
0055
0056 GenRunInfo(const GenRunInfo& r);
0057
0058 GenRunInfo& operator=(const GenRunInfo& r);
0059
0060 #if !defined(__CINT__)
0061
0062
0063 const std::vector<ToolInfo> & tools() const {
0064 return m_tools;
0065 }
0066
0067 std::vector<ToolInfo> & tools() {
0068 return m_tools;
0069 }
0070
0071
0072 bool has_weight(const std::string& name) const {
0073 return m_weight_indices.find(name) != m_weight_indices.end();
0074 }
0075
0076
0077 std::map<std::string, int> weight_indices() const {
0078 return m_weight_indices;
0079 }
0080
0081
0082
0083 int weight_index(const std::string& name) const {
0084 std::map<std::string, int>::const_iterator it = m_weight_indices.find(name);
0085 return it == m_weight_indices.end()? -1: it->second;
0086 }
0087
0088
0089 const std::vector<std::string> & weight_names() const {
0090 return m_weight_names;
0091 }
0092
0093
0094
0095
0096
0097 void set_weight_names(const std::vector<std::string> & names);
0098
0099
0100
0101
0102 void add_attribute(const std::string &name,
0103 const std::shared_ptr<Attribute> &att) {
0104 std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
0105 if ( att ) m_attributes[name] = att;
0106 }
0107
0108
0109 void remove_attribute(const std::string &name) {
0110 std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
0111 m_attributes.erase(name);
0112 }
0113
0114
0115 template<class T>
0116 std::shared_ptr<T> attribute(const std::string &name) const;
0117
0118
0119 std::string attribute_as_string(const std::string &name) const;
0120
0121
0122 std::vector<std::string> attribute_names() const;
0123
0124
0125
0126 std::map< std::string, std::shared_ptr<Attribute> > attributes() const {
0127 return m_attributes;
0128 }
0129
0130
0131 #endif
0132
0133
0134
0135
0136
0137 void write_data(GenRunInfoData &data) const;
0138
0139
0140 void read_data(const GenRunInfoData &data);
0141
0142 #ifdef HEPMC3_ROOTIO
0143
0144 void Streamer(TBuffer &b);
0145
0146 #endif
0147
0148 private:
0149
0150
0151
0152
0153 #if !defined(__CINT__)
0154
0155
0156 std::vector<ToolInfo> m_tools;
0157
0158
0159 std::map<std::string, int> m_weight_indices;
0160
0161
0162 std::vector<std::string> m_weight_names;
0163
0164
0165 mutable std::map< std::string, std::shared_ptr<Attribute> > m_attributes;
0166
0167
0168 mutable std::recursive_mutex m_lock_attributes;
0169
0170
0171 #endif
0172 };
0173
0174 #if !defined(__CINT__)
0175
0176
0177
0178
0179
0180 template<class T>
0181 std::shared_ptr<T> GenRunInfo::attribute(const std::string &name) const {
0182 std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
0183 std::map< std::string, std::shared_ptr<Attribute> >::iterator i =
0184 m_attributes.find(name);
0185 if ( i == m_attributes.end() ) return std::shared_ptr<T>();
0186
0187 if ( !i->second->is_parsed() ) {
0188
0189 std::shared_ptr<T> att = std::make_shared<T>();
0190 if ( att->from_string(i->second->unparsed_string()) &&
0191 att->init(*this) ) {
0192
0193 i->second = att;
0194
0195 return att;
0196 }
0197 else
0198 return std::shared_ptr<T>();
0199 }
0200 else return std::dynamic_pointer_cast<T>(i->second);
0201 }
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212 #endif
0213
0214 }
0215
0216 #endif