CMS 3D CMS Logo

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

Classes

struct  node
 

Public Member Functions

 DependencyGraph (const ParameterSet &, ActivityRegistry &)
 
void postBeginJob ()
 
void preBeginJob (PathsAndConsumesOfModulesBase const &, ProcessContext const &)
 
void preSourceConstruction (ModuleDescription const &)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Types

enum  EDMModuleType {
  EDMModuleType::Unknown, EDMModuleType::Source, EDMModuleType::ESSource, EDMModuleType::ESProducer,
  EDMModuleType::EDAnalyzer, EDMModuleType::EDProducer, EDMModuleType::EDFilter, EDMModuleType::OutputModule
}
 
using GraphType = boost::subgraph< boost::adjacency_list< boost::vecS, boost::vecS, boost::directedS, boost::property< boost::vertex_attribute_t, GraphvizAttributes, node >, boost::property< boost::edge_index_t, int, boost::property< boost::edge_attribute_t, GraphvizAttributes > >, boost::property< boost::graph_name_t, std::string, boost::property< boost::graph_graph_attribute_t, GraphvizAttributes, boost::property< boost::graph_vertex_attribute_t, GraphvizAttributes, boost::property< boost::graph_edge_attribute_t, GraphvizAttributes > >> >> >
 
using GraphvizAttributes = std::map< std::string, std::string >
 

Private Member Functions

bool highlighted (std::string const &module)
 

Static Private Member Functions

static const char * edmModuleType (edm::ModuleDescription const &module)
 
static EDMModuleType edmModuleTypeEnum (edm::ModuleDescription const &module)
 

Private Attributes

std::string m_filename
 
GraphType m_graph
 
std::unordered_set< std::string > m_highlightModules
 
bool m_initialized
 
bool m_showPathDependencies
 

Static Private Attributes

static constexpr const char * module_type_desc []
 
static constexpr const char * shapes []
 

Detailed Description

Definition at line 55 of file DependencyGraph.cc.

Member Typedef Documentation

◆ GraphType

using DependencyGraph::GraphType = boost::subgraph<boost::adjacency_list< boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_attribute_t, GraphvizAttributes, node>, boost::property<boost::edge_index_t, int, boost::property<boost::edge_attribute_t, GraphvizAttributes> >, boost::property< boost::graph_name_t, std::string, boost::property<boost::graph_graph_attribute_t, GraphvizAttributes, boost::property<boost::graph_vertex_attribute_t, GraphvizAttributes, boost::property<boost::graph_edge_attribute_t, GraphvizAttributes> >> >> >
private

Definition at line 121 of file DependencyGraph.cc.

◆ GraphvizAttributes

using DependencyGraph::GraphvizAttributes = std::map<std::string, std::string>
private

Definition at line 96 of file DependencyGraph.cc.

Member Enumeration Documentation

◆ EDMModuleType

enum DependencyGraph::EDMModuleType
strongprivate
Enumerator
Unknown 
Source 
ESSource 
ESProducer 
EDAnalyzer 
EDProducer 
EDFilter 
OutputModule 

Definition at line 68 of file DependencyGraph.cc.

68 { Unknown, Source, ESSource, ESProducer, EDAnalyzer, EDProducer, EDFilter, OutputModule };

Constructor & Destructor Documentation

◆ DependencyGraph()

DependencyGraph::DependencyGraph ( const ParameterSet config,
ActivityRegistry registry 
)

Definition at line 168 of file DependencyGraph.cc.

References postBeginJob(), preBeginJob(), preSourceConstruction(), edm::ActivityRegistry::watchPostBeginJob(), edm::ActivityRegistry::watchPreBeginJob(), and edm::ActivityRegistry::watchPreSourceConstruction().

