|
HepMC Reference DocumentationHepMC |
00001 //-------------------------------------------------------------------------- 00002 #ifndef HEPMC_WEIGHT_CONTAINER_H 00003 #define HEPMC_WEIGHT_CONTAINER_H 00004 00006 // Matt.Dobbs@Cern.CH, November 2000, refer to: 00007 // M. Dobbs and J.B. Hansen, "The HepMC C++ Monte Carlo Event Record for 00008 // High Energy Physics", Computer Physics Communications (to be published). 00009 // 00010 // Container for the Weights associated with an event or vertex. 00011 // Basically just an interface to STL vector. 00013 00014 #include <iostream> 00015 #include <vector> 00016 00017 namespace HepMC { 00018 00020 00024 class WeightContainer { 00025 00026 public: 00028 WeightContainer( unsigned int n = 0, const double& value = 0. ); 00030 WeightContainer( const std::vector<double>& weights ); 00032 WeightContainer( const WeightContainer& in ); 00033 virtual ~WeightContainer(); 00034 00036 void swap( WeightContainer & other); 00038 WeightContainer& operator=( const WeightContainer& ); 00040 WeightContainer& operator=( const std::vector<double>& in ); 00041 00043 void print( std::ostream& ostr = std::cout ) const; 00044 00046 int size() const; 00048 bool empty() const; 00050 void push_back( const double& ); 00052 void pop_back(); 00054 void clear(); 00055 00057 double& operator[]( unsigned int n ); // unchecked access 00059 const double& operator[]( unsigned int n ) const; 00060 00062 double& front(); 00064 const double& front() const; 00066 double& back(); 00068 const double& back() const; 00069 00071 typedef std::vector<double>::iterator iterator; 00073 typedef std::vector<double>::const_iterator const_iterator; 00075 iterator begin(); 00077 iterator end(); 00079 const_iterator begin() const; 00081 const_iterator end() const; 00082 00083 private: 00084 std::vector<double> m_weights; 00085 }; 00086 00088 // INLINES // 00090 00091 inline WeightContainer::WeightContainer( unsigned int n, 00092 const double& value ) 00093 : m_weights(n,value) 00094 {} 00095 00096 inline WeightContainer::WeightContainer( const std::vector<double>& wgts ) 00097 : m_weights(wgts) 00098 {} 00099 00100 inline WeightContainer::WeightContainer( const WeightContainer& in ) 00101 : m_weights(in.m_weights) 00102 {} 00103 00104 inline WeightContainer::~WeightContainer() {} 00105 00106 inline void WeightContainer::swap( WeightContainer & other) 00107 { m_weights.swap( other.m_weights ); } 00108 00109 inline WeightContainer& WeightContainer::operator= 00110 ( const WeightContainer& in ) 00111 { 00113 WeightContainer tmp( in ); 00114 swap( tmp ); 00115 return *this; 00116 } 00117 00118 inline WeightContainer& WeightContainer::operator= 00119 ( const std::vector<double>& in ) { 00121 WeightContainer tmp( in ); 00122 swap( tmp ); 00123 return *this; 00124 } 00125 00126 inline void WeightContainer::print( std::ostream& ostr ) const 00127 { 00128 for ( const_iterator w = begin(); w != end(); ++w ) 00129 { 00130 ostr << *w << " "; 00131 } 00132 ostr << std::endl; 00133 } 00134 00135 inline int WeightContainer::size() const { return m_weights.size(); } 00136 00137 inline bool WeightContainer::empty() const { return m_weights.empty(); } 00138 00139 inline void WeightContainer::push_back( const double& value) 00140 { m_weights.push_back(value); } 00141 00142 inline void WeightContainer::pop_back() { m_weights.pop_back(); } 00143 00144 inline void WeightContainer::clear() { m_weights.clear(); } 00145 00146 inline double& WeightContainer::operator[]( unsigned int n ) 00147 { return m_weights[(int)n]; } 00148 00149 inline const double& WeightContainer::operator[]( unsigned int n ) const 00150 { return m_weights[(int)n]; } 00151 00152 inline double& WeightContainer::front() { return m_weights.front(); } 00153 00154 inline const double& WeightContainer::front() const 00155 { return m_weights.front(); } 00156 00157 inline double& WeightContainer::back() { return m_weights.back(); } 00158 00159 inline const double& WeightContainer::back() const 00160 { return m_weights.back(); } 00161 00162 inline WeightContainer::iterator WeightContainer::begin() 00163 { return m_weights.begin(); } 00164 00165 inline WeightContainer::iterator WeightContainer::end() 00166 { return m_weights.end(); } 00167 00168 inline WeightContainer::const_iterator WeightContainer::begin() const 00169 { return m_weights.begin(); } 00170 00171 inline WeightContainer::const_iterator WeightContainer::end() const 00172 { return m_weights.end(); } 00173 00174 } // HepMC 00175 00176 #endif // HEPMC_WEIGHT_CONTAINER_H 00177 //-------------------------------------------------------------------------- 00178 00179 00180
1.5.1-3