test
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 
10 
12 
15 
16 namespace PhysicsTools {
17 
18 namespace {
19  template<typename T>
20  struct deleter : public std::unary_function<T*, void> {
21  inline void operator() (T *ptr) const { delete ptr; }
22  };
23 }
24 
25 // MVATrainerLooper::Trainer implementation
26 
28 {
29  const edm::Entry *entry = params.retrieveUntracked("trainDescription");
30  if (!entry)
32  "MissingParameter:")
33  << "The required parameter 'trainDescription' "
34  "was not specified." << std::endl;;
35  std::string trainDescription;
36  if (entry->typeCode() == 'F')
37  trainDescription = entry->getFileInPath().fullPath();
38  else
39  trainDescription = entry->getString();
40 
41  bool useXSLT = params.getUntrackedParameter<bool>("useXSLT", false);
42  bool doLoad = params.getUntrackedParameter<bool>("loadState", false);
43  bool doSave = params.getUntrackedParameter<bool>("saveState", false);
44  bool doMonitoring = params.getUntrackedParameter<bool>("monitoring", false);
45 
46  trainer.reset(new MVATrainer(trainDescription, useXSLT));
47 
48  if (doLoad)
49  trainer->loadState();
50 
51  trainer->setAutoSave(doSave);
52  trainer->setCleanup(!doSave);
53  trainer->setMonitoring(doMonitoring);
54 }
55 
56 // MVATrainerLooper::MVATrainerContainer implementation
57 
59 {
60  clear();
61 }
62 
64 {
65  std::for_each(begin(), end(), deleter<Trainer>());
66  content.clear();
67 }
68 
69 // MVATrainerLooper implementation
70 
73 {
74 }
75 
77 {
78 }
79 
81 {
82  dataProcessedInLoop = false;
83 
85  iter != trainers.end(); iter++) {
86  Trainer *trainer = *iter;
87 
88  trainer->trainCalib =
89  TrainObject(trainer->trainer->getTrainCalibration());
90  }
91 }
92 
95  const edm::EventSetup &es)
96 {
97  dataProcessedInLoop = true;
98 
99  if (trainers.empty())
100  return kStop;
101 
103  iter != trainers.end(); iter++)
104  if ((*iter)->getCalibration())
105  return kContinue;
106 
107  trainers.clear();
108  return kStop;
109 }
110 
112  unsigned int iteration)
113 {
114  if (!dataProcessedInLoop) {
115  cms::Exception ex("MVATrainerLooper");
116  ex << "No data processed during loop\n";
117  ex.addContext("Calling MVATrainerLooper::endOfLoop()");
118  throw ex;
119  }
120 
121  if (trainers.empty())
122  return kStop;
123 
125  iter != trainers.end(); iter++) {
126  Trainer *trainer = *iter;
127 
128  if (trainer->trainCalib)
129  trainer->trainer->doneTraining(
130  trainer->trainCalib.get());
131 
132  trainer->trainCalib.reset();
133  }
134 
135  return kContinue;
136 }
137 
138 } // 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:167
#define end
Definition: vmac.h:37
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
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:30
list entry
Definition: mps_splice.py:62
std::shared_ptr< Calibration::MVAComputer > TrainObject
char typeCode() const
Definition: Entry.h:175
Entry const * retrieveUntracked(char const *) const
volatile std::atomic< bool > shutdown_flag false
std::string fullPath() const
Definition: FileInPath.cc:184
long double T
std::string getString() const
Definition: Entry.cc:764