169  : m_filename(config.getUntrackedParameter<std::string>("fileName")),
171  make_unordered_set(config.getUntrackedParameter<std::vector<std::string>>("highlightModules"))),
172  m_showPathDependencies(config.getUntrackedParameter<bool>("showPathDependencies")),
173  m_initialized(false) {
177 }
void watchPreSourceConstruction(PreSourceConstruction::slot_type const &iSlot)
void preBeginJob(PathsAndConsumesOfModulesBase const &, ProcessContext const &)
Definition: config.py:1
void preSourceConstruction(ModuleDescription const &)
std::unordered_set< std::string > m_highlightModules
void watchPreBeginJob(PreBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
std::string m_filename
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal

Member Function Documentation

◆ edmModuleType()

const char * DependencyGraph::edmModuleType ( edm::ModuleDescription const &  module)
staticprivate

Definition at line 156 of file DependencyGraph.cc.

References edm::edmModuleTypeEnum(), and edm::module_type_desc.

156  {
157  return module_type_desc[static_cast<std::underlying_type_t<EDMModuleType>>(edmModuleTypeEnum(module))];
158 }
static constexpr const char * module_type_desc[]
static EDMModuleType edmModuleTypeEnum(edm::ModuleDescription const &module)

◆ edmModuleTypeEnum()

DependencyGraph::EDMModuleType DependencyGraph::edmModuleTypeEnum ( edm::ModuleDescription const &  module)
staticprivate

Definition at line 135 of file DependencyGraph.cc.

References mixOne_cfi::ESProducer, edm::pset::Registry::instance(), edm::module_type_desc, muonDTDigis_cfi::pset, CollectionTags_cfi::Source, AlCaHLTBitMon_QueryRunRegistry::string, submitPVValidationJobs::t, reco::Unknown, and findQualityFiles::v.

Referenced by preBeginJob().

135  {
136  auto const &registry = *edm::pset::Registry::instance();
137  auto const &pset = *registry.getMapped(module.parameterSetID());
138 
139  if (not pset.existsAs<std::string>("@module_edm_type"))
140  return EDMModuleType::Unknown;
141 
142  std::string const &t = pset.getParameter<std::string>("@module_edm_type");
150  if (t == module_type_desc[static_cast<std::underlying_type_t<EDMModuleType>>(v)])
151  return v;
152  }
153  return EDMModuleType::Unknown;
154 }
EDMModuleType
Definition: EDMModuleType.h:8
static constexpr const char * module_type_desc[]
static Registry * instance()
Definition: Registry.cc:12

◆ fillDescriptions()

void DependencyGraph::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 160 of file DependencyGraph.cc.

References edm::ConfigurationDescriptions::add(), submitPVResolutionJobs::desc, and AlCaHLTBitMon_QueryRunRegistry::string.

160  {
162  desc.addUntracked<std::string>("fileName", "dependency.dot");
163  desc.addUntracked<std::vector<std::string>>("highlightModules", {});
164  desc.addUntracked<bool>("showPathDependencies", true);
165  descriptions.add("DependencyGraph", desc);
166 }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ highlighted()

bool DependencyGraph::highlighted ( std::string const &  module)
inlineprivate

Definition at line 66 of file DependencyGraph.cc.

Referenced by preBeginJob(), and preSourceConstruction().

66 { return (m_highlightModules.find(module) != m_highlightModules.end()); }
std::unordered_set< std::string > m_highlightModules

◆ postBeginJob()

void DependencyGraph::postBeginJob ( )

Definition at line 404 of file DependencyGraph.cc.

References mps_fire::i, m_filename, m_graph, m_initialized, and MillePedeFileConverter_cfg::out.

Referenced by DependencyGraph().

404  {
405  if (not m_initialized)
406  return;
407 
408  // remove the nodes corresponding to the modules that have been removed from the process
409  for (int i = boost::num_vertices(m_graph) - 1; i > 1; --i) {
410  if (m_graph.m_graph[i].label.empty())
411  boost::remove_vertex(i, m_graph.m_graph);
412  }
413 
414  // draw the dependency graph
415  std::ofstream out(m_filename);
416  boost::write_graphviz(out, m_graph);
417  out.close();
418 }
std::string m_filename

◆ preBeginJob()

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

Definition at line 208 of file DependencyGraph.cc.

References edm::PathsAndConsumesOfModulesBase::allModules(), OfflineOutput_cfi::consumer, visDQMUpload::context, edmModuleTypeEnum(), edm::PathsAndConsumesOfModulesBase::endPaths(), newFWLiteAna::found, get, highlighted(), mps_fire::i, dqmiolumiharvest::j, edm::PathsAndConsumesOfModulesBase::largestModuleID(), m_graph, m_initialized, m_showPathDependencies, callgraph::module, edm::PathsAndConsumesOfModulesBase::modulesOnEndPath(), edm::PathsAndConsumesOfModulesBase::modulesOnPath(), edm::PathsAndConsumesOfModulesBase::modulesWhoseProductsAreConsumedBy(), Skims_PA_cff::paths, edm::PathsAndConsumesOfModulesBase::paths(), callgraph::previous, shapes, findQualityFiles::size, and triggerResults.

