DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dbe::tool::graph::gtool Class Reference

#include <gtool.hpp>

Classes

struct  vertex_label

Public Types

typedef boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, vertex_label > t_graph
typedef boost::graph_traits< t_graph >::edge_descriptor t_edge
typedef boost::graph_traits< t_graph >::vertex_descriptor t_vertex
typedef std::map< std::string, t_vertex > t_registry
typedef std::pair< bool, boost::graph_traits< gtool::t_graph >::vertex_iterator > t_lookup_ret

Public Member Functions

 gtool (std::string const &rl, dbinfo dbtype)
template<typename ALGO>
int load_and_run (ALGO const &)
t_graph const & getgraph () const

Static Public Member Functions

static t_vertex add_object_and_friends (t_graph &, tref const &, t_registry &registry)
static t_vertex add_object (t_graph &g, tref const &o, bool uniqueness=true)
static t_vertex add_object (t_graph &g, tref const &o, t_registry &registry)
static t_lookup_ret lookup (t_graph const &g, vertex_label const &l)

Private Types

typedef std::vector< tref > t_objects

Private Member Functions

void load_all ()
void load_all_class_objects (std::string const &cname)
void create_graph ()

Private Attributes

t_graph this_graph
t_objects this_all_objects
t_registry already_processed
std::string this_src

Detailed Description

Definition at line 35 of file gtool.hpp.

Member Typedef Documentation

◆ t_edge

typedef boost::graph_traits<t_graph>::edge_descriptor dbe::tool::graph::gtool::t_edge

Definition at line 52 of file gtool.hpp.

◆ t_graph

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, vertex_label> dbe::tool::graph::gtool::t_graph

Definition at line 50 of file gtool.hpp.

◆ t_lookup_ret

typedef std::pair<bool, boost::graph_traits<gtool::t_graph>::vertex_iterator> dbe::tool::graph::gtool::t_lookup_ret

Definition at line 110 of file gtool.hpp.

◆ t_objects

typedef std::vector<tref> dbe::tool::graph::gtool::t_objects
private

Definition at line 125 of file gtool.hpp.

◆ t_registry

typedef std::map<std::string, t_vertex> dbe::tool::graph::gtool::t_registry

Definition at line 55 of file gtool.hpp.

◆ t_vertex

typedef boost::graph_traits<t_graph>::vertex_descriptor dbe::tool::graph::gtool::t_vertex

Definition at line 53 of file gtool.hpp.

Constructor & Destructor Documentation

◆ gtool()

dbe::tool::graph::gtool::gtool ( std::string const & rl,
dbinfo dbtype )

Construct gtool object from string a resource location and db information type Resulting object loads a database from the resource location of the designated type

Parameters
fnis a string designating the resource location of the database
dbtypeis the type (dbinfo) of the database access method (e.g. oks, rdb ... )

Definition at line 34 of file gtool.cpp.

35 : this_src(rl)
36{
37 QFileInfo DatabaseFile(QString::fromStdString(rl));
38
39 if (DatabaseFile.exists()) {
40 QString path_to_database = QString(DatabaseFile.absoluteFilePath());
41 {
42 confaccessor::setdbinfo(path_to_database, dbtype);
43 INFO("Database location set", "Program execution control success");
44
45 if (confaccessor::load()) {
46 INFO("Database initialized", "User request");
47 } else {
48 ERROR("Could not load database", "OKS error ", " Actions : check environment variables e.g. DUNEDAQ_DB_PATH");
49 throw std::string("Could not load database");
50 }
51 }
52 } else {
53 ERROR("Cannot open database", "File error", "for file", rl);
54 }
55}
static bool load(bool subscribeToChanges=true)
static void setdbinfo(QString const &location, dbinfo const itype=dbinfo::oks)
std::string this_src
Definition gtool.hpp:131
#define ERROR(...)
Definition messenger.hpp:90
#define INFO(...)
Definition messenger.hpp:98

Member Function Documentation

◆ add_object() [1/2]

gtool::t_vertex dbe::tool::graph::gtool::add_object ( gtool::t_graph & g,
tref const & o,
bool uniqueness = true )
static

Add an object to a graph without its relations

Parameters
gis a reference to the graph
ois a reference to the object
uniquenessonly add the object if there is no vertex already abstracting it
Returns
the newly added vertex or an already existent vertex if uniqueness is set and the object has already been added as a vertex

Definition at line 108 of file gtool.cpp.

109{
110 vertex_label xl{ x.UID(), x.class_name(), x.full_name() };
111
112 if (not uniqueness) {
113 // Multiple vertices with the same properties can be added to this graph
114 return boost::add_vertex(xl, g);
115 } else {
116 bool result;
117 boost::graph_traits<t_graph>::vertex_iterator viter;
118 std::tie(result, viter) = lookup(g, xl);
119
120 if (result) {
121 return *viter;
122 } else {
123 return boost::add_vertex(xl, g);
124 }
125 }
126}
static t_lookup_ret lookup(t_graph const &g, vertex_label const &l)
Definition gtool.cpp:164

◆ add_object() [2/2]

gtool::t_vertex dbe::tool::graph::gtool::add_object ( gtool::t_graph & g,
tref const & o,
t_registry & registry )
static

Add an object to a graph without its relations if it is not found in the provided registry

Parameters
gis a reference to the graph
ois a reference to the object
registryis a set of tags already present , and implies adding the object only if its tag is not in the registry ( speed up lookups )
Returns
the newly added vertex or an already existent vertex if uniqueness is set and the object has already been added as a vertex

Definition at line 129 of file gtool.cpp.

