Belle II Software light-2406-ragdoll
DataStore Class Reference

In the store you can park objects that have to be accessed by various modules. More...

#include <DataStore.h>

Collaboration diagram for DataStore:

Classes

class  SwitchableDataStoreContents
 Encapsulates DataStoreContents, but allows transparently switching between different versions ('DataStore IDs'). More...
 

Public Types

enum  EDurability {
  c_Event ,
  c_Persistent
}
 Durability types. More...
 
enum  EStoreFlags {
  c_WriteOut = 0 ,
  c_DontWriteOut = 1 ,
  c_ErrorIfAlreadyRegistered = 2
}
 Flags describing behaviours of objects etc. More...
 
enum  ESearchSide {
  c_FromSide ,
  c_ToSide ,
  c_BothSides
}
 Which side of relations should be returned? More...
 
typedef Belle2::StoreEntry StoreEntry
 Wraps a stored array/object, stored under unique (name, durability) key.
 
typedef std::map< std::string, StoreEntryStoreEntryMap
 Map for StoreEntries.
 
typedef StoreEntryMap::iterator StoreEntryIter
 Iterator for a StoreEntry map.
 
typedef StoreEntryMap::const_iterator StoreEntryConstIter
 const_iterator for a StoreEntry map.
 
typedef std::array< StoreEntryMap, c_NDurabilityTypesDataStoreContents
 StoreEntry maps for each durability.
 

Public Member Functions

bool registerEntry (const std::string &name, EDurability durability, TClass *objClass, bool array, EStoreFlags storeFlags)
 Register an entry in the DataStore map.
 
bool registerRelation (const StoreAccessorBase &fromArray, const StoreAccessorBase &toArray, EDurability durability, EStoreFlags storeFlags, const std::string &namedRelation)
 Register a relation in the DataStore map.
 
bool hasRelation (const StoreAccessorBase &fromArray, const StoreAccessorBase &toArray, EDurability durability, const std::string &namedRelation)
 Check for the existence of a relation in the DataStore map.
 
bool requireInput (const StoreAccessorBase &accessor)
 Produce ERROR message if no entry of the given type is registered in the DataStore.
 
bool requireRelation (const StoreAccessorBase &fromArray, const StoreAccessorBase &toArray, EDurability durability, std::string const &namedRelation)
 Produce ERROR message if no relation of given durability exists between fromArray and toArray (in that direction).
 
bool optionalInput (const StoreAccessorBase &accessor)
 Register the given object/array as an optional input.
 
bool optionalRelation (const StoreAccessorBase &fromArray, const StoreAccessorBase &toArray, EDurability durability, std::string const &namedRelation)
 Register the given relation as an optional input.
 
StoreEntrygetEntry (const StoreAccessorBase &accessor)
 Check whether an entry with the correct type is registered in the DataStore map and return it.
 
TObject ** getObject (const StoreAccessorBase &accessor)
 Get a pointer to a pointer of an object in the DataStore.
 
bool createObject (TObject *object, bool replace, const StoreAccessorBase &accessor)
 Create a new object/array in the DataStore or add an existing one.
 
void replaceData (const StoreAccessorBase &from, const StoreAccessorBase &to)
 For two StoreAccessors of same type, move all data in 'from' into 'to', discarding previous contents of 'to' and leaving 'from' empty.
 
StoreEntryMapgetStoreEntryMap (EDurability durability)
 Get a reference to the object/array map.
 
void addRelation (const TObject *fromObject, StoreEntry *&fromEntry, int &fromIndex, const TObject *toObject, StoreEntry *&toEntry, int &toIndex, float weight, const std::string &namedRelation)
 Add a relation from an object in a store array to another object in a store array.
 
RelationVectorBase getRelationsWith (ESearchSide searchSide, const TObject *object, StoreEntry *&entry, int &index, const TClass *withClass, const std::string &withName, const std::string &namedRelation)
 Get the relations between an object and other objects in a store array.
 
Belle2::RelationEntry getRelationWith (ESearchSide searchSide, const TObject *object, StoreEntry *&entry, int &index, const TClass *withClass, const std::string &withName, const std::string &namedRelation)
 Get the first relation between an object and another object in a store array.
 
bool findStoreEntry (const TObject *object, StoreEntry *&entry, int &index)
 Find an object in an array in the data store.
 
std::vector< std::string > getListOfRelatedArrays (const StoreAccessorBase &array) const
 Returns a list of names of arrays which have registered relations that point to or from 'array'.
 
std::vector< std::string > getListOfArrays (const TClass *arrayClass, EDurability durability) const
 Returns a list of names of arrays which are of type (or inherit from) arrayClass.
 
std::vector< std::string > getListOfObjects (const TClass *objClass, EDurability durability) const
 Returns a list of names of StoreObjPtr-objects whose class is (or inherits from) objClass.
 
std::vector< std::string > getListOfRelations (EDurability durability) const
 Returns a list of names of StoreObjPtr-objects whose class is (or inherits from) RelationContainer.
 
std::vector< std::string > getSortedListOfDataStore (EDurability durability) const
 Returns a (sorted) list of all the content of the DataStore (Objs-Arrays-Relations).
 
void setInitializeActive (bool active)
 Setter for m_initializeActive.
 
bool getInitializeActive () const
 Are we currently initializing modules?
 
void invalidateData (EDurability durability)
 Clears all registered StoreEntry objects of a specified durability, invalidating all objects.
 
void reset (EDurability durability)
 Frees memory occupied by data store items and removes all objects from the map.
 
void reset ()
 Clears contents of the datastore (all durabilities)
 
DependencyMapgetDependencyMap ()
 Return map of depedencies between modules.
 
void createNewDataStoreID (const std::string &id)
 creates new datastore with given id, copying the registered objects/arrays from the current one.
 
void createEmptyDataStoreID (const std::string &id)
 creates empty datastore with given id.
 
std::string currentID () const
 returns ID of current DataStore.
 
void switchID (const std::string &id)
 switch to DataStore with given ID.
 
void copyEntriesTo (const std::string &id, const std::vector< std::string > &entrylist_event={}, bool mergeEntries=false)
 copy entries (not contents) of current DataStore to the DataStore with given ID.
 
void copyContentsTo (const std::string &id, const std::vector< std::string > &entrylist_event={})
 copy contents (actual array / object contents) of current DataStore to the DataStore with given ID.
 
void mergeContentsTo (const std::string &id, const std::vector< std::string > &entrylist_event={})
 merge contents (actual array / object contents) of current DataStore to the DataStore with given ID.
 

Static Public Member Functions

static DataStoreInstance ()
 Instance of singleton Store.
 
static TClass * getTClassFromDefaultObjectName (const std::string &objectName)
 Tries to deduce the TClass from a default object name, which is generally the name of the C++ class.
 
static TClass * getTClassFromDefaultArrayName (const std::string &arrayName)
 Tries to deduce the TClass from a default array name, which is generally the name of the C++ class with an appended 's'.
 
static std::string defaultObjectName (const std::string &classname)
 Return the default storage name for given class name.
 
static std::string defaultObjectName (const TClass *t)
 Return the default storage name for an object of the given TClass.
 
template<class T >
static std::string defaultObjectName ()
 Return the default storage name for an object of the given type.
 
static std::string objectName (const TClass *t, const std::string &name)
 Return the storage name for an object of the given TClass and name.
 
template<class T >
static std::string objectName (const std::string &name)
 Return the storage name for an object of the given type and name.
 
static std::string defaultArrayName (const std::string &classname)
 Return the default storage name for an given class name.
 
static std::string defaultArrayName (const TClass *t)
 Return the default storage name for an array of the given TClass.
 
template<class T >
static std::string defaultArrayName ()
 Return the default storage name for an array of the given type.
 
static std::string arrayName (const TClass *t, const std::string &name)
 Return the storage name for an object of the given TClass and name.
 
template<class T >
static std::string arrayName (const std::string &name)
 Return the storage name for an object of the given type and name.
 
template<class FROM , class TO >
static std::string defaultRelationName ()
 Return the default storage name for a relation between the given types.
 
static std::string relationName (const std::string &fromName, const std::string &toName, std::string const &namedRelation="")
 Return storage name for a relation between two arrays of the given names.
 
static void addRelationFromTo (const TObject *fromObject, const TObject *toObject, float weight=1.0, const std::string &namedRelation="")
 Add a relation from an object in a store array to another object in a store array.
 
template<class T >
static RelationVector< T > getRelationsWithObj (const TObject *object, const std::string &name="", const std::string &namedRelation="")
 Get the relations between an object and other objects in a store array.
 
template<class T >
static T * getRelated (const TObject *object, const std::string &name="", const std::string &namedRelation="")
 Get the object to or from which another object has a relation.
 

Static Public Attributes

static const int c_NDurabilityTypes = 2
 Number of Durability Types.
 
