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