DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dbe::inner::dbcontroller Class Reference

#include <dbcontroller.hpp>

Static Public Member Functions

static configobject::tref get (dbe::cokey const &desc)
static std::vector< configobject::tref > gets (std::string const &cname, std::string const &query="")
static configobject::tref create_object_request (dbe::t_config_object_preimage const &rep)
template<typename T>
static configobject::tref create_object_request (configobject::aref< T > const &obj)
template<typename T>
static configobject::tref create_object_request (configobject::gref< T > const &objref)
template<typename T>
static configobject::tref create_object_request (configobject::gref< T > &objref, typename configobject::gref< T >::config_action_notifiable notice)
template<typename T>
static configobject::gref< T > delete_object_request (configobject::tref const &obj)
template<typename T>
static configobject::gref< T > delete_object_request (configobject::tref const &obj, typename configobject::gref< T >::config_action_notifiable notice)
static configobject::tref move_object_request (configobject::tref objref, std::string const &destfile)
static configobject::tref rename_object_request (configobject::tref objref, std::string const &newname)
static void flush ()

Private Types

typedef dbe::cokey t_object_key
typedef std::shared_ptr< configobject::oref > t_object_handle
typedef std::unordered_map< t_object_key, t_object_handle, configobject::refhasher > t_object_map
typedef std::recursive_mutex t_mutex
typedef std::lock_guard< t_mutex > locker

Private Member Functions

configobject::tref insert (dunedaq::conffwk::ConfigObject const &)
configobject::tref lookup (dbe::cokey const &desc)
configobject::tref rename (configobject::tref objref, std::string const &aname)
template<typename T>
configobject::gref< T > remove (dbe::tref ref)
std::vector< configobject::tref > referenced_by (configobject::tref objref, std::string const &name="*", bool check_composite_only=true)
 dbcontroller ()
 dbcontroller (dbcontroller const &)=delete
dbcontroller & operator= (dbcontroller const &)=delete

Static Private Member Functions

static dbcontroller & ref ()

Private Attributes

t_object_map this_allobjects

Static Private Attributes

static t_mutex this_lock

Friends

class configobject::tref

Detailed Description

Definition at line 27 of file dbcontroller.hpp.

Member Typedef Documentation

◆ locker

typedef std::lock_guard<t_mutex> dbe::inner::dbcontroller::locker
private

Definition at line 180 of file dbcontroller.hpp.

◆ t_mutex

typedef std::recursive_mutex dbe::inner::dbcontroller::t_mutex
private

Definition at line 179 of file dbcontroller.hpp.

◆ t_object_handle

Definition at line 119 of file dbcontroller.hpp.

◆ t_object_key

Definition at line 118 of file dbcontroller.hpp.

◆ t_object_map

Definition at line 120 of file dbcontroller.hpp.

Constructor & Destructor Documentation

◆ dbcontroller() [1/2]

dbe::inner::dbcontroller::dbcontroller ( )
privatedefault

◆ dbcontroller() [2/2]

dbe::inner::dbcontroller::dbcontroller ( dbcontroller const & )
privatedelete

Member Function Documentation

◆ create_object_request() [1/4]

template<typename T>
configobject::tref dbe::inner::dbcontroller::create_object_request ( configobject::aref< T > const & obj)
static

creates an object to the database that is described from an aref

Parameters
objis an aref of an object, based on which the object is put onto the database
Returns
return a tref to the resulting object

Definition at line 276 of file dbcontroller.cpp.

277{
278 return dbcontroller::create_object_request(obj.this_object_image);
279}
static configobject::tref create_object_request(dbe::t_config_object_preimage const &rep)

◆ create_object_request() [2/4]

template<typename T>
configobject::tref dbe::inner::dbcontroller::create_object_request ( configobject::gref< T > & objref,
typename configobject::gref< T >::config_action_notifiable notice )
static

Definition at line 290 of file dbcontroller.cpp.

292{
293 tref ret = obj.rebuild();
294 obj.notify(notice);
295 return ret;
296}
friend class configobject::tref

◆ create_object_request() [3/4]