130{
131 t_registry::iterator vat = registry.find(x.full_name());
132
133 if (std::end(registry) == vat) {
134 FULLDEBUG("Adding object", "Program execution control", x.full_name());
135 // not in the registry implies it is not in the graph , i.e. its user responsibility
136 t_registry::iterator v;
137 std::tie(v, std::ignore) = registry.emplace(x.full_name(), add_object(g, x, false));
138 return v->second;
139 } else {
140 return vat->second;
141 }
142}
static t_vertex add_object(t_graph &g, tref const &o, bool uniqueness=true)
Definition gtool.cpp:108
#define FULLDEBUG(...)
default char v[0]

◆ add_object_and_friends()

gtool::t_vertex dbe::tool::graph::gtool::add_object_and_friends ( t_graph & g,
tref const & o,
t_registry & registry )
static

Add an object to a graph along with all connected objects through any relation

Parameters
areference to the graph
aregistry of tags of objects already present in the graph

Definition at line 145 of file gtool.cpp.

146{
147 DEBUG("Processing object", "Program execution control", o.full_name());
148 t_vertex ov = add_object(g, o, registry);
149
150 std::vector<tref> friends{ config::api::graph::linked::by::object<tref>(o) }; // get all neighbors
151 DEBUG(
152 "Processing object", "Program execution control", o.full_name(), " # friends: ", std::to_string(friends.size()));
153
154 for (tref const& x : friends) {
155 t_vertex xv = add_object(g, x, registry);
156 boost::add_edge(ov, xv, g);
157 FULLDEBUG("Add edge ", "Program excecution control", o.full_name(), "->", x.full_name());
158 }
159
160 return ov;
161}
boost::graph_traits< t_graph >::vertex_descriptor t_vertex
Definition gtool.hpp:53
#define DEBUG(...)
std::vector< T > object(tref const &item)
inner::configobject::tref tref
Definition tref.hpp:36

◆ create_graph()

void dbe::tool::graph::gtool::create_graph ( )
private

Definition at line 95 of file gtool.cpp.

96{
97 INFO("Database graph generation initiated", "Program execution control");
98 already_processed.clear();
99
100 for (auto const& x : this_all_objects) {
102 }
103
104 INFO("Graph generation completed successfully", "Program execution control success");
105}
t_objects this_all_objects
Definition gtool.hpp:128
t_registry already_processed
Definition gtool.hpp:129
static t_vertex add_object_and_friends(t_graph &, tref const &, t_registry &registry)
Definition gtool.cpp:145

◆ getgraph()

gtool::t_graph const & dbe::tool::graph::gtool::getgraph ( ) const

Retrieve the graph as it currently is

Returns
a const reference to the t_graph

Definition at line 58 of file gtool.cpp.

59{
60 return this_graph;
61}

◆ load_all()

void dbe::tool::graph::gtool::load_all ( )
private

Definition at line 64 of file gtool.cpp.

65{
66 INFO("Start load objects into internal cache", "Program execution control");
67
68 std::vector<std::string> all_classes = { config::api::info::onclass::allnames<std::vector<std::string>>() };
69
70 for (auto const& x : all_classes) {
72 }
73
74 INFO("All objects loaded into internal cache",
75 "Program execution control success",
76 "#objects:",
77 std::to_string(this_all_objects.size()));
78}
void load_all_class_objects(std::string const &cname)
Definition gtool.cpp:81

◆ load_all_class_objects()

void dbe::tool::graph::gtool::load_all_class_objects ( std::string const & cname)
private

Definition at line 81 of file gtool.cpp.

82{
83 std::vector<dbe::tref> all_objects = config::api::info::onclass::objects<false>(cname, false);
84
85 INFO("Class to load: ", "Program execution control", cname);
86
87 for (dbe::tref const& x : all_objects) {
88 this_all_objects.push_back(x);
89 }
90
91 INFO("Class load success: ", "Program execution control", cname, "#objects", std::to_string(all_objects.size()));
92}
static std::vector< dbe::inner::configobject::tref > objects(std::string const &cname, bool const keep_inherited=true)

◆ load_and_run()

template<typename ALGO>
int dbe::tool::graph::gtool::load_and_run ( ALGO const & algo)
inline

Definition at line 184 of file gtool.hpp.

185{
186 load_all();
187 create_graph();
188 return algo(static_cast<gtool const&>(*this));
189}
gtool(std::string const &rl, dbinfo dbtype)
Definition gtool.cpp:34

◆ lookup()

gtool::t_lookup_ret dbe::tool::graph::gtool::lookup ( t_graph const & g,
vertex_label const & l )
static

Lookup a vector in the graph , runs in O(N) worst case

Parameters
gis the graph
lis the graph label
Returns
a pair <true, valid vertex iterator > if found , otherwise <false, end iter>

Definition at line 164 of file gtool.cpp.

165{
166 auto const& vertices = boost::vertices(g);
167
168 for (auto v = vertices.first; v != vertices.second; ++v) {
169 if (l.label == boost::get(&vertex_label::label, g, *v)) {
170 return t_lookup_ret(true, v);
171 }
172 }
173
174 return t_lookup_ret(false, vertices.second);
175}
std::pair< bool, boost::graph_traits< gtool::t_graph >::vertex_iterator > t_lookup_ret
Definition gtool.hpp:110

Member Data Documentation

◆ already_processed

t_registry dbe::tool::graph::gtool::already_processed
private

Definition at line 129 of file gtool.hpp.

◆ this_all_objects

t_objects dbe::tool::graph::gtool::this_all_objects
private

Definition at line 128 of file gtool.hpp.

◆ this_graph

t_graph dbe::tool::graph::gtool::this_graph
private

Definition at line 127 of file gtool.hpp.

◆ this_src

std::string dbe::tool::graph::gtool::this_src
private

Definition at line 131 of file gtool.hpp.


The documentation for this class was generated from the following files: