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::trefgets (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::oreft_object_handle
 
typedef std::unordered_map< t_object_key, t_object_handle, configobject::refhashert_object_map
 
typedef std::recursive_mutex t_mutex
 
typedef std::lock_guard< t_mutexlocker
 

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::trefreferenced_by (configobject::tref objref, std::string const &name="*", bool check_composite_only=true)
 
 dbcontroller ()
 
 dbcontroller (dbcontroller const &)=delete
 
dbcontrolleroperator= (dbcontroller const &)=delete
 

Static Private Member Functions

static dbcontrollerref ()
 

Private Attributes

t_object_map this_allobjects
 

Static Private Attributes

static t_mutex this_lock
 

Friends

class configobject::tref
 

Detailed Description

Definition at line 24 of file dbcontroller.hpp.

Member Typedef Documentation

◆ locker

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

Definition at line 182 of file dbcontroller.hpp.

◆ t_mutex

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

Definition at line 181 of file dbcontroller.hpp.

◆ t_object_handle

Definition at line 121 of file dbcontroller.hpp.

◆ t_object_key

◆ t_object_map

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 297 of file dbcontroller.cpp.

299{
300 return dbcontroller::create_object_request(obj.this_object_image);
301}
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 309 of file dbcontroller.cpp.

312{
313 tref ret = obj.rebuild();
314 obj.notify(notice);
315 return ret;
316}
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 303 of file dbcontroller.cpp.

305{
306 return obj.rebuild();
307}

◆ 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 271 of file dbcontroller.cpp.

273{
275 image.ref.this_class,
276 image.ref.this_name);
277
278 tref el = dbcontroller::ref().insert(result);
279 try
280 {
281 return dbe::config::api::rwdacc::set_object(el,image.attributes, image.relations);
282 }
283 catch (dunedaq::conffwk::Exception const & e)
284 {
285 // just need to remove the object from the underlying database
287 throw;
288 }
289 catch (daq::dbe::Exception const & e)
290 {
291 // just need to remove the object from the underlying database
293 throw;
294 }
295}
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:42
static dbcontroller & ref()
configobject::gref< T > remove(dbe::tref ref)
configobject::tref insert(dunedaq::conffwk::ConfigObject const &)
Represents database objects.
config_object_aggregates config_object_aggregator

◆ delete_object_request() [1/2]

template<typename T >
static 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 244 of file dbcontroller.cpp.

247{
248 configobject::gref<T> subgraph = dbcontroller::ref().remove<T>(obj);
249 subgraph.notify(notice);
250 return subgraph;
251}

◆ 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 207 of file dbcontroller.cpp.

208{
210 locker l(me.this_lock);
211 me.this_allobjects.clear();
212}
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 383 of file dbcontroller.cpp.

384{
385 return dbcontroller::ref().lookup(key);
386}
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 388 of file dbcontroller.cpp.

390{
391 std::vector<ConfigObject> database_objects = config::api::rwdacc::query_class(cname,
392 query);
393 std::vector<configobject::tref> result;
394
395 for (ConfigObject const & keyin : database_objects)
396 {
397 try
398 {
399 result.push_back(dbcontroller::ref().lookup(
400 { keyin.UID(), keyin.class_name() }));
401 }
402 catch (daq::dbe::config_object_retrieval_result_is_null const & e)
403 {
404 // nothing needs be done to specifically handle this case, it just that in some
405 // cases the underlying database does not contain initialized objects
406 }
407 }
408 return result;
409}
static std::vector< dunedaq::conffwk::ConfigObject > query_class(std::string const &classname, std::string const &query)
Definition rwdacc.cpp:387

◆ 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 439 of file dbcontroller.cpp.

440{
441 // Construct the oref to add in the internal map
442 std::shared_ptr<configobject::oref> element(new configobject::oref(obj));
443
444 bool object_inserted;
445 t_object_map::iterator position;
446
448 std::tie(position, object_inserted) = this_allobjects.emplace(*element, element);
449
450 if (not object_inserted)
451 {
452 // Object is already defined in the database and we replace the old reference with the new.
453 // A case is if there have been external modification and we try to replay changes
454 static_cast<ConfigObject &>(*position->second) = obj;
455 }
456
457 return position->second;
458}

◆ 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 413 of file dbcontroller.cpp.

