CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Fit_Result_Vec.cc
Go to the documentation of this file.
1 //
2 //
3 // File: src/Fit_Result_Vec.cc
4 // Purpose: Hold a set of Fit_Result structures.
5 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
6 //
7 // CMSSW File : src/Fit_Result_Vec.cc
8 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0
9 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
10 //
11 
38 #include <cassert>
39 #include <ostream>
40 #include <algorithm>
41 
42 
43 using std::ostream;
44 using std::vector;
45 using std::lower_bound;
46 
47 
48 namespace hitfit {
49 
50 
52 //
53 // Purpose Constructor.
54 //
55 // Inputs:
56 // max_len - The maximum length of the vector.
57 //
58  : _max_len (max_len)
59 {
60  assert (max_len > 0);
61  _v.reserve (max_len + 1);
62 }
63 
64 
66 //
67 // Purpose: Copy constructor.
68 //
69 // Inputs:
70 // vec - The vector to copy.
71 //
72  : _v (vec._v),
73  _max_len (vec._max_len)
74 {
75  // Gotta increase the reference count on the contents.
76  for (std::vector<Fit_Result*>::size_type i=0; i < _v.size(); i++)
77  _v[i]->incref ();
78 }
79 
80 
82 //
83 // Purpose: Destructor.
84 //
85 {
86  for (std::vector<Fit_Result*>::size_type i=0; i < _v.size(); i++)
87  _v[i]->decref ();
88 }
89 
90 
92 //
93 // Purpose: Assignment.
94 //
95 // Inputs:
96 // vec - The vector to copy.
97 //
98 // Returns:
99 // This object.
100 //
101 {
102  for (std::vector<Fit_Result*>::size_type i=0; i < _v.size(); i++)
103  _v[i]->decref ();
104  _v = vec._v;
105  _max_len = vec._max_len;
106  for (std::vector<Fit_Result*>::size_type i=0; i < _v.size(); i++)
107  _v[i]->incref ();
108  return *this;
109 }
110 
111 
113 //
114 // Purpose: Get back the number of results in the vector.
115 //
116 // Returns:
117 // The number of results in the vector.
118 //
119 {
120  return _v.size ();
121 }
122 
123 
125 //
126 // Purpose: Get back the Ith result in the vector.
127 //
128 // Inputs:
129 // i - The index of the desired result.
130 //
131 // Returns:
132 // The Ith result.
133 //
134 {
135  assert (i < _v.size());
136  return *_v[i];
137 }
138 
139 
140 namespace {
141 
142 
143 struct Compare_Fitresptr
144 //
145 // Purpose: Helper for push().
146 //
147 {
148  bool operator() (const Fit_Result* a, const Fit_Result* b) const
149  {
150  return *a < *b;
151  }
152 };
153 
154 
155 } // unnamed namespace
156 
157 
159 //
160 // Purpose: Add a new result to the vector.
161 //
162 // Inputs:
163 // res - The result to add.
164 //
165 {
166  // Find where to add it.
167  vector<Fit_Result*>::iterator it = lower_bound (_v.begin(),
168  _v.end(),
169  res,
170  Compare_Fitresptr());
171 
172  // Insert it.
173  _v.insert (it, res);
174  res->incref ();
175 
176  // Knock off the guy at the end if we've exceeded our maximum size.
177  if (_v.size() > _max_len) {
178  _v.back()->decref ();
179  _v.erase (_v.end()-1);
180  }
181 }
182 
183 
192 std::ostream& operator<< (std::ostream& s, const Fit_Result_Vec& resvec)
193 //
194 // Purpose: Print the object to S.
195 //
196 // Inputs:
197 // s - The stream to which to write.
198 // resvec - The object to write.
199 //
200 // Returns:
201 // The stream S.
202 //
203 {
204  for (std::vector<Fit_Result*>::size_type i=0; i < resvec._v.size(); i++)
205  s << "Entry " << i << "\n" << *resvec._v[i];
206  return s;
207 }
208 
209 
210 } // namespace hitfit
int i
Definition: DBlmapReader.cc:9
Hold the result of one kinematic fit.
Definition: Fit_Result.h:53
void incref() const
Increment the reference count.
Fit_Result_Vec & operator=(const Fit_Result_Vec &vec)
Assignment operator.
~Fit_Result_Vec()
Destructor.
Hold the result of one kinematic fit.
Hold a list of pointers to a set of Fit_Result objects, resulting from different jet permutation with...
assert(m_qm.get())
const Fit_Result & operator[](std::vector< Fit_Result * >::size_type i) const
Return the i-th element of the Fit_Result objects in the vector.
uint16_t size_type
void push(Fit_Result *res)
Add a new Fit_Result to the list.
Fit_Result_Vec(std::vector< Fit_Result * >::size_type max_len)
Constructor.
double b
Definition: hdecay.h:120
string const
Definition: compareJSON.py:14
std::vector< Fit_Result * >::size_type _max_len
std::vector< Fit_Result * > _v
Holds pointers to a set of Fit_Result objects, resulting from different jet permutation with some con...
double a
Definition: hdecay.h:121
std::ostream & operator<<(std::ostream &s, const Constraint_Intermed &ci)
Output stream operator, print the content of this Constraint_Intermed to an output stream...
std::vector< Fit_Result * >::size_type size() const
Return the number of Fit_Result objects in the list.