Go to the documentation of this file.00001 #include "DataFormats/Luminosity/interface/LumiDetails.h"
00002 #include "FWCore/Utilities/interface/EDMException.h"
00003
00004 #include <cassert>
00005 #include <iomanip>
00006 #include <ostream>
00007
00008 std::vector<std::string> LumiDetails::m_algoNames;
00009
00010 LumiDetails::LumiDetails() :
00011 m_lumiVersion("-1"),
00012 m_algoToFirstIndex(kMaxNumAlgos + 1, 0),
00013 m_allValues(),
00014 m_allErrors(),
00015 m_allQualities(),
00016 m_beam1Intensities(),
00017 m_beam2Intensities()
00018 {
00019 }
00020
00021 LumiDetails::LumiDetails(std::string const& lumiVersion) :
00022 m_lumiVersion(lumiVersion),
00023 m_algoToFirstIndex(kMaxNumAlgos + 1, 0),
00024 m_allValues(),
00025 m_allErrors(),
00026 m_allQualities(),
00027 m_beam1Intensities(),
00028 m_beam2Intensities()
00029 {
00030 }
00031
00032 LumiDetails::~LumiDetails() {
00033 }
00034
00035 void
00036 LumiDetails::setLumiVersion(std::string const& lumiVersion){
00037 m_lumiVersion = lumiVersion;
00038 }
00039
00040 std::string const&
00041 LumiDetails::lumiVersion() const {
00042 return m_lumiVersion;
00043 }
00044
00045 bool
00046 LumiDetails::isValid() const {
00047 return m_allValues.size()!=0;
00048 }
00049
00050 void
00051 LumiDetails::fill(AlgoType algo,
00052 std::vector<float> const& values,
00053 std::vector<float> const& errors,
00054 std::vector<short> const& qualities) {
00055 checkAlgo(algo);
00056 if (values.size() != errors.size() ||
00057 values.size() != qualities.size() ||
00058 m_algoToFirstIndex[algo] != m_algoToFirstIndex[algo + 1U]) {
00059 throw edm::Exception(edm::errors::LogicError)
00060 << "Illegal input values passed to LumiDetails::fill.\n"
00061 << "The current implementation of LumiDetails only allows filling\n"
00062 << "vectors for each algorithm once and the input vectors must\n"
00063 << "all be the same size.\n";
00064 }
00065 m_allValues.insert(m_allValues.begin() + m_algoToFirstIndex[algo], values.begin(), values.end());
00066 m_allErrors.insert(m_allErrors.begin() + m_algoToFirstIndex[algo], errors.begin(), errors.end());
00067 m_allQualities.insert(m_allQualities.begin() + m_algoToFirstIndex[algo], qualities.begin(), qualities.end());
00068 for (unsigned i = algo + 1U; i <= kMaxNumAlgos; ++i) {
00069 m_algoToFirstIndex[i] += values.size();
00070 }
00071 }
00072
00073 void
00074 LumiDetails::fillBeamIntensities(std::vector<float> const& beam1Intensities,
00075 std::vector<float> const& beam2Intensities) {
00076 m_beam1Intensities = beam1Intensities;
00077 m_beam2Intensities = beam2Intensities;
00078 }
00079
00080 float
00081 LumiDetails::lumiValue(AlgoType algo, unsigned int bx) const {
00082 checkAlgoAndBX(algo, bx);
00083 return m_allValues[m_algoToFirstIndex[algo] + bx];
00084 }
00085
00086 float
00087 LumiDetails::lumiError(AlgoType algo, unsigned int bx) const {
00088 checkAlgoAndBX(algo, bx);
00089 return m_allErrors[m_algoToFirstIndex[algo] + bx];
00090 }
00091
00092 short
00093 LumiDetails::lumiQuality(AlgoType algo, unsigned int bx) const {
00094 checkAlgoAndBX(algo, bx);
00095 return m_allQualities[m_algoToFirstIndex[algo] + bx];
00096 }
00097
00098 float
00099 LumiDetails::lumiBeam1Intensity(unsigned int bx) const {
00100 return m_beam1Intensities.at(bx);
00101 }
00102
00103 float
00104 LumiDetails::lumiBeam2Intensity(unsigned int bx) const {
00105 return m_beam2Intensities.at(bx);
00106 }
00107
00108 LumiDetails::ValueRange
00109 LumiDetails::lumiValuesForAlgo(AlgoType algo) const {
00110 checkAlgo(algo);
00111 return ValueRange(m_allValues.begin() + m_algoToFirstIndex[algo],
00112 m_allValues.begin() + m_algoToFirstIndex[algo + 1U]);
00113 }
00114
00115 LumiDetails::ErrorRange
00116 LumiDetails::lumiErrorsForAlgo(AlgoType algo) const {
00117 checkAlgo(algo);
00118 return ErrorRange(m_allErrors.begin() + m_algoToFirstIndex[algo],
00119 m_allErrors.begin() + m_algoToFirstIndex[algo + 1U]);
00120 }
00121
00122 LumiDetails::QualityRange
00123 LumiDetails::lumiQualitiesForAlgo(AlgoType algo) const {
00124 checkAlgo(algo);
00125 return QualityRange(m_allQualities.begin() + m_algoToFirstIndex[algo],
00126 m_allQualities.begin() + m_algoToFirstIndex[algo + 1U]);
00127 }
00128
00129 std::vector<float> const&
00130 LumiDetails::lumiBeam1Intensities() const {
00131 return m_beam1Intensities;
00132 }
00133
00134 std::vector<float> const&
00135 LumiDetails::lumiBeam2Intensities() const {
00136 return m_beam2Intensities;
00137 }
00138
00139 std::vector<std::string> const&
00140 LumiDetails::algoNames() {
00141 if (m_algoNames.size() != kMaxNumAlgos) {
00142 assert(m_algoNames.size() == 0U);
00143
00144
00145
00146
00147 m_algoNames.push_back(std::string("OCC1"));
00148 m_algoNames.push_back(std::string("OCC2"));
00149 m_algoNames.push_back(std::string("ET"));
00150 m_algoNames.push_back(std::string("PLT"));
00151 assert(m_algoNames.size() == kMaxNumAlgos);
00152 }
00153 return m_algoNames;
00154 }
00155
00156 std::vector<std::string> const&
00157 LumiDetails::dipalgoNames() {
00158 m_algoNames.push_back(std::string("DIP"));
00159 return m_algoNames;
00160 }
00161 bool
00162 LumiDetails::isProductEqual(LumiDetails const& lumiDetails) const {
00163
00164 if (m_lumiVersion == lumiDetails.m_lumiVersion &&
00165 m_algoToFirstIndex == lumiDetails.m_algoToFirstIndex &&
00166 m_allValues == lumiDetails.m_allValues &&
00167 m_allErrors == lumiDetails.m_allErrors &&
00168 m_allQualities == lumiDetails.m_allQualities &&
00169 m_beam1Intensities == lumiDetails.m_beam1Intensities &&
00170 m_beam2Intensities == lumiDetails.m_beam2Intensities) {
00171 return true;
00172 }
00173 return false;
00174 }
00175
00176 void
00177 LumiDetails::checkAlgo(AlgoType algo) const {
00178 if (algo >= kMaxNumAlgos) {
00179 throw edm::Exception(edm::errors::LogicError)
00180 << "Algorithm type argument out of range in a call to a function in LumiDetails\n";
00181 }
00182 }
00183
00184 void
00185 LumiDetails::checkAlgoAndBX(AlgoType algo, unsigned int bx) const {
00186 checkAlgo(algo);
00187 if (bx >= (m_algoToFirstIndex[algo + 1U] - m_algoToFirstIndex[algo])) {
00188 throw edm::Exception(edm::errors::LogicError)
00189 << "Branch crossing argument out of range in call to a function in LumiDetails\n";
00190 }
00191 }
00192
00193 std::ostream& operator<<(std::ostream& s, LumiDetails const& lumiDetails) {
00194
00195 s << "\nDumping LumiDetails\n";
00196 s << std::setw(12) << "lumi version " << lumiDetails.lumiVersion() << "\n";
00197 std::vector<std::string>::const_iterator algo;
00198 std::vector<std::string>::const_iterator algoEnd;
00199 if(lumiDetails.lumiVersion()!=std::string("DIP")){
00200 algo = lumiDetails.algoNames().begin();
00201 algoEnd = lumiDetails.algoNames().end();
00202 }else{
00203 algo = lumiDetails.dipalgoNames().begin();
00204 algoEnd = lumiDetails.dipalgoNames().end();
00205 }
00206 LumiDetails::AlgoType i = 0;
00207
00208 for( ; algo != algoEnd; ++algo, ++i) {
00209
00210 std::vector<float>::const_iterator value = lumiDetails.lumiValuesForAlgo(i).first;
00211 std::vector<float>::const_iterator valueEnd = lumiDetails.lumiValuesForAlgo(i).second;
00212 std::vector<float>::const_iterator error = lumiDetails.lumiErrorsForAlgo(i).first;
00213 std::vector<short>::const_iterator quality = lumiDetails.lumiQualitiesForAlgo(i).first;
00214
00215 s << "algorithm: " << *algo << "\n";
00216 s << std::setw(12) << "value"
00217 << std::setw(12) << "error"
00218 << std::setw(12) << "quality" << "\n";
00219
00220 for( ; value != valueEnd; ++value, ++error, ++quality){
00221 s << std::setw(12) << *value
00222 << std::setw(12) << *error
00223 << std::setw(12) << *quality << "\n";
00224 }
00225 s << "\n";
00226 }
00227 s << "beam 1 intensities:\n";
00228 std::vector<float> const& beam1Intensities = lumiDetails.lumiBeam1Intensities();
00229 for (std::vector<float>::const_iterator intensity = beam1Intensities.begin(),
00230 iEnd = beam1Intensities.end();
00231 intensity != iEnd; ++intensity) {
00232 s << *intensity << "\n";
00233 }
00234 s << "\nbeam 2 intensities:\n";
00235 std::vector<float> const& beam2Intensities = lumiDetails.lumiBeam2Intensities();
00236 for (std::vector<float>::const_iterator intensity = beam2Intensities.begin(),
00237 iEnd = beam2Intensities.end();
00238 intensity != iEnd; ++intensity) {
00239 s << *intensity << "\n";
00240 }
00241 s << "\n";
00242 return s;
00243 }