static bool s_DoCleanup = false
 Global flag to to decide if we can do normal cleanup.
 

Private Member Functions

 DataStore ()
 Hidden constructor, as it is a singleton.
 
 DataStore (const DataStore &)=delete
 no copy constructor
 
DataStoreoperator= (const DataStore &)=delete
 no assignment operator
 
 ~DataStore ()
 Destructor.
 
bool checkType (const StoreEntry &entry, const StoreAccessorBase &accessor) const
 Check whether the given entry and the requested class match.
 
const std::vector< std::string > & getArrayNames (const std::string &arrayName, const TClass *arrayClass, EDurability durability=c_Event) const
 Returns a vector with the names of store arrays matching the given name and class.
 

Static Private Member Functions

static void updateRelationsObjectCache (StoreEntry &entry)
 For an array containing RelationsObjects, update index and entry cache for entire contents.
 

Private Attributes

SwitchableDataStoreContents m_storeEntryMap
 Maps (name, durability) key to StoreEntry objects.
 
bool m_initializeActive
 True if modules are currently being initialized.
 
const std::regex m_regexNamedRelationCheck = std::regex("^[a-zA-Z]*$")
 Regular expression to check that no special characters and no white spaces are in the string given for namedRelations.
 
DependencyMapm_dependencyMap
 Collect information about the dependencies between modules.
 

Detailed Description

In the store you can park objects that have to be accessed by various modules.

Normal users should access the store via StoreAccessorBase-derived classes like StoreObjPtr or StoreArray.

Nomenclature:

See also
EDurability StoreObjPtr StoreArray RelationsObject

Definition at line 51 of file DataStore.h.

Member Typedef Documentation

◆ DataStoreContents

StoreEntry maps for each durability.

Definition at line 90 of file DataStore.h.

◆ StoreEntry

Wraps a stored array/object, stored under unique (name, durability) key.

Definition at line 84 of file DataStore.h.

◆ StoreEntryConstIter

typedef StoreEntryMap::const_iterator StoreEntryConstIter

const_iterator for a StoreEntry map.

Definition at line 89 of file DataStore.h.

◆ StoreEntryIter

typedef StoreEntryMap::iterator StoreEntryIter

Iterator for a StoreEntry map.

Definition at line 88 of file DataStore.h.

◆ StoreEntryMap

typedef std::map<std::string, StoreEntry> StoreEntryMap

Map for StoreEntries.

Definition at line 87 of file DataStore.h.

Member Enumeration Documentation

◆ EDurability

Durability types.

Defines how long an object should be valid.

Enumerator
c_Event 

Different object in each event, all objects/arrays are invalidated after event() function has been called on last module in path.


c_Persistent 

Object is available during entire execution time.

Objects are never invalidated and are accessible even after process(Path) returns.

Definition at line 58 of file DataStore.h.

58 {
59 c_Event,
61 };
@ c_Persistent
Object is available during entire execution time.
Definition: DataStore.h:60
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
Definition: DataStore.h:59

◆ ESearchSide

Which side of relations should be returned?

Enumerator
c_FromSide 

Return relations/objects pointed from (to a given object).

c_ToSide 

Return relations/objects pointed to (from a given object).

c_BothSides 

Combination of c_FromSide and c_ToSide.

Definition at line 76 of file DataStore.h.

76 {
78 c_ToSide,
80 };
@ c_BothSides
Combination of c_FromSide and c_ToSide.
Definition: DataStore.h:79
@ c_FromSide
Return relations/objects pointed from (to a given object).
Definition: DataStore.h:77
@ c_ToSide
Return relations/objects pointed to (from a given object).
Definition: DataStore.h:78

◆ EStoreFlags

Flags describing behaviours of objects etc.

Bitwise operators (|, &, etc.) are provided via ADD_BITMASK_OPERATORS.

Enumerator
c_WriteOut 

Object/array should be saved by output modules.

(default)

c_DontWriteOut 

Object/array should be NOT saved by output modules.

Can be overridden using the 'branchNames' parameter of RootOutput.

c_ErrorIfAlreadyRegistered 

If the object/array was already registered, produce an error (aborting initialisation).

Definition at line 69 of file DataStore.h.

69 {
70 c_WriteOut = 0,
71 c_DontWriteOut = 1,
73 };
@ c_WriteOut
Object/array should be saved by output modules.
Definition: DataStore.h:70
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
Definition: DataStore.h:71
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
Definition: DataStore.h:72

Constructor & Destructor Documentation

◆ DataStore()

DataStore ( )
explicitprivate

Hidden constructor, as it is a singleton.

Definition at line 61 of file DataStore.cc.

62{
63}
DependencyMap * m_dependencyMap
Collect information about the dependencies between modules.
Definition: DataStore.h:637
bool m_initializeActive
True if modules are currently being initialized.
Definition: DataStore.h:628
Collect information about the dependencies between modules.
Definition: DependencyMap.h:29

◆ ~DataStore()

~DataStore ( )
private

Destructor.

Definition at line 65 of file DataStore.cc.

66{
67 if (s_DoCleanup) {
68 //release all memory in data store
69 reset();
70 }
71 delete m_dependencyMap;
72}
static bool s_DoCleanup
Global flag to to decide if we can do normal cleanup.
Definition: DataStore.h:100
void reset()
Clears contents of the datastore (all durabilities)
Definition: DataStore.cc:74

Member Function Documentation

◆ addRelation()

void addRelation ( const TObject *  fromObject,
StoreEntry *&  fromEntry,
int &  fromIndex,
const TObject *  toObject,
StoreEntry *&  toEntry,
int &  toIndex,
float  weight,
const std::string &  namedRelation 
)

Add a relation from an object in a store array to another object in a store array.

Parameters
fromObjectPointer to the object from which the relation points.
fromEntryData store entry that contains the fromObject. Used for caching. Will be set if NULL.
fromIndexIndex in TClonesArray that contains the fromObject. Used for caching. Will be set if < 0.
toObjectPointer to the object to which the relation points.
toEntryData store entry that contains the toObject. Used for caching. Will be set if NULL.
toIndexIndex in TClonesArray that contains the toObject. Used for caching. Will be set if < 0.
weightWeight of the relation.
namedRelationAdditional name for the relation, or "" for the default naming

Definition at line 492 of file DataStore.cc.

494{
495 if (!fromObject or !toObject)
496 return;
497
498 // get entry from which the relation points
499 if (!findStoreEntry(fromObject, fromEntry, fromIndex)) {
500 B2FATAL("Couldn't find from-side entry for relation between " << fromObject->ClassName() << " and " << toObject->ClassName() <<
501 ". Please make sure the object is part of a StoreArray before adding a relation.");
502 }
503
504 // get entry to which the relation points
505 if (!findStoreEntry(toObject, toEntry, toIndex)) {
506 B2FATAL("Couldn't find to-side entry for relation between " << fromObject->ClassName() << " and " << toObject->ClassName() <<
507 ". Please make sure the object is part of a StoreArray before adding a relation.");
508 }
509
510 // get the relations from -> to
511 const string& relationsName = relationName(fromEntry->name, toEntry->name, namedRelation);
512 const StoreEntryIter& it = m_storeEntryMap[c_Event].find(relationsName);
513 if (it == m_storeEntryMap[c_Event].end()) {
514 B2FATAL("No relation '" << relationsName <<
515 "' found. Please register it (using StoreArray::registerRelationTo()) before trying to add relations.");
516 }
517 StoreEntry* entry = &(it->second);
518
519 // auto create relations if needed (both if null pointer, or uninitialised object read from TTree)
520 if (!entry->ptr)
521 entry->recreate();
522 auto* relContainer = static_cast<RelationContainer*>(entry->ptr);
523 if (relContainer->isDefaultConstructed()) {
524 relContainer->setFromName(fromEntry->name);
525 relContainer->setFromDurability(c_Event);
526 relContainer->setToName(toEntry->name);
527 relContainer->setToDurability(c_Event);
528 }
529
530 // add relation
531 TClonesArray& relations = relContainer->elements();
532 new (relations.AddrAt(relations.GetLast() + 1)) RelationElement(fromIndex, toIndex, weight);
533
534 std::shared_ptr<RelationIndexContainer<TObject, TObject>> relIndex =
535 RelationIndexManager::Instance().getIndexIfExists<TObject, TObject>(relationsName, c_Event);
536 if (relIndex) {
537 // add it to index (so we avoid expensive rebuilding later)
538 relIndex->index().emplace(fromIndex, toIndex, fromObject, toObject, weight);
539 } else {
540 //mark for rebuilding later on
541 relContainer->setModified(true);
542 }
543}
bool findStoreEntry(const TObject *object, StoreEntry *&entry, int &index)
Find an object in an array in the data store.
Definition: DataStore.cc:398
StoreEntryMap::iterator StoreEntryIter
Iterator for a StoreEntry map.
Definition: DataStore.h:88
static std::string relationName(const std::string &fromName, const std::string &toName, std::string const &namedRelation="")
Return storage name for a relation between two arrays of the given names.
Definition: DataStore.h:180
SwitchableDataStoreContents m_storeEntryMap
Maps (name, durability) key to StoreEntry objects.
Definition: DataStore.h:621
Class to store relations between StoreArrays in the DataStore.
void setFromName(const std::string &name)
Set name of the StoreArray we relate from.
Class to store a single element of a relation.
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.
static RelationIndexManager & Instance()
Returns the singleton instance.
Wraps a stored array/object, stored under unique (name, durability) key.
Definition: StoreEntry.h:22
TObject * ptr
The pointer to the returned object, either equal to 'object' or null, depending on wether the object ...
Definition: StoreEntry.h:51
std::string name
Name of the entry.
Definition: StoreEntry.h:53
void recreate()
Reset stored object to defaults, set ptr to new object.
Definition: StoreEntry.cc:68