Referenced by DependencyGraph().

209  {
210  // if the Service is not in the main Process do not do anything
211  if (context.isSubProcess() and not m_initialized) {
212  edm::LogError("DependencyGraph") << "You have requested an instance of the DependencyGraph Service in the \""
213  << context.processName()
214  << "\" SubProcess, which is not supported.\nPlease move it to the main process.";
215  return;
216  }
217 
218  if (not context.isSubProcess()) {
219  // set the graph name property to the process name
220  boost::get_property(m_graph, boost::graph_name) = context.processName();
221  boost::get_property(m_graph, boost::graph_graph_attribute)["label"] = "process " + context.processName();
222  boost::get_property(m_graph, boost::graph_graph_attribute)["labelloc"] = "top";
223 
224  // create graph vertices associated to all modules in the process
225  auto size = pathsAndConsumes.largestModuleID() - boost::num_vertices(m_graph) + 1;
226  for (size_t i = 0; i < size; ++i)
227  boost::add_vertex(m_graph);
228 
229  m_initialized = true;
230  } else {
231  // create a subgraph to match the subprocess
232  auto &graph = m_graph.create_subgraph();
233 
234  // set the subgraph name property to the subprocess name
235  boost::get_property(graph, boost::graph_name) = "cluster" + context.processName();
236  boost::get_property(graph, boost::graph_graph_attribute)["label"] = "subprocess " + context.processName();
237  boost::get_property(graph, boost::graph_graph_attribute)["labelloc"] = "top";
238 
239  // create graph vertices associated to all modules in the subprocess
240  auto size = pathsAndConsumes.largestModuleID() - boost::num_vertices(m_graph) + 1;
241  for (size_t i = 0; i < size; ++i)
242  boost::add_vertex(graph);
243  }
244 
245  // set the vertices properties (use the module id as the global index into the graph)
246  for (edm::ModuleDescription const *module : pathsAndConsumes.allModules()) {
247  m_graph.m_graph[module->id()] = {
248  module->moduleLabel(), module->moduleName(), module->id(), edmModuleTypeEnum(*module), false};
249 
250  auto &attributes = boost::get(boost::get(boost::vertex_attribute, m_graph), module->id());
251  attributes["label"] = module->moduleLabel();
252  attributes["tooltip"] = module->moduleName();
253  attributes["shape"] = shapes[static_cast<std::underlying_type_t<EDMModuleType>>(edmModuleTypeEnum(*module))];
254  attributes["style"] = "filled";
255  attributes["color"] = "black";
256  attributes["fillcolor"] = highlighted(module->moduleLabel()) ? "green" : "lightgrey";
257  }
258 
259  // paths and endpaths
260  auto const &paths = pathsAndConsumes.paths();
261  auto const &endps = pathsAndConsumes.endPaths();
262 
263  // add graph edges associated to module dependencies
264  for (edm::ModuleDescription const *consumer : pathsAndConsumes.allModules()) {
265  for (edm::ModuleDescription const *module : pathsAndConsumes.modulesWhoseProductsAreConsumedBy(consumer->id())) {
266  edm::LogInfo("DependencyGraph") << "module " << consumer->moduleLabel() << " depends on module "
267  << module->moduleLabel();
268  auto edge_status = boost::add_edge(consumer->id(), module->id(), m_graph);
269  // highlight the edge between highlighted nodes
270  if (highlighted(module->moduleLabel()) and highlighted(consumer->moduleLabel())) {
271  auto const &edge = edge_status.first;
272  auto &attributes = boost::get(boost::get(boost::edge_attribute, m_graph), edge);
273  attributes["color"] = "darkgreen";
274  }
275  }
276  }
277 
278  // save each Path and EndPath as a Graphviz subgraph
279  for (unsigned int i = 0; i < paths.size(); ++i) {
280  // create a subgraph to match the Path
281  auto &graph = m_graph.create_subgraph();
282 
283  // set the subgraph name property to the Path name
284  boost::get_property(graph, boost::graph_name) = paths[i];
285  boost::get_property(graph, boost::graph_graph_attribute)["label"] = "Path " + paths[i];
286  boost::get_property(graph, boost::graph_graph_attribute)["labelloc"] = "bottom";
287 
288  // add to the subgraph the node corresponding to the scheduled modules on the Path
289  for (edm::ModuleDescription const *module : pathsAndConsumes.modulesOnPath(i)) {
290  boost::add_vertex(module->id(), graph);
291  }
292  }
293  for (unsigned int i = 0; i < endps.size(); ++i) {
294  // create a subgraph to match the EndPath
295  auto &graph = m_graph.create_subgraph();
296 
297  // set the subgraph name property to the EndPath name
298  boost::get_property(graph, boost::graph_name) = endps[i];
299  boost::get_property(graph, boost::graph_graph_attribute)["label"] = "EndPath " + endps[i];
300  boost::get_property(graph, boost::graph_graph_attribute)["labelloc"] = "bottom";
301 
302  // add to the subgraph the node corresponding to the scheduled modules on the EndPath
303  for (edm::ModuleDescription const *module : pathsAndConsumes.modulesOnEndPath(i)) {
304  boost::add_vertex(module->id(), graph);
305  }
306  }
307 
308  // optionally, add a dependency of the TriggerResults module on the PathStatusInserter modules
309  const int size = boost::num_vertices(m_graph);
310  int triggerResults = -1;
311  bool highlightTriggerResults = false;
312  for (int i = 0; i < size; ++i) {
313  if (m_graph.m_graph[i].label == "TriggerResults") {
314  triggerResults = i;
315  highlightTriggerResults = highlighted("TriggerResults");
316  break;
317  }
318  }
319 
320  // mark the modules in the paths as scheduled, and add a soft dependency to reflect the order of modules along each path
322  for (unsigned int i = 0; i < paths.size(); ++i) {
323  previous = nullptr;
324  for (edm::ModuleDescription const *module : pathsAndConsumes.modulesOnPath(i)) {
325  m_graph.m_graph[module->id()].scheduled = true;
326  auto &attributes = boost::get(boost::get(boost::vertex_attribute, m_graph), module->id());
327  attributes["fillcolor"] = highlighted(module->moduleLabel()) ? "lightgreen" : "white";
329  edm::LogInfo("DependencyGraph") << "module " << module->moduleLabel() << " follows module "
330  << previous->moduleLabel() << " in Path " << paths[i];
331  auto edge_status = boost::lookup_edge(module->id(), previous->id(), m_graph);
332  bool found = edge_status.second;
333  if (not found) {
334  edge_status = boost::add_edge(module->id(), previous->id(), m_graph);
335  auto const &edge = edge_status.first;
336  auto &edgeAttributes = boost::get(boost::get(boost::edge_attribute, m_graph), edge);
337  edgeAttributes["style"] = "dashed";
338  // highlight the edge between highlighted nodes
339  if (highlighted(module->moduleLabel()) and highlighted(previous->moduleLabel()))
340  edgeAttributes["color"] = "darkgreen";
341  }
342  }
343  previous = module;
344  }
345  // previous points to the last scheduled module on the path
347  // look for the PathStatusInserter module corresponding to this path
348  for (int j = 0; j < size; ++j) {
349  if (m_graph.m_graph[j].label == paths[i]) {
350  edm::LogInfo("DependencyGraph") << "module " << paths[i] << " implicitly follows module "
351  << previous->moduleLabel() << " in Path " << paths[i];
352  // add an edge from the PathStatusInserter module to the last module scheduled on the path
353  auto edge_status = boost::add_edge(j, previous->id(), m_graph);
354  auto const &edge = edge_status.first;
355  auto &edgeAttributes = boost::get(boost::get(boost::edge_attribute, m_graph), edge);
356  edgeAttributes["style"] = "dashed";
357  // highlight the edge between highlighted nodes
358  bool highlightedPath = highlighted(paths[i]);
359  if (highlightedPath and highlighted(previous->moduleLabel()))
360  edgeAttributes["color"] = "darkgreen";
361  if (triggerResults > 0) {
362  // add an edge from the TriggerResults module to the PathStatusInserter module
363  auto edge_status = boost::add_edge(triggerResults, j, m_graph);
364  auto const &edge = edge_status.first;
365  auto &edgeAttributes = boost::get(boost::get(boost::edge_attribute, m_graph), edge);
366  edgeAttributes["style"] = "dashed";
367  // highlight the edge between highlighted nodes
368  if (highlightedPath and highlightTriggerResults)
369  edgeAttributes["color"] = "darkgreen";
370  }
371  break;
372  }
373  }
374  }
375  }
376 
377  // mark the modules in the endpaths as scheduled, and add a soft dependency to reflect the order of modules along each endpath
378  for (unsigned int i = 0; i < endps.size(); ++i) {
379  previous = nullptr;
380  for (edm::ModuleDescription const *module : pathsAndConsumes.modulesOnEndPath(i)) {
381  m_graph.m_graph[module->id()].scheduled = true;
382  auto &attributes = boost::get(boost::get(boost::vertex_attribute, m_graph), module->id());
383  attributes["fillcolor"] = highlighted(module->moduleLabel()) ? "lightgreen" : "white";
385  edm::LogInfo("DependencyGraph") << "module " << module->moduleLabel() << " follows module "
386  << previous->moduleLabel() << " in EndPath " << i;
387  auto edge_status = boost::lookup_edge(module->id(), previous->id(), m_graph);
388  bool found = edge_status.second;
389  if (not found) {
390  edge_status = boost::add_edge(module->id(), previous->id(), m_graph);
391  auto const &edge = edge_status.first;
392  auto &edgeAttributes = boost::get(boost::get(boost::edge_attribute, m_graph), edge);
393  edgeAttributes["style"] = "dashed";
394  // highlight the edge between highlighted nodes
395  if (highlighted(module->moduleLabel()) and highlighted(previous->moduleLabel()))
396  edgeAttributes["color"] = "darkgreen";
397  }
398  }
399  previous = module;
400  }
401  }
402 }
size
Write out results.
Log< level::Error, false > LogError
static std::string const triggerResults
Definition: EdmProvDump.cc:47
Log< level::Info, false > LogInfo
static EDMModuleType edmModuleTypeEnum(edm::ModuleDescription const &module)
static constexpr const char * shapes[]
bool highlighted(std::string const &module)
#define get

