CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes
ProcessCallGraph Class Reference

#include <ProcessCallGraph.h>

Classes

struct  NodeType
 
struct  PathType
 
struct  ProcessType
 

Public Types

using GraphType = 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 > >>
 

Public Member Functions

std::pair< std::vector< unsigned int >, std::vector< unsigned int > > dependencies (std::vector< unsigned int > const &path)
 
std::vector< unsigned int > depends (unsigned int module) const
 
const edm::ModuleDescriptionmodule (unsigned int module) const
 
const NodeTypeoperator[] (unsigned int module) const
 
void preBeginJob (edm::PathsAndConsumesOfModulesBase const &, edm::ProcessContext const &)
 
void preSourceConstruction (edm::ModuleDescription const &)
 
 ProcessCallGraph ()
 
const ProcessTypeprocessDescription (edm::ProcessContext const &) const
 
const ProcessTypeprocessDescription (std::string const &) const
 
const ProcessTypeprocessDescription (unsigned int) const
 
const std::vector< ProcessType > & processes () const
 
unsigned int processId (edm::ProcessContext const &) const
 
unsigned int processId (std::string const &) const
 
unsigned int size () const
 
const edm::ModuleDescriptionsource () const
 

Private Member Functions

unsigned int registerProcess (edm::ProcessContext const &)
 

Private Attributes

GraphType graph_
 
std::vector< ProcessTypeprocess_description_
 
std::unordered_map< std::string, unsigned int > process_id_
 
unsigned int source_
 

Detailed Description

Definition at line 27 of file ProcessCallGraph.h.

Member Typedef Documentation

◆ GraphType

using ProcessCallGraph::GraphType = 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> >>

Definition at line 47 of file ProcessCallGraph.h.

Constructor & Destructor Documentation

◆ ProcessCallGraph()

ProcessCallGraph::ProcessCallGraph ( )
default

Member Function Documentation

◆ dependencies()

std::pair< std::vector< unsigned int >, std::vector< unsigned int > > ProcessCallGraph::dependencies ( std::vector< unsigned int > const &  path)

Definition at line 184 of file ProcessCallGraph.cc.

185  {
186  std::vector<unsigned int> colors(boost::num_vertices(graph_));
187  auto colormap = boost::make_container_vertex_map(colors);
188 
189  // first, find and count all the path's modules' dependencies
190  boost::default_dfs_visitor visitor;
191  for (unsigned int module : path)
192  boost::depth_first_visit(graph_, module, visitor, colormap);
193 
194  unsigned int size = 0;
195  for (unsigned int color : colors)
196  if (color == 0)
197  ++size;
198 
199  // allocate the output vectors
200  std::vector<unsigned int> dependencies(size);
201  dependencies.resize(0);
202  std::vector<unsigned int> indices(path.size());
203  indices.resize(0);
204 
205  // reset the color map
206  for (unsigned int& color : colors)
207  color = 0;
208 
209  // find again all the dependencies, and record those associated to each module
210  struct record_vertices : boost::default_dfs_visitor {
211  record_vertices(std::vector<unsigned int>& vertices) : vertices_(vertices) {}
212 
213  void discover_vertex(unsigned int vertex, GraphType const& graph) { vertices_.push_back(vertex); }
214 
215  std::vector<unsigned int>& vertices_;
216  };
217  record_vertices recorder(dependencies);
218 
219  for (unsigned int module : path) {
220  // skip modules that have already been added as dependencies
221  if (colors[module] != boost::black_color)
222  boost::depth_first_visit(graph_, module, recorder, colormap);
223  indices.push_back(dependencies.size());
224  }
225 
226  return std::make_pair(dependencies, indices);
227 }

References colors, graph_, dqmdumpme::indices, module(), castor_dqm_sourceclient_file_cfg::path, size(), bphysicsOniaDQM_cfi::vertex, and AlignmentTracksFromVertexSelector_cfi::vertices.

