Belle II Software  release-05-02-19
Interface.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Thomas Keck *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 #ifndef INCLUDE_GUARD_BELLE2_MVA_INTERFACE_HEADER
13 #define INCLUDE_GUARD_BELLE2_MVA_INTERFACE_HEADER
14 
15 #include <mva/interface/Teacher.h>
16 #include <mva/interface/Expert.h>
17 
18 #include <map>
19 #include <string>
20 #include <memory>
21 
22 namespace Belle2 {
27  namespace MVA {
28 
33  public:
38  explicit AbstractInterface(const std::string& name);
39 
43  virtual ~AbstractInterface();
44 
49  std::string getName() const;
50 
55  static std::map<std::string, AbstractInterface*> getSupportedInterfaces() { return s_supported_interfaces; }
56 
62  static void initSupportedInterfaces();
63 
67  virtual std::unique_ptr<SpecificOptions> getOptions() const = 0;
68 
74  virtual std::unique_ptr<Teacher> getTeacher(const GeneralOptions& general_options,
75  const SpecificOptions& specific_options) const = 0;
76 
80  virtual std::unique_ptr<MVA::Expert> getExpert() const = 0;
81 
82  private:
86  std::string m_name;
87 
91  static std::map<std::string, AbstractInterface*> s_supported_interfaces;
92 
93  };
94 
95 
100  template<class TemplateOptions, class TemplateTeacher, class TemplateExpert>
101  class Interface : public AbstractInterface {
102  public:
107  Interface() : AbstractInterface(TemplateOptions().getMethod()) { }
108 
112  virtual std::unique_ptr<SpecificOptions> getOptions() const override { return std::unique_ptr<SpecificOptions>(new TemplateOptions); }
113 
119  virtual std::unique_ptr<Teacher> getTeacher(const GeneralOptions& general_options,
120  const SpecificOptions& specific_options) const override
121  {
122  return std::unique_ptr<Teacher>(new TemplateTeacher(general_options, dynamic_cast<const TemplateOptions&>(specific_options)));
123  }
124 
128  virtual std::unique_ptr<MVA::Expert> getExpert() const override { return std::unique_ptr<MVA::Expert>(new TemplateExpert); }
129 
130  };
131 
132  }
134 }
135 #endif
Belle2::MVA::AbstractInterface
Abstract Interface to third-party MVA libraries.
Definition: Interface.h:32
Belle2::MVA::AbstractInterface::getSupportedInterfaces
static std::map< std::string, AbstractInterface * > getSupportedInterfaces()
Returns interfaces supported by the MVA Interface.
Definition: Interface.h:55
Belle2::MVA::AbstractInterface::~AbstractInterface
virtual ~AbstractInterface()
Virtual destructor.
Definition: Interface.cc:46
Belle2::MVA::AbstractInterface::m_name
std::string m_name
Name of the third-party library.
Definition: Interface.h:86
Belle2::MVA::AbstractInterface::getOptions
virtual std::unique_ptr< SpecificOptions > getOptions() const =0
Get Options of this MVA library.
Belle2::MVA::Interface::getTeacher
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:119
Belle2::MVA::SpecificOptions
Specific Options, all mehtod Options have to inherit from this class.
Definition: Options.h:99
Belle2::MVA::Interface::Interface
Interface()
Constructs a new interface with the given name.
Definition: Interface.h:107
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::MVA::Interface::getOptions
virtual std::unique_ptr< SpecificOptions > getOptions() const override
Get Options of this MVA library.
Definition: Interface.h:112
Belle2::MVA::AbstractInterface::getName
std::string getName() const
Returns the name of the third-party MVA library.
Definition: Interface.cc:51
Belle2::MVA::AbstractInterface::getTeacher
virtual std::unique_ptr< Teacher > getTeacher(const GeneralOptions &general_options, const SpecificOptions &specific_options) const =0
Get Teacher of this MVA library.
Belle2::MVA::GeneralOptions
General options which are shared by all MVA trainings.
Definition: Options.h:64
Belle2::MVA::AbstractInterface::initSupportedInterfaces
static void initSupportedInterfaces()
Static function which initliazes all supported interfaces, has to be called once before getSupportedI...
Definition: Interface.cc:55
Belle2::MVA::AbstractInterface::AbstractInterface
AbstractInterface(const std::string &name)
Creates a new Interface to a third-party library.
Definition: Interface.cc:37
Belle2::MVA::Interface::getExpert
virtual std::unique_ptr< MVA::Expert > getExpert() const override
Get Exoert of this MVA library.
Definition: Interface.h:128
Belle2::MVA::AbstractInterface::s_supported_interfaces
static std::map< std::string, AbstractInterface * > s_supported_interfaces
Map of supported interfaces.
Definition: Interface.h:91
Belle2::MVA::Interface
Template class to easily construct a interface for an MVA library using a library-specific Options,...
Definition: Interface.h:101
Belle2::MVA::AbstractInterface::getExpert
virtual std::unique_ptr< MVA::Expert > getExpert() const =0
Get Exoert of this MVA library.