◆ addRelationFromTo()

static void addRelationFromTo ( const TObject *  fromObject,
const TObject *  toObject,
float  weight = 1.0,
const std::string &  namedRelation = "" 
)
inlinestatic

Add a relation from an object in a store array to another object in a store array.

Note
If possible, use RelationsObject members instead, as they allow more efficent caching. Currently this should only be necessary if fromObject is of type genfit::...
See also
RelationsObject::addRelationTo
Parameters
fromObjectPointer to the object from which the relation points.
toObjectPointer to the object to which the relation points.
weightWeight of the relation.
namedRelationAdditional name for the relation, or "" for the default naming

Definition at line 387 of file DataStore.h.

389 {
390 DataStore::StoreEntry* fromEntry = nullptr;
391 int fromIndex = -1;
392 StoreEntry* toEntry = nullptr;
393 int toIndex = -1;
394 Instance().addRelation(fromObject, fromEntry, fromIndex, toObject, toEntry, toIndex, weight, namedRelation);
395 }
void addRelation(const TObject *fromObject, StoreEntry *&fromEntry, int &fromIndex, const TObject *toObject, StoreEntry *&toEntry, int &toIndex, float weight, const std::string &namedRelation)
Add a relation from an object in a store array to another object in a store array.
Definition: DataStore.cc:492
Belle2::StoreEntry StoreEntry
Wraps a stored array/object, stored under unique (name, durability) key.
Definition: DataStore.h:84
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54

◆ arrayName() [1/2]

static std::string arrayName ( const std::string &  name)
inlinestatic

Return the storage name for an object of the given type and name.

Definition at line 167 of file DataStore.h.

168 {
169 return ((name.empty()) ? defaultArrayName<T>() : name);
170 }

◆ arrayName() [2/2]

std::string arrayName ( const TClass *  t,
const std::string &  name 
)
static

Return the storage name for an object of the given TClass and name.

Definition at line 164 of file DataStore.cc.

165{
166 return ((name.empty()) ? defaultArrayName(t) : name);
167}
static std::string defaultArrayName()
Return the default storage name for an array of the given type.
Definition: DataStore.h:157

◆ checkType()

bool checkType ( const StoreEntry entry,
const StoreAccessorBase accessor 
) const
private

Check whether the given entry and the requested class match.

Name and durability are not checked.

Parameters
entryThe existing DataStore entry.
accessorEncapsulates name, durability, and type
Returns
True if both types match.

Definition at line 170 of file DataStore.cc.

171{
172 // Check whether the existing entry and the requested object are both arrays or both single objects
173 const char* entryType = (entry.isArray) ? "array" : "object";
174 if (entry.isArray != accessor.isArray()) {
175 B2FATAL("Existing entry '" << entry.name << "' is an " << entryType << " and the requested one an " << ((
176 accessor.isArray()) ? "array" : "object"));
177 }
178
179 // Check whether the existing entry has the same type
180 const TClass* entryClass = entry.objClass;
181 if (!entryClass->InheritsFrom(accessor.getClass())) {
182 B2FATAL("Existing " << accessor.readableName() << " of type " << entryClass->GetName() << " doesn't match requested type " <<
183 accessor.getClass()->GetName());
184 }
185
186 return true;
187}
std::string readableName() const
Convert this acessor into a readable string (for messages).
TClass * getClass() const
The underlying object's type.
bool isArray() const
Is this an accessor for an array?
bool isArray
Flag that indicates whether the object is a TClonesArray.
Definition: StoreEntry.h:39
TClass * objClass
class of object.
Definition: StoreEntry.h:41

◆ copyContentsTo()

void copyContentsTo ( const std::string &  id,
const std::vector< std::string > &  entrylist_event = {} 
)

copy contents (actual array / object contents) of current DataStore to the DataStore with given ID.

Definition at line 810 of file DataStore.cc.

811{
812 m_storeEntryMap.copyContentsTo(id, entrylist_event);
813}
void copyContentsTo(const std::string &id, const std::vector< std::string > &entrylist_event={})
copy contents (actual array / object contents) of current DataStore to the DataStore with given ID.
Definition: DataStore.cc:946

◆ copyEntriesTo()

void copyEntriesTo ( const std::string &  id,
const std::vector< std::string > &  entrylist_event = {},
bool  mergeEntries = false 
)

copy entries (not contents) of current DataStore to the DataStore with given ID.

Definition at line 805 of file DataStore.cc.

806{
807 m_storeEntryMap.copyEntriesTo(id, entrylist_event, mergeEntries);
808}
void copyEntriesTo(const std::string &id, const std::vector< std::string > &entrylist_event={}, bool mergeEntries=false)
copy entries (not contents) of current DataStore to the DataStore with given ID.
Definition: DataStore.cc:850

◆ createEmptyDataStoreID()

void createEmptyDataStoreID ( const std::string &  id)

creates empty datastore with given id.

Definition at line 784 of file DataStore.cc.

785{
787}
void createEmptyDataStoreID(const std::string &id)
creates empty datastore with given id.
Definition: DataStore.cc:838

◆ createNewDataStoreID()

void createNewDataStoreID ( const std::string &  id)

creates new datastore with given id, copying the registered objects/arrays from the current one.

Definition at line 779 of file DataStore.cc.

780{
782}
void createNewDataStoreID(const std::string &id)
creates new datastore with given id, copying the registered objects/arrays from the current one.
Definition: DataStore.cc:827

◆ createObject()

bool createObject ( TObject *  object,
bool  replace,
const StoreAccessorBase accessor 
)

Create a new object/array in the DataStore or add an existing one.

A matching map entry must already exist. Otherwise an error will be generated.

Parameters
objectPointer to the object that should be stored. If 0, a new default object is created.
replaceIf an object already exists, it will be replaced if this is true. If false, an error will be printed.
accessorEncapsulates name, durability, and type
Returns
Wether the object was successfully inserted/created

Definition at line 316 of file DataStore.cc.

317{
318 StoreEntry* entry = getEntry(accessor);
319 if (!entry) {
320 B2ERROR("No " << accessor.readableName() <<
321 " exists in the DataStore, did you forget to register it in your Module's initialize() function? Note: direct accesses to it will crash!");
322 return false;
323 }
324
325 if (entry->ptr && !replace && object != entry->object) {
326 B2ERROR("An " << accessor.readableName() << " was already created in the DataStore.");
327 return false;
328 }
329
330 if (object) {
331 if (object != entry->object) {
332 delete entry->object;
333 entry->object = object;
334 }
335 entry->ptr = entry->object;
336 } else {
337 entry->recreate();
338 }
339
340 return true;
341}
StoreEntry * getEntry(const StoreAccessorBase &accessor)
Check whether an entry with the correct type is registered in the DataStore map and return it.
Definition: DataStore.cc:294
TObject * object
The pointer to the actual object.
Definition: StoreEntry.h:48

◆ currentID()

std::string currentID ( ) const

returns ID of current DataStore.

Definition at line 789 of file DataStore.cc.

790{
791 return m_storeEntryMap.currentID();
792}
const std::string & currentID() const
returns ID of current DataStore.
Definition: DataStore.h:603

◆ defaultArrayName() [1/3]

static std::string defaultArrayName ( )
inlinestatic

Return the default storage name for an array of the given type.

Definition at line 157 of file DataStore.h.

158 {
159 const static std::string s = defaultArrayName(defaultObjectName<T>());
160 return s;
161 }

◆ defaultArrayName() [2/3]

static std::string defaultArrayName ( const std::string &  classname)
inlinestatic

Return the default storage name for an given class name.

Definition at line 143 of file DataStore.h.

144 {
145 const std::string& objName = defaultObjectName(classname);
146 std::string s;
147 s.reserve(objName.length() + 1);
148 s += objName;
149 s += 's';
150 return s;
151 }
static std::string defaultObjectName()
Return the default storage name for an object of the given type.
Definition: DataStore.h:127

