Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:51

0001 #ifndef CALIBRATION_INTERFACE_H
0002 #define CALIBRATION_INTERFACE_H
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include <vector>
0005 #include <utility>
0006 #include <iostream>
0007 
0008 /**
0009 
0010 */
0011 template <class CategoryT, class CalibDataT>
0012 class CalibrationInterface {
0013 public:
0014   CalibrationInterface();
0015   ~CalibrationInterface();
0016 
0017   const CalibDataT* getCalibData(const typename CategoryT::Input& calibrationInput) const {
0018     return (getCalibData(getIndex(calibrationInput)));
0019   }
0020 
0021   CalibDataT* getCalibData(const typename CategoryT::Input& calibrationInput) {
0022     return (getCalibData(getIndex(calibrationInput)));
0023   }
0024 
0025   const CalibDataT* getCalibData(int index) const;
0026   CalibDataT* getCalibData(int index);
0027 
0028   const CategoryT* getCategoryDefinition(int index) const;
0029 
0030   int getIndex(const typename CategoryT::Input& calibrationInput) const;
0031 
0032   int addCategoryDefinition(const CategoryT& categoryDefinition);
0033   int addEntry(const CategoryT& categoryDefinition, const CalibDataT& data);
0034 
0035   void setCalibData(int index, const CalibDataT& data);
0036 
0037   const std::vector<std::pair<CategoryT, CalibDataT> >& categoriesWithData() const { return m_categoriesWithData; }
0038   int size() const { return m_categoriesWithData.size(); }
0039 
0040 private:
0041   std::vector<std::pair<CategoryT, CalibDataT> > m_categoriesWithData;
0042 };
0043 
0044 template <class CategoryT, class CalibDataT>
0045 CalibrationInterface<CategoryT, CalibDataT>::CalibrationInterface() {}
0046 
0047 template <class CategoryT, class CalibDataT>
0048 CalibrationInterface<CategoryT, CalibDataT>::~CalibrationInterface() {}
0049 
0050 template <class CategoryT, class CalibDataT>
0051 int CalibrationInterface<CategoryT, CalibDataT>::getIndex(const typename CategoryT::Input& calibrationInput) const {
0052   int i = 0;
0053   int found = -1;
0054   for (typename std::vector<std::pair<CategoryT, CalibDataT> >::const_iterator it = m_categoriesWithData.begin();
0055        it != m_categoriesWithData.end();
0056        it++) {
0057     if ((*it).first.match(calibrationInput)) {
0058       if (found >= 0) {
0059         edm::LogWarning("BTagCalibration") << "WARNING: OVERLAP in categories, using latest one";
0060       }
0061 
0062       found = i;
0063     }
0064     i++;
0065   }
0066   return found;
0067 }
0068 template <class CategoryT, class CalibDataT>
0069 const CalibDataT* CalibrationInterface<CategoryT, CalibDataT>::getCalibData(int i) const {
0070   size_t ii = i;
0071   if (i >= 0 && ii < m_categoriesWithData.size())
0072     return &m_categoriesWithData[i].second;
0073   else
0074     return 0;
0075 }
0076 
0077 template <class CategoryT, class CalibDataT>
0078 CalibDataT* CalibrationInterface<CategoryT, CalibDataT>::getCalibData(int i) {
0079   size_t ii = i;
0080   if (i >= 0 && ii < m_categoriesWithData.size())
0081     return &m_categoriesWithData[i].second;
0082   else
0083     return nullptr;
0084 }
0085 
0086 template <class CategoryT, class CalibDataT>
0087 int CalibrationInterface<CategoryT, CalibDataT>::addCategoryDefinition(const CategoryT& categoryDefinition) {
0088   CalibDataT emptyData;
0089   return addEntry(categoryDefinition, emptyData);
0090 }
0091 
0092 template <class CategoryT, class CalibDataT>
0093 int CalibrationInterface<CategoryT, CalibDataT>::addEntry(const CategoryT& categoryDefinition, const CalibDataT& data) {
0094   std::pair<CategoryT, CalibDataT> newEntry(categoryDefinition, data);
0095   m_categoriesWithData.push_back(newEntry);
0096   return m_categoriesWithData.size();
0097 }
0098 
0099 template <class CategoryT, class CalibDataT>
0100 void CalibrationInterface<CategoryT, CalibDataT>::setCalibData(int index, const CalibDataT& data) {
0101   m_categoriesWithData[index].second = data;
0102 }
0103 #endif