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 33 of file gtool.hpp.

Member Typedef Documentation

◆ t_edge

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

Definition at line 52 of file gtool.hpp.

◆ t_graph

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

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

Definition at line 109 of file gtool.hpp.

◆ t_objects

Definition at line 124 of file gtool.hpp.

◆ t_registry

Definition at line 55 of file gtool.hpp.

◆ t_vertex

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

33 :
34 this_src ( rl )
35{
36 QFileInfo DatabaseFile ( QString::fromStdString ( rl ) );
37
38 if ( DatabaseFile.exists() )
39 {
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 {
47 INFO ( "Database initialized", "User request" );
48 }
49 else
50 {
51 ERROR ( "Could not load database", "OKS error ",
52 " Actions : check environment variables e.g. DUNEDAQ_DB_PATH" );
53 throw std::string ( "Could not load database" );
54 }
55 }
56 }
57 else
58 {
59 ERROR ( "Cannot open database", "File error", "for file", rl );
60 }
61}
static bool load(bool subscribeToChanges=true)
static void setdbinfo(QString const &location, dbinfo const itype=dbinfo::oks)
std::string this_src
Definition gtool.hpp:130
#define ERROR(...)
Definition messenger.hpp:88
#define INFO(...)
Definition messenger.hpp:96

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

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

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

143{
144 t_registry::iterator vat = registry.find ( x.full_name() );
145
146 if ( std::end ( registry ) == vat )
147 {
148 FULLDEBUG ( "Adding object", "Program execution control", x.full_name() );
149 // not in the registry implies it is not in the graph , i.e. its user responsibility
150 t_registry::iterator v;
151 std::tie ( v, std::ignore ) = registry.emplace ( x.full_name(), add_object ( g, x,
152 false ) );
153 return v->second;
154 }
155 else
156 {
157 return vat->second;
158 }
159}
static t_vertex add_object(t_graph &g, tref const &o, bool uniqueness=true)
Definition gtool.cpp:113
#define FULLDEBUG(...)

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

163{
164 DEBUG ( "Processing object", "Program execution control", o.full_name() );
165 t_vertex ov = add_object ( g, o, registry );
166
167 std::vector<tref> friends
168 { config::api::graph::linked::by::object<tref> ( o ) }; // get all neighbors
169 DEBUG ( "Processing object", "Program execution control", o.full_name(), " # friends: ",
170 std::to_string ( friends.size() ) );
171
172 for ( tref const & x : friends )
173 {
174 t_vertex xv = add_object ( g, x, registry );
175 boost::add_edge ( ov, xv, g );
176 FULLDEBUG ( "Add edge ", "Program excecution control", o.full_name() , "->",
177 x.full_name() );
178 }
179
180 return ov;
181}
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:30

◆ create_graph()

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

Definition at line 100 of file gtool.cpp.

101{
102 INFO ( "Database graph generation initiated", "Program execution control" );
103 already_processed.clear();
104
105 for ( auto const & x : this_all_objects )
106 {
108 }
109
110 INFO ( "Graph generation completed successfully", "Program execution control success" );
111}
t_objects this_all_objects
Definition gtool.hpp:127
t_registry already_processed
Definition gtool.hpp:128
static t_vertex add_object_and_friends(t_graph &, tref const &, t_registry &registry)
Definition gtool.cpp:161

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

64{
65 return this_graph;
66}

◆ load_all()

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

Definition at line 68 of file gtool.cpp.

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

◆ load_all_class_objects()

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

Definition at line 84 of file gtool.cpp.

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

178{
179 load_all();
180 create_graph();
181 return algo ( static_cast<gtool const &> ( *this ) );
182}
gtool(std::string const &rl, dbinfo dbtype)
Definition gtool.cpp:32

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

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

Member Data Documentation

◆ already_processed

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

Definition at line 128 of file gtool.hpp.

◆ this_all_objects

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

Definition at line 127 of file gtool.hpp.

◆ this_graph

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

Definition at line 126 of file gtool.hpp.

◆ this_src

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

Definition at line 130 of file gtool.hpp.


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