Fork me on GitHub

source: svn/trunk/Utilities/HepMC/interface/WeightContainer.h@ 476

Last change on this file since 476 was 349, checked in by severine ovyn, 16 years ago

first test

File size: 5.3 KB
Line 
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
17namespace HepMC {
18
19 //! Container for the Weights associated with an event or vertex.
20
21 ///
22 /// \class WeightContainer
23 /// Basically just an interface to STL vector.
24 class WeightContainer {
25
26 public:
27 /// default constructor
28 WeightContainer( unsigned int n = 0, const double& value = 0. );
29 /// construct from a vector of weights
30 WeightContainer( const std::vector<double>& weights );
31 /// copy
32 WeightContainer( const WeightContainer& in );
33 virtual ~WeightContainer();
34
35 /// swap
36 void swap( WeightContainer & other);
37 /// copy
38 WeightContainer& operator=( const WeightContainer& );
39 /// copy
40 WeightContainer& operator=( const std::vector<double>& in );
41
42 /// print weights
43 void print( std::ostream& ostr = std::cout ) const;
44
45 /// size of weight container
46 int size() const;
47 /// return true if weight container is empty
48 bool empty() const;
49 /// push onto weight container
50 void push_back( const double& );
51 /// pop from weight container
52 void pop_back();
53 /// clear the weight container
54 void clear();
55
56 /// access the weight container
57 double& operator[]( unsigned int n ); // unchecked access
58 /// access the weight container
59 const double& operator[]( unsigned int n ) const;
60
61 /// returns the first element
62 double& front();
63 /// returns the first element
64 const double& front() const;
65 /// returns the last element
66 double& back();
67 /// returns the last element
68 const double& back() const;
69
70 /// iterator for the weight container
71 typedef std::vector<double>::iterator iterator;
72 /// const iterator for the weight container
73 typedef std::vector<double>::const_iterator const_iterator;
74 /// begining of the weight container
75 iterator begin();
76 /// end of the weight container
77 iterator end();
78 /// begining of the weight container
79 const_iterator begin() const;
80 /// end of the weight container
81 const_iterator end() const;
82
83 private:
84 std::vector<double> m_weights;
85 };
86
87 ///////////////////////////
88 // INLINES //
89 ///////////////////////////
90
91 inline WeightContainer::WeightContainer( unsigned int n,
92 const double& value )
93 : m_weights(n,value)
94 {}
95
96 inline WeightContainer::WeightContainer( const std::vector<double>& wgts )
97 : m_weights(wgts)
98 {}
99
100 inline WeightContainer::WeightContainer( const WeightContainer& in )
101 : m_weights(in.m_weights)
102 {}
103
104 inline WeightContainer::~WeightContainer() {}
105
106 inline void WeightContainer::swap( WeightContainer & other)
107 { m_weights.swap( other.m_weights ); }
108
109 inline WeightContainer& WeightContainer::operator=
110 ( const WeightContainer& in ) {
111 /// best practices implementation
112 WeightContainer tmp( in );
113 swap( tmp );
114 return *this;
115 }
116
117 inline WeightContainer& WeightContainer::operator=
118 ( const std::vector<double>& in ) {
119 /// best practices implementation
120 WeightContainer tmp( in );
121 swap( tmp );
122 return *this;
123 }
124
125 inline void WeightContainer::print( std::ostream& ostr ) const
126 {
127 for ( const_iterator w = begin(); w != end(); ++w )
128 {
129 ostr << *w << " ";
130 }
131 ostr << std::endl;
132 }
133
134 inline int WeightContainer::size() const { return m_weights.size(); }
135
136 inline bool WeightContainer::empty() const { return m_weights.empty(); }
137
138 inline void WeightContainer::push_back( const double& value)
139 { m_weights.push_back(value); }
140
141 inline void WeightContainer::pop_back() { m_weights.pop_back(); }
142
143 inline void WeightContainer::clear() { m_weights.clear(); }
144
145 inline double& WeightContainer::operator[]( unsigned int n )
146 { return m_weights[(int)n]; }
147
148 inline const double& WeightContainer::operator[]( unsigned int n ) const
149 { return m_weights[(int)n]; }
150
151 inline double& WeightContainer::front() { return m_weights.front(); }
152
153 inline const double& WeightContainer::front() const
154 { return m_weights.front(); }
155
156 inline double& WeightContainer::back() { return m_weights.back(); }
157
158 inline const double& WeightContainer::back() const
159 { return m_weights.back(); }
160
161 inline WeightContainer::iterator WeightContainer::begin()
162 { return m_weights.begin(); }
163
164 inline WeightContainer::iterator WeightContainer::end()
165 { return m_weights.end(); }
166
167 inline WeightContainer::const_iterator WeightContainer::begin() const
168 { return m_weights.begin(); }
169
170 inline WeightContainer::const_iterator WeightContainer::end() const
171 { return m_weights.end(); }
172
173} // HepMC
174
175#endif // HEPMC_WEIGHT_CONTAINER_H
176//--------------------------------------------------------------------------
177
178
179
Note: See TracBrowser for help on using the repository browser.