Referenced by depends(), and preBeginJob().

◆ depends()

std::vector< unsigned int > ProcessCallGraph::depends ( unsigned int  module) const

Definition at line 155 of file ProcessCallGraph.cc.

155  {
156  std::vector<unsigned int> colors(boost::num_vertices(graph_));
157  auto colormap = boost::make_container_vertex_map(colors);
158 
159  // depht-first visit all vertices starting from the given module
160  boost::default_dfs_visitor visitor;
161  boost::depth_first_visit(graph_, module, visitor, colormap);
162 
163  // count the visited vertices (the `black' ones) in order to properly size the
164  // output vector; then fill the dependencies with the list of visited nodes
165  unsigned int size = 0;
166  for (unsigned int color : colors)
167  if (boost::black_color == color)
168  ++size;
169  std::vector<unsigned int> dependencies(size);
170  unsigned j = 0;
171  for (unsigned int i = 0; i < colors.size(); ++i)
172  if (boost::black_color == colors[i])
173  dependencies[j++] = i;
174  assert(size == j);
175 
176  return dependencies;
177 }

References cms::cuda::assert(), colors, dependencies(), graph_, mps_fire::i, dqmiolumiharvest::j, module(), and size().

◆ module()

edm::ModuleDescription const & ProcessCallGraph::module ( unsigned int  module) const

Definition at line 145 of file ProcessCallGraph.cc.

145  {
146  return graph_.m_graph[module].module_;
147 }

References graph_.

Referenced by FastTimerService::PlotsPerJob::book(), dependencies(), depends(), operator[](), preBeginJob(), and preSourceConstruction().

◆ operator[]()

ProcessCallGraph::NodeType const & ProcessCallGraph::operator[] ( unsigned int  module) const

Definition at line 150 of file ProcessCallGraph.cc.

150  {
151  return graph_.m_graph[module];
152 }

References graph_, and module().

◆ preBeginJob()

void ProcessCallGraph::preBeginJob ( edm::PathsAndConsumesOfModulesBase const &  pathsAndConsumes,
edm::ProcessContext const &  context 
)

Definition at line 64 of file ProcessCallGraph.cc.

65  {
66  unsigned int pid = registerProcess(context);
67 
68  // work on the full graph (for the main process) or a subgraph (for a subprocess)
69  GraphType& graph = context.isSubProcess() ? graph_.create_subgraph() : graph_.root();
70 
71  // set the graph name property to the process name
72  boost::get_property(graph, boost::graph_name) = context.processName();
73 
74  // create graph vertices associated to all modules in the process
75  unsigned int size = pathsAndConsumes.largestModuleID() - boost::num_vertices(graph) + 1;
76  for (size_t i = 0; i < size; ++i)
77  boost::add_vertex(graph);
78 
79  // set the vertices properties (use the module id as the global index into the graph)
80  std::vector<unsigned int> modules;
81  modules.reserve(size);
82  for (edm::ModuleDescription const* module : pathsAndConsumes.allModules()) {
83  modules.push_back(module->id());
84  graph_.m_graph[module->id()] = {*module, edmModuleTypeEnum(*module), false};
85  }
86 
87  // add graph edges associated to module dependencies
88  for (edm::ModuleDescription const* consumer : pathsAndConsumes.allModules()) {
89  for (edm::ModuleDescription const* module : pathsAndConsumes.modulesWhoseProductsAreConsumedBy(consumer->id())) {
90  // module `consumer' depends on module `module'
91  boost::add_edge(consumer->id(), module->id(), graph_);
92  }
93  }
94 
95  // extract path names from the TriggerNamesService
97 
98  // extract the details of the paths and endpaths: name, modules on the path, and their dependencies
99  size = pathsAndConsumes.paths().size();
100  assert(tns.getTrigPaths().size() == size);
101  std::vector<PathType> paths;
102  paths.reserve(size);
103  for (unsigned int i = 0; i < size; ++i) {
104  std::vector<unsigned int> modules;
105  for (edm::ModuleDescription const* module : pathsAndConsumes.modulesOnPath(i)) {
106  modules.push_back(module->id());
107  // mark the modules in the Paths as scheduled
108  graph_.m_graph[module->id()].scheduled_ = true;
109  }
110  auto deps = dependencies(modules);
111  paths.emplace_back(tns.getTrigPath(i), modules, deps.first, deps.second);
112  }
113  size = pathsAndConsumes.endPaths().size();
114  std::vector<PathType> endPaths;
115  endPaths.reserve(size);
116  for (unsigned int i = 0; i < size; ++i) {
117  std::vector<unsigned int> modules;
118  for (edm::ModuleDescription const* module : pathsAndConsumes.modulesOnEndPath(i)) {
119  modules.push_back(module->id());
120  // mark the modules in the EndPaths as scheduled
121  graph_.m_graph[module->id()].scheduled_ = true;
122  }
123  auto deps = dependencies(modules);
124  endPaths.emplace_back(tns.getEndPath(i), modules, deps.first, deps.second);
125  }
126 
127  // store the description of process, modules and paths
128  process_description_.emplace_back(context.processName(), graph, modules, paths, endPaths);
129  assert(process_description_.size() == pid + 1);
130 
131  // attach a subprocess to its parent
132  if (context.isSubProcess()) {
133  unsigned int parent_pid = processId(context.parentProcessContext());
134  process_description_[parent_pid].subprocesses_.push_back(pid);
135  }
136 }

