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 ) { 00112 WeightContainer tmp( in ); 00113 swap( tmp ); 00114 return *this; 00115 } 00116 00117 inline WeightContainer& WeightContainer::operator= 00118 ( const std::vector<double>& in ) { 00120 WeightContainer tmp( in ); 00121 swap( tmp ); 00122 return *this; 00123 } 00124 00125 inline void WeightContainer::print( std::ostream& ostr ) const 00126 { 00127 for ( const_iterator w = begin(); w != end(); ++w ) 00128 { 00129 ostr << *w << " "; 00130 } 00131 ostr << std::endl; 00132 } 00133 00134 inline int WeightContainer::size() const { return m_weights.size(); } 00135 00136 inline bool WeightContainer::empty() const { return m_weights.empty(); } 00137 00138 inline void WeightContainer::push_back( const double& value) 00139 { m_weights.push_back(value); } 00140 00141 inline void WeightContainer::pop_back() { m_weights.pop_back(); } 00142 00143 inline void WeightContainer::clear() { m_weights.clear(); } 00144 00145 inline double& WeightContainer::operator[]( unsigned int n ) 00146 { return m_weights[(int)n]; } 00147 00148 inline const double& WeightContainer::operator[]( unsigned int n ) const 00149 { return m_weights[(int)n]; } 00150 00151 inline double& WeightContainer::front() { return m_weights.front(); } 00152 00153 inline const double& WeightContainer::front() const 00154 { return m_weights.front(); } 00155 00156 inline double& WeightContainer::back() { return m_weights.back(); } 00157 00158 inline const double& WeightContainer::back() const 00159 { return m_weights.back(); } 00160 00161 inline WeightContainer::iterator WeightContainer::begin() 00162 { return m_weights.begin(); } 00163 00164 inline WeightContainer::iterator WeightContainer::end() 00165 { return m_weights.end(); } 00166 00167 inline WeightContainer::const_iterator WeightContainer::begin() const 00168 { return m_weights.begin(); } 00169 00170 inline WeightContainer::const_iterator WeightContainer::end() const 00171 { return m_weights.end(); } 00172 00173 } // HepMC 00174 00175 #endif // HEPMC_WEIGHT_CONTAINER_H 00176 //-------------------------------------------------------------------------- 00177 00178 00179