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 
74 {
75 }
76 
78 {
79 }
80 
82 {
84  iter != trainers.end(); iter++) {
85  Trainer *trainer = *iter;
86 
87  trainer->trainCalib =
88  TrainObject(trainer->trainer->getTrainCalibration());
89  }
90 }
91 
94  const edm::EventSetup &es)
95 {
96  if (trainers.empty())
97  return kStop;
98 
100  iter != trainers.end(); iter++)
101  if ((*iter)->getCalibration())
102  return kContinue;
103 
104  trainers.clear();
105  return kStop;
106 }
107 
109  unsigned int iteration)
110 {
111  if (trainers.empty())
112  return kStop;
113 
115  iter != trainers.end(); iter++) {
116  Trainer *trainer = *iter;
117 
118  if (trainer->trainCalib)
119  trainer->trainer->doneTraining(
120  trainer->trainCalib.get());
121 
122  trainer->trainCalib.reset();
123  }
124 
125  return kContinue;
126 }
127 
128 } // 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)
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:777
std::vector< Trainer * >::const_iterator const_iterator
#define begin
Definition: vmac.h:31
char typeCode() const
Definition: Entry.h:170
std::string fullPath() const
Definition: FileInPath.cc:170
Entry const *const retrieveUntracked(char const *) const
long double T
std::string getString() const
Definition: Entry.cc:754