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 29 of file dbcontroller.hpp.

Member Typedef Documentation

◆ locker

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

Definition at line 187 of file dbcontroller.hpp.

◆ t_mutex

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

Definition at line 186 of file dbcontroller.hpp.

◆ t_object_handle

Definition at line 126 of file dbcontroller.hpp.

◆ t_object_key

Definition at line 125 of file dbcontroller.hpp.

◆ t_object_map

Definition at line 128 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 302 of file dbcontroller.cpp.

304{
305 return dbcontroller::create_object_request(obj.this_object_image);
306}
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 314 of file dbcontroller.cpp.

317{
318 tref ret = obj.rebuild();
319 obj.notify(notice);
320 return ret;
321}
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 308 of file dbcontroller.cpp.

310{
311 return obj.rebuild();
312}

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

278{
279 ConfigObject result = config::api::rwdacc::create_object(image.fn,
280 image.ref.this_class,
281 image.ref.this_name);
282
283 tref el = dbcontroller::ref().insert(result);
284 try
285 {
286 return dbe::config::api::rwdacc::set_object(el,image.attributes, image.relations);
287 }
288 catch (dunedaq::conffwk::Exception const & e)
289 {
290 // just need to remove the object from the underlying database
292 throw;
293 }
294 catch (daq::dbe::Exception const & e)
295 {
296 // just need to remove the object from the underlying database
298 throw;
299 }
300}
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:88
static dunedaq::conffwk::ConfigObject create_object(std::string const &fn, std::string const &cn, std::string const &name)
Definition rwdacc.cpp:47
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 249 of file dbcontroller.cpp.

252{
253 configobject::gref<T> subgraph = dbcontroller::ref().remove<T>(obj);
254 subgraph.notify(notice);
255 return subgraph;
256}

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

213{
215 locker l(me.this_lock);
216 me.this_allobjects.clear();
217}
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 388 of file dbcontroller.cpp.

389{
390 return dbcontroller::ref().lookup(key);
391}
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 393 of file dbcontroller.cpp.

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

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

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

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

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

332{
333 if (not objref.is_null())
334 {
335 static_cast<ConfigObject &>(*(objref.refered)).move(destfile);
336 }
337
338 return objref;
339}

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

205{
206 static dbcontroller self;
207 return self;
208}

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

224{
225 std::vector<ConfigObject> linked;
226 objref.ref().referenced_by(linked, name, check_composite_only);
227
228 std::vector<configobject::tref> references;
229
230 for (ConfigObject const & anobj : linked)
231 {
232 try
233 {
234 references.push_back(get(
235 { anobj.UID(), anobj.class_name() }));
236 }
237 catch (daq::dbe::config_object_retrieval_result_is_null const & e)
238 {
239 // nothing needed to do here, since this just signal that
240 // some of the relation results are null
241 }
242 }
243
244 return references;
245}
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 467 of file dbcontroller.cpp.

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

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

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

345{
346 return dbcontroller::ref().rename(objref, newname);
347}
configobject::tref rename(configobject::tref objref, std::string const &aname)

◆ configobject::tref

friend class configobject::tref
friend

Definition at line 194 of file dbcontroller.hpp.

Member Data Documentation

◆ this_allobjects

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

Definition at line 184 of file dbcontroller.hpp.

◆ this_lock

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

Definition at line 188 of file dbcontroller.hpp.


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