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 // $Id: Fit_Result_Vec.cc,v 1.1 2011/05/26 09:47:00 mseidel Exp $
3 //
4 // File: src/Fit_Result_Vec.cc
5 // Purpose: Hold a set of Fit_Result structures.
6 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
7 //
8 // CMSSW File : src/Fit_Result_Vec.cc
9 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0
10 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
11 //
12 
39 #include <cassert>
40 #include <ostream>
41 #include <algorithm>
42 
43 
44 using std::ostream;
45 using std::vector;
46 using std::lower_bound;
47 
48 
49 namespace hitfit {
50 
51 
53 //
54 // Purpose Constructor.
55 //
56 // Inputs:
57 // max_len - The maximum length of the vector.
58 //
59  : _max_len (max_len)
60 {
61  assert (max_len > 0);
62  _v.reserve (max_len + 1);
63 }
64 
65 
67 //
68 // Purpose: Copy constructor.
69 //
70 // Inputs:
71 // vec - The vector to copy.
72 //
73  : _v (vec._v),
74  _max_len (vec._max_len)
75 {
76  // Gotta increase the reference count on the contents.
77  for (std::vector<Fit_Result*>::size_type i=0; i < _v.size(); i++)
78  _v[i]->incref ();
79 }
80 
81 
83 //
84 // Purpose: Destructor.
85 //
86 {
87  for (std::vector<Fit_Result*>::size_type i=0; i < _v.size(); i++)
88  _v[i]->decref ();
89 }
90 
91 
93 //
94 // Purpose: Assignment.
95 //
96 // Inputs:
97 // vec - The vector to copy.
98 //
99 // Returns:
100 // This object.
101 //
102 {
103  for (std::vector<Fit_Result*>::size_type i=0; i < _v.size(); i++)
104  _v[i]->decref ();
105  _v = vec._v;
106  _max_len = vec._max_len;
107  for (std::vector<Fit_Result*>::size_type i=0; i < _v.size(); i++)
108  _v[i]->incref ();
109  return *this;
110 }
111 
112 
114 //
115 // Purpose: Get back the number of results in the vector.
116 //
117 // Returns:
118 // The number of results in the vector.
119 //
120 {
121  return _v.size ();
122 }
123 
124 
126 //
127 // Purpose: Get back the Ith result in the vector.
128 //
129 // Inputs:
130 // i - The index of the desired result.
131 //
132 // Returns:
133 // The Ith result.
134 //
135 {
136  assert (i < _v.size());
137  return *_v[i];
138 }
139 
140 
141 namespace {
142 
143 
144 struct Compare_Fitresptr
145 //
146 // Purpose: Helper for push().
147 //
148 {
149  bool operator() (const Fit_Result* a, const Fit_Result* b) const
150  {
151  return *a < *b;
152  }
153 };
154 
155 
156 } // unnamed namespace
157 
158 
160 //
161 // Purpose: Add a new result to the vector.
162 //
163 // Inputs:
164 // res - The result to add.
165 //
166 {
167  // Find where to add it.
168  vector<Fit_Result*>::iterator it = lower_bound (_v.begin(),
169  _v.end(),
170  res,
171  Compare_Fitresptr());
172 
173  // Insert it.
174  _v.insert (it, res);
175  res->incref ();
176 
177  // Knock off the guy at the end if we've exceeded our maximum size.
178  if (_v.size() > _max_len) {
179  _v.back()->decref ();
180  _v.erase (_v.end()-1);
181  }
182 }
183 
184 
193 std::ostream& operator<< (std::ostream& s, const Fit_Result_Vec& resvec)
194 //
195 // Purpose: Print the object to S.
196 //
197 // Inputs:
198 // s - The stream to which to write.
199 // resvec - The object to write.
200 //
201 // Returns:
202 // The stream S.
203 //
204 {
205  for (std::vector<Fit_Result*>::size_type i=0; i < resvec._v.size(); i++)
206  s << "Entry " << i << "\n" << *resvec._v[i];
207  return s;
208 }
209 
210 
211 } // namespace hitfit
int i
Definition: DBlmapReader.cc:9
Hold the result of one kinematic fit.
Definition: Fit_Result.h:54
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...
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.