CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ProcMultiply.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <iterator>
3 #include <sstream>
4 #include <iostream>
5 #include <cstring>
6 #include <vector>
7 #include <string>
8 #include <set>
9 
10 #include <xercesc/dom/DOM.hpp>
11 
13 
15 
20 
21 XERCES_CPP_NAMESPACE_USE
22 
23 using namespace PhysicsTools;
24 
25 namespace { // anonymous
26 
27 class ProcMultiply : public TrainProcessor {
28  public:
30 
31  ProcMultiply(const char *name, const AtomicId *id,
32  MVATrainer *trainer);
33  virtual ~ProcMultiply();
34 
35  virtual void configure(DOMElement *elem) override;
36  virtual Calibration::VarProcessor *getCalibration() const override;
37 
38  private:
39  typedef std::vector<unsigned int> Config;
40  std::vector<Config> config;
41 };
42 
43 static ProcMultiply::Registry registry("ProcMultiply");
44 
45 ProcMultiply::ProcMultiply(const char *name, const AtomicId *id,
46  MVATrainer *trainer) :
47  TrainProcessor(name, id, trainer)
48 {
49 }
50 
51 ProcMultiply::~ProcMultiply()
52 {
53 }
54 
55 void ProcMultiply::configure(DOMElement *elem)
56 {
57  unsigned int nInputs = getInputs().size();
58 
59  for(DOMNode *node = elem->getFirstChild(); node;
60  node = node->getNextSibling()) {
61  if (node->getNodeType() != DOMNode::ELEMENT_NODE)
62  continue;
63 
64  if (std::strcmp(XMLSimpleStr(node->getNodeName()), "product") != 0)
65  throw cms::Exception("ProcMultiply")
66  << "Expected product tag in config section."
67  << std::endl;
68 
70  (const char*)XMLSimpleStr(node->getTextContent());
71 
72  Config indices;
73  for(size_t pos = 0, next = 0;
74  next != std::string::npos; pos = next + 1) {
75  next = data.find('*', pos);
76 
77  std::istringstream ss(data.substr(pos, next - pos));
78  unsigned int index;
79  ss >> index;
80  if (ss.bad() || ss.peek() !=
81  std::istringstream::traits_type::eof())
82  throw cms::Exception("ProcMultiply")
83  << "Expected list of indices separated"
84  << "by asterisks" << std::endl;
85  if (index >= nInputs)
86  throw cms::Exception("ProcMultiply")
87  << "Variable index " << index
88  << " out of range." << std::endl;
89  indices.push_back(index);
90  }
91 
92  config.push_back(indices);
93  }
94 
95  trained = true;
96 }
97 
98 Calibration::VarProcessor *ProcMultiply::getCalibration() const
99 {
101  calib->in = getInputs().size();
102  calib->out = config;
103  return calib;
104 }
105 
106 } // anonymous namespace
template to generate a registry singleton for a type.
tuple node
Definition: Node.py:50
Cheap generic unique keyword identifier class.
Definition: AtomicId.h:31
MVATrainerComputer * calib
Definition: MVATrainer.cc:64
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
tuple Config
Definition: helper.py:9
static Interceptor::Registry registry("Interceptor")