DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dbe::config::api::rwdacc Class Reference

#include <config_direct_access.hpp>

Static Private Member Functions

static std::vector< dunedaq::conffwk::ConfigObjectquery_class (std::string const &classname, std::string const &query)
 
static dunedaq::conffwk::ConfigObject create_object (std::string const &fn, std::string const &cn, std::string const &name)
 
static dunedaq::conffwk::ConfigObject get_object (std::string const &, std::string const &)
 
static tref set_object (tref newobj, dbe::t_config_object_preimage::type_attrmap const &attributes, dbe::t_config_object_preimage::type_relmap const &relations)
 
static void rename_object (dunedaq::conffwk::ConfigObject &object, std::string const &newname)
 
static void destroy_object (dunedaq::conffwk::ConfigObject &)
 

Friends

class inner::dbcontroller
 

Detailed Description

Direct access to Config layer through ConfigObjects

Definition at line 30 of file config_direct_access.hpp.

Member Function Documentation

◆ create_object()

ConfigObject dbe::config::api::rwdacc::create_object ( std::string const & fn,
std::string const & cn,
std::string const & name )
staticprivate

Creates the object in the database ( changes are not committed)

Parameters
fnis the file where the object is to be created in
cnis the name of the class that the object belongs to
nameis the UID that should be given to the object
attributesare the attributes of the object to be created
relationsare the relations for the object
Returns
a copy of the thin wrapper ConfigObject

Definition at line 42 of file rwdacc.cpp.

44{
45 if (info::onclass::definition(cn, false).p_abstract)
46 {
47 ERROR("Create Object: Was not possible to create object ",
48 "Abstract classes cannot hold objects", uid, "for abstract class" , cn);
49
50 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE);
51 }
52
53 // An empty object, if its creation does not succeed this object will be returned
55
56 try
57 {
58 dbaccessor::dbptr()->create(fn, cn, uid,newobj);
59 }
60 catch (dunedaq::conffwk::Exception const & ex)
61 {
62 FAIL ( "Object creation failed", dbe::config::errors::parse ( ex ), "\n\nObject UID:",
63 uid );
64
65 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE);
66 }
67
68 return newobj;
69
70}
#define ERS_HERE
static dunedaq::conffwk::class_t definition(std::string const &cn, bool direct_only)
static cptr< dunedaq::conffwk::Configuration > dbptr()
Represents database objects.
#define ERROR(...)
Definition messenger.hpp:88
#define FAIL(...)
void newobj(std::string const &fn, std::string const &class_name, std::string const &UID, dbe::t_config_object_preimage::type_attrmap const &attributes, dbe::t_config_object_preimage::type_relmap const &relations, QUuid const &src)
std::string const parse(ers::Issue const &)

◆ destroy_object()

void dbe::config::api::rwdacc::destroy_object ( dunedaq::conffwk::ConfigObject & todelete)
staticprivate

Destroys the object in the online database ( changes are not committed)

Parameters
theobject definition to create in the database

Definition at line 338 of file rwdacc.cpp.

339{
340 try
341 {
342 dbaccessor::dbptr()->destroy_obj(todelete);
343 }
344 catch (dunedaq::conffwk::Exception const & ex)
345 {
346 WARN("Object deletion did not succeed for object" , errors::parse(ex).c_str(),
347 todelete.UID().c_str());
348
349 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE);
350 }
351}
const std::string & UID() const noexcept
Return object identity.
#define WARN(...)
Definition messenger.hpp:80

◆ get_object()

ConfigObject dbe::config::api::rwdacc::get_object ( std::string const & classname,
std::string const & objectname )
staticprivate

Retrieve an object by class name and uid

Parameters
classname
objectuid
Returns
a config object that is not null only if it exists in the database

Definition at line 355 of file rwdacc.cpp.

357{
359 {
360 try
361 {
362 ConfigObject object;
363 dbaccessor::dbptr()->get(classname, objectname, object);
364 return object;
365 }
366 catch (dunedaq::conffwk::NotFound const & e)
367 {
368 TLOG_DEBUG(3) << "Object not found" ;
369 }
370 catch (dunedaq::conffwk::Generic const & e)
371 {
372 ERROR("Generic exception caught", dbe::config::errors::parse(e).c_str());
373 TLOG_DEBUG(3) << "Generic Exception Caught" ;
374 }
375 catch (...)
376 {
377 ERROR("Unknown exception caught", "");
378 TLOG_DEBUG(3) << "Unknown exception caught!" ;
379 }
380 }
381 return
382 {};
383}
T * get()
Definition cptr.hpp:83
static bool is_loaded()
Generic configuration exception.
Try to access non-existent object or class.
Definition Errors.hpp:47
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112

