CMS 3D CMS Logo

GBRForestWriter.h
Go to the documentation of this file.
1 #ifndef RecoMET_METPUSubtraction_GBRForestWriter_h
2 #define RecoMET_METPUSubtraction_GBRForestWriter_h
3 
17 
18 #include <vector>
19 #include <string>
20 
22 {
23  public:
25  ~GBRForestWriter() override;
26 
27  private:
28  void analyze(const edm::Event&, const edm::EventSetup&) override;
29 
31 
32  bool hasRun_;
33 
34  typedef std::vector<std::string> vstring;
35 
37  {
39  {
40  if ( cfg.existsAs<edm::FileInPath>("inputFileName") ) {
41  edm::FileInPath inputFileName_fip = cfg.getParameter<edm::FileInPath>("inputFileName");
42  inputFileName_ = inputFileName_fip.fullPath();
43  } else if ( cfg.existsAs<std::string>("inputFileName") ) {
44  inputFileName_ = cfg.getParameter<std::string>("inputFileName");
45  } else throw cms::Exception("GBRForestWriter")
46  << " Undefined Configuration Parameter 'inputFileName !!\n";
47  std::string inputFileType_string = cfg.getParameter<std::string>("inputFileType");
48  if ( inputFileType_string == "XML" ) inputFileType_ = kXML;
49  else if ( inputFileType_string == "GBRForest" ) inputFileType_ = kGBRForest;
50  else throw cms::Exception("GBRForestWriter")
51  << " Invalid Configuration Parameter 'inputFileType' = " << inputFileType_string << " !!\n";
52  if ( inputFileType_ == kXML ) {
53  inputVariables_ = cfg.getParameter<vstring>("inputVariables");
54  spectatorVariables_ = cfg.getParameter<vstring>("spectatorVariables");
55  methodName_ = cfg.getParameter<std::string>("methodName");
56  gbrForestName_ = ( cfg.existsAs<std::string>("gbrForestName") ? cfg.getParameter<std::string>("gbrForestName") : methodName_ );
57  }
58  else
59  gbrForestName_ = cfg.getParameter<std::string>("gbrForestName");
60  }
63  enum { kXML, kGBRForest };
65  vstring inputVariables_;
69  };
70  struct jobEntryType
71  {
73  {
74  if ( cfg.exists("categories") ) {
75  edm::VParameterSet cfgCategories = cfg.getParameter<edm::VParameterSet>("categories");
76  for ( edm::VParameterSet::const_iterator cfgCategory = cfgCategories.begin();
77  cfgCategory != cfgCategories.end(); ++cfgCategory ) {
78  categoryEntryType* category = new categoryEntryType(*cfgCategory);
79  categories_.push_back(category);
80  }
81  } else {
83  categories_.push_back(category);
84  }
85  std::string outputFileType_string = cfg.getParameter<std::string>("outputFileType");
86  if ( outputFileType_string == "GBRForest" ) outputFileType_ = kGBRForest;
87  else if ( outputFileType_string == "SQLLite" ) outputFileType_ = kSQLLite;
88  else throw cms::Exception("GBRForestWriter")
89  << " Invalid Configuration Parameter 'outputFileType' = " << outputFileType_string << " !!\n";
90  if ( outputFileType_ == kGBRForest ) {
91  outputFileName_ = cfg.getParameter<std::string>("outputFileName");
92  }
93  if ( outputFileType_ == kSQLLite ) {
94  outputRecord_ = cfg.getParameter<std::string>("outputRecord");
95  }
96  }
98  {
99  for ( std::vector<categoryEntryType*>::iterator it = categories_.begin();
100  it != categories_.end(); ++it ) {
101  delete (*it);
102  }
103  }
104  std::vector<categoryEntryType*> categories_;
105  enum { kGBRForest, kSQLLite };
109  };
110  std::vector<jobEntryType*> jobs_;
111 };
112 
113 #endif
T getParameter(std::string const &) const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
categoryEntryType(const edm::ParameterSet &cfg)
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:33
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::string moduleLabel_
GBRForestWriter(const edm::ParameterSet &)
std::vector< categoryEntryType * > categories_
~GBRForestWriter() override
jobEntryType(const edm::ParameterSet &cfg)
void analyze(const edm::Event &, const edm::EventSetup &) override
std::vector< jobEntryType * > jobs_
std::string fullPath() const
Definition: FileInPath.cc:197
std::vector< std::string > vstring