template<typename T>
configobject::tref dbe::inner::dbcontroller::create_object_request ( configobject::gref< T > const & objref)
static

Create an object in the database by first creating its associated subgraph as described in a gref

Parameters
objrefis the graph reference (gref) to the object
Returns
a transaction reference to a tref

Definition at line 283 of file dbcontroller.cpp.

284{
285 return obj.rebuild();
286}

◆ create_object_request() [4/4]

configobject::tref dbe::inner::dbcontroller::create_object_request ( dbe::t_config_object_preimage const & rep)
static

Create a new configuration object from its representation

Parameters
repis the representation, with attributes and relations included
Returns

Definition at line 256 of file dbcontroller.cpp.

257{
258 ConfigObject result = config::api::rwdacc::create_object(image.fn, image.ref.this_class, image.ref.this_name);
259
260 tref el = dbcontroller::ref().insert(result);
261 try {
262 return dbe::config::api::rwdacc::set_object(el, image.attributes, image.relations);
263 } catch (dunedaq::conffwk::Exception const& e) {
264 // just need to remove the object from the underlying database
266 throw;
267 } catch (daq::dbe::Exception const& e) {
268 // just need to remove the object from the underlying database
270 throw;
271 }
272}
static tref set_object(tref newobj, dbe::t_config_object_preimage::type_attrmap const &attributes, dbe::t_config_object_preimage::type_relmap const &relations)
Definition rwdacc.cpp:83
static dunedaq::conffwk::ConfigObject create_object(std::string const &fn, std::string const &cn, std::string const &name)
Definition rwdacc.cpp:45
static dbcontroller & ref()
configobject::gref< T > remove(dbe::tref ref)
configobject::tref insert(dunedaq::conffwk::ConfigObject const &)
config_object_aggregates config_object_aggregator

◆ delete_object_request() [1/2]

template<typename T>
configobject::gref< T > dbe::inner::dbcontroller::delete_object_request ( configobject::tref const & obj)
static

removes object from the database and returns an aref of the object before copying

Parameters
objis a tref to the object that must be removed from the database

◆ delete_object_request() [2/2]

template<typename T>
configobject::gref< T > dbe::inner::dbcontroller::delete_object_request ( configobject::tref const & obj,
typename configobject::gref< T >::config_action_notifiable notice )
static

Definition at line 230 of file dbcontroller.cpp.

232{
233 configobject::gref<T> subgraph = dbcontroller::ref().remove<T>(obj);
234 subgraph.notify(notice);
235 return subgraph;
236}

◆ flush()

void dbe::inner::dbcontroller::flush ( )
static

Empties the internal cache and sets all associated objects to destroyed This results in all previously held references to be set to null

Definition at line 197 of file dbcontroller.cpp.

198{
200 locker l(me.this_lock);
201 me.this_allobjects.clear();
202}
std::lock_guard< t_mutex > locker

◆ get()

configobject::tref dbe::inner::dbcontroller::get ( dbe::cokey const & desc)
static

Retrieve an object from the database, and empty reference is retrieved if the object cannot be found in the database

Parameters
descis a description of the object to be searched for in the database
Returns
a transaction reference to the object in the database

Definition at line 357 of file dbcontroller.cpp.

358{
359 return dbcontroller::ref().lookup(key);
360}
configobject::tref lookup(dbe::cokey const &desc)

◆ gets()

std::vector< configobject::tref > dbe::inner::dbcontroller::gets ( std::string const & cname,
std::string const & query = "" )
static

Retrieve all objects from the database of a specific class

Parameters
cnameis the class name for which to retrieve classes
Returns
a vector of references with the objects

Definition at line 363 of file dbcontroller.cpp.

364{
365 std::vector<ConfigObject> database_objects = config::api::rwdacc::query_class(cname, query);
366 std::vector<configobject::tref> result;
367
368 for (ConfigObject const& keyin : database_objects) {
369 try {
370 result.push_back(dbcontroller::ref().lookup({ keyin.UID(), keyin.class_name() }));
371 } catch (daq::dbe::config_object_retrieval_result_is_null const& e) {
372 // nothing needs be done to specifically handle this case, it just that in some
373 // cases the underlying database does not contain initialized objects
374 }
375 }
376 return result;
377}
static std::vector< dunedaq::conffwk::ConfigObject > query_class(std::string const &classname, std::string const &query)
Definition rwdacc.cpp:322

