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 constexpr const char * module_type_desc []
 
static constexpr const char * shapes []
 

Detailed Description

Definition at line 55 of file DependencyGraph.cc.

Member Typedef Documentation

◆ 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.

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 }

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

Member Function Documentation

◆ edmModuleType()

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

Definition at line 156 of file DependencyGraph.cc.

156  {
157  return module_type_desc[static_cast<std::underlying_type_t<EDMModuleType>>(edmModuleTypeEnum(module))];
158 }

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

◆ edmModuleTypeEnum()

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

Definition at line 135 of file DependencyGraph.cc.

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 }

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

Referenced by preBeginJob().

◆ fillDescriptions()

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

Definition at line 160 of file DependencyGraph.cc.

160  {
162  desc.addUntracked<std::string>("fileName", "dependency.gv");
163  desc.addUntracked<std::vector<std::string>>("highlightModules", {});
164  desc.addUntracked<bool>("showPathDependencies", true);
165  descriptions.add("DependencyGraph", desc);
166 }

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

◆ highlighted()

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

Definition at line 66 of file DependencyGraph.cc.

66 { return (m_highlightModules.find(module) != m_highlightModules.end()); }

Referenced by preBeginJob(), and preSourceConstruction().

◆ postBeginJob()

void DependencyGraph::postBeginJob ( )

Definition at line 330 of file DependencyGraph.cc.

330  {
331  if (not m_initialized)
332  return;
333 
334  // draw the dependency graph
335  std::ofstream out(m_filename);
336  boost::write_graphviz(out, m_graph);
337  out.close();
338 }

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

Referenced by DependencyGraph().

◆ preBeginJob()

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

Definition at line 208 of file DependencyGraph.cc.

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.allModules().size();
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.allModules().size();
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 arrow 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  // marke the modules in the paths as scheduled, and add a soft dependency to reflect the order of modules along each path
279  edm::ModuleDescription const *previous;
280  for (unsigned int i = 0; i < paths.size(); ++i) {
281  previous = nullptr;
282  for (edm::ModuleDescription const *module : pathsAndConsumes.modulesOnPath(i)) {
283  m_graph.m_graph[module->id()].scheduled = true;
284  auto &attributes = boost::get(boost::get(boost::vertex_attribute, m_graph), module->id());
285  attributes["fillcolor"] = highlighted(module->moduleLabel()) ? "lightgreen" : "white";
286  if (previous and m_showPathDependencies) {
287  edm::LogInfo("DependencyGraph") << "module " << module->moduleLabel() << " follows module "
288  << previous->moduleLabel() << " in Path " << i;
289  auto edge_status = boost::lookup_edge(module->id(), previous->id(), m_graph);
290  bool found = edge_status.second;
291  if (not found) {
292  edge_status = boost::add_edge(module->id(), previous->id(), m_graph);
293  auto const &edge = edge_status.first;
294  auto &edgeAttributes = boost::get(boost::get(boost::edge_attribute, m_graph), edge);
295  edgeAttributes["style"] = "dashed";
296  // highlight the arrow between highlighted nodes
297  if (highlighted(module->moduleLabel()) and highlighted(previous->moduleLabel()))
298  edgeAttributes["color"] = "darkgreen";
299  }
300  }
301  previous = module;
302  }
303  }
304  for (unsigned int i = 0; i < endps.size(); ++i) {
305  previous = nullptr;
306  for (edm::ModuleDescription const *module : pathsAndConsumes.modulesOnEndPath(i)) {
307  m_graph.m_graph[module->id()].scheduled = true;
308  auto &attributes = boost::get(boost::get(boost::vertex_attribute, m_graph), module->id());
309  attributes["fillcolor"] = highlighted(module->moduleLabel()) ? "lightgreen" : "white";
310  if (previous and m_showPathDependencies) {
311  edm::LogInfo("DependencyGraph") << "module " << module->moduleLabel() << " follows module "
312  << previous->moduleLabel() << " in EndPath " << i;
313  auto edge_status = boost::lookup_edge(module->id(), previous->id(), m_graph);
314  bool found = edge_status.second;
315  if (not found) {
316  edge_status = boost::add_edge(module->id(), previous->id(), m_graph);
317  auto const &edge = edge_status.first;
318  auto &edgeAttributes = boost::get(boost::get(boost::edge_attribute, m_graph), edge);
319  edgeAttributes["style"] = "dashed";
320  // highlight the arrow between highlighted nodes
321  if (highlighted(module->moduleLabel()) and highlighted(previous->moduleLabel()))
322  edgeAttributes["color"] = "darkgreen";
323  }
324  }
325  previous = module;
326  }
327  }
328 }

References edm::PathsAndConsumesOfModulesBase::allModules(), OfflineOutput_cfi::consumer, edmModuleTypeEnum(), edm::PathsAndConsumesOfModulesBase::endPaths(), newFWLiteAna::found, get, highlighted(), mps_fire::i, edm::ModuleDescription::id(), edm::ProcessContext::isSubProcess(), m_graph, m_initialized, m_showPathDependencies, edm::ModuleDescription::moduleLabel(), edm::PathsAndConsumesOfModulesBase::modulesOnEndPath(), edm::PathsAndConsumesOfModulesBase::modulesOnPath(), edm::PathsAndConsumesOfModulesBase::modulesWhoseProductsAreConsumedBy(), Skims_PA_cff::paths, edm::PathsAndConsumesOfModulesBase::paths(), edm::ProcessContext::processName(), shapes, and findQualityFiles::size.

