 |
Belle II Software
release-05-02-19
|
12 #include <framework/datastore/StoreEntry.h>
13 #include <framework/core/BitMask.h>
15 #if defined(__CINT__) || defined(__ROOTCLING__) || defined(R__DICTIONARY_FILENAME)
17 #include <framework/datastore/RelationVector.h>
18 #include <framework/datastore/RelationEntry.h>
35 class StoreAccessorBase;
37 class RelationVectorBase;
136 static std::string
objectName(
const TClass* t,
const std::string& name);
139 template<
class T>
static std::string
objectName(
const std::string& name)
141 return ((name.empty()) ? defaultObjectName<T>() : name);
149 s.reserve(objName.length() + 1);
166 static std::string
arrayName(
const TClass* t,
const std::string& name);
169 template<
class T>
static std::string
arrayName(
const std::string& name)
171 return ((name.empty()) ? defaultArrayName<T>() : name);
177 const static std::string s =
relationName(defaultArrayName<FROM>(), defaultArrayName<TO>());
182 static std::string
relationName(
const std::string& fromName,
const std::string& toName,
183 std::string
const& namedRelation =
"")
186 s.reserve(fromName.length() + toName.length() + 2);
190 if (namedRelation.length() > 0) {
215 TClass* objClass,
bool array,
EStoreFlags storeFlags);
229 EStoreFlags storeFlags,
const std::string& namedRelation);
241 const std::string& namedRelation);
259 std::string
const& namedRelation);
280 std::string
const& namedRelation);
336 int& toIndex,
float weight,
const std::string& namedRelation);
354 const TClass* withClass,
const std::string& withName,
const std::string& namedRelation);
371 const TClass* withClass,
const std::string& withName,
const std::string& namedRelation);
383 static void addRelationFromTo(
const TObject* fromObject,
const TObject* toObject,
float weight = 1.0,
384 const std::string& namedRelation =
"")
390 Instance().
addRelation(fromObject, fromEntry, fromIndex, toObject, toEntry, toIndex, weight, namedRelation);
409 const std::string& namedRelation =
"")
428 template <
class T>
static T*
getRelated(
const TObject*
object,
const std::string& name =
"",
const std::string& namedRelation =
"")
430 if (!
object)
return nullptr;
437 #if defined(__CINT__) || defined(__ROOTCLING__) || defined(R__DICTIONARY_FILENAME)
445 return getRelationsWithObj<TObject>(
object, name);
447 static TObject*
getRelated(
const TObject*
object,
const std::string& name) {
return getRelated<TObject>(
object, name); }
520 void switchID(
const std::string&
id);
522 void copyEntriesTo(
const std::string&
id,
const std::vector<std::string>& entrylist_event = {});
524 void copyContentsTo(
const std::string&
id,
const std::vector<std::string>& entrylist_event = {});
585 void switchID(
const std::string&
id);
589 void copyEntriesTo(
const std::string&
id,
const std::vector<std::string>& entrylist_event = {});
591 void copyContentsTo(
const std::string&
id,
const std::vector<std::string>& entrylist_event = {});
static std::string arrayName(const std::string &name)
Return the storage name for an object of the given type and name.
const std::string & currentID() const
returns ID of current DataStore.
@ c_BothSides
Combination of c_FromSide and c_ToSide.
std::vector< DataStoreContents > m_entries
wrapped DataStoreContents.
bool registerRelation(const StoreAccessorBase &fromArray, const StoreAccessorBase &toArray, EDurability durability, EStoreFlags storeFlags, const std::string &namedRelation)
Register a relation in the DataStore map.
static void updateRelationsObjectCache(StoreEntry &entry)
For an array containing RelationsObjects, update index and entry cache for entire contents.
bool m_initializeActive
True if modules are currently being initialized.
StoreEntryMap::iterator StoreEntryIter
Iterator for a StoreEntry map.
void createNewDataStoreID(const std::string &id)
creates new datastore with given id, copying the registered objects/arrays from the current one.
bool getInitializeActive() const
Are we currently initializing modules?
std::map< std::string, int > m_idToIndexMap
Maps DataStore ID to index in m_entries.
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.
DependencyMap & getDependencyMap()
Return map of depedencies between modules.
std::string currentID() const
returns ID of current DataStore.
void copyEntriesTo(const std::string &id, const std::vector< std::string > &entrylist_event={})
copy entries (not contents) of current DataStore to the DataStore with given ID.
static DataStore & Instance()
Instance of singleton Store.
static std::string arrayName(const TClass *t, const std::string &name)
Return the storage name for an object of the given TClass and name.
std::map< std::string, StoreEntry > StoreEntryMap
Map for StoreEntries.
Collect information about the dependencies between modules.
ESearchSide
Which side of relations should be returned?
void setInitializeActive(bool active)
Setter for m_initializeActive.
void reset(EDurability durability)
Frees memory occupied by data store items and removes all objects from the map.
EStoreFlags
Flags describing behaviours of objects etc.
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.
Wraps a stored array/object, stored under unique (name, durability) key.
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::string m_currentID
currently active DataStore ID.
void replaceData(const StoreAccessorBase &from, const StoreAccessorBase &to)
For two StoreAccessors of same type, move all data in 'from' into 'to', discarding previous contents ...
Base class for StoreObjPtr and StoreArray for easier common treatment.
static std::string defaultObjectName()
Return the default storage name for an object of the given type.
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
TObject ** getObject(const StoreAccessorBase &accessor)
Get a pointer to a pointer of an object in the DataStore.
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.
std::array< StoreEntryMap, c_NDurabilityTypes > DataStoreContents
StoreEntry maps for each durability.
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.
base class for RelationVector<T>
bool optionalInput(const StoreAccessorBase &accessor)
Register the given object/array as an optional input.
DependencyMap * m_dependencyMap
Collect information about the dependencies between modules.
static std::string objectName(const std::string &name)
Return the storage name for an object of the given type and name.
StoreEntryMap & getStoreEntryMap(EDurability durability)
Get a reference to the object/array map.
void createNewDataStoreID(const std::string &id)
creates new datastore with given id, copying the registered objects/arrays from the current one.
@ c_WriteOut
Object/array should be saved by output modules.
static bool s_DoCleanup
Global flag to to decide if we can do normal cleanup.
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 wi...
void copyEntriesTo(const std::string &id, const std::vector< std::string > &entrylist_event={})
copy entries (not contents) of current DataStore to the DataStore with given ID.
const std::regex m_regexNamedRelationCheck
Regular expression to check that no special characters and no white spaces are in the string given fo...
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.
int m_currentIdx
index of currently active DataStore.
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.
Class for type safe access to objects that are referred to in relations.
TObject * object
Pointer to the object.
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.
const StoreEntryMap & operator[](int durability) const
Get StoreEntry map for given durability (and current DataStore ID).
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 tha...
SwitchableDataStoreContents m_storeEntryMap
Maps (name, durability) key to StoreEntry objects.
Abstract base class for different kinds of events.
void switchID(const std::string &id)
switch to DataStore with given ID.
Encapsulates DataStoreContents, but allows transparently switching between different versions ('DataS...
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.
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.
static std::string defaultArrayName(const std::string &classname)
Return the default storage name for an given class name.
const static int c_NDurabilityTypes
Number of Durability Types.
@ c_ToSide
Return relations/objects pointed to (from a given object).
static std::string defaultArrayName()
Return the default storage name for an array of the given type.
void clear()
same as calling reset() for all durabilities + all non-default datastore IDs are removed.
bool registerEntry(const std::string &name, EDurability durability, TClass *objClass, bool array, EStoreFlags storeFlags)
Register an entry in the DataStore map.
void switchID(const std::string &id)
switch to DataStore with given ID.
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.
DataStore & operator=(const DataStore &)=delete
no assignment operator
void invalidateData(EDurability durability)
Clears all registered StoreEntry objects of a specified durability, invalidating all objects.
bool findStoreEntry(const TObject *object, StoreEntry *&entry, int &index)
Find an object in an array in the data store.
ADD_BITMASK_OPERATORS(DataStore::EStoreFlags)
Add bitmask operators to DataStore::EStoreFlags.
DataStore()
Hidden constructor, as it is a singleton.
Belle2::StoreEntry StoreEntry
Wraps a stored array/object, stored under unique (name, durability) key.
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
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.
@ c_Persistent
Object is available during entire execution time.
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.
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 std::string objectName(const TClass *t, const std::string &name)
Return the storage name for an object of the given TClass and name.
StoreEntryMap::const_iterator StoreEntryConstIter
const_iterator for a StoreEntry map.
bool createObject(TObject *object, bool replace, const StoreAccessorBase &accessor)
Create a new object/array in the DataStore or add an existing one.
bool optionalRelation(const StoreAccessorBase &fromArray, const StoreAccessorBase &toArray, EDurability durability, std::string const &namedRelation)
Register the given relation as an optional input.
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.
StoreEntry * getEntry(const StoreAccessorBase &accessor)
Check whether an entry with the correct type is registered in the DataStore map and return it.
bool checkType(const StoreEntry &entry, const StoreAccessorBase &accessor) const
Check whether the given entry and the requested class match.
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
void invalidateData(EDurability durability)
Clears all registered StoreEntry objects of a specified durability, invalidating all objects.
void reset()
Clears contents of the datastore (all durabilities)
In the store you can park objects that have to be accessed by various modules.
static std::string defaultRelationName()
Return the default storage name for a relation between the given types.
@ c_FromSide
Return relations/objects pointed from (to a given object).
bool requireInput(const StoreAccessorBase &accessor)
Produce ERROR message if no entry of the given type is registered in the DataStore.
EDurability
Durability types.