CMS 3D CMS Logo

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>
13 public:
16 
17  const CalibDataT* getCalibData(const typename CategoryT::Input& calibrationInput) const {
18  return (getCalibData(getIndex(calibrationInput)));
19  }
20 
21  CalibDataT* getCalibData(const typename CategoryT::Input& calibrationInput) {
22  return (getCalibData(getIndex(calibrationInput)));
23  }
24 
25  const CalibDataT* getCalibData(int index) const;
26  CalibDataT* getCalibData(int index);
27 
28  const CategoryT* getCategoryDefinition(int index) const;
29 
30  int getIndex(const typename CategoryT::Input& calibrationInput) const;
31 
32  int addCategoryDefinition(const CategoryT& categoryDefinition);
33  int addEntry(const CategoryT& categoryDefinition, const CalibDataT& data);
34 
35  void setCalibData(int index, const CalibDataT& data);
36 
37  const std::vector<std::pair<CategoryT, CalibDataT> >& categoriesWithData() const { return m_categoriesWithData; }
38  int size() const { return m_categoriesWithData.size(); }
39 
40 private:
41  std::vector<std::pair<CategoryT, CalibDataT> > m_categoriesWithData;
42 };
43 
44 template <class CategoryT, class CalibDataT>
46 
47 template <class CategoryT, class CalibDataT>
49 
50 template <class CategoryT, class CalibDataT>
51 int CalibrationInterface<CategoryT, CalibDataT>::getIndex(const typename CategoryT::Input& calibrationInput) const {
52  int i = 0;
53  int found = -1;
54  for (typename std::vector<std::pair<CategoryT, CalibDataT> >::const_iterator it = m_categoriesWithData.begin();
55  it != m_categoriesWithData.end();
56  it++) {
57  if ((*it).first.match(calibrationInput)) {
58  if (found >= 0) {
59  edm::LogWarning("BTagCalibration") << "WARNING: OVERLAP in categories, using latest one";
60  }
61 
62  found = i;
63  }
64  i++;
65  }
66  return found;
67 }
68 template <class CategoryT, class CalibDataT>
70  size_t ii = i;
71  if (i >= 0 && ii < m_categoriesWithData.size())
72  return &m_categoriesWithData[i].second;
73  else
74  return 0;
75 }
76 
77 template <class CategoryT, class CalibDataT>
79  size_t ii = i;
80  if (i >= 0 && ii < m_categoriesWithData.size())
81  return &m_categoriesWithData[i].second;
82  else
83  return nullptr;
84 }
85 
86 template <class CategoryT, class CalibDataT>
88  CalibDataT emptyData;
89  return addEntry(categoryDefinition, emptyData);
90 }
91 
92 template <class CategoryT, class CalibDataT>
93 int CalibrationInterface<CategoryT, CalibDataT>::addEntry(const CategoryT& categoryDefinition, const CalibDataT& data) {
94  std::pair<CategoryT, CalibDataT> newEntry(categoryDefinition, data);
95  m_categoriesWithData.push_back(newEntry);
96  return m_categoriesWithData.size();
97 }
98 
99 template <class CategoryT, class CalibDataT>
101  m_categoriesWithData[index].second = data;
102 }
103 #endif
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
CalibrationInterface::addCategoryDefinition
int addCategoryDefinition(const CategoryT &categoryDefinition)
Definition: CalibrationInterface.h:87
CalibrationInterface::getIndex
int getIndex(const typename CategoryT::Input &calibrationInput) const
Definition: CalibrationInterface.h:51
CalibrationInterface::getCalibData
CalibDataT * getCalibData(const typename CategoryT::Input &calibrationInput)
Definition: CalibrationInterface.h:21
CalibrationInterface::setCalibData
void setCalibData(int index, const CalibDataT &data)
Definition: CalibrationInterface.h:100
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
CalibrationInterface::~CalibrationInterface
~CalibrationInterface()
Definition: CalibrationInterface.h:48
CalibrationInterface::getCategoryDefinition
const CategoryT * getCategoryDefinition(int index) const
CalibrationInterface::CalibrationInterface
CalibrationInterface()
Definition: CalibrationInterface.h:45
CalibrationInterface::addEntry
int addEntry(const CategoryT &categoryDefinition, const CalibDataT &data)
Definition: CalibrationInterface.h:93
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
CalibrationInterface::getCalibData
const CalibDataT * getCalibData(const typename CategoryT::Input &calibrationInput) const
Definition: CalibrationInterface.h:17
TrackCandidateTopBottomHitFilter_cfi.Input
Input
Definition: TrackCandidateTopBottomHitFilter_cfi.py:4
CalibrationInterface::size
int size() const
Definition: CalibrationInterface.h:38
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
cuy.ii
ii
Definition: cuy.py:590
CalibrationInterface::m_categoriesWithData
std::vector< std::pair< CategoryT, CalibDataT > > m_categoriesWithData
Definition: CalibrationInterface.h:41
CalibrationInterface
Definition: CalibrationInterface.h:12
CalibrationInterface::categoriesWithData
const std::vector< std::pair< CategoryT, CalibDataT > > & categoriesWithData() const
Definition: CalibrationInterface.h:37