Belle II Software  release-08-01-10
Interface.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #pragma once
10 #ifndef INCLUDE_GUARD_BELLE2_MVA_INTERFACE_HEADER
11 #define INCLUDE_GUARD_BELLE2_MVA_INTERFACE_HEADER
12 
13 #include <mva/interface/Teacher.h>
14 #include <mva/interface/Expert.h>
15 
16 #include <map>
17 #include <string>
18 #include <memory>
19 
20 namespace Belle2 {
25  namespace MVA {
26 
31  public:
36  explicit AbstractInterface(const std::string& name);
37 
41  virtual ~AbstractInterface();
42 
47  std::string getName() const;
48 
53  static std::map<std::string, AbstractInterface*> getSupportedInterfaces() { return s_supported_interfaces; }
54 
60  static void initSupportedInterfaces();
61 
65  virtual std::unique_ptr<SpecificOptions> getOptions() const = 0;
66 
72  virtual std::unique_ptr<Teacher> getTeacher(const GeneralOptions& general_options,
73  const SpecificOptions& specific_options) const = 0;
74 
78  virtual std::unique_ptr<MVA::Expert> getExpert() const = 0;
79 
80  private:
84  std::string m_name;
85 
89  static std::map<std::string, AbstractInterface*> s_supported_interfaces;
90 
91  };
92 
93 
98  template<class TemplateOptions, class TemplateTeacher, class TemplateExpert>
99  class Interface : public AbstractInterface {
100  public:
105  Interface() : AbstractInterface(TemplateOptions().getMethod()) { }
106 
110  virtual std::unique_ptr<SpecificOptions> getOptions() const override { return std::unique_ptr<SpecificOptions>(new TemplateOptions); }
111 
117  virtual std::unique_ptr<Teacher> getTeacher(const GeneralOptions& general_options,
118  const SpecificOptions& specific_options) const override
119  {
120  return std::unique_ptr<Teacher>(new TemplateTeacher(general_options, dynamic_cast<const TemplateOptions&>(specific_options)));
121  }
122 
126  virtual std::unique_ptr<MVA::Expert> getExpert() const override { return std::unique_ptr<MVA::Expert>(new TemplateExpert); }
127 
128  };
129 
130  }
132 }
133 #endif
Abstract Interface to third-party MVA libraries.
Definition: Interface.h:30
static std::map< std::string, AbstractInterface * > getSupportedInterfaces()
Returns interfaces supported by the MVA Interface.
Definition: Interface.h:53
virtual std::unique_ptr< Teacher > getTeacher(const GeneralOptions &general_options, const SpecificOptions &specific_options) const =0
Get Teacher of this MVA library.
virtual std::unique_ptr< SpecificOptions > getOptions() const =0
Get Options of this MVA library.
static void initSupportedInterfaces()
Static function which initliazes all supported interfaces, has to be called once before getSupportedI...
Definition: Interface.cc:45
std::string getName() const
Returns the name of the third-party MVA library.
Definition: Interface.cc:41
static std::map< std::string, AbstractInterface * > s_supported_interfaces
Map of supported interfaces.
Definition: Interface.h:89
virtual std::unique_ptr< MVA::Expert > getExpert() const =0
Get Exoert of this MVA library.
AbstractInterface(const std::string &name)
Creates a new Interface to a third-party library.
Definition: Interface.cc:27
std::string m_name
Name of the third-party library.
Definition: Interface.h:84
virtual ~AbstractInterface()
Virtual destructor.
Definition: Interface.cc:36
General options which are shared by all MVA trainings.
Definition: Options.h:62
Template class to easily construct a interface for an MVA library using a library-specific Options,...
Definition: Interface.h:99
virtual std::unique_ptr< Teacher > getTeacher(const GeneralOptions &general_options, const SpecificOptions &specific_options) const override
Get Teacher of this MVA library.
Definition: Interface.h:117
Interface()
Constructs a new interface with the given name.
Definition: Interface.h:105
virtual std::unique_ptr< MVA::Expert > getExpert() const override
Get Exoert of this MVA library.
Definition: Interface.h:126
virtual std::unique_ptr< SpecificOptions > getOptions() const override
Get Options of this MVA library.
Definition: Interface.h:110
Specific Options, all method Options have to inherit from this class.
Definition: Options.h:98
Abstract base class for different kinds of events.