CMS 3D CMS Logo

MVATrainerFileSave.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <memory>
3 #include <vector>
4 #include <string>
5 
14 
16 
20 
21 namespace PhysicsTools {
22 
24  trained(params.getUntrackedParameter<bool>("trained", true)),
25  saved(false)
26 {
27  std::vector<std::string> names = params.getParameterNames();
28  for(std::vector<std::string>::const_iterator iter = names.begin();
29  iter != names.end(); iter++) {
30  if (iter->c_str()[0] == '@' || *iter == "trained")
31  continue;
32 
33  toPut[*iter] = params.getParameter<std::string>(*iter);
34  }
35 
36 }
37 
39  const edm::EventSetup& es)
40 {
41  if (calib.get() || saved)
42  return;
43 
44  const Calibration::MVAComputerContainer *toPutCalib = getToPut(es);
45  if (MVATrainerLooper::isUntrained(toPutCalib))
46  return;
47 
48  edm::LogInfo("MVATrainerFileSave")
49  << "Got the trained calibration data";
50 
51  std::unique_ptr<Calibration::MVAComputerContainer> calib(
53  *calib = *toPutCalib;
54 
55  this->calib = std::move(calib);
56 }
57 
59 {
60  if (!calib.get() || saved)
61  return;
62 
63  edm::LogInfo("MVATrainerFileSave")
64  << "Saving calibration data into plain MVA files.";
65 
66  for(LabelFileMap::const_iterator iter = toPut.begin();
67  iter != toPut.end(); iter++) {
68  const Calibration::MVAComputer *calibration =
69  &calib->find(iter->first);
70 
71  MVAComputer::writeCalibration(iter->second.c_str(),
72  calibration);
73  }
74 
75  saved = true;
76 }
77 
78 } // namespace PhysicsTools
T getParameter(std::string const &) const
virtual const Calibration::MVAComputerContainer * getToPut(const edm::EventSetup &es) const =0
MVATrainerFileSave(const edm::ParameterSet &params)
const std::string names[nVars_]
static void writeCalibration(const char *filename, const Calibration::MVAComputer *calib)
write calibration object to file
Definition: MVAComputer.cc:276
std::vector< std::string > getParameterNames() const
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
std::unique_ptr< Calibration::MVAComputerContainer > calib
static bool isUntrained(const T *ptr)
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1