DAS  3.0
Das Analysis System
IPlugin.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPLv3-or-later
2 //
3 // SPDX-FileCopyrightText: Patrick L.S. Connor <patrick.connor@cern.ch>
4 // SPDX-FileCopyrightText: Louis Moureaux <louis.moureaux@cern.ch>
5 
6 #pragma once
7 
8 #include <filesystem>
9 #include <iostream>
10 #include <memory>
11 #include <string>
12 #include <vector>
13 #include <type_traits>
14 
15 #include <Options.h>
16 #include <Variation.h>
17 
18 namespace Darwin::Tools {
19 
20 class Flow;
21 class MetaInfo;
22 
27 class IPlugin {
28 
29  std::filesystem::path file;
30 
31 protected:
32 
33  int steering = none;
34 
35  bool isMC = false;
36 
41  virtual int GetParamsVeto () noexcept { return none; }
42 
43 public:
44  IPlugin () = default;
45 
46  virtual ~IPlugin ()
47  {
48  using namespace std;
49  if (steering & verbose)
50  cout << "IPlugin: destroying plugin from " << file << endl;
51  }
52 
55  void SetPath (const std::filesystem::path& file) noexcept { this->file = file; }
56 
64  virtual void Load (Darwin::Tools::Flow&,
66  int = 0,
67  const boost::property_tree::ptree& = {}
68  );
69 };
70 
71 template<typename P> concept Plugin = std::is_base_of_v<IPlugin, P>;
72 
73 } // end of Darwin::Tools namespace
74 
75 using PluginsVec = std::vector<std::unique_ptr<Darwin::Tools::IPlugin>>;
76 
77 template<class... Plugins> PluginsVec * plugins()
78 {
79  using namespace std;
80  auto vec = new PluginsVec;
81  auto _ [[maybe_unused]] = (vec->emplace_back(make_unique<Plugins>()), ..., 0);
82  return vec;
83 }
84 #define DARWIN_EXPORT_PLUGIN(...) \
85  extern "C" PluginsVec * CreatePlugin () { return plugins<__VA_ARGS__>(); }
Darwin::Tools::IPlugin::IPlugin
IPlugin()=default
Darwin::Tools::Flow
User-friendly handling of input and output n-tuples.
Definition: Flow.h:80
Darwin::Tools::Plugin
concept Plugin
Definition: IPlugin.h:71
Darwin::Tools::IPlugin::~IPlugin
virtual ~IPlugin()
Definition: IPlugin.h:46
Darwin::Tools::none
@ none
default (for simple executables)
Definition: Options.h:28
Darwin::Tools::MetaInfo
Generic meta-information for n-tuple (including speficities to Darwin).
Definition: MetaInfo.h:68
Darwin::Tools::IPlugin::isMC
bool isMC
Definition: IPlugin.h:35
Variation.h
plugins
PluginsVec * plugins()
Definition: IPlugin.h:77
Darwin::Tools::IPlugin::GetParamsVeto
virtual int GetParamsVeto() noexcept
Plugin's forbidden modes.
Definition: IPlugin.h:41
Darwin::Tools::verbose
@ verbose
bit for debug mode (-v is always available)
Definition: Options.h:29
Darwin::Tools
Classes and functions related to the framework.
Definition: Darwin_dict.cxx:1144
Darwin::Tools::IPlugin::steering
int steering
runtime steering options from command line (
Definition: IPlugin.h:33
Darwin::Tools::IPlugin::SetPath
void SetPath(const std::filesystem::path &file) noexcept
Set location of plugin file.
Definition: IPlugin.h:55
Options.h
PluginsVec
std::vector< std::unique_ptr< Darwin::Tools::IPlugin > > PluginsVec
Definition: IPlugin.h:75
Darwin::Tools::IPlugin::file
std::filesystem::path file
plugin file
Definition: IPlugin.h:29
Darwin::Tools::IPlugin::Load
virtual void Load(Darwin::Tools::Flow &, Darwin::Tools::MetaInfo &, int=0, const boost::property_tree::ptree &={})
Set steering.