CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Private Attributes
PhysicsTools::MVATrainerFileSave Class Referenceabstract

#include <MVATrainerFileSave.h>

Inheritance diagram for PhysicsTools::MVATrainerFileSave:
edm::EDAnalyzer edm::EDConsumerBase PhysicsTools::MVATrainerFileSaveImpl< Record_t >

Public Member Functions

void analyze (const edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
void endJob () override
 
 MVATrainerFileSave (const edm::ParameterSet &params)
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
 ~EDAnalyzer () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Protected Member Functions

virtual const Calibration::MVAComputerContainergetToPut (const edm::EventSetup &es) const =0
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Protected Attributes

bool trained
 

Private Types

typedef std::map< std::string, std::string > LabelFileMap
 

Private Attributes

std::unique_ptr< Calibration::MVAComputerContainercalib
 
bool saved
 
LabelFileMap toPut
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 

Detailed Description

Definition at line 17 of file MVATrainerFileSave.h.

Member Typedef Documentation

typedef std::map<std::string, std::string> PhysicsTools::MVATrainerFileSave::LabelFileMap
private

Definition at line 33 of file MVATrainerFileSave.h.

Constructor & Destructor Documentation

PhysicsTools::MVATrainerFileSave::MVATrainerFileSave ( const edm::ParameterSet params)
explicit

Definition at line 23 of file MVATrainerFileSave.cc.

References edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNames(), names, AlCaHLTBitMon_QueryRunRegistry::string, and toPut.

23  :
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 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const std::string names[nVars_]
std::vector< std::string > getParameterNames() const

Member Function Documentation

void PhysicsTools::MVATrainerFileSave::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
override

Definition at line 38 of file MVATrainerFileSave.cc.

References calib, getToPut(), PhysicsTools::MVATrainerLooper::isUntrained(), eostools::move(), and saved.

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(
52  new Calibration::MVAComputerContainer);
53  *calib = *toPutCalib;
54 
55  this->calib = std::move(calib);
56 }
virtual const Calibration::MVAComputerContainer * getToPut(const edm::EventSetup &es) const =0
std::unique_ptr< Calibration::MVAComputerContainer > calib
static bool isUntrained(const T *ptr)
def move(src, dest)
Definition: eostools.py:510
void PhysicsTools::MVATrainerFileSave::endJob ( void  )
overridevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 58 of file MVATrainerFileSave.cc.

References saved, toPut, and PhysicsTools::MVAComputer::writeCalibration().

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 }
static void writeCalibration(const char *filename, const Calibration::MVAComputer *calib)
write calibration object to file
Definition: MVAComputer.cc:276
virtual const Calibration::MVAComputerContainer* PhysicsTools::MVATrainerFileSave::getToPut ( const edm::EventSetup es) const
protectedpure virtual

Member Data Documentation

std::unique_ptr<Calibration::MVAComputerContainer> PhysicsTools::MVATrainerFileSave::calib
private

Definition at line 36 of file MVATrainerFileSave.h.

Referenced by analyze().

bool PhysicsTools::MVATrainerFileSave::saved
private

Definition at line 37 of file MVATrainerFileSave.h.

Referenced by analyze(), and endJob().

LabelFileMap PhysicsTools::MVATrainerFileSave::toPut
private

Definition at line 35 of file MVATrainerFileSave.h.

Referenced by endJob(), and MVATrainerFileSave().

bool PhysicsTools::MVATrainerFileSave::trained
protected