◆ query_class()

std::vector< ConfigObject > dbe::config::api::rwdacc::query_class ( std::string const & classname,
std::string const & query )
staticprivate

Retrieve objects of class matching a query string (regex)

Parameters
classnameis the class to query for
queryis a regular expression to match against the objects in the given class
Returns
a list of configobjects

Definition at line 387 of file rwdacc.cpp.

389{
390 std::vector<ConfigObject> objects;
392 {
393 try
394 {
395 dbaccessor::dbptr()->get(classname, objects, query);
396 }
397 catch (dunedaq::conffwk::NotFound const & e)
398 {
399 TLOG_DEBUG(3) << "Object not found" ;
400 }
401 catch (dunedaq::conffwk::Generic const & e)
402 {
403 ERROR("Generic exception caught", dbe::config::errors::parse(e).c_str());
404 TLOG_DEBUG(3) << "Generic Exception Caught" ;
405 }
406 catch (...)
407 {
408 ERROR("Unknown exception caught", "");
409 TLOG_DEBUG(3) << "Unknown exception caught!" ;
410 }
411 }
412 return objects;
413}

◆ rename_object()

void dbe::config::api::rwdacc::rename_object ( dunedaq::conffwk::ConfigObject & object,
std::string const & newname )
staticprivate

Rename an object in the database

Parameters
objectreference to rename
newnameas a string
Returns
a reference with the object

Definition at line 417 of file rwdacc.cpp.

418{
419object.rename(newname);
420}

◆ set_object()

tref dbe::config::api::rwdacc::set_object ( tref newobj,
dbe::t_config_object_preimage::type_attrmap const & attributes,
dbe::t_config_object_preimage::type_relmap const & relations )
staticprivate

Given a reference to an object set its attributes and relations

Parameters
newobjto set
attributesto set in the object
relationsto set in the object
Returns
an empty tref in case of failure

Definition at line 83 of file rwdacc.cpp.