◆ insert()

configobject::tref dbe::inner::dbcontroller::insert ( dunedaq::conffwk::ConfigObject const & obj)
private

Insert or replace a ConfigObject into the internal store

Parameters
theconfiguration object to insert, actually makes a copy of it
Returns
a tref to the inserted copy of the object

Definition at line 403 of file dbcontroller.cpp.

404{
405 // Construct the oref to add in the internal map
406 std::shared_ptr<configobject::oref> element(new configobject::oref(obj));
407
408 bool object_inserted;
409 t_object_map::iterator position;
410
412 std::tie(position, object_inserted) = this_allobjects.emplace(*element, element);
413
414 if (not object_inserted) {
415 // Object is already defined in the database and we replace the old reference with the new.
416 // A case is if there have been external modification and we try to replay changes
417 static_cast<ConfigObject&>(*position->second) = obj;
418 }
419
420 return position->second;
421}

◆ lookup()

configobject::tref dbe::inner::dbcontroller::lookup ( dbe::cokey const & desc)
private

Searches for an object matching the criteria in the underlying database connection and then updates the internal map by comparing if it should be removed. All references to the object are transparently updated. If this cannot be done then they are replaced

Parameters
theconfiguration object to lookup for in the cache and the database
Returns
the tref that points to that object in case of success , a null tref in case of failure

Definition at line 382 of file dbcontroller.cpp.

383{
384 // Find the object in the database
385 t_object_map::iterator position = this_allobjects.find(key);
386
387 if (position == this_allobjects.end()) {
388 // if it is not in the cache we need to add it
389 ConfigObject toinsert = dbe::config::api::rwdacc::get_object(key.this_class, key.this_name);
390 if (not toinsert.is_null()) {
391 return insert(static_cast<ConfigObject>(toinsert));
392 }
393 } else {
394 return position->second;
395 }
396
397 throw daq::dbe::config_object_retrieval_result_is_null(ERS_HERE, key.this_name + "@" + key.this_class);
398}
#define ERS_HERE
static dunedaq::conffwk::ConfigObject get_object(std::string const &, std::string const &)
Definition rwdacc.cpp:299
bool is_null() const noexcept
Check if object's implementation points to null.

◆ move_object_request()

configobject::tref dbe::inner::dbcontroller::move_object_request ( configobject::tref objref,
std::string const & destfile )
static

Move an object to a new database file

Parameters
objrefis the tref of the associated ConfigObject to be moved to a new database file
destfileis the destination file where this object must be moved to
Returns
a tref pointing to the resulting object, in case that there has been any type of relocation inside this is going to be different from the original. If there has been no relocation, i.e. in case of failure a null reference is returned

Definition at line 306 of file dbcontroller.cpp.

307{
308 if (not objref.is_null()) {
309 static_cast<ConfigObject&>(*(objref.refered)).move(destfile);
310 }
311
312 return objref;
313}

◆ operator=()

dbcontroller & dbe::inner::dbcontroller::operator= ( dbcontroller const & )
privatedelete

◆ ref()

dbcontroller & dbe::inner::dbcontroller::ref ( )
staticprivate

Obtain a reference to the dbcontroller

Returns

Definition at line 188 of file dbcontroller.cpp.

189{
190 static dbcontroller self;
191 return self;
192}

◆ referenced_by()

std::vector< tref > dbe::inner::dbcontroller::referenced_by ( configobject::tref objref,
std::string const & name = "*",
bool check_composite_only = true )
private

Return a list of references to the objects in the database that reference and object

Parameters
objrefthe tref to the object for which references are to be retrieved
namethe name of the relation for which references are to be retrieved
check_composite_onlyreturn only composite connections
Returns

Definition at line 207 of file dbcontroller.cpp.

