CMS 3D CMS Logo

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 using std::lower_bound;
43 using std::ostream;
44 using std::vector;
45 
46 namespace hitfit {
47 
48  Fit_Result_Vec::Fit_Result_Vec(std::vector<std::shared_ptr<Fit_Result>>::size_type max_len)
49  //
50  // Purpose Constructor.
51  //
52  // Inputs:
53  // max_len - The maximum length of the vector.
54  //
55  : _max_len(max_len) {
56  assert(max_len > 0);
57  _v.reserve(max_len + 1);
58  }
59 
61  //
62  // Purpose: Copy constructor.
63  //
64  // Inputs:
65  // vec - The vector to copy.
66  //
67  : _v(vec._v), _max_len(vec._max_len) {}
68 
70  //
71  // Purpose: Destructor.
72  //
73  {}
74 
76  //
77  // Purpose: Assignment.
78  //
79  // Inputs:
80  // vec - The vector to copy.
81  //
82  // Returns:
83  // This object.
84  //
85  {
86  _v = vec._v;
87  _max_len = vec._max_len;
88  return *this;
89  }
90 
91  std::vector<std::shared_ptr<Fit_Result>>::size_type Fit_Result_Vec::size() const
92  //
93  // Purpose: Get back the number of results in the vector.
94  //
95  // Returns:
96  // The number of results in the vector.
97  //
98  {
99  return _v.size();
100  }
101 
102  const Fit_Result& Fit_Result_Vec::operator[](std::vector<std::shared_ptr<Fit_Result>>::size_type i) const
103  //
104  // Purpose: Get back the Ith result in the vector.
105  //
106  // Inputs:
107  // i - The index of the desired result.
108  //
109  // Returns:
110  // The Ith result.
111  //
112  {
113  assert(i < _v.size());
114  return *_v[i];
115  }
116 
117  namespace {
118 
119  struct Compare_Fitresptr
120  //
121  // Purpose: Helper for push().
122  //
123  {
124  bool operator()(std::shared_ptr<const Fit_Result> a, std::shared_ptr<const Fit_Result> b) const {
125  return *a < *b;
126  }
127  };
128 
129  } // unnamed namespace
130 
131  void Fit_Result_Vec::push(std::shared_ptr<Fit_Result> res)
132  //
133  // Purpose: Add a new result to the vector.
134  //
135  // Inputs:
136  // res - The result to add.
137  //
138  {
139  // Find where to add it.
140  vector<std::shared_ptr<Fit_Result>>::iterator it = lower_bound(_v.begin(), _v.end(), res, Compare_Fitresptr());
141 
142  // Insert it.
143  _v.insert(it, res);
144 
145  // Knock off the guy at the end if we've exceeded our maximum size.
146  if (_v.size() > _max_len) {
147  _v.erase(_v.end() - 1);
148  }
149  }
150 
159  std::ostream& operator<<(std::ostream& s, const Fit_Result_Vec& resvec)
160  //
161  // Purpose: Print the object to S.
162  //
163  // Inputs:
164  // s - The stream to which to write.
165  // resvec - The object to write.
166  //
167  // Returns:
168  // The stream S.
169  //
170  {
171  for (std::vector<std::shared_ptr<Fit_Result>>::size_type i = 0; i < resvec._v.size(); i++)
172  s << "Entry " << i << "\n" << *resvec._v[i];
173  return s;
174  }
175 
176 } // namespace hitfit
mps_fire.i
i
Definition: mps_fire.py:355
hitfit
Definition: Base_Constrainer.h:43
cms::cuda::assert
assert(be >=bs)
hitfit::Fit_Result
Hold the result of one kinematic fit.
Definition: Fit_Result.h:50
Fit_Result.h
Hold the result of one kinematic fit.
hitfit::Fit_Result_Vec::~Fit_Result_Vec
~Fit_Result_Vec()
Destructor.
Definition: Fit_Result_Vec.cc:69
hitfit::Fit_Result_Vec
Holds pointers to a set of Fit_Result objects, resulting from different jet permutation with some con...
Definition: Fit_Result_Vec.h:67
hitfit::Fit_Result_Vec::operator[]
const Fit_Result & operator[](std::vector< std::shared_ptr< Fit_Result >>::size_type i) const
Return the i-th element of the Fit_Result objects in the vector.
Definition: Fit_Result_Vec.cc:102
watchdog.const
const
Definition: watchdog.py:83
alignCSCRings.s
s
Definition: alignCSCRings.py:92
hitfit::Fit_Result_Vec::Fit_Result_Vec
Fit_Result_Vec(std::vector< std::shared_ptr< Fit_Result >>::size_type max_len)
Constructor.
Definition: Fit_Result_Vec.cc:48
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
hitfit::Fit_Result_Vec::push
void push(std::shared_ptr< Fit_Result > res)
Add a new Fit_Result to the list.
Definition: Fit_Result_Vec.cc:131
hitfit::operator<<
std::ostream & operator<<(std::ostream &s, const Constraint_Intermed &ci)
Output stream operator, print the content of this Constraint_Intermed to an output stream.
Definition: Constraint_Intermed.cc:268
b
double b
Definition: hdecay.h:118
cuda_std::lower_bound
__host__ constexpr __device__ RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
Definition: cudastdAlgorithm.h:27
Fit_Result_Vec.h
Hold a list of pointers to a set of Fit_Result objects, resulting from different jet permutation with...
a
double a
Definition: hdecay.h:119
hitfit::Fit_Result_Vec::_v
std::vector< std::shared_ptr< Fit_Result > > _v
Definition: Fit_Result_Vec.h:133
res
Definition: Electron.h:6
hitfit::Fit_Result_Vec::size
std::vector< std::shared_ptr< Fit_Result > >::size_type size() const
Return the number of Fit_Result objects in the list.
Definition: Fit_Result_Vec.cc:91
hitfit::Fit_Result_Vec::operator=
Fit_Result_Vec & operator=(const Fit_Result_Vec &vec)
Assignment operator.
Definition: Fit_Result_Vec.cc:75
hitfit::Fit_Result_Vec::_max_len
std::vector< std::shared_ptr< Fit_Result > >::size_type _max_len
Definition: Fit_Result_Vec.h:138