References edm::PathsAndConsumesOfModulesBase::allModules(), cms::cuda::assert(), OfflineOutput_cfi::consumer, visDQMUpload::context, dependencies(), symbols::deps, edm::edmModuleTypeEnum(), edm::PathsAndConsumesOfModulesBase::endPaths(), edm::service::TriggerNamesService::getEndPath(), edm::service::TriggerNamesService::getTrigPath(), edm::service::TriggerNamesService::getTrigPaths(), graph_, mps_fire::i, edm::ModuleDescription::id(), edm::PathsAndConsumesOfModulesBase::largestModuleID(), module(), LogMessageMonitor_cff::modules, edm::PathsAndConsumesOfModulesBase::modulesOnEndPath(), edm::PathsAndConsumesOfModulesBase::modulesOnPath(), edm::PathsAndConsumesOfModulesBase::modulesWhoseProductsAreConsumedBy(), Skims_PA_cff::paths, edm::PathsAndConsumesOfModulesBase::paths(), process_description_, processId(), registerProcess(), and size().

◆ preSourceConstruction()

void ProcessCallGraph::preSourceConstruction ( edm::ModuleDescription const &  module)

Definition at line 51 of file ProcessCallGraph.cc.

51  {
52  // keep track of the Source module id
53  source_ = module.id();
54 
55  // create graph vertex for the source module
56  boost::add_vertex(graph_);
57  graph_.m_graph[module.id()] = {module, edm::EDMModuleType::kSource, true};
58 }

References graph_, edm::ModuleDescription::id(), edm::kSource, module(), and source_.

◆ processDescription() [1/3]

ProcessCallGraph::ProcessType const & ProcessCallGraph::processDescription ( edm::ProcessContext const &  context) const

Definition at line 283 of file ProcessCallGraph.cc.

283  {
284  unsigned int pid = processId(context);
285  return process_description_[pid];
286 }

References visDQMUpload::context, process_description_, and processId().

◆ processDescription() [2/3]

ProcessCallGraph::ProcessType const & ProcessCallGraph::processDescription ( std::string const &  processName) const

Definition at line 289 of file ProcessCallGraph.cc.

289  {
290  unsigned int pid = processId(processName);
291  return process_description_[pid];
292 }

References process_description_, processId(), and SimL1EmulatorRepack_CalouGT_cff::processName.

◆ processDescription() [3/3]

