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 35 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 47 of file rwdacc.cpp.

49{
50 if (info::onclass::definition(cn, false).p_abstract)
51 {
52 ERROR("Create Object: Was not possible to create object ",
53 "Abstract classes cannot hold objects", uid, "for abstract class" , cn);
54
55 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE);
56 }
57
58 // An empty object, if its creation does not succeed this object will be returned
59 ConfigObject newobj;
60
61 try
62 {
63 dbaccessor::dbptr()->create(fn, cn, uid,newobj);
64 }
65 catch (dunedaq::conffwk::Exception const & ex)
66 {
67 FAIL ( "Object creation failed", dbe::config::errors::parse ( ex ), "\n\nObject UID:",
68 uid );
69
70 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE);
71 }
72
73 return newobj;
74
75}
#define ERS_HERE
static dunedaq::conffwk::class_t definition(std::string const &cn, bool direct_only)
static cptr< dunedaq::conffwk::Configuration > dbptr()
#define ERROR(...)
Definition messenger.hpp:93
#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 343 of file rwdacc.cpp.

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

◆ 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 360 of file rwdacc.cpp.

362{
364 {
365 try
366 {
367 ConfigObject object;
368 dbaccessor::dbptr()->get(classname, objectname, object);
369 return object;
370 }
371 catch (dunedaq::conffwk::NotFound const & e)
372 {
373 TLOG_DEBUG(3) << "Object not found" ;
374 }
375 catch (dunedaq::conffwk::Generic const & e)
376 {
377 ERROR("Generic exception caught", dbe::config::errors::parse(e).c_str());
378 TLOG_DEBUG(3) << "Generic Exception Caught" ;
379 }
380 catch (...)
381 {
382 ERROR("Unknown exception caught", "");
383 TLOG_DEBUG(3) << "Unknown exception caught!" ;
384 }
385 }
386 return
387 {};
388}
T * get()
Definition cptr.hpp:88
static bool is_loaded()
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
std::vector< T > object(tref const &)

◆ 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 392 of file rwdacc.cpp.

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

◆ 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 422 of file rwdacc.cpp.

423{
424object.rename(newname);
425}

◆ 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 88 of file rwdacc.cpp.

91{
92 auto relreader = [&relations ]( std::string const & name )
93 {
94 return relations.at(name);
95 };
96
97 auto attreader = [ & attributes ] ( std::string const & name )
98 {
99 return attributes.at(name);
100 };
101
102 if (not newobj.is_null())
103 {
104 dunedaq::conffwk::class_t ClassInfo = dbe::config::api::info::onclass::definition(
105 newobj.class_name(),
106 false);
107 std::vector<dunedaq::conffwk::attribute_t> AttList = ClassInfo.p_attributes;
108 std::vector<dunedaq::conffwk::relationship_t> RelList = ClassInfo.p_relationships;
109
110 for (dunedaq::conffwk::attribute_t const & att : AttList)
111 {
112 try
113 {
114 if(att.p_is_multi_value) {
115 switch(att.p_type) {
117 {
118 auto data = dbe::convert::to<std::vector<bool>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
119 set::noactions::attribute(newobj, att, data, true);
120 }
121 break;
123 {
125 set::noactions::anenum(newobj, att, data, true);
126 }
127 break;
129 {
131 set::noactions::adate(newobj, att, data, true);
132 }
133 break;
135 {
137 set::noactions::atime(newobj, att, data, true);
138 }
139 break;
141 {
143 set::noactions::attribute(newobj, att, data, true);
144 }
145 break;
147 {
149 set::noactions::aclass(newobj, att, data, true);
150 }
151 break;
153 {
154 auto data = dbe::convert::to<std::vector<float>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
155 set::noactions::attribute(newobj, att, data, true);
156 }
157 break;
159 {
160 auto data = dbe::convert::to<std::vector<double>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
161 set::noactions::attribute(newobj, att, data, true);
162 }
163 break;
165 {
166 auto data = dbe::convert::to<std::vector<int8_t>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
167 set::noactions::attribute(newobj, att, data, true);
168 }
169 break;
171 {
172 auto data = dbe::convert::to<std::vector<int16_t>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
173 set::noactions::attribute(newobj, att, data, true);
174 }
175 break;
177 {
178 auto data = dbe::convert::to<std::vector<int32_t>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
179 set::noactions::attribute(newobj, att, data, true);
180 }
181 break;
183 {
184 auto data = dbe::convert::to<std::vector<int64_t>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
185 set::noactions::attribute(newobj, att, data, true);
186 }
187 break;
189 {
190 auto data = dbe::convert::to<std::vector<u_int8_t>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
191 set::noactions::attribute(newobj, att, data, true);
192 }
193 break;
195 {
196 auto data = dbe::convert::to<std::vector<u_int16_t>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
197 set::noactions::attribute(newobj, att, data, true);
198 }
199 break;
201 {
202 auto data = dbe::convert::to<std::vector<u_int32_t>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
203 set::noactions::attribute(newobj, att, data, true);
204 }
205 break;
207 {
208 auto data = dbe::convert::to<std::vector<u_int64_t>>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
209 set::noactions::attribute(newobj, att, data, true);
210 }
211 break;
212 default:
213 break;
214 }
215 } else {
216 switch(att.p_type) {
218 {
219 auto data = dbe::convert::to<bool>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
220 set::noactions::attribute(newobj, att, data, true);
221 }
222 break;
224 {
226 set::noactions::anenum(newobj, att, data, true);
227 }
228 break;
230 {
232 set::noactions::adate(newobj, att, data, true);
233 }
234 break;
236 {
238 set::noactions::atime(newobj, att, data, true);
239 }
240 break;
242 {
244 set::noactions::attribute(newobj, att, data, true);
245 }
246 break;
248 {
250 set::noactions::aclass(newobj, att, data, true);
251 }
252 break;
254 {
255 auto data = dbe::convert::to<float>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
256 set::noactions::attribute(newobj, att, data, true);
257 }
258 break;
260 {
261 auto data = dbe::convert::to<double>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
262 set::noactions::attribute(newobj, att, data, true);
263 }
264 break;
266 {
267 auto data = dbe::convert::to<int8_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
268 set::noactions::attribute(newobj, att, data, true);
269 }
270 break;
272 {
273 auto data = dbe::convert::to<int16_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
274 set::noactions::attribute(newobj, att, data, true);
275 }
276 break;
278 {
279 auto data = dbe::convert::to<int32_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
280 set::noactions::attribute(newobj, att, data, true);
281 }
282 break;
284 {
285 auto data = dbe::convert::to<int64_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
286 set::noactions::attribute(newobj, att, data, true);
287 }
288 break;
290 {
291 auto data = dbe::convert::to<u_int8_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
292 set::noactions::attribute(newobj, att, data, true);
293 }
294 break;
296 {
297 auto data = dbe::convert::to<u_int16_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
298 set::noactions::attribute(newobj, att, data, true);
299 }
300 break;
302 {
303 auto data = dbe::convert::to<u_int32_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
304 set::noactions::attribute(newobj, att, data, true);
305 }
306 break;
308 {
309 auto data = dbe::convert::to<u_int64_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
310 set::noactions::attribute(newobj, att, data, true);
311 }
312 break;
313 default:
314 break;
315 }
316 }
317 }
318 catch (std::out_of_range const & e)
319 {
320 // nothing to do just ignore this , it might be the case that the attribute was not defined
321 }
322 }
323
324 for (dunedaq::conffwk::relationship_t const & rel : RelList)
325 {
326 try
327 {
328 auto data = relreader(rel.p_name);
329 set::noactions::relation(newobj, rel, data);
330 }
331 catch (std::out_of_range const & e)
332 {
333 // nothing to do just ignore this , it might be the case that the relation was not defined
334 }
335 }
336 }
337
338 return newobj;
339}
std::vector< T > attributes(tref const &item)
std::vector< T > relations(tref const &item)
void adate(inner::configobject::tref Object, dunedaq::conffwk::attribute_t const &AttributeData, T NewValueData, bool NotEmit=false)
void relation(dbe::inner::configobject::tref src, dunedaq::conffwk::relationship_t const &edge, std::vector< dbe::inner::configobject::tref > const &targets)
void aclass(inner::configobject::tref Object, dunedaq::conffwk::attribute_t const &AttributeData, T NewValueData, bool NotEmit=false)
void anenum(inner::configobject::tref Object, dunedaq::conffwk::attribute_t const &AttributeData, T NewValueData, bool NotEmit=false)
void atime(inner::configobject::tref Object, dunedaq::conffwk::attribute_t const &AttributeData, T NewValueData, bool NotEmit=false)
void attribute(inner::configobject::tref Object, dunedaq::conffwk::attribute_t const &AttributeData, T NewValueData, bool NotEmit=false)
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)
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:170
const std::vector< relationship_t > p_relationships
Definition Schema.hpp:171

◆ inner::dbcontroller

friend class inner::dbcontroller
friend

Definition at line 99 of file config_direct_access.hpp.


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