◆ defaultArrayName() [3/3]

std::string defaultArrayName ( const TClass *  t)
static

Return the default storage name for an array of the given TClass.

Definition at line 157 of file DataStore.cc.

158{
159 const std::string s = defaultArrayName(defaultObjectName(t));
160 return s;
161}

◆ defaultObjectName() [1/3]

static std::string defaultObjectName ( )
inlinestatic

Return the default storage name for an object of the given type.

Definition at line 127 of file DataStore.h.

128 {
129 const static std::string s = defaultObjectName(T::Class_Name());
130 return s;
131 }

◆ defaultObjectName() [2/3]

std::string defaultObjectName ( const std::string &  classname)
static

Return the default storage name for given class name.

Definition at line 128 of file DataStore.cc.

129{
130 const static string gfclass = "genfit::Track";
131 const static string gfobjectname = "GF2Track";
132 if (classname == gfclass)
133 return gfobjectname;
134 //Strip qualifiers like namespaces
135 size_t colon = classname.rfind(':');
136 if (colon != std::string::npos) {
137 return classname.substr(colon + 1);
138 }
139 return classname;
140}

◆ defaultObjectName() [3/3]

std::string defaultObjectName ( const TClass *  t)
static

Return the default storage name for an object of the given TClass.

Definition at line 143 of file DataStore.cc.

144{
145 B2ASSERT("Cannot deduce default object name from null pointer TClass", t);
146 const std::string s = defaultObjectName(t->GetName());
147 return s;
148}

◆ defaultRelationName()

static std::string defaultRelationName ( )
inlinestatic

Return the default storage name for a relation between the given types.

Definition at line 173 of file DataStore.h.

174 {
175 const static std::string s = relationName(defaultArrayName<FROM>(), defaultArrayName<TO>());
176 return s;
177 }

◆ findStoreEntry()

bool findStoreEntry ( const TObject *  object,
DataStore::StoreEntry *&  entry,
int &  index 
)

Find an object in an array in the data store.

entry/index are used to return the found array and index, should be set to NULL and -1, or some cached values (will be checked).

Given non-NULL entry and index>=0, this function returns immediately if the object is found at the given position.

Parameters
objectPointer to the object.
entryThe DataStore entry that contains the object.
indexThe index of the object in the array.
Returns
True if the object was found in the data store

Definition at line 398 of file DataStore.cc.

399{
400 if (!entry or index < 0) {
401 //usually entry/index should be passed for RelationsObject,
402 //but there are exceptions -> let's check again
403 const auto* relObj = dynamic_cast<const RelationsObject*>(object);
404 if (relObj) {
405 entry = relObj->m_cacheDataStoreEntry;
406 index = relObj->m_cacheArrayIndex;
407 }
408 }
409 // check whether the cached information is (still) valid
410 if (entry && entry->ptr && (index >= 0)) {
411 const TClonesArray* array = static_cast<TClonesArray*>(entry->ptr);
412 if (array->At(index) == object) return true;
413 B2INFO("findStoreEntry: cached index invalid, probably harmless but odd : " << entry->name << " idx " << index);
414 index = array->IndexOf(object);
415 if (index >= 0) return true;
416 B2INFO("findStoreEntry: cached entry was also wrong");
417 }
418 entry = nullptr;
419 index = -1;
420
421 //searching for nullptr should be safe
422 if (!object)
423 return false;
424
425 // search for the object and set the entry and index
426 const TClass* objectClass = object->IsA();
427 for (auto& mapEntry : m_storeEntryMap[c_Event]) {
428 if (mapEntry.second.ptr && mapEntry.second.isArray) {
429 const TClass* arrayClass = mapEntry.second.objClass;
430 if (arrayClass != objectClass)
431 continue;
432
433 const TClonesArray* array = static_cast<TClonesArray*>(mapEntry.second.ptr);
434 if (object == array->Last()) {
435 //quickly find entry if it's at the end of the array
436 index = array->GetLast();
437 } else {
438 if (arrayClass->InheritsFrom(RelationsObject::Class())) {
439 //update cache for entire array
440 updateRelationsObjectCache(mapEntry.second);
441
442 //if found, m_cacheArrayIndex is now correct, otherwise still -1
443 StoreEntry* objEntry = static_cast<const RelationsObject*>(object)->m_cacheDataStoreEntry;
444 index = static_cast<const RelationsObject*>(object)->m_cacheArrayIndex;
445 if (index >= 0 and objEntry) {
446 //if the cache of 'object' is filled, make sure to also set entry!
447 entry = objEntry;
448 return true;
449 }
450 } else {
451 //not a RelationsObject, so no caching
452 index = array->IndexOf(object);
453 }
454 }
455
456 if (index >= 0) {
457 entry = &mapEntry.second;
458 return true;
459 }
460 }
461 }
462 return false;
463}
static void updateRelationsObjectCache(StoreEntry &entry)
For an array containing RelationsObjects, update index and entry cache for entire contents.
Definition: DataStore.cc:387
Defines interface for accessing relations of objects in StoreArray.

◆ getArrayNames()

const std::vector< std::string > & getArrayNames ( const std::string &  arrayName,
const TClass *  arrayClass,
EDurability  durability = c_Event 
) const
private

Returns a vector with the names of store arrays matching the given name and class.

Note that the returned reference is only valid until the next call.

Parameters
arrayNameA given array name, the special string "ALL" for all arrays deriving from the given class, or an empty string for the default array name.
arrayClassThe class of the array(s).
durabilityDecide with which durability map you want to perform the requested action.

Definition at line 465 of file DataStore.cc.

467{
468 static vector<string> arrayNames;
469 arrayNames.clear();
470 if (name.empty()) {
471 static std::unordered_map<const TClass*, string> classToArrayName;
472 const auto& it = classToArrayName.find(arrayClass);
473 if (it != classToArrayName.end()) {
474 arrayNames.emplace_back(it->second);
475 } else {
476 const std::string& result = defaultArrayName(arrayClass->GetName());
477 classToArrayName[arrayClass] = result;
478 arrayNames.emplace_back(result);
479 }
480 } else if (name == "ALL") {
481 for (auto& mapEntry : m_storeEntryMap[durability]) {
482 if (mapEntry.second.object and mapEntry.second.isArray and mapEntry.second.objClass->InheritsFrom(arrayClass)) {
483 arrayNames.emplace_back(mapEntry.second.name);
484 }
485 }
486 } else {
487 arrayNames.emplace_back(name);
488 }
489 return arrayNames;
490}

◆ getDependencyMap()

DependencyMap & getDependencyMap ( )
inline

Return map of depedencies between modules.

Definition at line 524 of file DataStore.h.

524{ return *m_dependencyMap; }

◆ getEntry()

DataStore::StoreEntry * getEntry ( const StoreAccessorBase accessor)

Check whether an entry with the correct type is registered in the DataStore map and return it.

If the map of requested durability already contains an object under the key name with a DIFFERENT type than the given type one, an error will be reported.

Parameters
accessorEncapsulates name, durability, and type
Returns
StoreEntry, or NULL if not found

Definition at line 294 of file DataStore.cc.

295{
296 const auto& it = m_storeEntryMap[accessor.getDurability()].find(accessor.getName());
297
298 if (it != m_storeEntryMap[accessor.getDurability()].end() and checkType((it->second), accessor)) {
299 return &(it->second);
300 } else {
301 return nullptr;
302 }
303}
bool checkType(const StoreEntry &entry, const StoreAccessorBase &accessor) const
Check whether the given entry and the requested class match.
Definition: DataStore.cc:170
DataStore::EDurability getDurability() const
Return durability with which the object is saved in the DataStore.
const std::string & getName() const
Return name under which the object is saved in the DataStore.

◆ getInitializeActive()

bool getInitializeActive ( ) const
inline

Are we currently initializing modules?

Definition at line 502 of file DataStore.h.

502{ return m_initializeActive; }

◆ getListOfArrays()

std::vector< std::string > getListOfArrays ( const TClass *  arrayClass,
EDurability  durability 
) const

Returns a list of names of arrays which are of type (or inherit from) arrayClass.

Definition at line 666 of file DataStore.cc.

667{
668 return getArrayNames("ALL", arrayClass, durability);
669}
const std::vector< std::string > & getArrayNames(const std::string &arrayName, const TClass *arrayClass, EDurability durability=c_Event) const
Returns a vector with the names of store arrays matching the given name and class.
Definition: DataStore.cc:465

◆ getListOfObjects()

std::vector< std::string > getListOfObjects ( const TClass *  objClass,
EDurability  durability 
) const

Returns a list of names of StoreObjPtr-objects whose class is (or inherits from) objClass.

(this does NOT include the internal RelationContainer objects.)

Definition at line 671 of file DataStore.cc.