ProcessCallGraph::ProcessType const & ProcessCallGraph::processDescription ( unsigned int  pid) const

Definition at line 278 of file ProcessCallGraph.cc.

278  {
279  return process_description_.at(pid);
280 }

References process_description_.

Referenced by FastTimerService::PlotsPerJob::book(), and FastTimerService::PlotsPerJob::fill().

◆ processes()

std::vector< ProcessCallGraph::ProcessType > const & ProcessCallGraph::processes ( ) const

◆ processId() [1/2]

unsigned int ProcessCallGraph::processId ( edm::ProcessContext const &  context) const

Definition at line 255 of file ProcessCallGraph.cc.

255  {
256  auto id = process_id_.find(context.processName());
257  if (id == process_id_.end())
259  << "ProcessCallGraph::processId(): unexpected " << (context.isSubProcess() ? "subprocess" : "process") << " "
260  << context.processName();
261  return id->second;
262 }

References visDQMUpload::context, edm::errors::LogicError, and process_id_.

Referenced by preBeginJob(), and processDescription().

◆ processId() [2/2]

unsigned int ProcessCallGraph::processId ( std::string const &  processName) const

Definition at line 266 of file ProcessCallGraph.cc.

266  {
267  auto id = process_id_.find(processName);
268  if (id == process_id_.end())
270  << "ProcessCallGraph::processId(): unexpected (sub)process " << processName;
271  return id->second;
272 }

References edm::errors::LogicError, process_id_, and SimL1EmulatorRepack_CalouGT_cff::processName.

◆ registerProcess()

unsigned int ProcessCallGraph::registerProcess ( edm::ProcessContext const &  context)
private

Definition at line 231 of file ProcessCallGraph.cc.

231  {
232  static unsigned int s_id = 0;
233 
234  // registerProcess (called by preBeginJob) must be called for the parent process before its subprocess(es)
235  if (context.isSubProcess() and process_id_.find(context.parentProcessContext().processName()) == process_id_.end()) {
237  << "ProcessCallGraph::preBeginJob(): called for subprocess \"" << context.processName() << "\""
238  << " before being called for its parent process \"" << context.parentProcessContext().processName() << "\"";
239  }
240 
241  // registerProcess (called by preBeginJob) should be called once or each (sub)process
242  auto id = process_id_.find(context.processName());
243  if (id != process_id_.end()) {
245  << "ProcessCallGraph::preBeginJob(): called twice for the same "
246  << (context.isSubProcess() ? "subprocess" : "process") << " " << context.processName();
247  }
248 
249  std::tie(id, std::ignore) = process_id_.insert(std::make_pair(context.processName(), s_id++));
250  return id->second;
251 }

References visDQMUpload::context, Exception, SequenceTypes::ignore(), edm::errors::LogicError, process_id_, and s_id.

Referenced by preBeginJob().

◆ size()

unsigned int ProcessCallGraph::size ( void  ) const

Definition at line 139 of file ProcessCallGraph.cc.

139 { return boost::num_vertices(graph_); }

References graph_.

Referenced by ntupleDataFormat._Collection::__iter__(), ntupleDataFormat._Collection::__len__(), dependencies(), depends(), and preBeginJob().

◆ source()

edm::ModuleDescription const & ProcessCallGraph::source ( ) const

Definition at line 142 of file ProcessCallGraph.cc.

142 { return graph_.m_graph[source_].module_; }

References graph_, and source_.

Referenced by FastTimerService::PlotsPerJob::book().

Member Data Documentation

◆ graph_

GraphType ProcessCallGraph::graph_
private

◆ process_description_

std::vector<ProcessType> ProcessCallGraph::process_description_
private

Definition at line 181 of file ProcessCallGraph.h.

Referenced by preBeginJob(), processDescription(), and processes().

◆ process_id_

std::unordered_map<std::string, unsigned int> ProcessCallGraph::process_id_
private

