Belle II Software  release-05-01-25
test_Interface.cc
1 /* BASF2 (Belle Analysis Framework 2) *
2  * Copyright(C) 2016 - Belle II Collaboration *
3  * *
4  * Author: The Belle II Collaboration *
5  * Contributors: Thomas Keck *
6  * *
7  * This software is provided "as is" without any warranty. *
8  **************************************************************************/
9 
10 #include <mva/interface/Interface.h>
11 #include <framework/utilities/TestHelpers.h>
12 
13 #include <gtest/gtest.h>
14 
15 using namespace Belle2;
16 
17 namespace {
18 
19  class TestOptions : public MVA::SpecificOptions {
20 
21  public:
22  void load(const boost::property_tree::ptree&) override { }
23  void save(boost::property_tree::ptree&) const override { }
24  po::options_description getDescription() override
25  {
26  po::options_description description("General options");
27  description.add_options()
28  ("help", "print this message");
29  return description;
30  }
31  [[nodiscard]] std::string getMethod() const override { return "Test"; }
32  };
33 
34  class TestTeacher : public MVA::Teacher {
35  public:
36  TestTeacher(const MVA::GeneralOptions& g, const TestOptions&) : MVA::Teacher(g) { }
37  MVA::Weightfile train(MVA::Dataset&) const override { return MVA::Weightfile(); }
38  };
39 
40  class TestExpert : public MVA::Expert {
41  public:
42  void load(MVA::Weightfile&) override { }
43  std::vector<float> apply(MVA::Dataset&) const override { return std::vector<float>(); };
44  };
45 
46  TEST(InterfaceTest, InterfaceCreation)
47  {
48  {
50 
51  EXPECT_EQ(interface.getName(), "Test");
52  auto supported_interfaces = MVA::AbstractInterface::getSupportedInterfaces();
53  EXPECT_TRUE(supported_interfaces.find("Test") != supported_interfaces.end());
54  EXPECT_EQ(supported_interfaces["Test"], &interface);
55 
56  // These should just work
57  interface.getOptions();
58  interface.getExpert();
59  interface.getTeacher(MVA::GeneralOptions(), TestOptions());
60 
61  // Adding the same interface twice should emit a warning
63  }
64 
65  // Now it should be removed again
66  auto supported_interfaces = MVA::AbstractInterface::getSupportedInterfaces();
67  EXPECT_TRUE(supported_interfaces.find("Test") == supported_interfaces.end());
68 
69 
70  }
71 }
Belle2::MVA::AbstractInterface::getSupportedInterfaces
static std::map< std::string, AbstractInterface * > getSupportedInterfaces()
Returns interfaces supported by the MVA Interface.
Definition: Interface.h:55
Belle2::MVA::Dataset
Abstract base class of all Datasets given to the MVA interface The current event can always be access...
Definition: Dataset.h:34
Belle2::MVA::Weightfile
The Weightfile class serializes all information about a training into an xml tree.
Definition: Weightfile.h:40
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
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::MVA::Teacher
Abstract base class of all Teachers Each MVA library has its own implementation of this class,...
Definition: Teacher.h:31
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::Expert
Abstract base class of all Expert Each MVA library has its own implementation of this class,...
Definition: Expert.h:33
Belle2::MVA::GeneralOptions
General options which are shared by all MVA trainings.
Definition: Options.h:64
Belle2::TEST
TEST(TestgetDetectorRegion, TestgetDetectorRegion)
Test Constructors.
Definition: utilityFunctions.cc:18
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::Interface
Template class to easily construct a interface for an MVA library using a library-specific Options,...
Definition: Interface.h:101