672{
673 vector<string> list;
675 for (const auto& entrypair : map) {
676 if (!entrypair.second.isArray) {
677 const TObject* obj = entrypair.second.object;
678 if (dynamic_cast<const RelationContainer*>(obj))
679 continue; //ignore relations in list
680
681 if (obj and obj->IsA()->InheritsFrom(objClass))
682 list.emplace_back(entrypair.first);
683 }
684 }
685 return list;
686}
StoreEntryMap & getStoreEntryMap(EDurability durability)
Get a reference to the object/array map.
Definition: DataStore.h:325
EDurability
Durability types.
Definition: DataStore.h:58
std::map< std::string, StoreEntry > StoreEntryMap
Map for StoreEntries.
Definition: DataStore.h:87

◆ getListOfRelatedArrays()

std::vector< std::string > getListOfRelatedArrays ( const StoreAccessorBase array) const

Returns a list of names of arrays which have registered relations that point to or from 'array'.

This may be useful for internal purposes when modifying array contents.

Definition at line 640 of file DataStore.cc.

641{
642 std::vector<std::string> arrays;
643 if (!array.isArray()) {
644 B2ERROR("getListOfRelatedArrays(): " << array.readableName() << " is not an array!");
645 return arrays;
646 }
647
648 //loop over all arrays
649 EDurability durability = array.getDurability();
650 for (auto& mapEntry : m_storeEntryMap[durability]) {
651 if (mapEntry.second.isArray) {
652 const std::string& name = mapEntry.second.name;
653
654 //check both from & to 'array'
655 for (int searchSide = 0; searchSide < c_BothSides; searchSide++) {
656 const string& relationsName = (searchSide == c_ToSide) ? relationName(array.getName(), name) : relationName(name, array.getName());
657 const StoreEntryConstIter& it = m_storeEntryMap[durability].find(relationsName);
658 if (it != m_storeEntryMap[durability].end())
659 arrays.emplace_back(name);
660 }
661 }
662 }
663
664 return arrays;
665}
StoreEntryMap::const_iterator StoreEntryConstIter
const_iterator for a StoreEntry map.
Definition: DataStore.h:89

◆ getListOfRelations()

std::vector< std::string > getListOfRelations ( EDurability  durability) const

Returns a list of names of StoreObjPtr-objects whose class is (or inherits from) RelationContainer.

Definition at line 688 of file DataStore.cc.

689{
690 vector<string> list;
692 for (const auto& entrypair : map) {
693 if (!entrypair.second.isArray) {
694 const TObject* obj = entrypair.second.object;
695 if (dynamic_cast<const RelationContainer*>(obj))
696 list.emplace_back(entrypair.first);
697
698 }
699 }
700 return list;
701}

◆ getObject()

TObject ** getObject ( const StoreAccessorBase accessor)

Get a pointer to a pointer of an object in the DataStore.

If the map of requested durability already contains an object under the key name with a DIFFERENT type than the given type one, an error will be reported.

Parameters
accessorEncapsulates name, durability, and type
Returns
Pointer to pointer to object, NULL if none exists

Definition at line 306 of file DataStore.cc.

307{
308 StoreEntry* entry = getEntry(accessor);
309 if (!entry) {
310 return nullptr;
311 }
312 return &(entry->ptr);
313}

◆ getRelated()

static T * getRelated ( const TObject *  object,
const std::string &  name = "",
const std::string &  namedRelation = "" 
)
inlinestatic

Get the object to or from which another object has a relation.

Note
If possible, use RelationsObject members instead, as they allow more efficent caching. Currently this should only be necessary if type(object) == genfit::..
Parameters
objectPointer to the object to or from which the relation points.
Template Parameters
TThe class of objects to or from which the relation points.
Parameters
nameThe name of the store array to or from which the relation points. If empty the default store array name for class T will be used. If the special name "ALL" is given all store arrays containing objects of type T are considered.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
The related object or a null pointer.

Definition at line 432 of file DataStore.h.

433 {
434 if (!object) return nullptr;
435 StoreEntry* storeEntry = nullptr;
436 int index = -1;
437 return static_cast<T*>(DataStore::Instance().getRelationWith(c_BothSides, object, storeEntry, index, T::Class(), name,
438 namedRelation).object);
439 }
Belle2::RelationEntry getRelationWith(ESearchSide searchSide, const TObject *object, StoreEntry *&entry, int &index, const TClass *withClass, const std::string &withName, const std::string &namedRelation)
Get the first relation between an object and another object in a store array.
Definition: DataStore.cc:597
TObject * object
Pointer to the object.
Definition: RelationEntry.h:32

◆ getRelationsWith()

RelationVectorBase getRelationsWith ( ESearchSide  searchSide,
const TObject *  object,
DataStore::StoreEntry *&  entry,
int &  index,
const TClass *  withClass,
const std::string &  withName,
const std::string &  namedRelation 
)

Get the relations between an object and other objects in a store array.

Parameters
searchSideSearch objects of type withClass on this side of relations (with 'object' on the other side).
objectPointer to the object from or to which the relations point.
entryData store entry that contains the object. Used for caching. Will be set if 0.
indexIndex in TClonesArray that contains the object. Used for caching. Will be set if < 0.
withClassClass of the objects to or from which the relations point.
withNameThe name of the store array to or from which the relations point. If empty the default store array name for withClass will be used. If the special name "ALL" is given all store arrays containing object of type withClass are considered.
namedRelationAdditional name for the relation, or "" for the default naming. If withName is "ALL", the namedRelation parameter is ignored and all related objects are returned.
Returns
Vector of relation entry objects (not type-safe).

Definition at line 545 of file DataStore.cc.

547{
548 if (searchSide == c_BothSides) {
549 auto result = getRelationsWith(c_ToSide, object, entry, index, withClass, withName, namedRelation);
550 const auto& fromResult = getRelationsWith(c_FromSide, object, entry, index, withClass, withName, namedRelation);
551 result.add(fromResult);
552 return result;
553 }
554
555 std::vector<RelationEntry> result;
556
557 // get StoreEntry for 'object'
558 if (!findStoreEntry(object, entry, index)) return RelationVectorBase();
559
560 // get names of store arrays to search
561 const std::vector<string>& names = getArrayNames(withName, withClass);
562 vector<string> relationNames;
563
564 // loop over found store arrays
565 for (const std::string& name : names) {
566 // get the relations from -> to
567 const string& relationsName = (searchSide == c_ToSide) ? relationName(entry->name, name, namedRelation) : relationName(name,
568 entry->name, namedRelation);
569 RelationIndex<TObject, TObject> relIndex(relationsName, c_Event);
570 if (!relIndex)
571 continue;
572
573 const size_t prevsize = result.size();
574
575 //get relations with object
576 if (searchSide == c_ToSide) {
577 for (const auto& rel : relIndex.getElementsFrom(object)) {
578 auto* const toObject = const_cast<TObject*>(rel.to);
579 if (toObject)
580 result.emplace_back(toObject, rel.weight);
581 }
582 } else {
583 for (const auto& rel : relIndex.getElementsTo(object)) {
584 auto* const fromObject = const_cast<TObject*>(rel.from);
585 if (fromObject)
586 result.emplace_back(fromObject, rel.weight);
587 }
588 }
589
590 if (result.size() != prevsize)
591 relationNames.push_back(relationsName);
592 }
593
594 return RelationVectorBase(entry->name, index, result, relationNames);
595}
RelationVectorBase getRelationsWith(ESearchSide searchSide, const TObject *object, StoreEntry *&entry, int &index, const TClass *withClass, const std::string &withName, const std::string &namedRelation)
Get the relations between an object and other objects in a store array.
Definition: DataStore.cc:545
Provides access to fast ( O(log n) ) bi-directional lookups on a specified relation.
Definition: RelationIndex.h:76
base class for RelationVector<T>

◆ getRelationsWithObj()

static RelationVector< T > getRelationsWithObj ( const TObject *  object,
const std::string &  name = "",
const std::string &  namedRelation = "" 
)
inlinestatic

Get the relations between an object and other objects in a store array.

Relations in both directions are returned.

Note
Using this function should only be necessary if type(object) == genfit::.... If possible, use RelationsObject members instead, as they allow more efficent caching.
See also
RelationsObject::getRelationsWith
Parameters
objectPointer to the object from or to which the relations point.
Template Parameters
TClass of the objects to or from which the relations point.
Parameters
nameThe name of the store array to or from which the relations point. If empty the default store array name for withClass will be used. If the special name "ALL" is given all store arrays containing objects of type T are considered.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
Vector of relation entry objects.

Definition at line 412 of file DataStore.h.

414 {
415 StoreEntry* storeEntry = nullptr;
416 int index = -1;
417 return RelationVector<T>(Instance().getRelationsWith(c_BothSides, object, storeEntry, index, T::Class(), name, namedRelation));
418 }

