File indexing completed on 2024-04-06 12:31:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #include "TopQuarkAnalysis/TopHitFit/interface/Fit_Result_Vec.h"
0037 #include "TopQuarkAnalysis/TopHitFit/interface/Fit_Result.h"
0038 #include <cassert>
0039 #include <ostream>
0040 #include <algorithm>
0041
0042 using std::lower_bound;
0043 using std::ostream;
0044 using std::vector;
0045
0046 namespace hitfit {
0047
0048 Fit_Result_Vec::Fit_Result_Vec(std::vector<std::shared_ptr<Fit_Result>>::size_type max_len)
0049
0050
0051
0052
0053
0054
0055 : _max_len(max_len) {
0056 assert(max_len > 0);
0057 _v.reserve(max_len + 1);
0058 }
0059
0060 Fit_Result_Vec::Fit_Result_Vec(const Fit_Result_Vec& vec)
0061
0062
0063
0064
0065
0066
0067 : _v(vec._v), _max_len(vec._max_len) {}
0068
0069 Fit_Result_Vec::~Fit_Result_Vec()
0070
0071
0072
0073 {}
0074
0075 Fit_Result_Vec& Fit_Result_Vec::operator=(const Fit_Result_Vec& vec)
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085 {
0086 _v = vec._v;
0087 _max_len = vec._max_len;
0088 return *this;
0089 }
0090
0091 std::vector<std::shared_ptr<Fit_Result>>::size_type Fit_Result_Vec::size() const
0092
0093
0094
0095
0096
0097
0098 {
0099 return _v.size();
0100 }
0101
0102 const Fit_Result& Fit_Result_Vec::operator[](std::vector<std::shared_ptr<Fit_Result>>::size_type i) const
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112 {
0113 assert(i < _v.size());
0114 return *_v[i];
0115 }
0116
0117 namespace {
0118
0119 struct Compare_Fitresptr
0120
0121
0122
0123 {
0124 bool operator()(std::shared_ptr<const Fit_Result> a, std::shared_ptr<const Fit_Result> b) const {
0125 return *a < *b;
0126 }
0127 };
0128
0129 }
0130
0131 void Fit_Result_Vec::push(std::shared_ptr<Fit_Result> res)
0132
0133
0134
0135
0136
0137
0138 {
0139
0140 vector<std::shared_ptr<Fit_Result>>::iterator it = lower_bound(_v.begin(), _v.end(), res, Compare_Fitresptr());
0141
0142
0143 _v.insert(it, res);
0144
0145
0146 if (_v.size() > _max_len) {
0147 _v.erase(_v.end() - 1);
0148 }
0149 }
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159 std::ostream& operator<<(std::ostream& s, const Fit_Result_Vec& resvec)
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170 {
0171 for (std::vector<std::shared_ptr<Fit_Result>>::size_type i = 0; i < resvec._v.size(); i++)
0172 s << "Entry " << i << "\n" << *resvec._v[i];
0173 return s;
0174 }
0175
0176 }