CMS 3D CMS Logo

MVATrainerContainerSave.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <memory>
3 #include <vector>
4 #include <string>
5 
14 
18 
20 
23 
24 namespace PhysicsTools {
25 
27  const edm::ParameterSet &params) :
28  toPut(params.getParameter<std::vector<std::string> >("toPut")),
29  toCopy(params.getParameter<std::vector<std::string> >("toCopy")),
30  saved(false)
31 {
32 }
33 
35  const edm::EventSetup& es)
36 {
37  if (calib.get() || saved)
38  return;
39 
40  const Calibration::MVAComputerContainer *toPutCalib = 0;
41  if (!toPut.empty()) {
42  toPutCalib = getToPut(es);
43  if (MVATrainerLooper::isUntrained(toPutCalib))
44  return;
45  }
46 
47  const Calibration::MVAComputerContainer *toCopyCalib = 0;
48  if (!toCopy.empty())
49  toCopyCalib = getToCopy(es);
50 
51  edm::LogInfo("MVATrainerSave") << "Got the trained calibration data";
52 
53  std::unique_ptr<Calibration::MVAComputerContainer> calib(
55 
56  for(std::vector<std::string>::const_iterator iter = toCopy.begin();
57  iter != toCopy.end(); iter++)
58  calib->add(*iter) = toCopyCalib->find(*iter);
59 
60  for(std::vector<std::string>::const_iterator iter = toPut.begin();
61  iter != toPut.end(); iter++)
62  calib->add(*iter) = toPutCalib->find(*iter);
63 
64  this->calib = std::move(calib);
65 }
66 
68 {
69  if (!calib.get() || saved)
70  return;
71 
72  edm::LogInfo("MVATrainerSave") << "Saving calibration data in CondDB.";
73 
75  if (!dbService.isAvailable())
76  throw cms::Exception("MVATrainerContainerSave")
77  << "DBService unavailable" << std::endl;
78 
80  calib.release(), dbService->beginOfTime(),
81  dbService->endOfTime(), getRecordName().c_str());
82 
83  saved = true;
84 }
85 
86 } // namespace PhysicsTools
virtual const MVAComputer & find(const std::string &label) const
Definition: MVAComputer.cc:222
virtual std::string getRecordName() const =0
std::unique_ptr< Calibration::MVAComputerContainer > calib
bool isAvailable() const
Definition: Service.h:46
virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup)
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
virtual const Calibration::MVAComputerContainer * getToCopy(const edm::EventSetup &es) const =0
MVATrainerContainerSave(const edm::ParameterSet &params)
static bool isUntrained(const T *ptr)
virtual const Calibration::MVAComputerContainer * getToPut(const edm::EventSetup &es) const =0
def move(src, dest)
Definition: eostools.py:510
Definition: event.py:1