◆ getRelationWith()

RelationEntry getRelationWith ( ESearchSide  searchSide,
const TObject *  object,
DataStore::StoreEntry *&  entry,
int &  index,
const TClass *  withClass,
const std::string &  withName,
const std::string &  namedRelation 
)

Get the first relation between an object and another object in a store array.

Parameters
searchSideSearch objects of type withClass on this side of relations (with 'object' on the other side).
objectPointer to the object from or to which the relation points.
entryData store entry that contains the object. Used for caching. Will be set if 0.
indexIndex in TClonesArray that contains the object. Used for caching. Will be set if < 0.
withClassClass of the objects to or from which the relation points.
withNameThe name of the store array to or from which the relation points. If empty the default store array name for withClass will be used. If the special name "ALL" is given all store arrays containing object of type withClass are considered.
namedRelationAdditional name for the relation, or "" for the default naming. If withName is "ALL", the namedRelation parameter is ignored and all related objects are returned.
Returns
The entry of the first related object.

Definition at line 597 of file DataStore.cc.

599{
600 if (searchSide == c_BothSides) {
601 RelationEntry result = getRelationWith(c_ToSide, object, entry, index, withClass, withName, namedRelation);
602 if (!result.object) {
603 result = getRelationWith(c_FromSide, object, entry, index, withClass, withName, namedRelation);
604 }
605 return result;
606 }
607
608 // get StoreEntry for 'object'
609 if (!findStoreEntry(object, entry, index)) return RelationEntry(nullptr);
610
611 // get names of store arrays to search
612 const std::vector<string>& names = getArrayNames(withName, withClass);
613
614 // loop over found store arrays
615 for (const std::string& name : names) {
616 // get the relations from -> to
617 const string& relationsName = (searchSide == c_ToSide) ? relationName(entry->name, name, namedRelation) : relationName(name,
618 entry->name, namedRelation);
619 RelationIndex<TObject, TObject> relIndex(relationsName, c_Event);
620 if (!relIndex)
621 continue;
622
623 // get first element
624 if (searchSide == c_ToSide) {
625 const RelationIndex<TObject, TObject>::Element* element = relIndex.getFirstElementFrom(object);
626 if (element && element->to) {
627 return RelationEntry(const_cast<TObject*>(element->to), element->weight);
628 }
629 } else {
630 const RelationIndex<TObject, TObject>::Element* element = relIndex.getFirstElementTo(object);
631 if (element && element->from) {
632 return RelationEntry(const_cast<TObject*>(element->from), element->weight);
633 }
634 }
635 }
636
637 return RelationEntry(nullptr);
638}
Struct for relations.
Definition: RelationEntry.h:24
const FROM * from
pointer of the element from which the relation points.
const TO * to
pointer of the element to which the relation points.
RelationElement::weight_type weight
weight of the relation.

◆ getSortedListOfDataStore()

std::vector< std::string > getSortedListOfDataStore ( EDurability  durability) const

Returns a (sorted) list of all the content of the DataStore (Objs-Arrays-Relations).

Definition at line 703 of file DataStore.cc.

704{
705 std::vector<string> list;
706 std::vector<std::string> mergeContent = getListOfObjects(TObject::Class(), durability);
707 list.insert(std::end(list), std::begin(mergeContent), std::end(mergeContent));
708 mergeContent = getListOfArrays(TObject::Class(), durability);
709 list.insert(std::end(list), std::begin(mergeContent), std::end(mergeContent));
710 mergeContent = getListOfRelations(durability);
711 list.insert(std::end(list), std::begin(mergeContent), std::end(mergeContent));
712 return list;
713}
std::vector< std::string > getListOfRelations(EDurability durability) const
Returns a list of names of StoreObjPtr-objects whose class is (or inherits from) RelationContainer.
Definition: DataStore.cc:688
std::vector< std::string > getListOfArrays(const TClass *arrayClass, EDurability durability) const
Returns a list of names of arrays which are of type (or inherit from) arrayClass.
Definition: DataStore.cc:666
std::vector< std::string > getListOfObjects(const TClass *objClass, EDurability durability) const
Returns a list of names of StoreObjPtr-objects whose class is (or inherits from) objClass.
Definition: DataStore.cc:671

◆ getStoreEntryMap()

StoreEntryMap & getStoreEntryMap ( EDurability  durability)
inline

Get a reference to the object/array map.

This is intended to be used for input/output or other framework-internal modules.

Definition at line 325 of file DataStore.h.

325{ return m_storeEntryMap[durability]; }

◆ getTClassFromDefaultArrayName()

TClass * getTClassFromDefaultArrayName ( const std::string &  arrayName)
static

Tries to deduce the TClass from a default array name, which is generally the name of the C++ class with an appended 's'.

The namespace qualification Belle2:: can be ommitted

Definition at line 116 of file DataStore.cc.

117{
118 if (arrayName.empty()) {
119 return nullptr;
120 } else if ('s' == arrayName.back()) {
121 std::string objectName = arrayName.substr(0, arrayName.size() - 1);
123 } else {
124 return nullptr;
125 }
126}
static std::string objectName(const TClass *t, const std::string &name)
Return the storage name for an object of the given TClass and name.
Definition: DataStore.cc:151
static TClass * getTClassFromDefaultObjectName(const std::string &objectName)
Tries to deduce the TClass from a default object name, which is generally the name of the C++ class.
Definition: DataStore.cc:105
static std::string arrayName(const TClass *t, const std::string &name)
Return the storage name for an object of the given TClass and name.
Definition: DataStore.cc:164

◆ getTClassFromDefaultObjectName()

TClass * getTClassFromDefaultObjectName ( const std::string &  objectName)
static

Tries to deduce the TClass from a default object name, which is generally the name of the C++ class.

The namespace qualification Belle2:: can be ommitted.

Definition at line 105 of file DataStore.cc.

106{
107 // First look for an name without the namespace Belle2::
108 TClass* cl = TClass::GetClass(("Belle2::" + objectName).c_str());
109 if (not cl) {
110 // If this fails look for a name that already has the full namespace.
111 cl = TClass::GetClass(objectName.c_str());
112 }
113 return cl;
114}

◆ hasRelation()

bool hasRelation ( const StoreAccessorBase fromArray,
const StoreAccessorBase toArray,
EDurability  durability,
const std::string &  namedRelation 
)

Check for the existence of a relation in the DataStore map.

Parameters
fromArrayOrigin of the relation
toArrayTarget of the relation
durabilityDecide with which durability map you want to perform the requested action.
namedRelationAdditional name for the relation, or "" for the default naming.
Returns
True if there is a registered relation.
See also
DependencyMap

Definition at line 271 of file DataStore.cc.

273{
274 // check that the input makes sense
275 if (!fromArray.isArray())
276 B2FATAL(fromArray.readableName() << " is not an array!");
277 if (!toArray.isArray())
278 B2FATAL(toArray.readableName() << " is not an array!");
279
280 // check the the namedRelation only contains regular characters
281 if (!std::regex_match(namedRelation, m_regexNamedRelationCheck))
282 B2FATAL("Named Relations can only contain alphabetic characters, given was: " << namedRelation);
283
284 // get the internal relation name from the name provided
285 const std::string& realname = relationName(fromArray.getName(), toArray.getName(), namedRelation);
286
287 // check whether the map entry exists
288 const auto& it = m_storeEntryMap[durability].find(realname);
289 if (it != m_storeEntryMap[durability].end()) return true;
290
291 return false;
292}
const std::regex m_regexNamedRelationCheck
Regular expression to check that no special characters and no white spaces are in the string given fo...
Definition: DataStore.h:634

◆ Instance()

DataStore & Instance ( )
static

Instance of singleton Store.

This method is used to access the DataStore directly. It is used internally in the Store accessor classes.

Definition at line 54 of file DataStore.cc.

55{
56 static DataStore instance;
57 return instance;
58}
In the store you can park objects that have to be accessed by various modules.
Definition: DataStore.h:51

◆ invalidateData()

void invalidateData ( EDurability  durability)

Clears all registered StoreEntry objects of a specified durability, invalidating all objects.

Called by the framework once the given durability is over. Users should usually not use this function without a good reason.

Definition at line 715 of file DataStore.cc.

716{
717 B2DEBUG(100, "Invalidating objects for durability " << durability);
720}
void invalidateData(EDurability durability)
Clears all registered StoreEntry objects of a specified durability, invalidating all objects.
Definition: DataStore.cc:1177
void clear(DataStore::EDurability durability=DataStore::c_Event)
Clear the cache of RelationIndexContainers with the given durability.

◆ mergeContentsTo()

void mergeContentsTo ( const std::string &  id,
const std::vector< std::string > &  entrylist_event = {} 
)

merge contents (actual array / object contents) of current DataStore to the DataStore with given ID.

