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 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
 
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 > > > > > > m_graph
 
std::unordered_set< std::string > m_highlightModules
 
bool m_initialized
 
bool m_showPathDependencies
 

Static Private Attributes

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

Detailed Description

Definition at line 56 of file DependencyGraph.cc.

Member Typedef Documentation

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

Definition at line 120 of file DependencyGraph.cc.

Member Enumeration Documentation

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

Definition at line 71 of file DependencyGraph.cc.

Constructor & Destructor Documentation

DependencyGraph::DependencyGraph ( const ParameterSet ,
ActivityRegistry  
)

Definition at line 198 of file DependencyGraph.cc.

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

198  :
199  m_filename( config.getUntrackedParameter<std::string>("fileName") ),
200  m_highlightModules( make_unordered_set(config.getUntrackedParameter<std::vector<std::string>>("highlightModules")) ),
201  m_showPathDependencies( config.getUntrackedParameter<bool>("showPathDependencies") ),
202  m_initialized( false )
203 {
204  registry.watchPreSourceConstruction(this, &DependencyGraph::preSourceConstruction);
205  registry.watchPreBeginJob(this, &DependencyGraph::preBeginJob);
206  registry.watchPostBeginJob(this, &DependencyGraph::postBeginJob);
207 }
void preBeginJob(PathsAndConsumesOfModulesBase const &, ProcessContext const &)
Definition: config.py:1
void preSourceConstruction(ModuleDescription const &)
std::unordered_set< std::string > m_highlightModules
std::string m_filename
static Interceptor::Registry registry("Interceptor")

Member Function Documentation

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

Definition at line 181 of file DependencyGraph.cc.

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

182 {
183  return module_type_desc[static_cast<std::underlying_type_t<EDMModuleType>>(edmModuleTypeEnum(module))];
184 }
static EDMModuleType edmModuleTypeEnum(edm::ModuleDescription const &module)
static const char * module_type_desc[]
Definition: vlib.h:208
DependencyGraph::EDMModuleType DependencyGraph::edmModuleTypeEnum ( edm::ModuleDescription const &  module)
staticprivate

Definition at line 156 of file DependencyGraph.cc.

References mixOne_cfi::ESProducer, edm::pset::Registry::instance(), edm::module_type_desc, edm::ModuleDescription::parameterSetID(), muonDTDigis_cfi::pset, PhysicsTools::registry, PFJetToCaloProducer_cfi::Source, AlCaHLTBitMon_QueryRunRegistry::string, lumiQTWidget::t, Unknown, and findQualityFiles::v.

Referenced by preBeginJob().

157 {
158  auto const & registry = * edm::pset::Registry::instance();
159  auto const & pset = * registry.getMapped(module.parameterSetID());
160 
161  if (not pset.existsAs<std::string>("@module_edm_type"))
162  return EDMModuleType::Unknown;
163 
164  std::string const & t = pset.getParameter<std::string>("@module_edm_type");
165  for (EDMModuleType v: {
173  }) {
174  if (t == module_type_desc[static_cast<std::underlying_type_t<EDMModuleType>>(v)])
175  return v;
176  }
177  return EDMModuleType::Unknown;
178 }
EDMModuleType
Definition: EDMModuleType.h:8
static Interceptor::Registry registry("Interceptor")
static const char * module_type_desc[]
Definition: vlib.h:208
static Registry * instance()
Definition: Registry.cc:12
void DependencyGraph::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 188 of file DependencyGraph.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::addUntracked(), and AlCaHLTBitMon_QueryRunRegistry::string.

189 {
191  desc.addUntracked<std::string>("fileName", "dependency.gv");
192  desc.addUntracked<std::vector<std::string>>("highlightModules", {});
193  desc.addUntracked<bool>("showPathDependencies", true);
194  descriptions.add("DependencyGraph", desc);
195 }
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool DependencyGraph::highlighted ( std::string const &  module)
inlineprivate

Definition at line 67 of file DependencyGraph.cc.

Referenced by preBeginJob(), and preSourceConstruction().

67  {
68  return (m_highlightModules.find(module) != m_highlightModules.end());
69  }
std::unordered_set< std::string > m_highlightModules
Definition: vlib.h:208
void DependencyGraph::postBeginJob ( )

Definition at line 363 of file DependencyGraph.cc.

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

Referenced by DependencyGraph().

363  {
364 
365  if (not m_initialized)
366  return;
367 
368  // draw the dependency graph
369  std::ofstream out(m_filename);
370  boost::write_graphviz(
371  out,
372  m_graph
373  );
374  out.close();
375 }
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 > > > > > > m_graph
std::string m_filename
void DependencyGraph::preBeginJob ( PathsAndConsumesOfModulesBase const &  pathsAndConsumes,
ProcessContext const &  context 
)

Definition at line 244 of file DependencyGraph.cc.

