CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes
GBRForestWriter Class Reference

#include <GBRForestWriter.h>

Inheritance diagram for GBRForestWriter:
edm::EDAnalyzer edm::EDConsumerBase

Classes

struct  categoryEntryType
 
struct  jobEntryType
 

Public Member Functions

 GBRForestWriter (const edm::ParameterSet &)
 
 ~GBRForestWriter ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Types

typedef std::vector< std::string > vstring
 

Private Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 

Private Attributes

bool hasRun_
 
std::vector< jobEntryType * > jobs_
 
std::string moduleLabel_
 

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 &)
 
- 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)
 

Detailed Description

Read GBRForest objects from ROOT file input and store it in SQL-lite output file

Authors
Christian Veelken, LLR

Definition at line 21 of file GBRForestWriter.h.

Member Typedef Documentation

typedef std::vector<std::string> GBRForestWriter::vstring
private

Definition at line 34 of file GBRForestWriter.h.

Constructor & Destructor Documentation

GBRForestWriter::GBRForestWriter ( const edm::ParameterSet cfg)

Definition at line 21 of file GBRForestWriter.cc.

References edm::ParameterSet::getParameter(), runGlobalFakeInputProducer::job, and jobs_.

22  : moduleLabel_(cfg.getParameter<std::string>("@module_label"))
23 {
24  edm::VParameterSet cfgJobs = cfg.getParameter<edm::VParameterSet>("jobs");
25  for ( edm::VParameterSet::const_iterator cfgJob = cfgJobs.begin();
26  cfgJob != cfgJobs.end(); ++cfgJob ) {
27  jobEntryType* job = new jobEntryType(*cfgJob);
28  jobs_.push_back(job);
29  }
30 }
T getParameter(std::string const &) const
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:33
std::string moduleLabel_
std::vector< jobEntryType * > jobs_
GBRForestWriter::~GBRForestWriter ( )

Definition at line 32 of file GBRForestWriter.cc.

References jobs_.

33 {
34  for ( std::vector<jobEntryType*>::iterator it = jobs_.begin();
35  it != jobs_.end(); ++it ) {
36  delete (*it);
37  }
38 }
std::vector< jobEntryType * > jobs_

Member Function Documentation

void GBRForestWriter::analyze ( const edm::Event ,
const edm::EventSetup  
)
privatevirtual

Implements edm::EDAnalyzer.

Definition at line 40 of file GBRForestWriter.cc.

References cond::service::PoolDBOutputService::beginOfTime(), python.rootplot.argparse::category, Exception, analyzePatCleaning_cfg::inputFile, edm::Service< T >::isAvailable(), runGlobalFakeInputProducer::job, jobs_, GBRForestWriter::categoryEntryType::kGBRForest, GBRForestWriter::jobEntryType::kGBRForest, GBRForestWriter::jobEntryType::kSQLLite, GBRForestWriter::categoryEntryType::kXML, reco::details::loadTMVAWeights(), download_sqlite_cfg::outputFile, writeAntiElectronDiscrMVA_cfi::outputRecord, AlCaHLTBitMon_QueryRunRegistry::string, and cond::service::PoolDBOutputService::writeOne().

