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 191 of file ProcessCallGraph.cc.

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

References colors, graph_, bTagCombinedSVVariables_cff::indices, castor_dqm_sourceclient_file_cfg::path, size(), bphysicsOniaDQM_cfi::vertex, and pwdgSkimBPark_cfi::vertices.

Referenced by depends(), and preBeginJob().

◆ depends()

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

Definition at line 162 of file ProcessCallGraph.cc.

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

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

◆ module()

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

Definition at line 152 of file ProcessCallGraph.cc.

152  {
153  return graph_.m_graph[module].module_;
154 }

References graph_.

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

◆ operator[]()

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

Definition at line 157 of file ProcessCallGraph.cc.

157  {
158  return graph_.m_graph[module];
159 }

References graph_, and module().

◆ preBeginJob()

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

Definition at line 65 of file ProcessCallGraph.cc.

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

References edm::PathsAndConsumesOfModulesBase::allModules(), edmTracerLogToSimpleConfig::allModules, cms::cuda::assert(), OfflineOutput_cfi::consumer, 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::ProcessContext::isSubProcess(), SiStripPI::max, module(), LogMessageMonitor_cff::modules, edm::PathsAndConsumesOfModulesBase::modulesOnEndPath(), edm::PathsAndConsumesOfModulesBase::modulesOnPath(), edm::PathsAndConsumesOfModulesBase::modulesWhoseProductsAreConsumedBy(), edm::ProcessContext::parentProcessContext(), Skims_PA_cff::paths, edm::PathsAndConsumesOfModulesBase::paths(), process_description_, processId(), edm::ProcessContext::processName(), registerProcess(), alignCSCRings::s, and size().

◆ preSourceConstruction()

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

Definition at line 52 of file ProcessCallGraph.cc.

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

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

◆ processDescription() [1/3]

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

Definition at line 290 of file ProcessCallGraph.cc.

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

References process_description_, and processId().

◆ processDescription() [2/3]

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

Definition at line 296 of file ProcessCallGraph.cc.

296  {
297  unsigned int pid = processId(processName);
298  return process_description_[pid];
299 }

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

◆ processDescription() [3/3]

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

Definition at line 285 of file ProcessCallGraph.cc.

285  {
286  return process_description_.at(pid);
287 }

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 262 of file ProcessCallGraph.cc.

262  {
263  auto id = process_id_.find(context.processName());
264  if (id == process_id_.end())
266  << "ProcessCallGraph::processId(): unexpected " << (context.isSubProcess() ? "subprocess" : "process") << " "
267  << context.processName();
268  return id->second;
269 }

References edm::ProcessContext::isSubProcess(), edm::errors::LogicError, process_id_, and edm::ProcessContext::processName().

Referenced by preBeginJob(), and processDescription().

◆ processId() [2/2]

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

Definition at line 273 of file ProcessCallGraph.cc.

273  {
274  auto id = process_id_.find(processName);
275  if (id == process_id_.end())
277  << "ProcessCallGraph::processId(): unexpected (sub)process " << processName;
278  return id->second;
279 }

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

◆ registerProcess()

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

Definition at line 238 of file ProcessCallGraph.cc.

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

References Exception, SequenceTypes::ignore(), edm::ProcessContext::isSubProcess(), edm::errors::LogicError, edm::ProcessContext::parentProcessContext(), process_id_, edm::ProcessContext::processName(), and s_id.

Referenced by preBeginJob().

◆ size()

unsigned int ProcessCallGraph::size ( void  ) const

Definition at line 146 of file ProcessCallGraph.cc.

146 { 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 149 of file ProcessCallGraph.cc.

149 { 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
bTagCombinedSVVariables_cff.indices
indices
Definition: bTagCombinedSVVariables_cff.py:67
s_id
static const edm::ProductID s_id
Definition: EventBase.cc:27
mps_fire.i
i
Definition: mps_fire.py:355
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: ZHLTMatchFilter.cc:17
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
edm::ModuleDescription
Definition: ModuleDescription.h:21
ProcessCallGraph::size
unsigned int size() const
Definition: ProcessCallGraph.cc:146
edm::Exception
Definition: EDMException.h:77
edm::EDMModuleType::kSource
alignCSCRings.s
s
Definition: alignCSCRings.py:92
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:191
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
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
edm::Service
Definition: Service.h:30
module
Definition: vlib.h:198
SequenceTypes.ignore
def ignore(seq)
Definition: SequenceTypes.py:630
ProcessCallGraph::registerProcess
unsigned int registerProcess(edm::ProcessContext const &)
Definition: ProcessCallGraph.cc:238
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:246
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:262
edmTracerLogToSimpleConfig.allModules
allModules
Definition: edmTracerLogToSimpleConfig.py:132
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
symbols.deps
deps
Definition: symbols.py:55
ProcessCallGraph::module
const edm::ModuleDescription & module(unsigned int module) const
Definition: ProcessCallGraph.cc:152
pwdgSkimBPark_cfi.vertices
vertices
Definition: pwdgSkimBPark_cfi.py:7