Go to the documentation of this file.00001 #ifndef CALIBRATION_INTERFACE_H
00002 #define CALIBRATION_INTERFACE_H
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 #include <vector>
00005 #include <utility>
00006 #include <iostream>
00007
00011 template <class CategoryT,class CalibDataT> class CalibrationInterface
00012 {
00013 public:
00014
00015 CalibrationInterface();
00016 ~CalibrationInterface();
00017
00018 const CalibDataT* getCalibData(const typename CategoryT::Input & calibrationInput) const
00019 {
00020 return(getCalibData(getIndex(calibrationInput)));
00021 }
00022
00023 CalibDataT* getCalibData(const typename CategoryT::Input & calibrationInput)
00024 {
00025 return(getCalibData(getIndex(calibrationInput)));
00026 }
00027
00028 const CalibDataT* getCalibData(int index) const ;
00029 CalibDataT* getCalibData(int index);
00030
00031 const CategoryT* getCategoryDefinition(int index) const ;
00032
00033 int getIndex(const typename CategoryT::Input & calibrationInput) const ;
00034
00035
00036 int addCategoryDefinition(const CategoryT & categoryDefinition);
00037 int addEntry(const CategoryT & categoryDefinition,const CalibDataT & data);
00038
00039 void setCalibData(int index,const CalibDataT & data);
00040
00041 const std::vector<std::pair<CategoryT, CalibDataT> > & categoriesWithData() const {return m_categoriesWithData; }
00042 int size() const {return m_categoriesWithData.size(); }
00043
00044 private:
00045 std::vector<std::pair<CategoryT, CalibDataT> > m_categoriesWithData;
00046 };
00047
00048
00049 template <class CategoryT,class CalibDataT>
00050 CalibrationInterface<CategoryT,CalibDataT>::CalibrationInterface()
00051 {
00052 }
00053
00054 template <class CategoryT,class CalibDataT>
00055 CalibrationInterface<CategoryT,CalibDataT>::~CalibrationInterface()
00056 {
00057 }
00058
00059 template <class CategoryT,class CalibDataT>
00060 int CalibrationInterface<CategoryT,CalibDataT>::getIndex(const typename CategoryT::Input & calibrationInput) const
00061 {
00062 int i=0;
00063 int found=-1;
00064 for(typename std::vector<std::pair<CategoryT,CalibDataT> >::const_iterator it = m_categoriesWithData.begin();it!=m_categoriesWithData.end();it++)
00065 {
00066
00067 if((*it).first.match(calibrationInput))
00068 {
00069 if(found >=0 )
00070 {
00071 edm::LogWarning("BTagCalibration") << "WARNING: OVERLAP in categories, using latest one" ;
00072 }
00073
00074 found=i;
00075 }
00076 i++;
00077 }
00078 return found;
00079 }
00080 template <class CategoryT,class CalibDataT>
00081 const CalibDataT * CalibrationInterface<CategoryT,CalibDataT>::getCalibData(int i) const
00082 {
00083 size_t ii=i;
00084 if(i>=0 && ii < m_categoriesWithData.size() )
00085 return &m_categoriesWithData[i].second;
00086 else
00087 return 0;
00088 }
00089
00090
00091 template <class CategoryT,class CalibDataT>
00092 CalibDataT * CalibrationInterface<CategoryT,CalibDataT>::getCalibData(int i)
00093 {
00094 size_t ii=i;
00095 if(i>=0 && ii < m_categoriesWithData.size() )
00096 return &m_categoriesWithData[i].second;
00097 else
00098 return 0;
00099 }
00100
00101 template <class CategoryT,class CalibDataT>
00102 int CalibrationInterface<CategoryT,CalibDataT>::addCategoryDefinition(const CategoryT & categoryDefinition)
00103 {
00104 CalibDataT emptyData;
00105 return addEntry(categoryDefinition,emptyData);
00106 }
00107
00108 template <class CategoryT,class CalibDataT>
00109 int CalibrationInterface<CategoryT,CalibDataT>::addEntry(const CategoryT & categoryDefinition,const CalibDataT & data)
00110 {
00111 std::pair<CategoryT,CalibDataT> newEntry(categoryDefinition,data);
00112 m_categoriesWithData.push_back(newEntry);
00113 return m_categoriesWithData.size();
00114 }
00115
00116
00117 template <class CategoryT,class CalibDataT>
00118 void CalibrationInterface<CategoryT,CalibDataT>::setCalibData(int index,const CalibDataT & data)
00119 {
00120 m_categoriesWithData[index].second=data;
00121 }
00122 #endif