Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-06-04 22:36:16

0001 #ifndef HLTrigger_Timer_interface_ProcessCallGraph_h
0002 #define HLTrigger_Timer_interface_ProcessCallGraph_h
0003 
0004 #include <memory>
0005 #include <utility>
0006 #include <vector>
0007 #include <string>
0008 
0009 // boost optional (used by boost graph) results in some false positives with -Wmaybe-uninitialized
0010 #pragma GCC diagnostic push
0011 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
0012 #include <boost/graph/adjacency_list.hpp>
0013 #include <boost/graph/lookup_edge.hpp>
0014 #include <boost/graph/subgraph.hpp>
0015 #pragma GCC diagnostic pop
0016 
0017 #include "DataFormats/Provenance/interface/ModuleDescription.h"
0018 #include "FWCore/ServiceRegistry/interface/ServiceRegistryfwd.h"
0019 #include "HLTrigger/Timer/interface/EDMModuleType.h"
0020 
0021 class ProcessCallGraph {
0022 public:
0023   struct NodeType {
0024     edm::ModuleDescription module_;
0025     edm::EDMModuleType type_ = edm::EDMModuleType::kUnknown;
0026     bool scheduled_ = false;
0027   };
0028 
0029   // directed graph, with `NodeType` properties attached to each vertex
0030   using GraphType = boost::subgraph<boost::adjacency_list<
0031       // edge list
0032       boost::vecS,
0033       // vertex list
0034       boost::vecS,
0035       boost::directedS,
0036       // vertex properties
0037       NodeType,
0038       // edge propoerties, used internally by boost::subgraph
0039       boost::property<boost::edge_index_t, int>,
0040       // graph properties, used to name each boost::subgraph
0041       boost::property<boost::graph_name_t, std::string>>>;
0042 
0043   // store the details of each path: name, modules on the path, and their dependencies
0044   struct PathType {
0045     std::string name_;
0046     std::vector<unsigned int> modules_on_path_;
0047     std::vector<unsigned int> modules_and_dependencies_;
0048     std::vector<unsigned int>
0049         last_dependency_of_module_;  // one-after-the-last dependency of each module, as indices into modules_and_dependencies_
0050 
0051     PathType() = default;
0052 
0053     PathType(std::string name,
0054              std::vector<unsigned int> mop,
0055              std::vector<unsigned int> mad,
0056              std::vector<unsigned int> ldom)
0057         : name_(std::move(name)),
0058           modules_on_path_(std::move(mop)),
0059           modules_and_dependencies_(std::move(mad)),
0060           last_dependency_of_module_(std::move(ldom)) {}
0061   };
0062 
0063   // store the details of the process: name, modules call subgraph, modules, paths and endpaths
0064   struct ProcessType {
0065     std::string name_;
0066     GraphType const &graph_;
0067     std::vector<unsigned int> modules_;
0068     std::vector<PathType> paths_;
0069     std::vector<PathType> endPaths_;
0070 
0071     ProcessType(std::string name,
0072                 GraphType const &graph,
0073                 std::vector<unsigned int> modules,
0074                 std::vector<PathType> paths,
0075                 std::vector<PathType> endPaths)
0076         : name_(std::move(name)),
0077           graph_(graph),
0078           modules_(std::move(modules)),
0079           paths_(std::move(paths)),
0080           endPaths_(std::move(endPaths)) {}
0081   };
0082 
0083   // default c'tor
0084   ProcessCallGraph() = default;
0085 
0086   // to be called from preSourceConstruction(...)
0087   void preSourceConstruction(edm::ModuleDescription const &);
0088 
0089   // to be called from lookupInitializationComplete(...)
0090   void lookupInitializationComplete(edm::PathsAndConsumesOfModulesBase const &, edm::ProcessContext const &);
0091 
0092   // number of modules stored in the call graph
0093   unsigned int size() const;
0094 
0095   // retrieve the ModuleDescription associated to the Source
0096   edm::ModuleDescription const &source() const;
0097 
0098   // retrieve the ModuleDescription associated to the given id
0099   edm::ModuleDescription const &module(unsigned int module) const;
0100 
0101   // retrieve the full information for a given module
0102   NodeType const &operator[](unsigned int module) const;
0103 
0104   // find the dependencies of the given module
0105   std::vector<unsigned int> depends(unsigned int module) const;
0106 
0107   // find the dependencies of all modules in the given path
0108   std::pair<std::vector<unsigned int>, std::vector<unsigned int>> dependencies(std::vector<unsigned int> const &path);
0109 
0110   // retrieve information about the process
0111   ProcessType const &processDescription() const;
0112 
0113 private:
0114   GraphType graph_;
0115 
0116   // module id of the Source
0117   unsigned int source_ = edm::ModuleDescription::invalidID();
0118 
0119   // description of the process
0120   std::unique_ptr<ProcessType> process_description_;
0121 };
0122 
0123 #endif  // not defined HLTrigger_Timer_interface_ProcessCallGraph_h