86{
87 auto relreader = [&relations ]( std::string const & name )
88 {
89 return relations.at(name);
90 };
91
92 auto attreader = [ & attributes ] ( std::string const & name )
93 {
94 return attributes.at(name);
95 };
96
97 if (not newobj.is_null())
98 {
100 newobj.class_name(),
101 false);
102 std::vector<dunedaq::conffwk::attribute_t> AttList = ClassInfo.p_attributes;
103 std::vector<dunedaq::conffwk::relationship_t> RelList = ClassInfo.p_relationships;
104
105 for (dunedaq::conffwk::attribute_t const & att : AttList)
106 {
107 try
108 {
109 if(att.p_is_multi_value) {
110 switch(att.p_type) {
112 {
113 auto data = dbe::convert::to<std::vector<bool>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
114 set::noactions::attribute(newobj, att, data, true);
115 }
116 break;
118 {
120 set::noactions::anenum(newobj, att, data, true);
121 }
122 break;
124 {
126 set::noactions::adate(newobj, att, data, true);
127 }
128 break;
130 {
132 set::noactions::atime(newobj, att, data, true);
133 }
134 break;
136 {
138 set::noactions::attribute(newobj, att, data, true);
139 }
140 break;
142 {
144 set::noactions::aclass(newobj, att, data, true);
145 }
146 break;
148 {
149 auto data = dbe::convert::to<std::vector<float>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
150 set::noactions::attribute(newobj, att, data, true);
151 }
152 break;
154 {
155 auto data = dbe::convert::to<std::vector<double>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
156 set::noactions::attribute(newobj, att, data, true);
157 }
158 break;
160 {
161 auto data = dbe::convert::to<std::vector<int8_t>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
162 set::noactions::attribute(newobj, att, data, true);
163 }
164 break;
166 {
167 auto data = dbe::convert::to<std::vector<int16_t>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
168 set::noactions::attribute(newobj, att, data, true);
169 }
170 break;
172 {
173 auto data = dbe::convert::to<std::vector<int32_t>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
174 set::noactions::attribute(newobj, att, data, true);
175 }
176 break;
178 {
179 auto data = dbe::convert::to<std::vector<int64_t>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
180 set::noactions::attribute(newobj, att, data, true);
181 }
182 break;
184 {
185 auto data = dbe::convert::to<std::vector<u_int8_t>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
186 set::noactions::attribute(newobj, att, data, true);
187 }
188 break;
190 {
191 auto data = dbe::convert::to<std::vector<u_int16_t>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
192 set::noactions::attribute(newobj, att, data, true);
193 }
194 break;
196 {
197 auto data = dbe::convert::to<std::vector<u_int32_t>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
198 set::noactions::attribute(newobj, att, data, true);
199 }
200 break;
202 {
203 auto data = dbe::convert::to<std::vector<u_int64_t>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
204 set::noactions::attribute(newobj, att, data, true);
205 }
206 break;
207 default:
208 break;
209 }
210 } else {
211 switch(att.p_type) {
213 {
214 auto data = dbe::convert::to<bool>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
215 set::noactions::attribute(newobj, att, data, true);
216 }
217 break;
219 {
221 set::noactions::anenum(newobj, att, data, true);
222 }
223 break;
225 {
227 set::noactions::adate(newobj, att, data, true);
228 }
229 break;
231 {
233 set::noactions::atime(newobj, att, data, true);
234 }
235 break;
237 {
239 set::noactions::attribute(newobj, att, data, true);
240 }
241 break;
243 {
245 set::noactions::aclass(newobj, att, data, true);
246 }
247 break;
249 {
250 auto data = dbe::convert::to<float>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
251 set::noactions::attribute(newobj, att, data, true);
252 }
253 break;
255 {
256 auto data = dbe::convert::to<double>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
257 set::noactions::attribute(newobj, att, data, true);
258 }
259 break;
261 {
262 auto data = dbe::convert::to<int8_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
263 set::noactions::attribute(newobj, att, data, true);
264 }
265 break;
267 {
268 auto data = dbe::convert::to<int16_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
269 set::noactions::attribute(newobj, att, data, true);
270 }
271 break;
273 {
274 auto data = dbe::convert::to<int32_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
275 set::noactions::attribute(newobj, att, data, true);
276 }
277 break;
279 {
280 auto data = dbe::convert::to<int64_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
281 set::noactions::attribute(newobj, att, data, true);
282 }
283 break;
285 {
286 auto data = dbe::convert::to<u_int8_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
287 set::noactions::attribute(newobj, att, data, true);
288 }
289 break;
291 {
292 auto data = dbe::convert::to<u_int16_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
293 set::noactions::attribute(newobj, att, data, true);
294 }
295 break;
297 {
298 auto data = dbe::convert::to<u_int32_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
299 set::noactions::attribute(newobj, att, data, true);
300 }
301 break;
303 {
304 auto data = dbe::convert::to<u_int64_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
305 set::noactions::attribute(newobj, att, data, true);
306 }
307 break;
308 default:
309 break;
310 }
311 }
312 }
313 catch (std::out_of_range const & e)
314 {
315 // nothing to do just ignore this , it might be the case that the attribute was not defined
316 }
317 }
318
319 for (dunedaq::conffwk::relationship_t const & rel : RelList)
320 {
321 try
322 {
323 auto data = relreader(rel.p_name);
324 set::noactions::relation(newobj, rel, data);
325 }
326 catch (std::out_of_range const & e)
327 {
328 // nothing to do just ignore this , it might be the case that the relation was not defined
329 }
330 }
331 }
332
333 return newobj;
334}
std::vector< T > attributes(tref const &item)
std::vector< T > relations(tref const &item)
int8_t to< int8_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
u_int64_t to< u_int64_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
int16_t to< int16_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
u_int8_t to< u_int8_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
int64_t to< int64_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
T to(QStringList const &DataList)
QStringList to< QStringList >(std::vector< std::string > const &x)
Definition Conversion.cpp:7
std::string to< std::string >(QStringList const &DataList)
int32_t to< int32_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
u_int32_t to< u_int32_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
double to< double >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
u_int16_t to< u_int16_t >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
float to< float >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
bool to< bool >(QStringList const &DataList, dunedaq::conffwk::int_format_t Format)
const std::vector< attribute_t > p_attributes
Definition Schema.hpp:163
const std::vector< relationship_t > p_relationships
Definition Schema.hpp:164

Friends And Related Symbol Documentation

◆ inner::dbcontroller

friend class inner::dbcontroller
friend

Definition at line 94 of file config_direct_access.hpp.


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