CMS 3D CMS Logo

AlgorithmCalibration.h
Go to the documentation of this file.
1 #ifndef ALGORITHM_CALIBRATION_H
2 #define ALGORITHM_CALIBRATION_H
3 
4 #include <map>
5 #include <string>
6 #include <vector>
7 #include <xercesc/dom/DOM.hpp>
8 #include <xercesc/dom/DOMElement.hpp>
9 #include <xercesc/util/XMLString.hpp>
10 #include <string>
11 #include <list>
12 #include <iostream>
13 
14 #include "CalibrationXML.h"
15 //#include "CondFormats/BTagObjects/interface/CalibrationInterface.h"
16 //#include "RecoBTag/TrackProbability/interface/CalibrationInterface.h"
18 
19 namespace XERCES_CPP_NAMESPACE {
20  class DOMNode;
21 }
22 
23 //template <class T,class CO> class CalibrationInterface;
37 template <class T, class CO>
39  // friend class CalibrationInterface<T,CO>;
40 public:
41  typedef XERCES_CPP_NAMESPACE::DOMElement DOMElement;
42  typedef XERCES_CPP_NAMESPACE::DOMNode DOMNode;
43 
49 
51 
55  void startCalibration();
56 
60  void updateCalibration(const typename T::Input &calibrationInput);
61  template <class CI>
62  void updateCalibration(const typename T::Input &calibrationInputForCategory, const CI &inputForCalibration);
63 
67  void saveCalibration(const std::string &fileName);
68 
69 protected:
70  CO *readObject(DOMNode *);
71  bool readCategories();
72 
73 protected:
74  DOMElement *dom() {
75  if (m_xml == 0) {
76  m_xml = new CalibrationXML();
77  m_xml->openFile(m_filename);
78  }
79  return m_xml->calibrationDOM();
80  }
81 
82 private:
85 };
86 
87 template <class T, class CO>
90  if (m_xml) {
91  m_xml->closeFile();
92  }
93 }
94 
95 template <class T, class CO>
97  if (m_xml)
98  delete m_xml;
99 }
100 
101 template <class T, class CO>
103  if (dom() == 0)
104  return false;
105 
106  DOMNode *n1 = dom()->getFirstChild();
107  while (n1) {
108  if (n1->getNodeType() == DOMNode::ELEMENT_NODE) {
109  T *cat = new T();
110  cat->readFromDOM((DOMElement *)n1);
111  CO *obj = readObject(n1->getFirstChild());
112  if (obj) {
113  this->addEntry(*cat, *obj);
114  delete obj;
115  }
116  delete cat;
117  }
118  n1 = n1->getNextSibling();
119  }
120 
121  return true;
122 }
123 template <class T, class CO>
125  DOMNode *n1 = dom;
126  while (n1) {
127  if (n1->getNodeType() == DOMNode::ELEMENT_NODE)
128  break;
129  n1 = n1->getNextSibling();
130  }
131 
132  if (n1 == 0)
133  return 0; //Cannot find any calibrated objects
134 
135  CO *co = new CO();
136  co->read((DOMElement *)n1);
137  return co;
138 }
139 
140 #endif
AlgorithmCalibration(const std::string &fileName)
#define Input(cl)
Definition: vmac.h:190
XERCES_CPP_NAMESPACE::DOMNode DOMNode
def cat(path)
Definition: eostools.py:401
XERCES_CPP_NAMESPACE::DOMElement DOMElement
int addEntry(const T &categoryDefinition, const CO &data)
long double T