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_labelt_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_vertext_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< treft_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 38 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 57 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 55 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 114 of file gtool.hpp.

◆ t_objects

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

Definition at line 129 of file gtool.hpp.

◆ t_registry

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

Definition at line 60 of file gtool.hpp.

◆ t_vertex

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

Definition at line 58 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 37 of file gtool.cpp.

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

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 118 of file gtool.cpp.

119{
120 vertex_label xl
121 { x.UID(), x.class_name(), x.full_name() };
122
123 if ( not uniqueness )
124 {
125 // Multiple vertices with the same properties can be added to this graph
126 return boost::add_vertex ( xl, g );
127 }
128 else
129 {
130 bool result;
131 boost::graph_traits<t_graph>::vertex_iterator viter;
132 std::tie ( result, viter ) = lookup ( g, xl );
133
134 if ( result )
135 {
136 return *viter;
137 }
138 else
139 {
140 return boost::add_vertex ( xl, g );
141
142 }
143 }
144}
static t_lookup_ret lookup(t_graph const &g, vertex_label const &l)
Definition gtool.cpp:188

◆ 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 146 of file gtool.cpp.

148{
149 t_registry::iterator vat = registry.find ( x.full_name() );
150
151 if ( std::end ( registry ) == vat )
152 {
153 FULLDEBUG ( "Adding object", "Program execution control", x.full_name() );
154 // not in the registry implies it is not in the graph , i.e. its user responsibility
155 t_registry::iterator v;
156 std::tie ( v, std::ignore ) = registry.emplace ( x.full_name(), add_object ( g, x,
157 false ) );
158 return v->second;
159 }
160 else
161 {
162 return vat->second;
163 }
164}
static t_vertex add_object(t_graph &g, tref const &o, bool uniqueness=true)
Definition gtool.cpp:118
#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 166 of file gtool.cpp.

168{
169 DEBUG ( "Processing object", "Program execution control", o.full_name() );
170 t_vertex ov = add_object ( g, o, registry );
171
172 std::vector<tref> friends
173 { config::api::graph::linked::by::object<tref> ( o ) }; // get all neighbors
174 DEBUG ( "Processing object", "Program execution control", o.full_name(), " # friends: ",
175 std::to_string ( friends.size() ) );
176
177 for ( tref const & x : friends )
178 {
179 t_vertex xv = add_object ( g, x, registry );
180 boost::add_edge ( ov, xv, g );
181 FULLDEBUG ( "Add edge ", "Program excecution control", o.full_name() , "->",
182 x.full_name() );
183 }
184
185 return ov;
186}
boost::graph_traits< t_graph >::vertex_descriptor t_vertex
Definition gtool.hpp:58
#define DEBUG(...)
std::vector< T > object(tref const &item)
inner::configobject::tref tref
Definition tref.hpp:35

◆ create_graph()

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

Definition at line 105 of file gtool.cpp.

106{
107 INFO ( "Database graph generation initiated", "Program execution control" );
108 already_processed.clear();
109
110 for ( auto const & x : this_all_objects )
111 {
113 }
114
115 INFO ( "Graph generation completed successfully", "Program execution control success" );
116}
t_objects this_all_objects
Definition gtool.hpp:132
t_registry already_processed
Definition gtool.hpp:133
static t_vertex add_object_and_friends(t_graph &, tref const &, t_registry &registry)
Definition gtool.cpp:166

◆ 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 68 of file gtool.cpp.

69{
70 return this_graph;
71}

◆ load_all()

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

Definition at line 73 of file gtool.cpp.

74{
75 INFO ( "Start load objects into internal cache", "Program execution control" );
76
77 std::vector<std::string> all_classes =
79
80 for ( auto const & x : all_classes )
81 {
83 }
84
85 INFO ( "All objects loaded into internal cache", "Program execution control success",
86 "#objects:", std::to_string ( this_all_objects.size() ) );
87}
void load_all_class_objects(std::string const &cname)
Definition gtool.cpp:89

◆ load_all_class_objects()

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

Definition at line 89 of file gtool.cpp.

90{
91 std::vector<dbe::tref> all_objects = config::api::info::onclass::objects<false> ( cname,
92 false );
93
94 INFO ( "Class to load: ", "Program execution control", cname );
95
96 for ( dbe::tref const & x : all_objects )
97 {
98 this_all_objects.push_back ( x );
99 }
100
101 INFO ( "Class load success: ", "Program execution control", cname,
102 "#objects", std::to_string ( all_objects.size() ) );
103}
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 182 of file gtool.hpp.

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

◆ 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 188 of file gtool.cpp.

189{
190 auto const & vertices = boost::vertices ( g );
191
192 for ( auto v = vertices.first; v != vertices.second; ++v )
193 {
194 if ( l.label == boost::get ( &vertex_label::label, g, *v ) )
195 {
196 return t_lookup_ret ( true, v );
197 }
198 }
199
200 return t_lookup_ret ( false, vertices.second );
201}
std::pair< bool, boost::graph_traits< gtool::t_graph >::vertex_iterator > t_lookup_ret
Definition gtool.hpp:114

Member Data Documentation

◆ already_processed

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

Definition at line 133 of file gtool.hpp.

◆ this_all_objects

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

Definition at line 132 of file gtool.hpp.

◆ this_graph

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

Definition at line 131 of file gtool.hpp.

◆ this_src

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

Definition at line 135 of file gtool.hpp.


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