Definition at line 178 of file ProcessCallGraph.h.

Referenced by processId(), and registerProcess().

◆ source_

unsigned int ProcessCallGraph::source_
private
s_id
static const edm::ProductID s_id
Definition: EventBase.cc:27
mps_fire.i
i
Definition: mps_fire.py:428
LogMessageMonitor_cff.modules
modules
Definition: LogMessageMonitor_cff.py:7
colors
vector< Color_t > colors
Definition: trackSplitPlot.h:37
colors
Definition: colors.py:1
ProcessCallGraph::process_description_
std::vector< ProcessType > process_description_
Definition: ProcessCallGraph.h:181
edm::errors::LogicError
Definition: EDMException.h:37
modules
Definition: MuonCleanerBySegments.cc:35
cms::cuda::assert
assert(be >=bs)
ProcessCallGraph::graph_
GraphType graph_
Definition: ProcessCallGraph.h:172
ProcessCallGraph::GraphType
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
Definition: ProcessCallGraph.h:47
AlignmentTracksFromVertexSelector_cfi.vertices
vertices
Definition: AlignmentTracksFromVertexSelector_cfi.py:5
edm::ModuleDescription
Definition: ModuleDescription.h:21
ProcessCallGraph::size
unsigned int size() const
Definition: ProcessCallGraph.cc:139
edm::Exception
Definition: EDMException.h:77
visDQMUpload.context
context
Definition: visDQMUpload.py:37
edm::EDMModuleType::kSource
dependencies
Definition: dependencies.py:1
ProcessCallGraph::source_
unsigned int source_
Definition: ProcessCallGraph.h:175
ProcessCallGraph::dependencies
std::pair< std::vector< unsigned int >, std::vector< unsigned int > > dependencies(std::vector< unsigned int > const &path)
Definition: ProcessCallGraph.cc:184
bphysicsOniaDQM_cfi.vertex
vertex
Definition: bphysicsOniaDQM_cfi.py:7
edm::service::TriggerNamesService::getTrigPath
std::string const & getTrigPath(size_type const i) const
Definition: TriggerNamesService.h:56
edm::Service
Definition: Service.h:30
SequenceTypes.ignore
def ignore(seq)
Definition: SequenceTypes.py:628
ProcessCallGraph::registerProcess
unsigned int registerProcess(edm::ProcessContext const &)
Definition: ProcessCallGraph.cc:231
SimL1EmulatorRepack_CalouGT_cff.processName
processName
Definition: SimL1EmulatorRepack_CalouGT_cff.py:17
edm::service::TriggerNamesService
Definition: TriggerNamesService.h:42
edm::edmModuleTypeEnum
EDMModuleType edmModuleTypeEnum(edm::ModuleDescription const &module)
Definition: EDMModuleType.cc:10
edm::service::TriggerNamesService::getTrigPaths
Strings const & getTrigPaths() const
Definition: TriggerNamesService.h:55
edm::service::TriggerNamesService::getEndPath
std::string const & getEndPath(size_type const i) const
Definition: TriggerNamesService.h:75
Exception
Definition: hltDiff.cc:245
Skims_PA_cff.paths
paths
Definition: Skims_PA_cff.py:18
OfflineOutput_cfi.consumer
consumer
Definition: OfflineOutput_cfi.py:3
ProcessCallGraph::process_id_
std::unordered_map< std::string, unsigned int > process_id_
Definition: ProcessCallGraph.h:178
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
ProcessCallGraph::processId
unsigned int processId(edm::ProcessContext const &) const
Definition: ProcessCallGraph.cc:255
dqmdumpme.indices
indices
Definition: dqmdumpme.py:50
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
symbols.deps
deps
Definition: symbols.py:61
ProcessCallGraph::module
const edm::ModuleDescription & module(unsigned int module) const
Definition: ProcessCallGraph.cc:145
edm::ModuleDescription::id
unsigned int id() const
Definition: ModuleDescription.h:46