RDFAnalysis  0.1.1
Physics analysis with ROOT::RDataFrame
OutputWriter.h
Go to the documentation of this file.
1 #ifndef RDFAnalysis_OutputWriter_H
2 #define RDFAnalysis_OutputWriter_H
3 
4 // package includes
7 
8 // ROOT includes
9 #include <TDirectory.h>
10 
11 // STL includes
12 #include <memory>
13 
19 namespace RDFAnalysis {
28  template <typename Detail>
29  class OutputWriter {
30  public:
32  using detail_t = Detail;
37  OutputWriter(const std::shared_ptr<TDirectory>& directory);
38 
45  const std::string& fileName,
46  bool overwrite = false);
47 
52  void write(Node<Detail>& node) { writeFullTree(node, m_directory.get() ); }
53 
58  void write(Scheduler<Detail>& scheduler)
59  { write(scheduler.regions() ); }
60 
65  void write(std::map<std::string, typename Scheduler<Detail>::Region>& regions);
66 
68  void addWriter(const std::shared_ptr<INodeWriter<Detail>>& writer)
69  { m_writers.push_back(writer); }
70 
72  template <typename T> std::enable_if_t<std::is_base_of<INodeWriter<Detail>, T>{},
73  void> addWriter(T&& writer)
74  { addWriter(std::make_shared<T>(std::move(writer) ) ); }
75 
85  template <template<class> class T, typename... Args>
86  std::enable_if_t<std::is_base_of<INodeWriter<Detail>, T<Detail>>{}, void> addWriter(
87  Args&&... args)
88  { addWriter(std::make_shared<T<Detail>>(std::forward<Args>(args)...) ); }
89 
91  std::vector<std::shared_ptr<INodeWriter<Detail>>>& writers()
92  { return m_writers; }
93 
95  const std::vector<std::shared_ptr<INodeWriter<Detail>>>& writers() const
96  { return m_writers; }
97 
98  private:
100  std::shared_ptr<TDirectory> m_directory;
101 
103  std::vector<std::shared_ptr<INodeWriter<Detail>>> m_writers;
104 
105  void writeFullTree(
106  Node<Detail>& node,
107  TDirectory* directory,
108  std::size_t depth = 0);
109 
110  void writeNode(
111  Node<Detail>& node,
112  TDirectory* directory,
113  std::size_t depth);
114  }; //> end class OutputWriter
115 } //> end namespace RDFAnalysis
116 #include "RDFAnalysis/OutputWriter.icc"
117 #endif //> !RDFAnalysis_OutputWriter_H
void addWriter(const std::shared_ptr< INodeWriter< Detail >> &writer)
Add a writer.
Definition: OutputWriter.h:68
Helper struct to define a region.
Definition: Scheduler.h:49
Abstract base class for node writers.
Base class for writing specific information from Nodes to file.
Definition: INodeWriter.h:28
Definition: CutflowDetail.h:11
Class to write out objects from an RDFAnalysis.
Definition: OutputWriter.h:29
Class to represent a single step in the analysis process.
Definition: Node.h:32
Job scheduler.
Definition: Scheduler.h:25
void write(Scheduler< Detail > &scheduler)
Write information from the regions defined by a scheduler.
Definition: OutputWriter.h:58
void write(Node< Detail > &node)
Write information from the given node and all downstream.
Definition: OutputWriter.h:52
std::map< std::string, Region > & regions()
Get the string->region mapping.
Definition: Scheduler.h:63
const std::vector< std::shared_ptr< INodeWriter< Detail > > > & writers() const
Get the writers.
Definition: OutputWriter.h:95
Detail detail_t
The node detail type we&#39;re templated on.
Definition: OutputWriter.h:32
std::enable_if_t< std::is_base_of< INodeWriter< Detail >, T >{}, void > addWriter(T &&writer)
Add a writer.
Definition: OutputWriter.h:73
std::enable_if_t< std::is_base_of< INodeWriter< Detail >, T< Detail > >{}, void > addWriter(Args &&...args)
Add a writer.
Definition: OutputWriter.h:86
OutputWriter(const std::shared_ptr< TDirectory > &directory)
Create the writer.
std::vector< std::shared_ptr< INodeWriter< Detail > > > & writers()
Get the writers.
Definition: OutputWriter.h:91