41 {
42 
43  for ( std::vector<jobEntryType*>::iterator job = jobs_.begin();
44  job != jobs_.end(); ++job ) {
45  std::map<std::string, const GBRForest*> gbrForests; // key = name
46  for ( std::vector<categoryEntryType*>::iterator category = (*job)->categories_.begin();
47  category != (*job)->categories_.end(); ++category ) {
48  const GBRForest* gbrForest = nullptr;
49  if ( (*category)->inputFileType_ == categoryEntryType::kXML ) {
50  TMVA::Tools::Instance();
51  TMVA::Reader* mvaReader = new TMVA::Reader("!V:!Silent");
52  std::vector<Float_t> dummyVariables;
53  for ( vstring::const_iterator inputVariable = (*category)->inputVariables_.begin();
54  inputVariable != (*category)->inputVariables_.end(); ++inputVariable ) {
55  dummyVariables.push_back(0.);
56  mvaReader->AddVariable(inputVariable->data(), &dummyVariables.back());
57  }
58  for ( vstring::const_iterator spectatorVariable = (*category)->spectatorVariables_.begin();
59  spectatorVariable != (*category)->spectatorVariables_.end(); ++spectatorVariable ) {
60  dummyVariables.push_back(0.);
61  mvaReader->AddSpectator(spectatorVariable->data(), &dummyVariables.back());
62  }
63  reco::details::loadTMVAWeights(mvaReader, (*category)->methodName_.data(), (*category)->inputFileName_.data());
64  TMVA::MethodBDT* bdt = dynamic_cast<TMVA::MethodBDT*>(mvaReader->FindMVA((*category)->methodName_.data()));
65  if ( !bdt )
66  throw cms::Exception("GBRForestWriter")
67  << "Failed to load MVA = " << (*category)->methodName_.data() << " from file = " << (*category)->inputFileName_ << " !!\n";
68  gbrForest = new GBRForest(bdt);
69  delete mvaReader;
70  TMVA::Tools::DestroyInstance();
71  } else if ( (*category)->inputFileType_ == categoryEntryType::kGBRForest ) {
72  TFile* inputFile = new TFile((*category)->inputFileName_.data());
73  //gbrForest = dynamic_cast<GBRForest*>(inputFile->Get((*category)->gbrForestName_.data())); // CV: dynamic_cast<GBRForest*> fails for some reason ?!
74  gbrForest = (GBRForest*)inputFile->Get((*category)->gbrForestName_.data());
75  delete inputFile;
76  }
77  if ( !gbrForest )
78  throw cms::Exception("GBRForestWriter")
79  << " Failed to load GBRForest = " << (*category)->gbrForestName_.data() << " from file = " << (*category)->inputFileName_ << " !!\n";
80  gbrForests[(*category)->gbrForestName_] = gbrForest;
81  }
82  if ( (*job)->outputFileType_ == jobEntryType::kGBRForest ) {
83  TFile* outputFile = new TFile((*job)->outputFileName_.data(), "RECREATE");
84 
85  for ( std::map<std::string, const GBRForest*>::iterator gbrForest = gbrForests.begin();
86  gbrForest != gbrForests.end(); ++gbrForest ) {
87  outputFile->WriteObject(gbrForest->second, gbrForest->first.data());
88  }
89  delete outputFile;
90  } else if ( (*job)->outputFileType_ == jobEntryType::kSQLLite ) {
92  if ( !dbService.isAvailable() )
93  throw cms::Exception("GBRForestWriter")
94  << " Failed to access PoolDBOutputService !!\n";
95 
96  for ( std::map<std::string, const GBRForest*>::iterator gbrForest = gbrForests.begin();
97  gbrForest != gbrForests.end(); ++gbrForest ) {
98  std::string outputRecord = (*job)->outputRecord_;
99  if ( gbrForests.size() > 1 ) outputRecord.append("_").append(gbrForest->first);
100  dbService->writeOne(gbrForest->second, dbService->beginOfTime(), outputRecord);
101  }
102  }
103 
104  //gbrforest deletion
105  for ( std::map<std::string, const GBRForest*>::iterator gbrForest = gbrForests.begin();
106  gbrForest != gbrForests.end(); ++gbrForest ) {
107  delete gbrForest->second;
108  }
109 
110  }
111 
112 }
bool isAvailable() const
Definition: Service.h:46
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
TMVA::IMethod * loadTMVAWeights(TMVA::Reader *reader, const std::string &method, const std::string &weightFile, bool verbose=false)
std::vector< jobEntryType * > jobs_

Member Data Documentation

bool GBRForestWriter::hasRun_
private

Definition at line 32 of file GBRForestWriter.h.

std::vector<jobEntryType*> GBRForestWriter::jobs_
private

Definition at line 110 of file GBRForestWriter.h.

Referenced by analyze(), GBRForestWriter(), and ~GBRForestWriter().

std::string GBRForestWriter::moduleLabel_
private