DAS  3.0
Das Analysis System
PluginLoader.cc File Reference
#include <boost/test/included/unit_test.hpp>
#include <boost/exception/all.hpp>
#include <boost/property_tree/info_parser.hpp>
#include <filesystem>
#include "Flow.h"
#include "GenericPlugin.h"
#include "Jet.h"
#include "MetaInfo.h"
#include "PluginLoader.h"
#include "exceptions.h"
+ Include dependency graph for PluginLoader.cc:

Classes

struct  AnotherPlugin
 

Macros

#define BOOST_TEST_MODULE   PluginLoader
 

Functions

 BOOST_AUTO_TEST_CASE (basic_call)
 
 BOOST_AUTO_TEST_CASE (basic_exceptions)
 
 BOOST_AUTO_TEST_CASE (move_constructor)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   PluginLoader

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/3]

BOOST_AUTO_TEST_CASE ( basic_call  )
40  {
41  fs::path file1 = "plugin_test_input.root",
42  file2 = "plugin_test_output.root";
43 
44  BOOST_TEST_MESSAGE( "Creating a tree" );
45  {
46  DT::Flow flow(DT::verbose);
47  auto tOut = flow.GetOutputTree(file1);
48  pt::ptree config;
49  pt::read_info("example.info", config);
50  DT::MetaInfo metainfo(tOut, config);
51  BOOST_TEST( metainfo.Get<bool>("flags", "isMC") == true );
52 
53  auto recJets = flow.GetBranchWriteOnly<vector<DP::RecJet>>("recJets");
54  DP::RecJet recJet;
55  recJet.p4.SetPt(1.f);
56  recJets->emplace_back(recJet);
57 
58  auto genJets = flow.GetBranchWriteOnly<vector<DP::GenJet>>("genJets");
59  DP::GenJet genJet;
60  genJet.p4.SetPt(2.f);
61  genJets->emplace_back(genJet);
62 
63  tOut->Fill();
64  }
65 
66  BOOST_TEST_MESSAGE( "Running the plugin on the tree" );
67  {
68  fs::path plugin_file = "../plugins/libFlattener." DLL_EXT;
69  vector plugin_files(2, plugin_file);
70 
71  DT::Flow flow(DT::verbose, {file1});
72  auto tIn = flow.GetInputTree();
73  auto tOut = flow.GetOutputTree(file2);
74  auto plugins = flow.GetPlugins<DT::GenericPlugin>(plugin_files);
75 
76  DT::MetaInfo metainfo(tOut, pt::ptree{});
77  BOOST_TEST( metainfo.Get<bool>("flags", "isMC") == true );
78 
80  plugin->Load(flow, metainfo);
81 
82  tIn->GetEntry(0);
83  for (auto& plugin: plugins)
84  plugin->ExecuteAtBegin();
85  for (auto& plugin: plugins | views::reverse)
86  plugin->ExecuteAtEnd();
87 
88  tOut->Fill();
89  }
90 
91  BOOST_TEST_MESSAGE( "Checking the result from the plugin" );
92  {
93  DT::Flow flow(DT::verbose, {file2});
94  auto tIn = flow.GetInputTree();
95  tIn->Scan("recJets.CorrPt():Jet_pt");
96  auto recJets = flow.GetBranchReadOnly<vector<DP::RecJet>>("recJets");
97  auto Jet_pt = flow.GetBranchReadOnly<vector<float>>("Jet_pt");
98  tIn->GetEntry(0);
99  BOOST_TEST( 2*recJets->size() == Jet_pt->size() );
100  BOOST_TEST( recJets->front().CorrPt() == Jet_pt->front() );
101  BOOST_TEST( Jet_pt->at(0) == Jet_pt->at(1) );
102  }
103 
104  BOOST_TEST_MESSAGE( "Testing forbidden modes" );
105  {
106  DT::Flow flow(DT::verbose, {file2});
107  auto tIn [[ maybe_unused ]] = flow.GetInputTree();
108  auto tOut = flow.GetOutputTree("/dev/null");
109  DT::MetaInfo metainfo(tOut, pt::ptree{});
110  BOOST_TEST( metainfo.Get<bool>("flags", "isMC") == true );
111 
112  BOOST_TEST_MESSAGE( "Testing an option forbidden by the plugin" );
113  auto plugins = flow.GetPlugins<DT::IPlugin>(vector<fs::path>{"../plugins/libFlattener." DLL_EXT});
114  BOOST_REQUIRE_THROW( (*ranges::begin(plugins))->Load(flow, metainfo, DT::syst), DE::PluginException );
115  BOOST_REQUIRE_NO_THROW( (*ranges::begin(plugins))->Load(flow, metainfo, DT::verbose) );
116  }
117 
118  BOOST_TEST_MESSAGE( "Testing veto" );
119  {
120  DT::Flow flow(DT::verbose, {file2});
121  auto tIn [[ maybe_unused ]] = flow.GetInputTree();
122  auto tOut = flow.GetOutputTree("/dev/null");
123  DT::MetaInfo metainfo(tOut, pt::ptree{});
124  BOOST_TEST( metainfo.Get<bool>("flags", "isMC") == true );
125  auto plugins = flow.GetPlugins<DT::IPlugin>(vector<fs::path>{"libVetoPlugin." DLL_EXT});
126 
127  BOOST_TEST_MESSAGE( "Trying to veto DT::verbose" );
128  auto plugin = ranges::begin(plugins);
129  BOOST_REQUIRE_THROW( (*plugin)->Load(flow, metainfo, DT::verbose), DE::PluginException );
130 
131  BOOST_TEST_MESSAGE( "Trying default mode" );
132  ++plugin;
133  BOOST_REQUIRE_NO_THROW( (*plugin)->Load(flow, metainfo, DT::verbose) );
134  }
135  }

