RDFAnalysis  0.1.1
Physics analysis with ROOT::RDataFrame
Scheduler.h
Go to the documentation of this file.
1 #ifndef RDFAnalysis_Scheduler_H
2 #define RDFAnalysis_Scheduler_H
3 
4 // Package includes
5 #include "RDFAnalysis/Node.h"
8 
14 namespace RDFAnalysis {
24  template <typename Detail>
25  class Scheduler : public SchedulerBase {
26  public:
28  using detail_t = Detail;
31 
36  Scheduler(node_t* root) : m_root(root), m_namer(root->namer() ) {}
37 
40  node_t* root() { return m_root; }
41 
46  ScheduleNode& schedule(const std::string& graphFile = "");
47 
49  struct Region {
52 
54  std::vector<SysResultPtr<TObject>> objects;
55  }; //> end struct Region
56 
63  std::map<std::string, Region>& regions() { return m_regions; }
64 
71  const std::map<std::string, Region>& regions() const
72  { return m_regions; }
73 
83  const std::string& name,
84  std::function<void(node_t*)> action,
85  const std::set<std::string>& variables = {},
86  const std::set<std::string>& filters = {},
87  float cost = 0);
88 
98  template <typename F>
100  const std::string& name,
101  F f,
102  const ColumnNames_t& columns = {},
103  const std::set<std::string>& filters = {},
104  float cost = 0);
105 
113  void registerVariable(
114  const std::string& name,
115  const std::string& expression,
116  const std::set<std::string>& filters = {},
117  float cost = 0);
118 
127  void registerVariable(
128  const std::string& name,
129  const std::string& expression,
130  const ColumnNames_t& columns,
131  const std::set<std::string>& filters,
132  float cost = 0);
133 
134 
144  template <std::size_t N>
146  const std::array<std::string, N>& names,
147  std::function<void(node_t*)> action,
148  const std::set<std::string>& variables = {},
149  const std::set<std::string>& filters = {},
150  float cost = 0);
151 
162  template <std::size_t N, typename F>
164  const std::array<std::string, N>& names,
165  F f,
166  const ColumnNames_t& columns,
167  const std::set<std::string>& filters = {},
168  float cost = 0);
169 
182  void registerFilterImpl(
183  const std::string& name,
184  std::function<node_t*(node_t*)> action,
185  const std::set<std::string>& variables = {},
186  const std::set<std::string>& filters = {},
187  float cost = 0);
188 
203  template <typename F>
204  std::enable_if_t<std::is_convertible<typename ROOT::TTraits::CallableTraits<F>::ret_type, std::tuple<bool, float>>::value, void> registerFilter(
205  F f,
206  const ColumnNames_t& columns,
207  const std::string& name,
208  const std::string& cutflowName = "",
210  const std::set<std::string>& filters = {},
211  float cost = 0);
212 
225  template <typename F>
226  std::enable_if_t<std::is_convertible<typename ROOT::TTraits::CallableTraits<F>::ret_type, bool>::value, void> registerFilter(
227  F f,
228  const ColumnNames_t& columns,
229  const std::string& name,
230  const std::string& cutflowName = "",
231  const std::string& weight = "",
233  const std::set<std::string>& filters = {},
234  float cost = 0);
235 
246  void registerFilter(
247  const std::string& expression,
248  const std::string& name,
249  const std::string& cutflowName = "",
250  const std::string& weight = "",
252  const std::set<std::string>& filters = {},
253  float cost = 0);
254 
269  template <typename F, typename W>
270  std::enable_if_t<!std::is_convertible<F, std::string>::value && !std::is_convertible<W, std::string>::value, void> registerFilter(
271  F f,
272  const ColumnNames_t& columns,
273  const std::string& name,
274  const std::string& cutflowName,
275  W w,
276  const ColumnNames_t& weightColumns = {},
278  const std::set<std::string>& filters = {},
279  float cost = 0);
280 
293  template <typename W>
295  const std::string& expression,
296  const std::string& name,
297  const std::string& cutflowName,
298  W w,
299  const ColumnNames_t& weightColumns = {},
301  const std::set<std::string>& filters = {},
302  float cost = 0);
303 
314  void registerFillImpl(
315  const std::string& name,
316  std::function<SysResultPtr<TObject>(node_t*)> action,
317  const std::set<std::string>& variables = {},
318  const std::set<std::string>& filters = {});
319 
332  template <typename T>
333  void registerFill(
334  const T& model,
335  const ColumnNames_t& columns,
336  const std::string& weight = "",
338  const std::set<std::string>& filters = {});
339 
340  protected:
342  std::map<std::string, std::function<node_t*(node_t*)>> m_filters;
344  std::map<std::string, std::function<void(node_t*)>> m_variables;
346  std::map<std::string, std::function<SysResultPtr<TObject>(node_t*)>> m_fills;
353  std::map<std::string, Region> m_regions;
355  void addNode(const ScheduleNode& source,
356  node_t* target,
357  const std::string& currentRegion = "");
358  }; //> end class Scheduler
359 } //> end namespace RDFAnalysis
360 #include "RDFAnalysis/Scheduler.icc"
361 #endif //> !RDFAnalysis_Scheduler_H
std::map< std::string, Region > m_regions
After scheduling, pointers to the end nodes for all defined regions will be here. ...
Definition: Scheduler.h:353
std::map< std::string, std::function< node_t *(node_t *)> > m_filters
The defined filters.
Definition: Scheduler.h:342
Namer class to be used by the scheduler.
Definition: ScheduleNamer.h:20
node_t * node
The node that defines the final selection of this region.
Definition: Scheduler.h:51
std::map< std::string, std::function< void(node_t *)> > m_variables
The defined variables.
Definition: Scheduler.h:344
File containing the central analysis class.
Helper struct to define a region.
Definition: Scheduler.h:49
The namer used by the scheduler.
ROOT::RDataFrame::ColumnNames_t ColumnNames_t
Helper typedef.
Definition: NodeBase.h:30
Helper struct used to build and express the schedule.
Definition: SchedulerBase.h:157
std::enable_if_t<!std::is_convertible< F, std::string >{}, T > enable_ifn_string_t
Reduce size of enable_if statements.
Definition: Helpers.h:114
std::enable_if_t< std::is_convertible< typename ROOT::TTraits::CallableTraits< F >::ret_type, std::tuple< bool, float > >::value, void > registerFilter(F f, const ColumnNames_t &columns, const std::string &name, const std::string &cutflowName="", WeightStrategy strategy=WeightStrategy::Default, const std::set< std::string > &filters={}, float cost=0)
Register a new filter.
ScheduleNamer m_namer
The namer.
Definition: Scheduler.h:350
const std::map< std::string, Region > & regions() const
Get the string->region mapping.
Definition: Scheduler.h:71
node_t * m_root
The root node.
Definition: Scheduler.h:348
void registerVariableImpl(const std::string &name, std::function< void(node_t *)> action, const std::set< std::string > &variables={}, const std::set< std::string > &filters={}, float cost=0)
Register a new variable.
Scheduler(node_t *root)
Create the scheduler from a node.
Definition: Scheduler.h:36
void addNode(const ScheduleNode &source, node_t *target, const std::string &currentRegion="")
Copy information across from the Schedule node to the actual node.
Base class for the scheduler.
Definition: SchedulerBase.h:18
Definition: CutflowDetail.h:11
Class to represent a single step in the analysis process.
Definition: Node.h:32
Job scheduler.
Definition: Scheduler.h:25
WeightStrategy
enum class to describe how weights are applied.
Definition: WeightStrategy.h:33
Detail detail_t
The node detail type.
Definition: Scheduler.h:28
void registerFilterImpl(const std::string &name, std::function< node_t *(node_t *)> action, const std::set< std::string > &variables={}, const std::set< std::string > &filters={}, float cost=0)
Register a new filter.
std::map< std::string, Region > & regions()
Get the string->region mapping.
Definition: Scheduler.h:63
Class to wrap together RResultPtrs for different systematic variations.
Definition: SysResultPtr.h:24
enable_ifn_string_t< F, void > registerVariable(const std::string &name, F f, const ColumnNames_t &columns={}, const std::set< std::string > &filters={}, float cost=0)
Register a new variable definition.
node_t * root()
Get the root node. After schedule has been called this will contain the whole data structure...
Definition: Scheduler.h:40
ScheduleNode & schedule(const std::string &graphFile="")
Schedule the analysis.
std::vector< SysResultPtr< TObject > > objects
The TObject fills associated with this region.
Definition: Scheduler.h:54
void registerVariablesImpl(const std::array< std::string, N > &names, std::function< void(node_t *)> action, const std::set< std::string > &variables={}, const std::set< std::string > &filters={}, float cost=0)
Register a single action that defines multiple new variables.
void registerFillImpl(const std::string &name, std::function< SysResultPtr< TObject >(node_t *)> action, const std::set< std::string > &variables={}, const std::set< std::string > &filters={})
Register a new fill.
void registerFill(const T &model, const ColumnNames_t &columns, const std::string &weight="", WeightStrategy strategy=WeightStrategy::Default, const std::set< std::string > &filters={})
register a new fill
enable_ifn_string_t< F, void > registerVariables(const std::array< std::string, N > &names, F f, const ColumnNames_t &columns, const std::set< std::string > &filters={}, float cost=0)
Register a single action that defines multiple new variables.
std::map< std::string, std::function< SysResultPtr< TObject >node_t *)> > m_fills
The defined fills.
Definition: Scheduler.h:346