RDFAnalysis  0.1.1
Physics analysis with ROOT::RDataFrame
BoostGraphBuilder.h
Go to the documentation of this file.
1 #ifndef RDFAnalysis_Utils_BoostGraphBuilder_H
2 #define RDFAnalysis_Utils_BoostGraphBuilder_H
3 
4 #include <boost/graph/adjacency_list.hpp>
5 
6 #include <vector>
7 #include <functional>
8 #include <type_traits>
9 
15 namespace RDFAnalysis { namespace detail {
28  template <typename InputNode,
29  typename VertexInfo,
30  typename ChildItr=typename std::vector<std::decay_t<InputNode>>::const_iterator>
32  public:
34  struct Vertex {
36  Vertex() {}
38  Vertex(const VertexInfo& info) : info(info) {}
40  VertexInfo info;
41  }; //> end struct Vertex
42  // Type defs
44  using input_node_t = InputNode;
46  using vertex_info_t = VertexInfo;
48  using child_itr_t = ChildItr;
50  using graph_t = boost::adjacency_list<
51  boost::vecS, boost::vecS, boost::directedS, Vertex>;
53  using vert_desc_t = typename boost::graph_traits<graph_t>::vertex_descriptor;
55  using prop_map_t = typename boost::property_map<graph_t, vertex_info_t Vertex::*>::type;
56 
63  std::function<ChildItr(InputNode)> childBegin,
64  std::function<ChildItr(InputNode)> childEnd);
65 
66  virtual ~BoostGraphBuilder() = 0;
67 
72  graph_t buildGraph(InputNode root);
73 
74  protected:
76  virtual VertexInfo info(InputNode input) = 0;
77 
79  enum class NodeDecision {
80  Write,
81  Skip,
82  Terminate
83  };
84 
86  virtual NodeDecision processNode(InputNode input);
87 
89  void addToGraph(
90  InputNode input,
91  const vert_desc_t& parent,
92  graph_t& graph);
93 
95  std::function<ChildItr(InputNode)> m_childBegin;
97  std::function<ChildItr(InputNode)> m_childEnd;
98 
99  }; //> end class BoostGraphBuilder<InputNode, ChildBegin, ChildEnd, VertexInfo>
100 } } //> end namespace RDFAnalysis::detail
101 #include "RDFAnalysis/Utils/BoostGraphBuilder.icc"
102 
103 #endif //> !RDFAnalysis_Utils_BoostGraphBuilder_H
VertexInfo info
The information attached to a vertex.
Definition: BoostGraphBuilder.h:40
NodeDecision
Enum to describe what should be done with a node.
Definition: BoostGraphBuilder.h:79
Vertex()
Default construct the vertex.
Definition: BoostGraphBuilder.h:36
void addToGraph(InputNode input, const vert_desc_t &parent, graph_t &graph)
Add a node into the graph.
std::function< ChildItr(InputNode)> m_childBegin
Get the start of a node&#39;s children.
Definition: BoostGraphBuilder.h:95
virtual NodeDecision processNode(InputNode input)
Choose whether or not to add a node to a graph.
InputNode input_node_t
The input node type.
Definition: BoostGraphBuilder.h:44
Definition: CutflowDetail.h:11
boost::adjacency_list< boost::vecS, boost::vecS, boost::directedS, Vertex > graph_t
The BGL graph type.
Definition: BoostGraphBuilder.h:51
Class to build Boost Graph Library graphs from a recursive tree structure.
Definition: BoostGraphBuilder.h:31
std::function< ChildItr(InputNode)> m_childEnd
Get the end of a node&#39;s children.
Definition: BoostGraphBuilder.h:97
VertexInfo vertex_info_t
The vertex info type.
Definition: BoostGraphBuilder.h:46
typename boost::property_map< graph_t, vertex_info_t Vertex::* >::type prop_map_t
The BGL property map type.
Definition: BoostGraphBuilder.h:55
BoostGraphBuilder(std::function< ChildItr(InputNode)> childBegin, std::function< ChildItr(InputNode)> childEnd)
Create the builder.
ChildItr child_itr_t
The child iterator type.
Definition: BoostGraphBuilder.h:48
graph_t buildGraph(InputNode root)
Build the graph.
typename boost::graph_traits< graph_t >::vertex_descriptor vert_desc_t
The BGL vertex type.
Definition: BoostGraphBuilder.h:53
Vertex(const VertexInfo &info)
Construct the vertex from its info.
Definition: BoostGraphBuilder.h:38
The vertex struct.
Definition: BoostGraphBuilder.h:34