Definition at line 815 of file DataStore.cc.

816{
817 m_storeEntryMap.mergeContentsTo(id, entrylist_event);
818}
void mergeContentsTo(const std::string &id, const std::vector< std::string > &entrylist_event={})
merge contents (actual array / object contents) of current DataStore to the DataStore with given ID.
Definition: DataStore.cc:987

◆ objectName() [1/2]

static std::string objectName ( const std::string &  name)
inlinestatic

Return the storage name for an object of the given type and name.

Definition at line 137 of file DataStore.h.

138 {
139 return ((name.empty()) ? defaultObjectName<T>() : name);
140 }

◆ objectName() [2/2]

std::string objectName ( const TClass *  t,
const std::string &  name 
)
static

Return the storage name for an object of the given TClass and name.

Definition at line 151 of file DataStore.cc.

152{
153 return ((name.empty()) ? defaultObjectName(t) : name);
154}

◆ optionalInput()

bool optionalInput ( const StoreAccessorBase accessor)

Register the given object/array as an optional input.

Mainly useful for creating diagrams of module inputs and outputs.

Parameters
accessorEncapsulates name, durability, and type
Returns
True if the requested object exists.
See also
DependencyMap

Definition at line 739 of file DataStore.cc.

740{
741 if (m_initializeActive) {
743 (accessor.getClass() == RelationContainer::Class()));
744 }
745
746 return (getEntry(accessor) != nullptr);
747}
@ c_OptionalInput
optional input.
Definition: DependencyMap.h:34
ModuleInfo & getCurrentModuleInfo()
Get info for current module.
Definition: DependencyMap.h:63
void addEntry(const std::string &name, EEntryType type, bool isRelation)
Adds given entry/relation.

◆ optionalRelation()

bool optionalRelation ( const StoreAccessorBase fromArray,
const StoreAccessorBase toArray,
EDurability  durability,
std::string const &  namedRelation 
)

Register the given relation as an optional input.

Mainly useful for creating diagrams of module inputs and outputs.

Parameters
fromArrayOrigin of the relation
toArrayTarget of the relation
durabilityDecide with which durability map you want to perform the requested action.
namedRelationAdditional name for the relation, or "" for the default naming1
Returns
True if the requested object exists.
See also
DependencyMap

Definition at line 766 of file DataStore.cc.

768{
769 if (!fromArray.isArray())
770 B2FATAL(fromArray.readableName() << " is not an array!");
771 if (!toArray.isArray())
772 B2FATAL(toArray.readableName() << " is not an array!");
773
774 const std::string& relName = relationName(fromArray.getName(), toArray.getName(), namedRelation);
775 return DataStore::Instance().optionalInput(StoreAccessorBase(relName, durability, RelationContainer::Class(), false));
776}
bool optionalInput(const StoreAccessorBase &accessor)
Register the given object/array as an optional input.
Definition: DataStore.cc:739
Base class for StoreObjPtr and StoreArray for easier common treatment.

◆ registerEntry()

bool registerEntry ( const std::string &  name,
EDurability  durability,
TClass *  objClass,
bool  array,
EStoreFlags  storeFlags 
)

Register an entry in the DataStore map.

If the map of requested durability already contains an object under the key name with a DIFFERENT type than the given type, an error will be reported.
Otherwise a new map slot is created. This must be called in the initialization phase. Otherwise an error is returned.

Parameters
nameName under which you want to save the object in the DataStore.
durabilityDecide with which durability map you want to perform the requested action.
objClassThe class of the object.
arrayWhether it is a TClonesArray or not.
storeFlagsORed combination of DataStore::EStoreFlags.
Returns
True if the registration succeeded.
See also
DependencyMap

Definition at line 190 of file DataStore.cc.

192{
193 const StoreAccessorBase accessor(name, durability, objClass, array);
194 // Check whether this method is called in the initialization phase
195 if (!m_initializeActive) {
196 B2ERROR("Attempt to register " << accessor.readableName() <<
197 " outside of the initialization phase. Please move calls to registerInDataStore() into your Module's initialize() function.");
198 return false;
199 }
200 const bool dontwriteout = storeFlags & c_DontWriteOut;
201
202 //add to current module's outputs
203 m_dependencyMap->getCurrentModuleInfo().addEntry(name, DependencyMap::c_Output, (objClass == RelationContainer::Class()));
204
205 // Check whether the map entry already exists
206 const auto& it = m_storeEntryMap[durability].find(name);
207 if (it != m_storeEntryMap[durability].end()) {
208 StoreEntry& entry = it->second;
209
210 // Complain about existing entry
211 if (storeFlags & c_ErrorIfAlreadyRegistered) {
212 B2ERROR("An " << accessor.readableName() << " of type " << entry.object->ClassName() <<
213 " was already registered before. (Multiple calls to registerInDataStore() are fine if the c_ErrorIfAlreadyRegistered flag is not set. For objects you will want to make sure that you don't discard existing data from other modules in that case.");
214 return false;
215 }
216
217 // Check whether the types match
218 if (!checkType(entry, accessor)) return false;
219
220 // Check whether the persistency type matches
221 if (entry.dontWriteOut != dontwriteout) {
222 B2WARNING("Existing " << accessor.readableName() << " has different persistency type than requested. Changing to " <<
223 (dontwriteout ? "c_DontWriteOut" : "c_WriteOut") << ".");
224 entry.dontWriteOut = dontwriteout;
225 }
226
227 B2DEBUG(100, "An " << accessor.readableName() << " was registered once more.");
228 return true;
229 }
230
231 // check reserved names
232 if (array and name == "ALL") {
233 B2ERROR("Creating an array with the reserved name 'ALL' is not allowed!");
234 return false;
235 }
236
237 // Add the DataStore entry
238 m_storeEntryMap[durability][name] = StoreEntry(array, objClass, name, dontwriteout);
239
240 B2DEBUG(100, "Successfully registered " << accessor.readableName());
241 return true;
242}
@ c_Output
registered output.
Definition: DependencyMap.h:35
bool dontWriteOut
Flag that indicates whether the object should be written to the output by default.
Definition: StoreEntry.h:40

◆ registerRelation()

bool registerRelation ( const StoreAccessorBase fromArray,
const StoreAccessorBase toArray,
EDurability  durability,
EStoreFlags  storeFlags,
const std::string &  namedRelation 
)

Register a relation in the DataStore map.

This must be called in the initialization phase. Otherwise an error is returned.

Parameters
fromArrayOrigin of the relation
toArrayTarget of the relation
durabilityDecide with which durability map you want to perform the requested action.
storeFlagsORed combination of DataStore::EStoreFlags.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
True if the registration succeeded.
See also
DependencyMap

Definition at line 244 of file DataStore.cc.

246{
247 if (!fromArray.isArray())
248 B2FATAL(fromArray.readableName() << " is not an array!");
249 if (!toArray.isArray())
250 B2FATAL(toArray.readableName() << " is not an array!");
251
252 // check the the namedRelation only contains regular characters
253 if (!std::regex_match(namedRelation, m_regexNamedRelationCheck))
254 B2FATAL("Named Relations can only contain alphabetic characters, given was: " << namedRelation);
255
256 const std::string& relName = relationName(fromArray.getName(), toArray.getName(), namedRelation);
257 /*
258 if ((fromArray.notWrittenOut() or toArray.notWrittenOut()) and !(storeFlags & c_DontWriteOut)) {
259 B2WARNING("You're trying to register a persistent relation " << relName << " from/to an array which is not written out (DataStore::c_DontWriteOut flag)! Relation will also not be saved!");
260 storeFlags |= c_DontWriteOut;
261 }
262 */
263
264 if (fromArray.getDurability() > durability or toArray.getDurability() > durability) {
265 B2FATAL("Tried to create a relation '" << relName << "' with a durability larger than the StoreArrays it relates");
266 }
267
268 return DataStore::Instance().registerEntry(relName, durability, RelationContainer::Class(), false, storeFlags);
269}
bool registerEntry(const std::string &name, EDurability durability, TClass *objClass, bool array, EStoreFlags storeFlags)
Register an entry in the DataStore map.
Definition: DataStore.cc:190

◆ relationName()

static std::string relationName ( const std::string &  fromName,
const std::string &  toName,
std::string const &  namedRelation = "" 
)
inlinestatic

Return storage name for a relation between two arrays of the given names.

Definition at line 180 of file DataStore.h.

182 {
183 std::string s;
184 s.reserve(fromName.length() + toName.length() + 2);
185 s += fromName;
186 s += "To";
187 s += toName;
188 if (namedRelation.length() > 0) {
189 s += "Named";
190 // Characters are not escaped here, because in registerRelation, the namedRelation
191 // given is checked to contain no special characters or white spaces
192 s += namedRelation;
193 }
194 return s;
195 }

◆ replaceData()

