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::ConfigObject > query_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 32 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 45 of file rwdacc.cpp.

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

286{
287 try {
288 dbaccessor::dbptr()->destroy_obj(todelete);
289 } catch (dunedaq::conffwk::Exception const& ex) {
290 WARN("Object deletion did not succeed for object", errors::parse(ex).c_str(), todelete.UID().c_str());
291
292 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE);
293 }
294}
const std::string & UID() const noexcept
Return object identity.
#define WARN(...)
Definition messenger.hpp:82

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

300{
301 if (dbaccessor::is_loaded()) {
302 try {
303 ConfigObject object;
304 dbaccessor::dbptr()->get(classname, objectname, object);
305 return object;
306 } catch (dunedaq::conffwk::NotFound const& e) {
307 TLOG_DEBUG(3) << "Object not found";
308 } catch (dunedaq::conffwk::Generic const& e) {
309 ERROR("Generic exception caught", dbe::config::errors::parse(e).c_str());
310 TLOG_DEBUG(3) << "Generic Exception Caught";
311 } catch (...) {
312 ERROR("Unknown exception caught", "");
313 TLOG_DEBUG(3) << "Unknown exception caught!";
314 }
315 }
316 return {};
317}
T * get()
Definition cptr.hpp:87
static bool is_loaded()
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:116
Changes could not be no object was Database change was not no object was not An invalid qmodel index has been Config layer returned null reference for object

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

323{
324 std::vector<ConfigObject> objects;
325 if (dbaccessor::is_loaded()) {
326 try {
327 dbaccessor::dbptr()->get(classname, objects, query);
328 } catch (dunedaq::conffwk::NotFound const& e) {
329 TLOG_DEBUG(3) << "Object not found";
330 } catch (dunedaq::conffwk::Generic const& e) {
331 ERROR("Generic exception caught", dbe::config::errors::parse(e).c_str());
332 TLOG_DEBUG(3) << "Generic Exception Caught";
333 } catch (...) {
334 ERROR("Unknown exception caught", "");
335 TLOG_DEBUG(3) << "Unknown exception caught!";
336 }
337 }
338 return objects;
339}

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

345{
346 object.rename(newname);
347}

◆ 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) { return relations.at(name); };
88
89 auto attreader = [&attributes](std::string const& name) { return attributes.at(name); };
90
91 if (not newobj.is_null()) {
92 dunedaq::conffwk::class_t ClassInfo = dbe::config::api::info::onclass::definition(newobj.class_name(), false);
93 std::vector<dunedaq::conffwk::attribute_t> AttList = ClassInfo.p_attributes;
94 std::vector<dunedaq::conffwk::relationship_t> RelList = ClassInfo.p_relationships;
95
96 for (dunedaq::conffwk::attribute_t const& att : AttList) {
97 try {
98 if (att.p_is_multi_value) {
99 switch (att.p_type) {
102 att.p_int_format);
103 set::noactions::attribute(newobj, att, data, true);
104 } break;
106 auto data =
108 set::noactions::anenum(newobj, att, data, true);
109 } break;
111 auto data =
113 set::noactions::adate(newobj, att, data, true);
114 } break;
116 auto data =
118 set::noactions::atime(newobj, att, data, true);
119 } break;
121 auto data =
123 set::noactions::attribute(newobj, att, data, true);
124 } break;
126 auto data =
128 set::noactions::aclass(newobj, att, data, true);
129 } break;
132 att.p_int_format);
133 set::noactions::attribute(newobj, att, data, true);
134 } break;
137 att.p_int_format);
138 set::noactions::attribute(newobj, att, data, true);
139 } break;
142 att.p_int_format);
143 set::noactions::attribute(newobj, att, data, true);
144 } break;
147 att.p_int_format);
148 set::noactions::attribute(newobj, att, data, true);
149 } break;
152 att.p_int_format);
153 set::noactions::attribute(newobj, att, data, true);
154 } break;
157 att.p_int_format);
158 set::noactions::attribute(newobj, att, data, true);
159 } break;
162 att.p_int_format);
163 set::noactions::attribute(newobj, att, data, true);
164 } break;
167 att.p_int_format);
168 set::noactions::attribute(newobj, att, data, true);
169 } break;
172 att.p_int_format);
173 set::noactions::attribute(newobj, att, data, true);
174 } break;
177 att.p_int_format);
178 set::noactions::attribute(newobj, att, data, true);
179 } break;
180 default:
181 break;
182 }
183 } else {
184 switch (att.p_type) {
186 auto data =
187 dbe::convert::to<bool>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
188 set::noactions::attribute(newobj, att, data, true);
189 } break;
192 set::noactions::anenum(newobj, att, data, true);
193 } break;
196 set::noactions::adate(newobj, att, data, true);
197 } break;
200 set::noactions::atime(newobj, att, data, true);
201 } break;
204 set::noactions::attribute(newobj, att, data, true);
205 } break;
208 set::noactions::aclass(newobj, att, data, true);
209 } break;
211 auto data =
212 dbe::convert::to<float>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
213 set::noactions::attribute(newobj, att, data, true);
214 } break;
216 auto data =
217 dbe::convert::to<double>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
218 set::noactions::attribute(newobj, att, data, true);
219 } break;
221 auto data =
222 dbe::convert::to<int8_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
223 set::noactions::attribute(newobj, att, data, true);
224 } break;
226 auto data =
227 dbe::convert::to<int16_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
228 set::noactions::attribute(newobj, att, data, true);
229 } break;
231 auto data =
232 dbe::convert::to<int32_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
233 set::noactions::attribute(newobj, att, data, true);
234 } break;
236 auto data =
237 dbe::convert::to<int64_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
238 set::noactions::attribute(newobj, att, data, true);
239 } break;
241 auto data =
242 dbe::convert::to<u_int8_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
243 set::noactions::attribute(newobj, att, data, true);
244 } break;
246 auto data =
247 dbe::convert::to<u_int16_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
248 set::noactions::attribute(newobj, att, data, true);
249 } break;
251 auto data =
252 dbe::convert::to<u_int32_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
253 set::noactions::attribute(newobj, att, data, true);
254 } break;
256 auto data =
257 dbe::convert::to<u_int64_t>(dbe::convert::to<QStringList>(attreader(att.p_name)), att.p_int_format);
258 set::noactions::attribute(newobj, att, data, true);
259 } break;
260 default:
261 break;
262 }
263 }
264 } catch (std::out_of_range const& e) {
265 // nothing to do just ignore this , it might be the case that the attribute was not defined
266 }
267 }
268
269 for (dunedaq::conffwk::relationship_t const& rel : RelList) {
270 try {
271 auto data = relreader(rel.p_name);
272 set::noactions::relation(newobj, rel, data);
273 } catch (std::out_of_range const& e) {
274 // nothing to do just ignore this , it might be the case that the relation was not defined
275 }
276 }
277 }
278
279 return newobj;
280}
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:161
const std::vector< relationship_t > p_relationships
Definition Schema.hpp:162

◆ inner::dbcontroller

friend class inner::dbcontroller
friend

Definition at line 96 of file config_direct_access.hpp.


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