Belle II Software light-2406-ragdoll
RelationIndexManager Class Reference

Manager to keep a cache of existing RelationIndexContainers. More...

#include <RelationIndexManager.h>

Collaboration diagram for RelationIndexManager:

Public Member Functions

template<class FROM , class TO >
std::shared_ptr< RelationIndexContainer< FROM, TO > > get (const RelationArray &relation)
 Get a RelationIndexContainer.
 
void clear (DataStore::EDurability durability=DataStore::c_Event)
 Clear the cache of RelationIndexContainers with the given durability.
 
void reset ()
 Reset the cache completely, that is clear all caches and don't even keep the Index objects around.
 

Static Public Member Functions

static RelationIndexManagerInstance ()
 Returns the singleton instance.
 

Protected Types

typedef std::map< std::string, std::shared_ptr< RelationIndexBase > > RelationMap
 Maptype to keep track of all Containers of one durability.
 
typedef std::array< RelationMap, DataStore::c_NDurabilityTypesRelationCache
 Cachetype for all Containers.
 

Protected Member Functions

 RelationIndexManager ()=default
 No Constructor hidden.
 
 RelationIndexManager (const RelationIndexManager &)=delete
 No copy-constructor.
 
 RelationIndexManager (RelationIndexManager &&)=delete
 No move constructor.
 
RelationIndexManageroperator= (const RelationIndexManager &)=delete
 Also no assignment.
 
template<class FROM , class TO >
std::shared_ptr< RelationIndexContainer< FROM, TO > > getIndexIfExists (const std::string &name, DataStore::EDurability durability) const
 if the index exists in the cache, it is returned; otherwise NULL.
 
 ~RelationIndexManager ()
 Clean cache on exit.
 

Protected Attributes

RelationCache m_cache
 Cache for all Containers.
 

Friends

class DataStore
 only DataStore should be able to get non-const indices.
 

Detailed Description

Manager to keep a cache of existing RelationIndexContainers.

This singleton keeps track of all RelationIndexContainers that where created to make sure indices are not created more often than needed.

This class is only used internally, users should use RelationsObject/RelationsInterface to access/add relations.

Definition at line 30 of file RelationIndexManager.h.

Member Typedef Documentation

◆ RelationCache

Cachetype for all Containers.

Definition at line 122 of file RelationIndexManager.h.

◆ RelationMap

typedef std::map<std::string, std::shared_ptr<RelationIndexBase> > RelationMap
protected

Maptype to keep track of all Containers of one durability.

Definition at line 120 of file RelationIndexManager.h.

Constructor & Destructor Documentation

◆ ~RelationIndexManager()

~RelationIndexManager ( )
inlineprotected

Clean cache on exit.

Definition at line 114 of file RelationIndexManager.h.

115 {
116 reset();
117 }
void reset()
Reset the cache completely, that is clear all caches and don't even keep the Index objects around.

Member Function Documentation

◆ clear()

void clear ( DataStore::EDurability  durability = DataStore::c_Event)

Clear the cache of RelationIndexContainers with the given durability.

Parameters
durabilityWhich cache to clear

Definition at line 18 of file RelationIndexManager.cc.

19{
20 RelationMap& relations = m_cache[durability];
21 for (auto& e : relations) {
22 if (e.second) e.second->clear();
23 }
24}
RelationCache m_cache
Cache for all Containers.
std::map< std::string, std::shared_ptr< RelationIndexBase > > RelationMap
Maptype to keep track of all Containers of one durability.

◆ get()

std::shared_ptr< RelationIndexContainer< FROM, TO > > get ( const RelationArray relation)
inline

Get a RelationIndexContainer.

Return a const reference to a RelationIndexContainer for the given name and durability. If none exists it will be created. If it already exists we rebuild the index if the underlying RelationArray has changed in the meantime

Parameters
relationRelation to build an index for
Returns
A RelationIndexContainer

Definition at line 45 of file RelationIndexManager.h.

46 {
47 const static bool doTypeCheck = (FROM::Class() != TObject::Class() or TO::Class() != TObject::Class());
48 if (doTypeCheck)
49 relation.isValid();
50
51 const std::string& name = relation.getName();
52 DataStore::EDurability durability = relation.getDurability();
53 RelationMap& relations = m_cache[durability];
54 std::shared_ptr<RelationIndexContainer<FROM, TO>> indexContainer;
55 RelationMap::iterator it = relations.find(name);
56 if (it != relations.end()) {
57 //if existing array is of wrong type, we'll overwrite the shared_ptr here, but the index will live on with any RelationIndex objects that use it.
58 indexContainer = std::dynamic_pointer_cast<RelationIndexContainer<FROM, TO>>(it->second);
59 }
60 if (!indexContainer) {
61 indexContainer.reset(new RelationIndexContainer<FROM, TO>(relation));
62 relations[name] = indexContainer;
63 } else {
64 indexContainer->rebuild(false);
65 }
66 return indexContainer;
67 }
friend class DataStore
only DataStore should be able to get non-const indices.
STL namespace.

◆ getIndexIfExists()

std::shared_ptr< RelationIndexContainer< FROM, TO > > getIndexIfExists ( const std::string &  name,
DataStore::EDurability  durability 
) const
inlineprotected

if the index exists in the cache, it is returned; otherwise NULL.

The index is not rebuilt, which makes this mostly useful to do minor changes to the index in DataStore::addRelation().

Definition at line 101 of file RelationIndexManager.h.

103 {
104 const RelationMap& relations = m_cache[durability];
105 RelationMap::const_iterator it = relations.find(name);
106 if (it != relations.end()) {
107 return std::dynamic_pointer_cast<RelationIndexContainer<FROM, TO>>(it->second);
108 } else {
109 return nullptr;
110 }
111 }

◆ Instance()

RelationIndexManager & Instance ( )
static

Returns the singleton instance.

Definition at line 13 of file RelationIndexManager.cc.

14{
15 static RelationIndexManager instance;
16 return instance;
17}
Manager to keep a cache of existing RelationIndexContainers.

◆ reset()

void reset ( )
inline

Reset the cache completely, that is clear all caches and don't even keep the Index objects around.

Needed when the DataStore is reset to make sure we don't have dangling pointer into the previous DataStore contents.

Definition at line 81 of file RelationIndexManager.h.

82 {
83 for (int i = 0; i < DataStore::c_NDurabilityTypes; i++)
84 m_cache[i].clear();
85 }
static const int c_NDurabilityTypes
Number of Durability Types.
Definition: DataStore.h:63
void clear(DataStore::EDurability durability=DataStore::c_Event)
Clear the cache of RelationIndexContainers with the given durability.

Friends And Related Function Documentation

◆ DataStore

friend class DataStore
friend

only DataStore should be able to get non-const indices.

Definition at line 127 of file RelationIndexManager.h.

Member Data Documentation

◆ m_cache

RelationCache m_cache
protected

Cache for all Containers.

Definition at line 124 of file RelationIndexManager.h.


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