test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CalibrationInterface.h
Go to the documentation of this file.
1 #ifndef CALIBRATION_INTERFACE_H
2 #define CALIBRATION_INTERFACE_H
4 #include <vector>
5 #include <utility>
6 #include <iostream>
7 
11 template <class CategoryT,class CalibDataT> class CalibrationInterface
12 {
13  public:
14 
17 
18  const CalibDataT* getCalibData(const typename CategoryT::Input & calibrationInput) const
19  {
20  return(getCalibData(getIndex(calibrationInput)));
21  }
22 
23  CalibDataT* getCalibData(const typename CategoryT::Input & calibrationInput)
24  {
25  return(getCalibData(getIndex(calibrationInput)));
26  }
27 
28  const CalibDataT* getCalibData(int index) const ;
29  CalibDataT* getCalibData(int index);
30 
31  const CategoryT* getCategoryDefinition(int index) const ;
32 
33  int getIndex(const typename CategoryT::Input & calibrationInput) const ;
34 
35 
36  int addCategoryDefinition(const CategoryT & categoryDefinition);
37  int addEntry(const CategoryT & categoryDefinition,const CalibDataT & data);
38 
39  void setCalibData(int index,const CalibDataT & data);
40 
41  const std::vector<std::pair<CategoryT, CalibDataT> > & categoriesWithData() const {return m_categoriesWithData; }
42  int size() const {return m_categoriesWithData.size(); }
43 
44  private:
45  std::vector<std::pair<CategoryT, CalibDataT> > m_categoriesWithData;
46 };
47 
48 
49 template <class CategoryT,class CalibDataT>
51 {
52 }
53 
54 template <class CategoryT,class CalibDataT>
56 {
57 }
58 
59 template <class CategoryT,class CalibDataT>
60 int CalibrationInterface<CategoryT,CalibDataT>::getIndex(const typename CategoryT::Input & calibrationInput) const
61 {
62  int i=0;
63  int found=-1;
64  for(typename std::vector<std::pair<CategoryT,CalibDataT> >::const_iterator it = m_categoriesWithData.begin();it!=m_categoriesWithData.end();it++)
65  {
66 
67  if((*it).first.match(calibrationInput))
68  {
69  if(found >=0 )
70  {
71  edm::LogWarning("BTagCalibration") << "WARNING: OVERLAP in categories, using latest one" ;
72  }
73 
74  found=i;
75  }
76  i++;
77  }
78  return found;
79 }
80 template <class CategoryT,class CalibDataT>
82 {
83  size_t ii=i;
84  if(i>=0 && ii < m_categoriesWithData.size() )
85  return &m_categoriesWithData[i].second;
86  else
87  return 0;
88 }
89 
90 
91 template <class CategoryT,class CalibDataT>
93 {
94  size_t ii=i;
95  if(i>=0 && ii < m_categoriesWithData.size() )
96  return &m_categoriesWithData[i].second;
97  else
98  return 0;
99 }
100 
101 template <class CategoryT,class CalibDataT>
103 {
104  CalibDataT emptyData;
105  return addEntry(categoryDefinition,emptyData);
106 }
107 
108 template <class CategoryT,class CalibDataT>
109 int CalibrationInterface<CategoryT,CalibDataT>::addEntry(const CategoryT & categoryDefinition,const CalibDataT & data)
110 {
111  std::pair<CategoryT,CalibDataT> newEntry(categoryDefinition,data);
112  m_categoriesWithData.push_back(newEntry);
113  return m_categoriesWithData.size();
114 }
115 
116 
117 template <class CategoryT,class CalibDataT>
119 {
120  m_categoriesWithData[index].second=data;
121 }
122 #endif
int i
Definition: DBlmapReader.cc:9
#define Input(cl)
Definition: vmac.h:188
int getIndex(const typename CategoryT::Input &calibrationInput) const
int ii
Definition: cuy.py:588
U second(std::pair< T, U > const &p)
void setCalibData(int index, const CalibDataT &data)
const std::vector< std::pair< CategoryT, CalibDataT > > & categoriesWithData() const
std::vector< std::pair< CategoryT, CalibDataT > > m_categoriesWithData
const CalibDataT * getCalibData(const typename CategoryT::Input &calibrationInput) const
CalibDataT * getCalibData(const typename CategoryT::Input &calibrationInput)
int addEntry(const CategoryT &categoryDefinition, const CalibDataT &data)
const CategoryT * getCategoryDefinition(int index) const
int addCategoryDefinition(const CategoryT &categoryDefinition)