414{
415 // Find the object in the database
416 t_object_map::iterator position = this_allobjects.find(key);
417
418 if (position == this_allobjects.end())
419 {
420 // if it is not in the cache we need to add it
421 ConfigObject toinsert = dbe::config::api::rwdacc::get_object(key.this_class,
422 key.this_name);
423 if (not toinsert.is_null())
424 {
425 return insert(static_cast<ConfigObject>(toinsert));
426 }
427 }
428 else
429 {
430 return position->second;
431 }
432
433 throw daq::dbe::config_object_retrieval_result_is_null ( ERS_HERE,
434 key.this_name + "@" + key.this_class );
435}
#define ERS_HERE
static dunedaq::conffwk::ConfigObject get_object(std::string const &, std::string const &)
Definition rwdacc.cpp:355
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 325 of file dbcontroller.cpp.

327{
328 if (not objref.is_null())
329 {
330 static_cast<ConfigObject &>(*(objref.refered)).move(destfile);
331 }
332
333 return objref;
334}

◆ 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 199 of file dbcontroller.cpp.

200{
201 static dbcontroller self;
202 return self;
203}

◆ 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 216 of file dbcontroller.cpp.

219{
220 std::vector<ConfigObject> linked;
221 objref.ref().referenced_by(linked, name, check_composite_only);
222
223 std::vector<configobject::tref> references;
224
225 for (ConfigObject const & anobj : linked)
226 {
227 try
228 {
229 references.push_back(get(
230 { anobj.UID(), anobj.class_name() }));
231 }
232 catch (daq::dbe::config_object_retrieval_result_is_null const & e)
233 {
234 // nothing needed to do here, since this just signal that
235 // some of the relation results are null
236 }
237 }
238
239 return references;
240}
static configobject::tref get(dbe::cokey const &desc)
Only Configuration DB opened by rdbconfig or oksconflibs plug in can be const char *message Internal DBE references cannot point to null ConfigObject references

◆ 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 462 of file dbcontroller.cpp.

463{
464 configobject::gref<T> subgraph;
465
466 {
468 // Record the associated subgraph
469 if (not ref.is_null())
470 {
471 subgraph.record(ref);
472 }
473
474 // Need to remove from the internal map all candidates, they will be added at post processing
475 for (T const & key : subgraph.this_remove_stack)
476 {
477 // Remove from the internal map
478 this_allobjects.erase({ key.ref.UID(), key.ref.class_name() });
479 }
480 }
481
482 // Delete the object from the database
484 // Post-process the object recorded subgraph
485 subgraph.post();
486
487 return subgraph;
488}
static void destroy_object(dunedaq::conffwk::ConfigObject &)
Definition rwdacc.cpp:338

◆ 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 346 of file dbcontroller.cpp.

348{
349 if (not objref.is_null())
350 {
351 // pick up the pointer
352 std::shared_ptr<configobject::oref> current_ptr = objref.refered;
353
354 // remove the current reference from the internal map
355 this_allobjects.erase(*current_ptr);
356 try
357 {
358 // rename the refered object
359 dbe::config::api::rwdacc::rename_object(static_cast<ConfigObject &>(*current_ptr),
360 aname);
361 }
362 catch (dunedaq::conffwk::Generic const & e)
363 {
364 // Logging the error but this may not affect program execution per-se
365 FAIL("Object rename failure", dbe::config::errors::parse(e).c_str());
366 }
367 // position it in its proper place
368 bool nofail;
369 t_object_map::iterator position;
370 std::tie(position, nofail) = this_allobjects.emplace(*current_ptr, current_ptr);
371
372 if (not nofail)
373 {
374 throw daq::dbe::dbcontroller_internal_cache_failure(ERS_HERE);
375 }
376 return position->second;
377 }
378 return objref;
379}
static void rename_object(dunedaq::conffwk::ConfigObject &object, std::string const &newname)
Definition rwdacc.cpp:417
Generic configuration exception.
#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 338 of file dbcontroller.cpp.

340{
341 return dbcontroller::ref().rename(objref, newname);
342}
configobject::tref rename(configobject::tref objref, std::string const &aname)

Friends And Related Symbol Documentation

◆ configobject::tref

friend class configobject::tref
friend

Definition at line 189 of file dbcontroller.hpp.

Member Data Documentation

◆ this_allobjects

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

Definition at line 179 of file dbcontroller.hpp.

◆ this_lock

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

Definition at line 183 of file dbcontroller.hpp.


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