File indexing completed on 2025-01-18 10:01:10
0001
0002 #ifndef HEPMC_WEIGHT_CONTAINER_H
0003 #define HEPMC_WEIGHT_CONTAINER_H
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include <iostream>
0017 #include <vector>
0018 #include <string>
0019 #include <map>
0020
0021 namespace HepMC {
0022
0023
0024
0025
0026
0027
0028
0029
0030 class WeightContainer {
0031 friend class GenEvent;
0032
0033 public:
0034
0035 typedef std::size_t size_type;
0036
0037 typedef std::vector<double>::iterator iterator;
0038
0039 typedef std::vector<double>::const_iterator const_iterator;
0040
0041
0042 explicit WeightContainer( size_type n = 0, double value = 0. );
0043
0044 WeightContainer( const std::vector<double>& weights );
0045
0046 WeightContainer( const WeightContainer& in );
0047 ~WeightContainer();
0048
0049
0050 void swap( WeightContainer & other);
0051
0052 WeightContainer& operator=( const WeightContainer& );
0053
0054 WeightContainer& operator=( const std::vector<double>& in );
0055
0056
0057 void print( std::ostream& ostr = std::cout ) const;
0058
0059 void write( std::ostream& ostr = std::cout ) const;
0060
0061
0062 size_type size() const;
0063
0064 bool empty() const;
0065
0066 void push_back( const double& );
0067
0068 void pop_back();
0069
0070 void clear();
0071
0072
0073 std::vector<double>& weights() { return m_weights; }
0074
0075 const std::vector<double>& weights() const { return m_weights; }
0076
0077
0078
0079 std::vector<std::string> weight_names() const;
0080
0081 bool has_key( const std::string& s ) const;
0082
0083
0084 double& operator[]( size_type n );
0085
0086 const double& operator[]( size_type n ) const;
0087
0088 double& operator[]( const std::string& s );
0089
0090 const double& operator[]( const std::string& s ) const;
0091
0092
0093 bool operator==( const WeightContainer & ) const;
0094
0095 bool operator!=( const WeightContainer & ) const;
0096
0097
0098 double& front();
0099
0100 const double& front() const;
0101
0102 double& back();
0103
0104 const double& back() const;
0105
0106
0107 iterator begin();
0108
0109 iterator end();
0110
0111 const_iterator begin() const;
0112
0113 const_iterator end() const;
0114
0115 private:
0116
0117
0118
0119
0120 typedef std::map<std::string,size_type>::iterator map_iterator;
0121
0122
0123 typedef std::map<std::string,size_type>::const_iterator const_map_iterator;
0124
0125
0126 map_iterator map_begin();
0127
0128
0129 map_iterator map_end();
0130
0131
0132 const_map_iterator map_begin() const;
0133
0134
0135 const_map_iterator map_end() const;
0136
0137
0138
0139 void set_default_names( size_type n );
0140
0141 private:
0142 std::vector<double> m_weights;
0143 std::map<std::string,size_type> m_names;
0144 };
0145
0146
0147
0148
0149
0150 inline WeightContainer::WeightContainer( const WeightContainer& in )
0151 : m_weights(in.m_weights), m_names(in.m_names)
0152 {}
0153
0154 inline WeightContainer::~WeightContainer() {}
0155
0156 inline void WeightContainer::swap( WeightContainer & other)
0157 {
0158 m_weights.swap( other.m_weights );
0159 m_names.swap( other.m_names );
0160 }
0161
0162 inline WeightContainer& WeightContainer::operator=
0163 ( const WeightContainer& in ) {
0164
0165 WeightContainer tmp( in );
0166 swap( tmp );
0167 return *this;
0168 }
0169
0170 inline WeightContainer& WeightContainer::operator=
0171 ( const std::vector<double>& in ) {
0172
0173 WeightContainer tmp( in );
0174 swap( tmp );
0175 return *this;
0176 }
0177
0178 inline WeightContainer::size_type WeightContainer::size() const { return m_weights.size(); }
0179
0180 inline bool WeightContainer::empty() const { return m_weights.empty(); }
0181
0182 inline void WeightContainer::clear()
0183 {
0184 m_weights.clear();
0185 m_names.clear();
0186 }
0187
0188 inline double& WeightContainer::operator[]( size_type n )
0189 { return m_weights[n]; }
0190
0191 inline const double& WeightContainer::operator[]( size_type n ) const
0192 { return m_weights[n]; }
0193
0194 inline double& WeightContainer::front() { return m_weights.front(); }
0195
0196 inline const double& WeightContainer::front() const
0197 { return m_weights.front(); }
0198
0199 inline double& WeightContainer::back() { return m_weights.back(); }
0200
0201 inline const double& WeightContainer::back() const
0202 { return m_weights.back(); }
0203
0204 inline WeightContainer::iterator WeightContainer::begin()
0205 { return m_weights.begin(); }
0206
0207 inline WeightContainer::iterator WeightContainer::end()
0208 { return m_weights.end(); }
0209
0210 inline WeightContainer::const_iterator WeightContainer::begin() const
0211 { return m_weights.begin(); }
0212
0213 inline WeightContainer::const_iterator WeightContainer::end() const
0214 { return m_weights.end(); }
0215
0216 inline WeightContainer::map_iterator WeightContainer::map_begin()
0217 { return m_names.begin(); }
0218
0219 inline WeightContainer::map_iterator WeightContainer::map_end()
0220 { return m_names.end(); }
0221
0222 inline WeightContainer::const_map_iterator WeightContainer::map_begin() const
0223 { return m_names.begin(); }
0224
0225 inline WeightContainer::const_map_iterator WeightContainer::map_end() const
0226 { return m_names.end(); }
0227
0228 }
0229
0230 #endif
0231