CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ProcessCallGraph.h
Go to the documentation of this file.
1 #ifndef HLTrigger_Timer_interface_ProcessCallGraph_h
2 #define HLTrigger_Timer_interface_ProcessCallGraph_h
3 
4 /*
5  *
6  */
7 
8 #include <iostream>
9 #include <utility>
10 #include <vector>
11 #include <string>
12 #include <type_traits>
13 
14 // boost optional (used by boost graph) results in some false positives with -Wmaybe-uninitialized
15 #pragma GCC diagnostic push
16 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
17 #include <boost/graph/adjacency_list.hpp>
18 #include <boost/graph/lookup_edge.hpp>
19 #include <boost/graph/subgraph.hpp>
20 #pragma GCC diagnostic pop
21 
26 
28 public:
29  struct NodeType {
32  bool scheduled_ = false;
33  };
34 
35  // directed graph, with `NodeType` properties attached to each vertex
36  using GraphType = boost::subgraph<boost::adjacency_list<
37  // edge list
38  boost::vecS,
39  // vertex list
40  boost::vecS,
41  boost::directedS,
42  // vertex properties
43  NodeType,
44  // edge propoerties, used internally by boost::subgraph
45  boost::property<boost::edge_index_t, int>,
46  // graph properties, used to name each boost::subgraph
47  boost::property<boost::graph_name_t, std::string>>>;
48 
49  // store the details of each path: name, modules on the path, and their dependencies
50  struct PathType {
52  std::vector<unsigned int> modules_on_path_;
53  std::vector<unsigned int> modules_and_dependencies_;
54  std::vector<unsigned int>
55  last_dependency_of_module_; // one-after-the-last dependency of each module, as indices into modules_and_dependencies_
56 
57  PathType() = default;
58 
60  std::vector<unsigned int> mop,
61  std::vector<unsigned int> mad,
62  std::vector<unsigned int> ldom)
63  : name_(std::move(name)),
64  modules_on_path_(std::move(mop)),
66  last_dependency_of_module_(std::move(ldom)) {}
67 
68  PathType(PathType const &other) = default;
69 
70  PathType(PathType &&other) = default;
71 
72  ~PathType() = default;
73 
74  PathType &operator=(PathType const &other) = default;
75  };
76 
77  // store the details of each process: name, modules call subgraph, modules, paths and endpaths, subprocess pids
78  struct ProcessType {
80  GraphType const &graph_;
81  std::vector<unsigned int> modules_;
82  std::vector<PathType> paths_;
83  std::vector<PathType> endPaths_;
84  std::vector<unsigned int> subprocesses_;
85 
86  ProcessType() = delete;
87 
89  GraphType const &graph,
90  std::vector<unsigned int> modules,
91  std::vector<PathType> paths,
92  std::vector<PathType> endPaths,
93  std::vector<unsigned int> subprocesses = {})
94  : name_(std::move(name)),
95  graph_(graph),
96  modules_(std::move(modules)),
97  paths_(std::move(paths)),
98  endPaths_(std::move(endPaths)),
99  subprocesses_(std::move(subprocesses)) {}
100 
102  GraphType const &graph,
103  std::vector<unsigned int> &&modules,
104  std::vector<PathType> &&paths,
105  std::vector<PathType> &&endPaths,
106  std::vector<unsigned int> &&subprocesses = {})
107  : name_(std::move(name)),
108  graph_(graph),
109  modules_(std::move(modules)),
110  paths_(std::move(paths)),
111  endPaths_(std::move(endPaths)),
112  subprocesses_(std::move(subprocesses)) {}
113 
114  ProcessType(ProcessType const &other) = default;
115  ProcessType(ProcessType &&other) = default;
116 
117  ProcessType &operator=(ProcessType const &other) = delete;
118  ProcessType &operator=(ProcessType &&other) = delete;
119  };
120 
121 public:
122  // default c'tor
124 
125  // to be called from preSourceConstruction(...)
127 
128  // to be called from preBeginJob(...)
130 
131  // number of modules stored in the call graph
132  unsigned int size() const;
133 
134  // retrieve the ModuleDescription associated to the Source
135  edm::ModuleDescription const &source() const;
136 
137  // retrieve the ModuleDescription associated to the given id
138  edm::ModuleDescription const &module(unsigned int module) const;
139 
140  // retrieve the full information for a given module
141  NodeType const &operator[](unsigned int module) const;
142 
143  // find the dependencies of the given module
144  std::vector<unsigned int> depends(unsigned int module) const;
145 
146  // find the dependencies of all modules in the given path
147  std::pair<std::vector<unsigned int>, std::vector<unsigned int>> dependencies(std::vector<unsigned int> const &path);
148 
149  // retrieve the "process id" of a process, given its ProcessContex
150  unsigned int processId(edm::ProcessContext const &) const;
151 
152  // retrieve the "process id" of a process, given its name
153  unsigned int processId(std::string const &) const;
154 
155  // retrieve the processes
156  std::vector<ProcessType> const &processes() const;
157 
158  // retrieve information about a process, given its "process id"
159  ProcessType const &processDescription(unsigned int) const;
160 
161  // retrieve information about a process, given its ProcessContex
162  ProcessType const &processDescription(edm::ProcessContext const &) const;
163 
164  // retrieve information about a process, given its name
165  ProcessType const &processDescription(std::string const &) const;
166 
167 private:
168  // register a (sub)process and assigns it a "process id"
169  unsigned int registerProcess(edm::ProcessContext const &);
170 
171 private:
173 
174  // module id of the Source
175  unsigned int source_;
176 
177  // map each (sub)process name to a "process id"
178  std::unordered_map<std::string, unsigned int> process_id_;
179 
180  // description of each process
181  std::vector<ProcessType> process_description_;
182 };
183 
184 #endif // not defined HLTrigger_Timer_interface_ProcessCallGraph_h
std::vector< unsigned int > modules_on_path_
unsigned int registerProcess(edm::ProcessContext const &)
std::vector< unsigned int > modules_and_dependencies_
EDMModuleType
Definition: EDMModuleType.h:8
unsigned int processId(edm::ProcessContext const &) const
std::unordered_map< std::string, unsigned int > process_id_
edm::ModuleDescription const & source() const
PathType & operator=(PathType const &other)=default
ProcessType(std::string &&name, GraphType const &graph, std::vector< unsigned int > &&modules, std::vector< PathType > &&paths, std::vector< PathType > &&endPaths, std::vector< unsigned int > &&subprocesses={})
def move
Definition: eostools.py:511
void preBeginJob(edm::PathsAndConsumesOfModulesBase const &, edm::ProcessContext const &)
std::vector< ProcessType > const & processes() const
std::vector< PathType > paths_
ProcessType const & processDescription(unsigned int) const
edm::ModuleDescription module_
void preSourceConstruction(edm::ModuleDescription const &)
std::vector< ProcessType > process_description_
std::vector< unsigned int > depends(unsigned int module) const
ProcessType & operator=(ProcessType const &other)=delete
edm::EDMModuleType type_
std::vector< unsigned int > subprocesses_
std::vector< PathType > endPaths_
std::pair< std::vector< unsigned int >, std::vector< unsigned int > > dependencies(std::vector< unsigned int > const &path)
unsigned int size() const
edm::ModuleDescription const & module(unsigned int module) const
unsigned int source_
std::vector< unsigned int > last_dependency_of_module_
ProcessType(std::string name, GraphType const &graph, std::vector< unsigned int > modules, std::vector< PathType > paths, std::vector< PathType > endPaths, std::vector< unsigned int > subprocesses={})
PathType(std::string name, std::vector< unsigned int > mop, std::vector< unsigned int > mad, std::vector< unsigned int > ldom)
std::vector< unsigned int > modules_
boost::subgraph< boost::adjacency_list< boost::vecS, boost::vecS, boost::directedS, NodeType, boost::property< boost::edge_index_t, int >, boost::property< boost::graph_name_t, std::string >>> GraphType
NodeType const & operator[](unsigned int module) const