CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/DataFormats/Luminosity/src/LumiDetails.cc

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_lumiVersion != "-1");
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     // If in the future additional algorithm names are added,
00144     // it is important that they be added at the end of the list.
00145     // The Algos enum in LumiDetails.h also would need to be
00146     // updated to keep the list of names in sync.
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 bool
00157 LumiDetails::isProductEqual(LumiDetails const& lumiDetails) const {
00158 
00159   if (m_lumiVersion == lumiDetails.m_lumiVersion &&
00160       m_algoToFirstIndex == lumiDetails.m_algoToFirstIndex &&
00161       m_allValues == lumiDetails.m_allValues &&
00162       m_allErrors == lumiDetails.m_allErrors &&
00163       m_allQualities == lumiDetails.m_allQualities &&
00164       m_beam1Intensities == lumiDetails.m_beam1Intensities &&
00165       m_beam2Intensities == lumiDetails.m_beam2Intensities) {
00166     return true;
00167   }
00168   return false;
00169 }
00170 
00171 void
00172 LumiDetails::checkAlgo(AlgoType algo) const {
00173   if (algo >= kMaxNumAlgos) {
00174     throw edm::Exception(edm::errors::LogicError)
00175       << "Algorithm type argument out of range in a call to a function in LumiDetails\n";
00176   }
00177 }
00178 
00179 void
00180 LumiDetails::checkAlgoAndBX(AlgoType algo, unsigned int bx) const {
00181   checkAlgo(algo);
00182   if (bx >= (m_algoToFirstIndex[algo + 1U] - m_algoToFirstIndex[algo])) {
00183     throw edm::Exception(edm::errors::LogicError)
00184       << "Branch crossing argument out of range in call to a function in LumiDetails\n";
00185   }
00186 }
00187 
00188 std::ostream& operator<<(std::ostream& s, LumiDetails const& lumiDetails) {
00189   
00190   s << "\nDumping LumiDetails\n";
00191   s << std::setw(12) << "lumi version " << lumiDetails.lumiVersion() << "\n";
00192 
00193   std::vector<std::string>::const_iterator algo = lumiDetails.algoNames().begin();
00194   std::vector<std::string>::const_iterator algoEnd = lumiDetails.algoNames().end();
00195 
00196   LumiDetails::AlgoType i = 0;
00197 
00198   for( ; algo != algoEnd; ++algo, ++i) {
00199 
00200     std::vector<float>::const_iterator value = lumiDetails.lumiValuesForAlgo(i).first;
00201     std::vector<float>::const_iterator valueEnd = lumiDetails.lumiValuesForAlgo(i).second;
00202     std::vector<float>::const_iterator error = lumiDetails.lumiErrorsForAlgo(i).first;
00203     std::vector<short>::const_iterator quality = lumiDetails.lumiQualitiesForAlgo(i).first;
00204 
00205     s << "algorithm: " << *algo << "\n";
00206     s << std::setw(12) << "value"
00207       << std::setw(12) << "error"
00208       << std::setw(12) << "quality" << "\n";
00209 
00210     for( ; value != valueEnd; ++value, ++error, ++quality){
00211       s << std::setw(12) << *value
00212         << std::setw(12) << *error
00213         << std::setw(12) << *quality << "\n";
00214     }
00215     s << "\n";
00216   }
00217   s << "beam 1 intensities:\n";
00218   std::vector<float> const& beam1Intensities = lumiDetails.lumiBeam1Intensities();
00219   for (std::vector<float>::const_iterator intensity = beam1Intensities.begin(),
00220                                                iEnd = beam1Intensities.end();
00221        intensity != iEnd; ++intensity) {
00222     s << *intensity << "\n";
00223   }
00224   s << "\nbeam 2 intensities:\n";
00225   std::vector<float> const& beam2Intensities = lumiDetails.lumiBeam2Intensities();
00226   for (std::vector<float>::const_iterator intensity = beam2Intensities.begin(),
00227                                                iEnd = beam2Intensities.end();
00228        intensity != iEnd; ++intensity) {
00229     s << *intensity << "\n";
00230   }
00231   s << "\n";
00232   return s;
00233 }