CMS 3D CMS Logo

ProcOptional.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <iterator>
3 #include <iostream>
4 #include <cstring>
5 #include <vector>
6 #include <string>
7 
8 #include <xercesc/dom/DOM.hpp>
9 
11 
13 
18 
20 
21 using namespace PhysicsTools;
22 
23 namespace { // anonymous
24 
25 class ProcOptional : public TrainProcessor {
26  public:
28 
29  ProcOptional(const char *name, const AtomicId *id,
30  MVATrainer *trainer);
31  virtual ~ProcOptional();
32 
33  virtual void configure(DOMElement *elem) override;
34  virtual Calibration::VarProcessor *getCalibration() const override;
35 
36  private:
37  std::vector<double> neutrals;
38 };
39 
40 ProcOptional::Registry registry("ProcOptional");
41 
42 ProcOptional::ProcOptional(const char *name, const AtomicId *id,
43  MVATrainer *trainer) :
44  TrainProcessor(name, id, trainer)
45 {
46 }
47 
48 ProcOptional::~ProcOptional()
49 {
50 }
51 
52 void ProcOptional::configure(DOMElement *elem)
53 {
54  for(DOMNode *node = elem->getFirstChild();
55  node; node = node->getNextSibling()) {
56  if (node->getNodeType() != DOMNode::ELEMENT_NODE)
57  continue;
58 
59  if (std::strcmp(XMLSimpleStr(node->getNodeName()),
60  "neutral") != 0)
61  throw cms::Exception("ProcOptional")
62  << "Expected neutral tag in config section."
63  << std::endl;
64  elem = static_cast<DOMElement*>(node);
65 
66  double neutral =
67  XMLDocument::readAttribute<double>(elem, "pos");
68 
69  neutrals.push_back(neutral);
70  }
71 
72  trained = true;
73 
74  if (neutrals.size() != getInputs().size())
75  throw cms::Exception("ProcOptional")
76  << "Got " << neutrals.size()
77  << " neutral pos values for "
78  << getInputs().size() << " input variables."
79  << std::endl;
80 }
81 
82 Calibration::VarProcessor *ProcOptional::getCalibration() const
83 {
85 
86  std::copy(neutrals.begin(), neutrals.end(),
87  std::back_inserter(calib->neutralPos));
88 
89  return calib;
90 }
91 
92 } // anonymous namespace
template to generate a registry singleton for a type.
Cheap generic unique keyword identifier class.
Definition: AtomicId.h:31
MVATrainerComputer * calib
Definition: MVATrainer.cc:64
def elem(elemtype, innerHTML='', html_class='', kwargs)
Definition: HTMLExport.py:18
static Interceptor::Registry registry("Interceptor")