◆ BOOST_AUTO_TEST_CASE() [2/3]

BOOST_AUTO_TEST_CASE ( basic_exceptions  )
138  {
139  BOOST_TEST_MESSAGE( "Testing inexisting plugin" );
140  BOOST_REQUIRE_THROW( DT::PluginLoader loader("/this/plugin/does/not/exist." DLL_EXT), DE::PluginException );
141 
142  BOOST_TEST_MESSAGE( "Testing fake plugin (creating empty file on the fly)" );
143  const fs::path fake = "fake_plugin." DLL_EXT;
144  fs::remove(fake);
145  ofstream(fake.c_str());
146  BOOST_REQUIRE_THROW( DT::PluginLoader loader(fake), DE::PluginException );
147 
148  BOOST_TEST_MESSAGE( "Testing inexisting plugin function" );
149  BOOST_REQUIRE_THROW( DT::PluginLoader loader("libHist.so"), DE::PluginException );
150 
151  BOOST_TEST_MESSAGE( "Testing CreatePlugin when returning nullptr" );
152  BOOST_REQUIRE_THROW( DT::PluginLoader loader("libFakePlugin." DLL_EXT), DE::PluginException );
153 
154  BOOST_TEST_MESSAGE( "Testing CreatePlugin when throwing an exception" );
155  BOOST_REQUIRE_THROW( DT::PluginLoader loader("libBadPlugin." DLL_EXT), DE::PluginException );
156 
157  BOOST_TEST_MESSAGE( "Testing Get() with wrong plugin type" );
158  DT::PluginLoader loader("../plugins/libFlattener." DLL_EXT);
159  auto plugins = loader.Get<AnotherPlugin>();
160  BOOST_REQUIRE_THROW( *ranges::begin(plugins), logic_error );
161  }

◆ BOOST_AUTO_TEST_CASE() [3/3]

BOOST_AUTO_TEST_CASE ( move_constructor  )
164  {
165  BOOST_TEST_MESSAGE( "Loading a plugin" );
166  DT::PluginLoader loader("../plugins/libFlattener." DLL_EXT, DT::verbose);
167 
168  BOOST_TEST_MESSAGE( "Moving a plugin" );
169  DT::PluginLoader loader2(std::move(loader));
170  }
Darwin::Exceptions::PluginException
Exception type to throw from plugins.
Definition: exceptions.h:132
Darwin::Tools::Flow
User-friendly handling of input and output n-tuples.
Definition: Flow.h:80
Step::verbose
static bool verbose
Definition: Step.h:40
Darwin::Tools::GenericPlugin
Generic plugin class.
Definition: GenericPlugin.h:42
BOOST_TEST
BOOST_TEST(gendijet.Rapidity()==1.3573785791881385)
Darwin::Tools::IPlugin
Dummy, common type for all plugins in Darwin.
Definition: IPlugin.h:27
Ntupliser_cfg.f
f
Definition: Ntupliser_cfg.py:322
Darwin::Tools::syst
@ syst
activate -s to systematic uncertainties
Definition: Options.h:34
Darwin::Tools::MetaInfo
Generic meta-information for n-tuple (including speficities to Darwin).
Definition: MetaInfo.h:68
Darwin::Tools::plugin
@ plugin
activate -p to run a plugin
Definition: Options.h:35
Darwin::Physics::GenJet
Generic generator-level jet.
Definition: Jet.h:14
plugins
PluginsVec * plugins()
Definition: IPlugin.h:77
Ntupliser_cfg.config
config
Definition: Ntupliser_cfg.py:330
Darwin::Tools::PluginLoader
Agnostic plugin loader.
Definition: PluginLoader.h:36
Darwin::Physics::RecJet
Generic detector-level jet.
Definition: Jet.h:33
Darwin::Tools::Flow::GetInputTree
ChainSlice * GetInputTree(const Slice, const std::string &="events")
Load chain from a list of files with non-empty trees.
Definition: Flow.cc:67
Darwin::Tools::ChainSlice::GetEntry
Int_t GetEntry(Long64_t entry, Int_t getall=0) override
Get entry from the chain to memory.
Definition: FriendUtils.h:135
AnotherPlugin
Definition: PluginLoader.cc:30