hepmc - Blame information for rev 65

Subversion Repositories:
Rev:
Rev Author Line No. Line
2 garren 1 //--------------------------------------------------------------------------
2 #ifndef HEPMC_WEIGHT_CONTAINER_H
3 #define HEPMC_WEIGHT_CONTAINER_H
4  
5 //////////////////////////////////////////////////////////////////////////
6 // Matt.Dobbs@Cern.CH, November 2000, refer to:
7 // M. Dobbs and J.B. Hansen, "The HepMC C++ Monte Carlo Event Record for
8 // High Energy Physics", Computer Physics Communications (to be published).
9 //
10 // Container for the Weights associated with an event or vertex.
11 // Basically just an interface to STL vector.
12 //////////////////////////////////////////////////////////////////////////
13  
14 #include <iostream>
15 #include <vector>
16  
17 namespace HepMC {
18  
65 garren 19     //! Container for the Weights associated with an event or vertex.
20  
21     ///
22     /// \class  WeightContainer
23     /// Basically just an interface to STL vector.
2 garren 24     class WeightContainer {
25  
26     public:
65 garren 27         /// default constructor
2 garren 28         WeightContainer( unsigned int n = 0, const double& value = 0. );
65 garren 29         /// construct from a vector of weights
2 garren 30         WeightContainer( const std::vector<double>& weights );
65 garren 31         /// copy
2 garren 32         WeightContainer( const WeightContainer& in );
33         virtual ~WeightContainer();
34  
65 garren 35         /// copy
2 garren 36         WeightContainer& operator=( const WeightContainer& );
65 garren 37         /// copy
2 garren 38         WeightContainer& operator=( const std::vector<double>& in );
39  
65 garren 40         /// print weights
2 garren 41         void          print( std::ostream& ostr = std::cout ) const;
42  
65 garren 43         /// size of weight container
2 garren 44         int           size() const;
65 garren 45         /// return true if weight container is empty
2 garren 46         bool          empty() const;
65 garren 47         /// push onto weight container
2 garren 48         void          push_back( const double& );
65 garren 49         /// pop from weight container
2 garren 50         void          pop_back();
65 garren 51         /// clear the weight container
2 garren 52         void          clear();
53  
65 garren 54         /// access the weight container
2 garren 55         double&       operator[]( unsigned int n );  // unchecked access
65 garren 56         /// access the weight container
2 garren 57         const double& operator[]( unsigned int n ) const;
58  
65 garren 59         /// returns the first element
60         double&       front();
61         /// returns the first element
2 garren 62         const double& front() const;  
65 garren 63         /// returns the last element
64         double&       back();
65         /// returns the last element
2 garren 66         const double& back() const;
67  
65 garren 68         /// iterator for the weight container
2 garren 69         typedef std::vector<double>::iterator iterator;
65 garren 70         /// const iterator for the weight container
2 garren 71         typedef std::vector<double>::const_iterator const_iterator;
65 garren 72         /// begining of the weight container
2 garren 73         iterator            begin();
65 garren 74         /// end of the weight container
2 garren 75         iterator            end();
65 garren 76         /// begining of the weight container
2 garren 77         const_iterator      begin() const;
65 garren 78         /// end of the weight container
2 garren 79         const_iterator      end() const;
80  
81     private:
82         std::vector<double>  m_weights;
83     };
84  
85     ///////////////////////////
86     // INLINES               //
87     ///////////////////////////
88  
89     inline WeightContainer::WeightContainer( unsigned int n,
90                                              const double& value )
91         : m_weights(n,value)
92     {}
93  
94     inline WeightContainer::WeightContainer( const std::vector<double>& wgts )
95         : m_weights(wgts)
96     {}
97  
98     inline WeightContainer::WeightContainer( const WeightContainer& in )
99         : m_weights(in.m_weights)
100     {}
101  
102     inline WeightContainer::~WeightContainer() {}
103  
104     inline WeightContainer& WeightContainer::operator=
105     ( const WeightContainer& in ) {
106         m_weights = in.m_weights;
107         return *this;
108     }
109  
110     inline WeightContainer& WeightContainer::operator=
111     ( const std::vector<double>& in ) {
112         m_weights = in;
113         return *this;
114     }
115  
116     inline void WeightContainer::print( std::ostream& ostr ) const
117     {
118         for ( const_iterator w = begin(); w != end(); ++w )
119         {
120             ostr << *w << " ";
121         }
122         ostr << std::endl;
123     }
124  
125     inline int WeightContainer::size() const { return m_weights.size(); }
126  
127     inline bool WeightContainer::empty() const { return m_weights.empty(); }
128  
129     inline void WeightContainer::push_back( const double& value)
130     { m_weights.push_back(value); }
131  
132     inline void WeightContainer::pop_back() { m_weights.pop_back(); }
133  
134     inline void WeightContainer::clear() { m_weights.clear(); }
135  
136     inline double& WeightContainer::operator[]( unsigned int n )
137     { return m_weights[(int)n]; }
138  
139     inline const double& WeightContainer::operator[]( unsigned int n ) const
140     { return m_weights[(int)n]; }
141  
142     inline double& WeightContainer::front() { return m_weights.front(); }
143  
144     inline const double& WeightContainer::front() const
145     { return m_weights.front(); }
146  
147     inline double& WeightContainer::back() { return m_weights.back(); }
148  
149     inline const double& WeightContainer::back() const
150     { return m_weights.back(); }
151  
152     inline WeightContainer::iterator WeightContainer::begin()
153     { return m_weights.begin(); }
154  
155     inline WeightContainer::iterator WeightContainer::end()
156     { return m_weights.end(); }
157  
158     inline WeightContainer::const_iterator WeightContainer::begin() const
159     { return m_weights.begin(); }
160  
161     inline WeightContainer::const_iterator WeightContainer::end() const
162     { return m_weights.end(); }
163  
164 } // HepMC
165  
166 #endif  // HEPMC_WEIGHT_CONTAINER_H
167 //--------------------------------------------------------------------------
168  
169  
170