◆ preSourceConstruction()

void DependencyGraph::preSourceConstruction ( ModuleDescription const &  module)

Definition at line 194 of file DependencyGraph.cc.

References get, highlighted(), m_graph, shapes, and Source.

Referenced by DependencyGraph().

194  {
195  // create graph vertex for the source module and fill its attributes
196  boost::add_vertex(m_graph);
197  m_graph.m_graph[module.id()] =
198  node{module.moduleLabel(), module.moduleName(), module.id(), EDMModuleType::Source, true};
199  auto &attributes = boost::get(boost::get(boost::vertex_attribute, m_graph), 0);
200  attributes["label"] = module.moduleLabel();
201  attributes["tooltip"] = module.moduleName();
202  attributes["shape"] = shapes[static_cast<std::underlying_type_t<EDMModuleType>>(EDMModuleType::Source)];
203  attributes["style"] = "filled";
204  attributes["color"] = "black";
205  attributes["fillcolor"] = highlighted(module.moduleLabel()) ? "lightgreen" : "white";
206 }
static constexpr const char * shapes[]
bool highlighted(std::string const &module)
#define get

Member Data Documentation

◆ m_filename

std::string DependencyGraph::m_filename
private

Definition at line 124 of file DependencyGraph.cc.

Referenced by postBeginJob().

