CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LumiDetails.cc
Go to the documentation of this file.
3 
4 #include <cassert>
5 #include <iomanip>
6 #include <ostream>
7 
8 std::vector<std::string> LumiDetails::m_algoNames;
9 
11  m_lumiVersion("-1"),
12  m_algoToFirstIndex(kMaxNumAlgos + 1, 0),
13  m_allValues(),
14  m_allErrors(),
15  m_allQualities(),
16  m_beam1Intensities(),
17  m_beam2Intensities()
18 {
19 }
20 
21 LumiDetails::LumiDetails(std::string const& lumiVersion) :
22  m_lumiVersion(lumiVersion),
23  m_algoToFirstIndex(kMaxNumAlgos + 1, 0),
24  m_allValues(),
25  m_allErrors(),
26  m_allQualities(),
27  m_beam1Intensities(),
28  m_beam2Intensities()
29 {
30 }
31 
33 }
34 
35 void
36 LumiDetails::setLumiVersion(std::string const& lumiVersion){
38 }
39 
40 std::string const&
42  return m_lumiVersion;
43 }
44 
45 bool
47  return (m_lumiVersion != "-1");
48 }
49 
50 void
52  std::vector<float> const& values,
53  std::vector<float> const& errors,
54  std::vector<short> const& qualities) {
55  checkAlgo(algo);
56  if (values.size() != errors.size() ||
57  values.size() != qualities.size() ||
60  << "Illegal input values passed to LumiDetails::fill.\n"
61  << "The current implementation of LumiDetails only allows filling\n"
62  << "vectors for each algorithm once and the input vectors must\n"
63  << "all be the same size.\n";
64  }
65  m_allValues.insert(m_allValues.begin() + m_algoToFirstIndex[algo], values.begin(), values.end());
66  m_allErrors.insert(m_allErrors.begin() + m_algoToFirstIndex[algo], errors.begin(), errors.end());
67  m_allQualities.insert(m_allQualities.begin() + m_algoToFirstIndex[algo], qualities.begin(), qualities.end());
68  for (unsigned i = algo + 1U; i <= kMaxNumAlgos; ++i) {
69  m_algoToFirstIndex[i] += values.size();
70  }
71 }
72 
73 void
74 LumiDetails::fillBeamIntensities(std::vector<float> const& beam1Intensities,
75  std::vector<float> const& beam2Intensities) {
76  m_beam1Intensities = beam1Intensities;
77  m_beam2Intensities = beam2Intensities;
78 }
79 
80 float
81 LumiDetails::lumiValue(AlgoType algo, unsigned int bx) const {
82  checkAlgoAndBX(algo, bx);
83  return m_allValues[m_algoToFirstIndex[algo] + bx];
84 }
85 
86 float
87 LumiDetails::lumiError(AlgoType algo, unsigned int bx) const {
88  checkAlgoAndBX(algo, bx);
89  return m_allErrors[m_algoToFirstIndex[algo] + bx];
90 }
91 
92 short
93 LumiDetails::lumiQuality(AlgoType algo, unsigned int bx) const {
94  checkAlgoAndBX(algo, bx);
96 }
97 
98 float
99 LumiDetails::lumiBeam1Intensity(unsigned int bx) const {
100  return m_beam1Intensities.at(bx);
101 }
102 
103 float
104 LumiDetails::lumiBeam2Intensity(unsigned int bx) const {
105  return m_beam2Intensities.at(bx);
106 }
107 
110  checkAlgo(algo);
111  return ValueRange(m_allValues.begin() + m_algoToFirstIndex[algo],
112  m_allValues.begin() + m_algoToFirstIndex[algo + 1U]);
113 }
114 
117  checkAlgo(algo);
118  return ErrorRange(m_allErrors.begin() + m_algoToFirstIndex[algo],
119  m_allErrors.begin() + m_algoToFirstIndex[algo + 1U]);
120 }
121 
124  checkAlgo(algo);
126  m_allQualities.begin() + m_algoToFirstIndex[algo + 1U]);
127 }
128 
129 std::vector<float> const&
131  return m_beam1Intensities;
132 }
133 
134 std::vector<float> const&
136  return m_beam2Intensities;
137 }
138 
139 std::vector<std::string> const&
141  if (m_algoNames.size() != kMaxNumAlgos) {
142  assert(m_algoNames.size() == 0U);
143  // If in the future additional algorithm names are added,
144  // it is important that they be added at the end of the list.
145  // The Algos enum in LumiDetails.h also would need to be
146  // updated to keep the list of names in sync.
147  m_algoNames.push_back(std::string("OCC1"));
148  m_algoNames.push_back(std::string("OCC2"));
149  m_algoNames.push_back(std::string("ET"));
150  m_algoNames.push_back(std::string("PLT"));
151  assert(m_algoNames.size() == kMaxNumAlgos);
152  }
153  return m_algoNames;
154 }
155 
156 bool
157 LumiDetails::isProductEqual(LumiDetails const& lumiDetails) const {
158 
159  if (m_lumiVersion == lumiDetails.m_lumiVersion &&
160  m_algoToFirstIndex == lumiDetails.m_algoToFirstIndex &&
161  m_allValues == lumiDetails.m_allValues &&
162  m_allErrors == lumiDetails.m_allErrors &&
163  m_allQualities == lumiDetails.m_allQualities &&
164  m_beam1Intensities == lumiDetails.m_beam1Intensities &&
165  m_beam2Intensities == lumiDetails.m_beam2Intensities) {
166  return true;
167  }
168  return false;
169 }
170 
171 void
173  if (algo >= kMaxNumAlgos) {
175  << "Algorithm type argument out of range in a call to a function in LumiDetails\n";
176  }
177 }
178 
179 void
180 LumiDetails::checkAlgoAndBX(AlgoType algo, unsigned int bx) const {
181  checkAlgo(algo);
182  if (bx >= (m_algoToFirstIndex[algo + 1U] - m_algoToFirstIndex[algo])) {
184  << "Branch crossing argument out of range in call to a function in LumiDetails\n";
185  }
186 }
187 
188 std::ostream& operator<<(std::ostream& s, LumiDetails const& lumiDetails) {
189 
190  s << "\nDumping LumiDetails\n";
191  s << std::setw(12) << "lumi version " << lumiDetails.lumiVersion() << "\n";
192 
193  std::vector<std::string>::const_iterator algo = lumiDetails.algoNames().begin();
194  std::vector<std::string>::const_iterator algoEnd = lumiDetails.algoNames().end();
195 
197 
198  for( ; algo != algoEnd; ++algo, ++i) {
199 
200  std::vector<float>::const_iterator value = lumiDetails.lumiValuesForAlgo(i).first;
201  std::vector<float>::const_iterator valueEnd = lumiDetails.lumiValuesForAlgo(i).second;
202  std::vector<float>::const_iterator error = lumiDetails.lumiErrorsForAlgo(i).first;
203  std::vector<short>::const_iterator quality = lumiDetails.lumiQualitiesForAlgo(i).first;
204 
205  s << "algorithm: " << *algo << "\n";
206  s << std::setw(12) << "value"
207  << std::setw(12) << "error"
208  << std::setw(12) << "quality" << "\n";
209 
210  for( ; value != valueEnd; ++value, ++error, ++quality){
211  s << std::setw(12) << *value
212  << std::setw(12) << *error
213  << std::setw(12) << *quality << "\n";
214  }
215  s << "\n";
216  }
217  s << "beam 1 intensities:\n";
218  std::vector<float> const& beam1Intensities = lumiDetails.lumiBeam1Intensities();
219  for (std::vector<float>::const_iterator intensity = beam1Intensities.begin(),
220  iEnd = beam1Intensities.end();
221  intensity != iEnd; ++intensity) {
222  s << *intensity << "\n";
223  }
224  s << "\nbeam 2 intensities:\n";
225  std::vector<float> const& beam2Intensities = lumiDetails.lumiBeam2Intensities();
226  for (std::vector<float>::const_iterator intensity = beam2Intensities.begin(),
227  iEnd = beam2Intensities.end();
228  intensity != iEnd; ++intensity) {
229  s << *intensity << "\n";
230  }
231  s << "\n";
232  return s;
233 }
int i
Definition: DBlmapReader.cc:9
float lumiBeam2Intensity(unsigned int bx) const
Definition: LumiDetails.cc:104
std::vector< float > const & lumiBeam2Intensities() const
Definition: LumiDetails.cc:135
std::pair< std::vector< float >::const_iterator, std::vector< float >::const_iterator > ValueRange
Definition: LumiDetails.h:35
ValueRange lumiValuesForAlgo(AlgoType algo) const
Definition: LumiDetails.cc:109
bool isValid() const
Definition: LumiDetails.cc:46
void checkAlgoAndBX(AlgoType algo, unsigned int bx) const
Definition: LumiDetails.cc:180
std::vector< float > m_allErrors
Definition: LumiDetails.h:92
std::pair< std::vector< float >::const_iterator, std::vector< float >::const_iterator > ErrorRange
Definition: LumiDetails.h:36
std::vector< float > const & lumiBeam1Intensities() const
Definition: LumiDetails.cc:130
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
float lumiValue(AlgoType algo, unsigned int bx) const
Definition: LumiDetails.cc:81
std::vector< float > m_beam2Intensities
Definition: LumiDetails.h:95
float lumiBeam1Intensity(unsigned int bx) const
Definition: LumiDetails.cc:99
short lumiQuality(AlgoType algo, unsigned int bx) const
Definition: LumiDetails.cc:93
void setLumiVersion(std::string const &lumiVersion)
Definition: LumiDetails.cc:36
std::string m_lumiVersion
Definition: LumiDetails.h:81
std::pair< std::vector< short >::const_iterator, std::vector< short >::const_iterator > QualityRange
Definition: LumiDetails.h:37
static std::vector< std::string > m_algoNames
Definition: LumiDetails.h:79
ErrorRange lumiErrorsForAlgo(AlgoType algo) const
Definition: LumiDetails.cc:116
void fill(AlgoType algo, std::vector< float > const &values, std::vector< float > const &errors, std::vector< short > const &qualities)
Definition: LumiDetails.cc:51
std::vector< float > m_allValues
Definition: LumiDetails.h:91
static std::vector< std::string > const & algoNames()
Definition: LumiDetails.cc:140
unsigned int AlgoType
Definition: LumiDetails.h:34
void checkAlgo(AlgoType algo) const
Definition: LumiDetails.cc:172
std::vector< unsigned int > m_algoToFirstIndex
Definition: LumiDetails.h:90
QualityRange lumiQualitiesForAlgo(AlgoType algo) const
Definition: LumiDetails.cc:123
float lumiError(AlgoType algo, unsigned int bx) const
Definition: LumiDetails.cc:87
std::vector< short > m_allQualities
Definition: LumiDetails.h:93
void fillBeamIntensities(std::vector< float > const &beam1Intensities, std::vector< float > const &beam2Intensities)
Definition: LumiDetails.cc:74
string s
Definition: asciidump.py:422
std::string const & lumiVersion() const
Definition: LumiDetails.cc:41
bool isProductEqual(LumiDetails const &lumiDetails) const
Definition: LumiDetails.cc:157
std::vector< float > m_beam1Intensities
Definition: LumiDetails.h:94