Referenced by DependencyGraph().

◆ preSourceConstruction()

void DependencyGraph::preSourceConstruction ( ModuleDescription const &  module)

Definition at line 194 of file DependencyGraph.cc.

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 }

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

Referenced by DependencyGraph().

Member Data Documentation

◆ m_filename

std::string DependencyGraph::m_filename
private

Definition at line 124 of file DependencyGraph.cc.

Referenced by postBeginJob().

◆ m_graph

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 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
staticconstexprprivate
Initial value:
{
"Unknown", "Source", "ESSource", "ESProducer", "EDAnalyzer", "EDProducer", "EDFilter", "OutputModule"}

Definition at line 70 of file DependencyGraph.cc.

◆ shapes

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

Definition at line 73 of file DependencyGraph.cc.

Referenced by preBeginJob(), and preSourceConstruction().

DependencyGraph::EDMModuleType::ESProducer
edm::pset::Registry::instance
static Registry * instance()
Definition: Registry.cc:12
DependencyGraph::EDMModuleType::Unknown
edm::ModuleDescription::moduleLabel
std::string const & moduleLabel() const
Definition: ModuleDescription.h:43
mixOne_cfi.ESProducer
ESProducer
Definition: mixOne_cfi.py:33
mps_fire.i
i
Definition: mps_fire.py:355
DependencyGraph::m_filename
std::string m_filename
Definition: DependencyGraph.cc:124
DependencyGraph::m_showPathDependencies
bool m_showPathDependencies
Definition: DependencyGraph.cc:127
edm::LogInfo
Definition: MessageLogger.h:254
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
DependencyGraph::highlighted
bool highlighted(std::string const &module)
Definition: DependencyGraph.cc:66
DependencyGraph::EDMModuleType::Source
reco::Unknown
Definition: MuonSimInfo.h:32
findQualityFiles.v
v
Definition: findQualityFiles.py:179
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::ModuleDescription
Definition: ModuleDescription.h:21
edm::EDAnalyzer
Definition: EDAnalyzer.h:29
config
Definition: config.py:1
DependencyGraph::EDMModuleType::EDAnalyzer
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
edm::ActivityRegistry::watchPreBeginJob
void watchPreBeginJob(PreBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
Definition: ActivityRegistry.h:149
DependencyGraph::preBeginJob
void preBeginJob(PathsAndConsumesOfModulesBase const &, ProcessContext const &)
Definition: DependencyGraph.cc:208
edm::ActivityRegistry::watchPostBeginJob
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
Definition: ActivityRegistry.h:156
OrderedSet.t
t
Definition: OrderedSet.py:90
edm::ActivityRegistry::watchPreSourceConstruction
void watchPreSourceConstruction(PreSourceConstruction::slot_type const &iSlot)
Definition: ActivityRegistry.h:949
DependencyGraph::postBeginJob
void postBeginJob()
Definition: DependencyGraph.cc:330
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::EDMModuleType
EDMModuleType
Definition: EDMModuleType.h:8
edm::ParameterSetDescription::addUntracked
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:100
edm::LogError
Definition: MessageLogger.h:183
DependencyGraph::m_highlightModules
std::unordered_set< std::string > m_highlightModules
Definition: DependencyGraph.cc:125
DependencyGraph::m_initialized
bool m_initialized
Definition: DependencyGraph.cc:128
edm::EDFilter
Definition: EDFilter.h:39
module
Definition: vlib.h:198
get
#define get
DependencyGraph::preSourceConstruction
void preSourceConstruction(ModuleDescription const &)
Definition: DependencyGraph.cc:194
DependencyGraph::EDMModuleType::OutputModule
DependencyGraph::shapes
static constexpr const char * shapes[]
Definition: DependencyGraph.cc:73
DependencyGraph::module_type_desc
static constexpr const char * module_type_desc[]
Definition: DependencyGraph.cc:70
DependencyGraph::m_graph
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
Definition: DependencyGraph.cc:122
DependencyGraph::EDMModuleType::ESSource
edm::EDProducer
Definition: EDProducer.h:36
Skims_PA_cff.paths
paths
Definition: Skims_PA_cff.py:18
OfflineOutput_cfi.consumer
consumer
Definition: OfflineOutput_cfi.py:3
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
DependencyGraph::edmModuleTypeEnum
static EDMModuleType edmModuleTypeEnum(edm::ModuleDescription const &module)
Definition: DependencyGraph.cc:135
DependencyGraph::EDMModuleType::EDProducer
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
CollectionTags_cfi.Source
Source
Definition: CollectionTags_cfi.py:11
edm::ModuleDescription::id
unsigned int id() const
Definition: ModuleDescription.h:46
DependencyGraph::EDMModuleType::EDFilter