CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MVATrainerLooper.cc
Go to the documentation of this file.
1 #include <assert.h>
2 #include <algorithm>
3 #include <string>
4 #include <memory>
5 
6 #include <boost/shared_ptr.hpp>
7 
12 
14 
17 
18 namespace PhysicsTools {
19 
20 namespace {
21  template<typename T>
22  struct deleter : public std::unary_function<T*, void> {
23  inline void operator() (T *ptr) const { delete ptr; }
24  };
25 }
26 
27 // MVATrainerLooper::Trainer implementation
28 
30 {
31  const edm::Entry *entry = params.retrieveUntracked("trainDescription");
32  if (!entry)
34  "MissingParameter:")
35  << "The required parameter 'trainDescription' "
36  "was not specified." << std::endl;;
37  std::string trainDescription;
38  if (entry->typeCode() == 'F')
39  trainDescription = entry->getFileInPath().fullPath();
40  else
41  trainDescription = entry->getString();
42 
43  bool useXSLT = params.getUntrackedParameter<bool>("useXSLT", false);
44  bool doLoad = params.getUntrackedParameter<bool>("loadState", false);
45  bool doSave = params.getUntrackedParameter<bool>("saveState", false);
46  bool doMonitoring = params.getUntrackedParameter<bool>("monitoring", false);
47 
48  trainer.reset(new MVATrainer(trainDescription, useXSLT));
49 
50  if (doLoad)
51  trainer->loadState();
52 
53  trainer->setAutoSave(doSave);
54  trainer->setCleanup(!doSave);
55  trainer->setMonitoring(doMonitoring);
56 }
57 
58 // MVATrainerLooper::MVATrainerContainer implementation
59 
61 {
62  clear();
63 }
64 
66 {
67  std::for_each(begin(), end(), deleter<Trainer>());
68  content.clear();
69 }
70 
71 // MVATrainerLooper implementation
72 
75 {
76 }
77 
79 {
80 }
81 
83 {
84  dataProcessedInLoop = false;
85 
87  iter != trainers.end(); iter++) {
88  Trainer *trainer = *iter;
89 
90  trainer->trainCalib =
91  TrainObject(trainer->trainer->getTrainCalibration());
92  }
93 }
94 
97  const edm::EventSetup &es)
98 {
99  dataProcessedInLoop = true;
100 
101  if (trainers.empty())
102  return kStop;
103 
105  iter != trainers.end(); iter++)
106  if ((*iter)->getCalibration())
107  return kContinue;
108 
109  trainers.clear();
110  return kStop;
111 }
112 
114  unsigned int iteration)
115 {
116  if (!dataProcessedInLoop) {
117  cms::Exception ex("MVATrainerLooper");
118  ex << "No data processed during loop\n";
119  ex.addContext("Calling MVATrainerLooper::endOfLoop()");
120  throw ex;
121  }
122 
123  if (trainers.empty())
124  return kStop;
125 
127  iter != trainers.end(); iter++) {
128  Trainer *trainer = *iter;
129 
130  if (trainer->trainCalib)
131  trainer->trainer->doneTraining(
132  trainer->trainCalib.get());
133 
134  trainer->trainCalib.reset();
135  }
136 
137  return kContinue;
138 }
139 
140 } // namespace PhysicsTools
T getUntrackedParameter(std::string const &, T const &) const
virtual Status duringLoop(const edm::Event &ev, const edm::EventSetup &es)
std::auto_ptr< MVATrainer > trainer
MVATrainerLooper(const edm::ParameterSet &params)
virtual void startingNewLoop(unsigned int iteration)
tuple iteration
Definition: align_cfg.py:5
virtual Status endOfLoop(const edm::EventSetup &es, unsigned int iteration)
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:168
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
#define end
Definition: vmac.h:38
Trainer(const edm::ParameterSet &params)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
boost::shared_ptr< Calibration::MVAComputer > TrainObject
FileInPath getFileInPath() const
Definition: Entry.cc:787
void addContext(std::string const &context)
Definition: Exception.cc:227
std::vector< Trainer * >::const_iterator const_iterator
#define begin
Definition: vmac.h:31
char typeCode() const
Definition: Entry.h:175
Entry const * retrieveUntracked(char const *) const
std::string fullPath() const
Definition: FileInPath.cc:171
long double T
std::string getString() const
Definition: Entry.cc:764