◆ m_graph

GraphType DependencyGraph::m_graph
private

Definition at line 122 of file DependencyGraph.cc.

Referenced by postBeginJob(), preBeginJob(), and preSourceConstruction().

◆ m_highlightModules

std::unordered_set<std::string> DependencyGraph::m_highlightModules
private

Definition at line 125 of file DependencyGraph.cc.

◆ m_initialized

bool DependencyGraph::m_initialized
private

Definition at line 128 of file DependencyGraph.cc.

Referenced by postBeginJob(), and preBeginJob().

◆ m_showPathDependencies

bool DependencyGraph::m_showPathDependencies
private

Definition at line 127 of file DependencyGraph.cc.

Referenced by preBeginJob().

◆ module_type_desc

constexpr const char * DependencyGraph::module_type_desc
staticprivate
Initial value:
{
"Unknown", "Source", "ESSource", "ESProducer", "EDAnalyzer", "EDProducer", "EDFilter", "OutputModule"}

Definition at line 70 of file DependencyGraph.cc.

◆ shapes

constexpr const char * DependencyGraph::shapes
staticprivate
Initial value:
{
"note",
"oval",
"cylinder",
"cylinder",
"oval",
"box",
"diamond",
"oval",
}

Definition at line 73 of file DependencyGraph.cc.

Referenced by preBeginJob(), and preSourceConstruction().