208{
209 std::vector<ConfigObject> linked;
210 objref.ref().referenced_by(linked, name, check_composite_only);
211
212 std::vector<configobject::tref> references;
213
214 for (ConfigObject const& anobj : linked) {
215 try {
216 references.push_back(get({ anobj.UID(), anobj.class_name() }));
217 } catch (daq::dbe::config_object_retrieval_result_is_null const& e) {
218 // nothing needed to do here, since this just signal that
219 // some of the relation results are null
220 }
221 }
222
223 return references;
224}
static configobject::tref get(dbe::cokey const &desc)

◆ remove()

template<typename T>
configobject::gref< T > dbe::inner::dbcontroller::remove ( dbe::tref ref)
private

Takes care of removing an object from the underlying implementation and setting all held references to it null . Performs check for derived objects having be removed.

Parameters
theconfigobject to remove from the underlying database
Returns
returns a list of objects that have been removed from the database these are in a form that permits to recreate the deleted objects

Definition at line 427 of file dbcontroller.cpp.

428{
429 configobject::gref<T> subgraph;
430
431 {
433 // Record the associated subgraph
434 if (not ref.is_null()) {
435 subgraph.record(ref);
436 }
437
438 // Need to remove from the internal map all candidates, they will be added at post processing
439 for (T const& key : subgraph.this_remove_stack) {
440 // Remove from the internal map
441 this_allobjects.erase({ key.ref.UID(), key.ref.class_name() });
442 }
443 }
444
445 // Delete the object from the database
447 // Post-process the object recorded subgraph
448 subgraph.post();
449
450 return subgraph;
451}
static void destroy_object(dunedaq::conffwk::ConfigObject &)
Definition rwdacc.cpp:285
dunedaq::conffwk::ConfigObject & ref(bool check_null=true) const

◆ rename()

configobject::tref dbe::inner::dbcontroller::rename ( configobject::tref objref,
std::string const & aname )
private

Rename an object and update the internal cache

Parameters
objref
newname
Returns

Definition at line 326 of file dbcontroller.cpp.

327{
328 if (not objref.is_null()) {
329 // pick up the pointer
330 std::shared_ptr<configobject::oref> current_ptr = objref.refered;
331
332 // remove the current reference from the internal map
333 this_allobjects.erase(*current_ptr);
334 try {
335 // rename the refered object
336 dbe::config::api::rwdacc::rename_object(static_cast<ConfigObject&>(*current_ptr), aname);
337 } catch (dunedaq::conffwk::Generic const& e) {
338 // Logging the error but this may not affect program execution per-se
339 FAIL("Object rename failure", dbe::config::errors::parse(e).c_str());
340 }
341 // position it in its proper place
342 bool nofail;
343 t_object_map::iterator position;
344 std::tie(position, nofail) = this_allobjects.emplace(*current_ptr, current_ptr);
345
346 if (not nofail) {
347 throw daq::dbe::dbcontroller_internal_cache_failure(ERS_HERE);
348 }
349 return position->second;
350 }
351 return objref;
352}
static void rename_object(dunedaq::conffwk::ConfigObject &object, std::string const &newname)
Definition rwdacc.cpp:344
#define FAIL(...)
std::string const parse(ers::Issue const &)

◆ rename_object_request()

configobject::tref dbe::inner::dbcontroller::rename_object_request ( configobject::tref objref,
std::string const & newname )
static

Rename an object in the database

Parameters
objrefis a tref to the current object
newnameis the new name of the object
Returns
a tref pointing to the resulting object. In case of failure this results in returning a null reference. In rare cases there may be relocations that will change the reference.

Definition at line 318 of file dbcontroller.cpp.

319{
320 return dbcontroller::ref().rename(objref, newname);
321}
configobject::tref rename(configobject::tref objref, std::string const &aname)

◆ configobject::tref

friend class configobject::tref
friend

Definition at line 187 of file dbcontroller.hpp.

Member Data Documentation

◆ this_allobjects

t_object_map dbe::inner::dbcontroller::this_allobjects
private

Definition at line 177 of file dbcontroller.hpp.

◆ this_lock

dbcontroller::t_mutex dbe::inner::dbcontroller::this_lock
staticprivate

Definition at line 181 of file dbcontroller.hpp.


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