void replaceData ( const StoreAccessorBase from,
const StoreAccessorBase to 
)

For two StoreAccessors of same type, move all data in 'from' into 'to', discarding previous contents of 'to' and leaving 'from' empty.

Meta-data like c_DontWriteOut flags or info about associated arrays for RelationContainers is not replaced.

Definition at line 343 of file DataStore.cc.

344{
345 StoreEntry* fromEntry = getEntry(from);
346 StoreEntry* toEntry = getEntry(to);
347 if (!fromEntry)
348 B2FATAL("No " << from.readableName() << " exists in the DataStore!");
349 if (!toEntry)
350 B2FATAL("No " << to.readableName() << " exists in the DataStore!");
351 if (from.isArray() != to.isArray() or from.getClass() != to.getClass())
352 B2FATAL("cannot replace " << to.readableName() << " with " << from.readableName() << " (incompatible types)!");
353
354 if (!fromEntry->ptr) {
355 //since we don't need to move any data, just invalidate toEntry instead.
356 toEntry->ptr = nullptr;
357 } else if (fromEntry->isArray) {
358 if (!toEntry->ptr)
359 toEntry->ptr = toEntry->object;
360 toEntry->getPtrAsArray()->Delete();
361
362 fixAbsorbObjects(fromEntry->getPtrAsArray(), toEntry->getPtrAsArray());
364 } else if (fromEntry->objClass == RelationContainer::Class()) {
365 if (!toEntry->ptr)
366 toEntry->ptr = toEntry->object;
367 auto* fromRel = static_cast<RelationContainer*>(fromEntry->ptr);
368 auto* toRel = static_cast<RelationContainer*>(toEntry->ptr);
369
370 toRel->elements().Delete();
371
372 fixAbsorbObjects(&fromRel->elements(), &toRel->elements());
373
374 //indices need a rebuild
375 fromRel->setModified(true);
376 toRel->setModified(true);
377 } else {
378 delete toEntry->object;
379
380 toEntry->object = fromEntry->ptr->Clone();
381 toEntry->ptr = toEntry->object;
382
383 fromEntry->ptr = nullptr;
384 }
385}
TClonesArray & elements()
Get reference to the elements.
TClonesArray * getPtrAsArray() const
Return ptr cast to TClonesArray.
Definition: StoreEntry.cc:83

◆ requireInput()

bool requireInput ( const StoreAccessorBase accessor)

Produce ERROR message if no entry of the given type is registered in the DataStore.

Note
can only be used in initialize() function
Parameters
accessorEncapsulates name, durability, and type
Returns
True if the requested object exists.
See also
DependencyMap

Definition at line 722 of file DataStore.cc.

723{
724 if (m_initializeActive) {
726 (accessor.getClass() == RelationContainer::Class()));
727 } else {
728 B2FATAL("Attempt to require input " << accessor.readableName() <<
729 " outside of the initialization phase. Please move isRequired() calls into your Module's initialize() function.");
730 }
731
732 if (!getEntry(accessor)) {
733 B2ERROR("The required " << accessor.readableName() << " does not exist. Maybe you forgot the module that registers it?");
734 return false;
735 }
736 return true;
737}
@ c_Input
required input.
Definition: DependencyMap.h:33

◆ requireRelation()

bool requireRelation ( const StoreAccessorBase fromArray,
const StoreAccessorBase toArray,
EDurability  durability,
std::string const &  namedRelation 
)

Produce ERROR message if no relation of given durability exists between fromArray and toArray (in that direction).

Note
can only be used in initialize() function
Parameters
fromArrayOrigin of the relation
toArrayTarget of the relation
durabilityDecide with which durability map you want to perform the requested action.
namedRelationAdditional name for the relation, or "" for the default naming
Returns
True if the requested object exists.
See also
DependencyMap

Definition at line 749 of file DataStore.cc.

751{
752 if (!m_initializeActive) {
753 B2FATAL("Attempt to require relation " << fromArray.readableName() << " -> " << toArray.readableName() <<
754 " outside of the initialization phase. Please move requireRelationTo() calls into your Module's initialize() function.");
755 }
756
757 if (!fromArray.isArray())
758 B2FATAL(fromArray.readableName() << " is not an array!");
759 if (!toArray.isArray())
760 B2FATAL(toArray.readableName() << " is not an array!");
761
762 const std::string& relName = relationName(fromArray.getName(), toArray.getName(), namedRelation);
763 return DataStore::Instance().requireInput(StoreAccessorBase(relName, durability, RelationContainer::Class(), false));
764}
bool requireInput(const StoreAccessorBase &accessor)
Produce ERROR message if no entry of the given type is registered in the DataStore.
Definition: DataStore.cc:722

◆ reset() [1/2]

void reset ( )

Clears contents of the datastore (all durabilities)

Called by the framework. Users should usually not use this function without good reason.

Definition at line 74 of file DataStore.cc.

75{
76 B2DEBUG(31, "DataStore::reset(): Removing all elements from DataStore");
77 m_initializeActive = true;
79
80 for (int i = 0; i < c_NDurabilityTypes; i++)
82
84}
void clear()
same as calling reset() for all durabilities + all non-default datastore IDs are removed.
Definition: DataStore.cc:1154
static const int c_NDurabilityTypes
Number of Durability Types.
Definition: DataStore.h:63
void clear()
Reset all collected data.
Definition: DependencyMap.h:69

◆ reset() [2/2]

void reset ( EDurability  durability)

Frees memory occupied by data store items and removes all objects from the map.

Afterwards, m_storeEntryMap[durability] is empty. Called by the framework. Users should usually not use this function without good reason.

Definition at line 86 of file DataStore.cc.

87{
88 m_storeEntryMap.reset(durability);
89
90 //invalidate any cached relations (expect RelationArrays to remain valid)
92}
void reset(EDurability durability)
Frees memory occupied by data store items and removes all objects from the map.
Definition: DataStore.cc:1167
void reset()
Reset the cache completely, that is clear all caches and don't even keep the Index objects around.

◆ setInitializeActive()

void setInitializeActive ( bool  active)

Setter for m_initializeActive.

This should only be called by EventProcessor.

Definition at line 94 of file DataStore.cc.

95{
96 m_initializeActive = active;
97
98 static bool firstCall = true;
99 if (firstCall) {
100 atexit(cleanDataStore);
101 firstCall = false;
102 }
103}

◆ switchID()

void switchID ( const std::string &  id)

switch to DataStore with given ID.

Definition at line 794 of file DataStore.cc.

795{
796 if (id == m_storeEntryMap.currentID())
797 return;
798
799 //remember to clear caches
801
803}
void switchID(const std::string &id)
switch to DataStore with given ID.
Definition: DataStore.cc:1144

◆ updateRelationsObjectCache()

void updateRelationsObjectCache ( StoreEntry entry)
staticprivate

For an array containing RelationsObjects, update index and entry cache for entire contents.

You must ensure the array actually contains objects inheriting from RelationsObject!

Definition at line 387 of file DataStore.cc.

388{
389 const TClonesArray* array = static_cast<TClonesArray*>(entry.ptr);
390 const int nEntries = array->GetEntriesFast();
391 for (int i = 0; i < nEntries; i++) {
392 auto* relobj = static_cast<RelationsObject*>(array->At(i));
393 relobj->m_cacheArrayIndex = i;
394 relobj->m_cacheDataStoreEntry = &entry;
395 }
396}
int m_cacheArrayIndex
Cache of the index in the TClonesArray to which this object belongs.

Member Data Documentation

◆ c_NDurabilityTypes

const int c_NDurabilityTypes = 2
static

Number of Durability Types.


Definition at line 63 of file DataStore.h.

◆ m_dependencyMap

DependencyMap* m_dependencyMap
private

Collect information about the dependencies between modules.

Definition at line 637 of file DataStore.h.

◆ m_initializeActive

bool m_initializeActive
private

True if modules are currently being initialized.

Creating new map slots is only allowed in a Module's initialize() function.

Definition at line 628 of file DataStore.h.

◆ m_regexNamedRelationCheck

const std::regex m_regexNamedRelationCheck = std::regex("^[a-zA-Z]*$")
private

Regular expression to check that no special characters and no white spaces are in the string given for namedRelations.

Definition at line 634 of file DataStore.h.

◆ m_storeEntryMap

SwitchableDataStoreContents m_storeEntryMap
private

Maps (name, durability) key to StoreEntry objects.

Definition at line 621 of file DataStore.h.

◆ s_DoCleanup

bool s_DoCleanup = false
static

Global flag to to decide if we can do normal cleanup.

If the normal basf2 execution is bypassed, e.g. in tests or separate binaries, we cannot guarantee that exit handlers are called in the correct order. Since this may lead to double deletion of objects through ROOT and misleading error stack traces, we will skip cleanup in these exceptional cases.

Definition at line 100 of file DataStore.h.


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