CMS 3D CMS Logo

GBRForestWriter.h
Go to the documentation of this file.
1 #ifndef CommonTools_MVAUtils_GBRForestWriter_h
2 #define CommonTools_MVAUtils_GBRForestWriter_h
3 
17 
18 #include <string>
19 #include <vector>
20 
22 public:
24  ~GBRForestWriter() override;
25 
26 private:
27  void analyze(const edm::Event&, const edm::EventSetup&) override;
28 
30 
31  bool hasRun_;
32 
33  typedef std::vector<std::string> vstring;
34 
37  {
38  if (cfg.existsAs<edm::FileInPath>("inputFileName")) {
39  edm::FileInPath inputFileName_fip = cfg.getParameter<edm::FileInPath>("inputFileName");
40  inputFileName_ = inputFileName_fip.fullPath();
41  } else if (cfg.existsAs<std::string>("inputFileName")) {
42  inputFileName_ = cfg.getParameter<std::string>("inputFileName");
43  } else
44  throw cms::Exception("GBRForestWriter") << " Undefined Configuration Parameter 'inputFileName !!\n";
45  std::string inputFileType_string = cfg.getParameter<std::string>("inputFileType");
46  if (inputFileType_string == "XML")
48  else if (inputFileType_string == "GBRForest")
50  else
51  throw cms::Exception("GBRForestWriter")
52  << " Invalid Configuration Parameter 'inputFileType' = " << inputFileType_string << " !!\n";
53  if (inputFileType_ == kXML) {
54  inputVariables_ = cfg.getParameter<vstring>("inputVariables");
55  spectatorVariables_ = cfg.getParameter<vstring>("spectatorVariables");
56  methodName_ = cfg.getParameter<std::string>("methodName");
58  = (cfg.existsAs<std::string>("gbrForestName") ? cfg.getParameter<std::string>("gbrForestName")
59  : methodName_);
60  } else {
61  gbrForestName_ = cfg.getParameter<std::string>("gbrForestName");
62  }
63  }
66  enum { kXML, kGBRForest };
68  vstring inputVariables_;
72  };
73  struct jobEntryType {
75  {
76  if (cfg.exists("categories")) {
77  edm::VParameterSet cfgCategories = cfg.getParameter<edm::VParameterSet>("categories");
78  for (edm::VParameterSet::const_iterator cfgCategory = cfgCategories.begin();
79  cfgCategory != cfgCategories.end(); ++cfgCategory) {
80  categoryEntryType* category = new categoryEntryType(*cfgCategory);
81  categories_.push_back(category);
82  }
83  } else {
85  categories_.push_back(category);
86  }
87  std::string outputFileType_string = cfg.getParameter<std::string>("outputFileType");
88  if (outputFileType_string == "GBRForest")
89  outputFileType_ = kGBRForest;
90  else if (outputFileType_string == "SQLLite")
91  outputFileType_ = kSQLLite;
92  else
93  throw cms::Exception("GBRForestWriter")
94  << " Invalid Configuration Parameter 'outputFileType' = " << outputFileType_string << " !!\n";
95  if (outputFileType_ == kGBRForest) {
96  outputFileName_ = cfg.getParameter<std::string>("outputFileName");
97  }
98  if (outputFileType_ == kSQLLite) {
99  outputRecord_ = cfg.getParameter<std::string>("outputRecord");
100  }
101  }
103  {
104  for (std::vector<categoryEntryType*>::iterator it = categories_.begin(); it != categories_.end(); ++it) {
105  delete (*it);
106  }
107  }
108  std::vector<categoryEntryType*> categories_;
109  enum { kGBRForest, kSQLLite };
113  };
114  std::vector<jobEntryType*> jobs_;
115 };
116 
117 #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:185
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