References edm::PathsAndConsumesOfModulesBase::allModules(), edmModuleTypeEnum(), edm::PathsAndConsumesOfModulesBase::endPaths(), runEdmFileComparison::found, reco::get(), highlighted(), mps_fire::i, edm::ModuleDescription::id(), edm::ProcessContext::isSubProcess(), m_graph, m_initialized, m_showPathDependencies, python.rootplot.argparse::module, edm::ModuleDescription::moduleLabel(), edm::PathsAndConsumesOfModulesBase::modulesOnEndPath(), edm::PathsAndConsumesOfModulesBase::modulesOnPath(), edm::PathsAndConsumesOfModulesBase::modulesWhoseProductsAreConsumedBy(), edm::PathsAndConsumesOfModulesBase::paths(), edm::ProcessContext::processName(), shapes, and findQualityFiles::size.

Referenced by DependencyGraph().

244  {
245 
246  // if the Service is not in the main Process do not do anything
247  if (context.isSubProcess() and not m_initialized) {
248  edm::LogError("DependencyGraph")
249  << "You have requested an instance of the DependencyGraph Service in the \"" << context.processName()
250  << "\" SubProcess, which is not supported.\nPlease move it to the main process.";
251  return;
252  }
253 
254  if (not context.isSubProcess()) {
255  // set the graph name property to the process name
256  boost::get_property(m_graph, boost::graph_name) = context.processName();
257  boost::get_property(m_graph, boost::graph_graph_attribute)["label"] = "process " + context.processName();
258  boost::get_property(m_graph, boost::graph_graph_attribute)["labelloc"] = "top";
259 
260  // create graph vertices associated to all modules in the process
261  auto size = pathsAndConsumes.allModules().size();
262  for (size_t i = 0; i < size; ++i)
263  boost::add_vertex(m_graph);
264 
265  m_initialized = true;
266  } else {
267  // create a subgraph to match the subprocess
268  auto & graph = m_graph.create_subgraph();
269 
270  // set the subgraph name property to the subprocess name
271  boost::get_property(graph, boost::graph_name) = "cluster" + context.processName();
272  boost::get_property(graph, boost::graph_graph_attribute)["label"] = "subprocess " + context.processName();
273  boost::get_property(graph, boost::graph_graph_attribute)["labelloc"] = "top";
274 
275  // create graph vertices associated to all modules in the subprocess
276  auto size = pathsAndConsumes.allModules().size();
277  for (size_t i = 0; i < size; ++i)
278  boost::add_vertex(graph);
279  }
280 
281  // set the vertices properties (use the module id as the global index into the graph)
282  for (edm::ModuleDescription const * module: pathsAndConsumes.allModules()) {
283  m_graph.m_graph[module->id()] = { module->moduleLabel(), module->moduleName(), module->id(), edmModuleTypeEnum(*module), false };
284 
285  auto & attributes = boost::get(boost::get(boost::vertex_attribute, m_graph), module->id());
286  attributes["label"] = module->moduleLabel();
287  attributes["tooltip"] = module->moduleName();
288  attributes["shape"] = shapes[static_cast<std::underlying_type_t<EDMModuleType>>(edmModuleTypeEnum(*module))];
289  attributes["style"] = "filled";
290  attributes["color"] = "black";
291  attributes["fillcolor"] = highlighted(module->moduleLabel()) ? "green" : "lightgrey";
292  }
293 
294  // paths and endpaths
295  auto const & paths = pathsAndConsumes.paths();
296  auto const & endps = pathsAndConsumes.endPaths();
297 
298  // add graph edges associated to module dependencies
299  for (edm::ModuleDescription const * consumer: pathsAndConsumes.allModules()) {
300  for (edm::ModuleDescription const * module: pathsAndConsumes.modulesWhoseProductsAreConsumedBy(consumer->id())) {
301  edm::LogInfo("DependencyGraph") << "module " << consumer->moduleLabel() << " depends on module " << module->moduleLabel();
302  auto edge_status = boost::add_edge(consumer->id(), module->id(), m_graph);
303  // highlight the arrow between highlighted nodes
304  if (highlighted(module->moduleLabel()) and highlighted(consumer->moduleLabel())) {
305  auto const & edge = edge_status.first;
306  auto & attributes = boost::get(boost::get(boost::edge_attribute, m_graph), edge);
307  attributes["color"] = "darkgreen";
308  }
309  }
310  }
311 
312  // marke the modules in the paths as scheduled, and add a soft dependency to reflect the order of modules along each path
313  edm::ModuleDescription const * previous;
314  for (unsigned int i = 0; i < paths.size(); ++i) {
315  previous = nullptr;
316  for (edm::ModuleDescription const * module: pathsAndConsumes.modulesOnPath(i)) {
317  m_graph.m_graph[module->id()].scheduled = true;
318  auto & attributes = boost::get(boost::get(boost::vertex_attribute, m_graph), module->id());
319  attributes["fillcolor"] = highlighted(module->moduleLabel()) ? "lightgreen" : "white";
320  if (previous and m_showPathDependencies) {
321  edm::LogInfo("DependencyGraph") << "module " << module->moduleLabel() << " follows module " << previous->moduleLabel() << " in Path " << i;
322  auto edge_status = boost::lookup_edge(module->id(), previous->id(), m_graph);
323  bool found = edge_status.second;
324  if (not found) {
325  edge_status = boost::add_edge(module->id(), previous->id(), m_graph);
326  auto const & edge = edge_status.first;
327  auto & attributes = boost::get(boost::get(boost::edge_attribute, m_graph), edge);
328  attributes["style"] = "dashed";
329  // highlight the arrow between highlighted nodes
330  if (highlighted(module->moduleLabel()) and highlighted(previous->moduleLabel()))
331  attributes["color"] = "darkgreen";
332  }
333  }
334  previous = module;
335  }
336  }
337  for (unsigned int i = 0; i < endps.size(); ++i) {
338  previous = nullptr;
339  for (edm::ModuleDescription const * module: pathsAndConsumes.modulesOnEndPath(i)) {
340  m_graph.m_graph[module->id()].scheduled = true;
341  auto & attributes = boost::get(boost::get(boost::vertex_attribute, m_graph), module->id());
342  attributes["fillcolor"] = highlighted(module->moduleLabel()) ? "lightgreen" : "white";
343  if (previous and m_showPathDependencies) {
344  edm::LogInfo("DependencyGraph") << "module " << module->moduleLabel() << " follows module " << previous->moduleLabel() << " in EndPath " << i;
345  auto edge_status = boost::lookup_edge(module->id(), previous->id(), m_graph);
346  bool found = edge_status.second;
347  if (not found) {
348  edge_status = boost::add_edge(module->id(), previous->id(), m_graph);
349  auto const & edge = edge_status.first;
350  auto & attributes = boost::get(boost::get(boost::edge_attribute, m_graph), edge);
351  attributes["style"] = "dashed";
352  // highlight the arrow between highlighted nodes
353  if (highlighted(module->moduleLabel()) and highlighted(previous->moduleLabel()))
354  attributes["color"] = "darkgreen";
355  }
356  }
357  previous = module;
358  }
359  }
360 }
size
Write out results.
std::string const & moduleLabel() const
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 > > > > > > m_graph
static EDMModuleType edmModuleTypeEnum(edm::ModuleDescription const &module)
static const char * shapes[]
bool highlighted(std::string const &module)
Definition: vlib.h:208
T get(const Candidate &c)
Definition: component.h:55
unsigned int id() const
void DependencyGraph::preSourceConstruction ( ModuleDescription const &  module)

