CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/PhysicsTools/MVATrainer/src/MVATrainerSave.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <memory>
00003 #include <vector>
00004 #include <string>
00005 
00006 #include "FWCore/Utilities/interface/Exception.h"
00007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00008 #include "FWCore/Framework/interface/Event.h"
00009 #include "FWCore/Framework/interface/EventSetup.h"
00010 #include "FWCore/Framework/interface/ESHandle.h"
00011 #include "FWCore/Framework/interface/EDAnalyzer.h"
00012 #include "FWCore/Framework/interface/MakerMacros.h"
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014 
00015 #include "FWCore/Framework/interface/IOVSyncValue.h"
00016 #include "FWCore/ServiceRegistry/interface/Service.h"
00017 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00018 
00019 #include "CondFormats/PhysicsToolsObjects/interface/MVAComputer.h"
00020 
00021 #include "PhysicsTools/MVATrainer/interface/MVATrainerLooper.h"
00022 #include "PhysicsTools/MVATrainer/interface/MVATrainerSave.h"
00023 
00024 namespace PhysicsTools {
00025 
00026 MVATrainerSave::MVATrainerSave(const edm::ParameterSet &params) :
00027         saved(false)
00028 {
00029 }
00030 
00031 void MVATrainerSave::analyze(const edm::Event& event,
00032                              const edm::EventSetup& es)
00033 {
00034         if (calib.get() || saved)
00035                 return;
00036 
00037         const Calibration::MVAComputer *toPutCalib = getToPut(es);
00038         if (MVATrainerLooper::isUntrained(toPutCalib))
00039                 return;
00040 
00041         edm::LogInfo("MVATrainerSave") << "Got the trained calibration data";
00042 
00043         std::auto_ptr<Calibration::MVAComputer> calib(
00044                                                 new Calibration::MVAComputer);
00045         *calib = *toPutCalib;
00046 
00047         this->calib = calib;
00048 }
00049 
00050 void MVATrainerSave::endJob()
00051 {
00052         if (!calib.get() || saved)
00053                 return;
00054 
00055         edm::LogInfo("MVATrainerSave") << "Saving calibration data in CondDB.";
00056 
00057         edm::Service<cond::service::PoolDBOutputService> dbService;
00058         if (!dbService.isAvailable())
00059                 throw cms::Exception("MVATrainerSave")
00060                         << "DBService unavailable" << std::endl;
00061 
00062         dbService->createNewIOV<Calibration::MVAComputer>(
00063                 calib.release(), dbService->beginOfTime(),
00064                 dbService->endOfTime(), getRecordName().c_str());
00065 
00066         saved = true;
00067 }
00068 
00069 } // namespace PhysicsTools