Belle II Software light-2406-ragdoll
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
14using namespace Belle2;
15
16namespace {
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}
std::string getName() const
Returns the name of the third-party MVA library.
Definition: Interface.cc:41
static std::map< std::string, AbstractInterface * > getSupportedInterfaces()
Returns interfaces supported by the MVA Interface.
Definition: Interface.h:53
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
virtual std::vector< float > apply(Dataset &test_data) const =0
Apply this expert onto a dataset.
virtual void load(Weightfile &weightfile)=0
Load the expert from a Weightfile.
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< MVA::Expert > getExpert() const override
Get Exoert of this MVA library.
Definition: Interface.h:125
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:116
virtual std::unique_ptr< SpecificOptions > getOptions() const override
Get Options of this MVA library.
Definition: Interface.h:109
virtual po::options_description getDescription()=0
Returns a program options description for all available options.
virtual void load(const boost::property_tree::ptree &pt)=0
Load mechanism (used by Weightfile) to load Options from a xml tree.
virtual void save(boost::property_tree::ptree &pt) const =0
Save mechanism (used by Weightfile) to store Options in a xml tree.
Specific Options, all method Options have to inherit from this class.
Definition: Options.h:98
virtual std::string getMethod() const =0
Returns method name, used in the interface to register the method.
Abstract base class of all Teachers Each MVA library has its own implementation of this class,...
Definition: Teacher.h:29
virtual Weightfile train(Dataset &training_data) const =0
Train a mva method using the given dataset returning a Weightfile.
The Weightfile class serializes all information about a training into an xml tree.
Definition: Weightfile.h:38
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24