Definition at line 229 of file DependencyGraph.cc.

References reco::get(), highlighted(), edm::ModuleDescription::id(), m_graph, edm::ModuleDescription::moduleLabel(), edm::ModuleDescription::moduleName(), shapes, and Source.

Referenced by DependencyGraph().

229  {
230  // create graph vertex for the source module and fill its attributes
231  boost::add_vertex(m_graph);
232  m_graph.m_graph[module.id()] = node{ module.moduleLabel(), module.moduleName(), module.id(), EDMModuleType::Source, true };
233  auto & attributes = boost::get(boost::get(boost::vertex_attribute, m_graph), 0);
234  attributes["label"] = module.moduleLabel();
235  attributes["tooltip"] = module.moduleName();
236  attributes["shape"] = shapes[static_cast<std::underlying_type_t<EDMModuleType>>(EDMModuleType::Source)];
237  attributes["style"] = "filled";
238  attributes["color"] = "black";
239  attributes["fillcolor"] = highlighted(module.moduleLabel()) ? "lightgreen" : "white";
240 }
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 > > > > > > m_graph
static const char * shapes[]
bool highlighted(std::string const &module)
Definition: vlib.h:208
T get(const Candidate &c)
Definition: component.h:55

Member Data Documentation

std::string DependencyGraph::m_filename
private

Definition at line 142 of file DependencyGraph.cc.

Referenced by postBeginJob().

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> > > > > > DependencyGraph::m_graph
private

Definition at line 140 of file DependencyGraph.cc.

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

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

Definition at line 143 of file DependencyGraph.cc.

bool DependencyGraph::m_initialized
private

Definition at line 146 of file DependencyGraph.cc.

Referenced by postBeginJob(), and preBeginJob().

bool DependencyGraph::m_showPathDependencies
private

Definition at line 145 of file DependencyGraph.cc.

Referenced by preBeginJob().

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

Definition at line 83 of file DependencyGraph.cc.

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

Definition at line 95 of file DependencyGraph.cc.

Referenced by preBeginJob(), and preSourceConstruction().