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
 
- 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 20 of file GBRForestWriter.cc.

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

21  : moduleLabel_(cfg.getParameter<std::string>("@module_label"))
22 {
23  edm::VParameterSet cfgJobs = cfg.getParameter<edm::VParameterSet>("jobs");
24  for ( edm::VParameterSet::const_iterator cfgJob = cfgJobs.begin();
25  cfgJob != cfgJobs.end(); ++cfgJob ) {
26  jobEntryType* job = new jobEntryType(*cfgJob);
27  jobs_.push_back(job);
28  }
29 }
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 31 of file GBRForestWriter.cc.

References jobs_.

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

Member Function Documentation

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

Implements edm::EDAnalyzer.

Definition at line 39 of file GBRForestWriter.cc.

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

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

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

std::string GBRForestWriter::moduleLabel_
private