10#include <framework/datastore/StoreEntry.h>
11#include <framework/core/BitMask.h>
13#if defined(__CINT__) || defined(__ROOTCLING__) || defined(R__DICTIONARY_FILENAME)
15#include <framework/datastore/RelationVector.h>
16#include <framework/datastore/RelationEntry.h>
134 static std::string
objectName(
const TClass* t,
const std::string& name);
137 template<
class T>
static std::string
objectName(
const std::string& name)
137 template<
class T>
static std::string
objectName(
const std::string& name) {
…}
147 s.reserve(objName.length() + 1);
164 static std::string
arrayName(
const TClass* t,
const std::string& name);
167 template<
class T>
static std::string
arrayName(
const std::string& name)
167 template<
class T>
static std::string
arrayName(
const std::string& name) {
…}
180 static std::string
relationName(
const std::string& fromName,
const std::string& toName,
181 std::string
const& namedRelation =
"")
184 s.reserve(fromName.length() + toName.length() + 2);
188 if (namedRelation.length() > 0) {
180 static std::string
relationName(
const std::string& fromName,
const std::string& toName, {
…}
227 EStoreFlags storeFlags,
const std::string& namedRelation);
239 const std::string& namedRelation);
261 std::string
const& namedRelation);
284 std::string
const& namedRelation);
340 int& toIndex,
float weight,
const std::string& namedRelation);
358 const TClass* withClass,
const std::string& withName,
const std::string& namedRelation);
375 const TClass* withClass,
const std::string& withName,
const std::string& namedRelation);
387 static void addRelationFromTo(
const TObject* fromObject,
const TObject* toObject,
float weight = 1.0,
388 const std::string& namedRelation =
"")
394 Instance().
addRelation(fromObject, fromEntry, fromIndex, toObject, toEntry, toIndex, weight, namedRelation);
387 static void addRelationFromTo(
const TObject* fromObject,
const TObject* toObject,
float weight = 1.0, {
…}
413 const std::string& namedRelation =
"")
432 template <
class T>
static T*
getRelated(
const TObject*
object,
const std::string& name =
"",
const std::string& namedRelation =
"")
434 if (!
object)
return nullptr;
432 template <
class T>
static T*
getRelated(
const TObject*
object,
const std::string& name =
"",
const std::string& namedRelation =
"") {
…}
441#if defined(__CINT__) || defined(__ROOTCLING__) || defined(R__DICTIONARY_FILENAME)
534 void switchID(
const std::string&
id);
536 void copyEntriesTo(
const std::string&
id,
const std::vector<std::string>& entrylist_event = {},
bool mergeEntries =
false);
538 void copyContentsTo(
const std::string&
id,
const std::vector<std::string>& entrylist_event = {});
540 void mergeContentsTo(
const std::string&
id,
const std::vector<std::string>& entrylist_event = {});
581 class SwitchableDataStoreContents {
583 SwitchableDataStoreContents();
596 const SwitchableDataStoreContents* this2 =
this;
601 void switchID(
const std::string&
id);
605 void copyEntriesTo(
const std::string&
id,
const std::vector<std::string>& entrylist_event = {},
bool mergeEntries =
false);
607 void copyContentsTo(
const std::string&
id,
const std::vector<std::string>& entrylist_event = {});
609 void mergeContentsTo(
const std::string&
id,
const std::vector<std::string>& entrylist_event = {});
581 class SwitchableDataStoreContents {
…};
Encapsulates DataStoreContents, but allows transparently switching between different versions ('DataS...
std::string m_currentID
currently active DataStore ID.
void createNewDataStoreID(const std::string &id)
creates new datastore with given id, copying the registered objects/arrays from the current one.
std::vector< DataStoreContents > m_entries
wrapped DataStoreContents.
void createEmptyDataStoreID(const std::string &id)
creates empty datastore with given id.
const StoreEntryMap & operator[](int durability) const
Get StoreEntry map for given durability (and current DataStore 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 switchID(const std::string &id)
switch to DataStore with given ID.
std::map< std::string, int > m_idToIndexMap
Maps DataStore ID to index in m_entries.
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.
const std::string & currentID() const
returns ID of current DataStore.
int m_currentIdx
index of currently active DataStore.
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 clear()
same as calling reset() for all durabilities + all non-default datastore IDs are removed.
void invalidateData(EDurability durability)
Clears all registered StoreEntry objects of a specified durability, invalidating all objects.
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.
std::array< StoreEntryMap, c_NDurabilityTypes > DataStoreContents
StoreEntry maps for each durability.
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.
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 > getListOfRelations(EDurability durability) const
Returns a list of names of StoreObjPtr-objects whose class is (or inherits from) RelationContainer.
bool getInitializeActive() const
Are we currently initializing modules?
void createNewDataStoreID(const std::string &id)
creates new datastore with given id, copying the registered objects/arrays from the current one.
static std::string defaultArrayName(const std::string &classname)
Return the default storage name for an given class name.
static std::string defaultObjectName(const std::string &classname)
Return the default storage name for given class name.
void createEmptyDataStoreID(const std::string &id)
creates empty 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.
bool findStoreEntry(const TObject *object, StoreEntry *&entry, int &index)
Find an object in an array in the data store.
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.
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.
static std::string defaultObjectName()
Return the default storage name for an object of the given type.
bool checkType(const StoreEntry &entry, const StoreAccessorBase &accessor) const
Check whether the given entry and the requested class match.
bool optionalRelation(const StoreAccessorBase &fromArray, const StoreAccessorBase &toArray, EDurability durability, std::string const &namedRelation)
Register the given relation as an optional input.
EStoreFlags
Flags describing behaviours of objects etc.
@ c_WriteOut
Object/array should be saved by output modules.
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
void switchID(const std::string &id)
switch to DataStore with given ID.
std::vector< std::string > getSortedListOfDataStore(EDurability durability) const
Returns a (sorted) list of all the content of the DataStore (Objs-Arrays-Relations).
StoreEntryMap::iterator StoreEntryIter
Iterator for a StoreEntry map.
const std::regex m_regexNamedRelationCheck
Regular expression to check that no special characters and no white spaces are in the string given fo...
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 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 std::string objectName(const std::string &name)
Return the storage name for an object of the given type and name.
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.
bool registerRelation(const StoreAccessorBase &fromArray, const StoreAccessorBase &toArray, EDurability durability, EStoreFlags storeFlags, const std::string &namedRelation)
Register a relation in the DataStore map.
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.
DataStore()
Hidden constructor, as it is a singleton.
DependencyMap * m_dependencyMap
Collect information about the dependencies between modules.
static std::string defaultArrayName()
Return the default storage name for an array of the given type.
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.
ESearchSide
Which side of relations should be returned?
@ c_BothSides
Combination of c_FromSide and c_ToSide.
@ c_FromSide
Return relations/objects pointed from (to a given object).
@ c_ToSide
Return relations/objects pointed to (from a given object).
StoreEntryMap & getStoreEntryMap(EDurability durability)
Get a reference to the object/array map.
static void updateRelationsObjectCache(StoreEntry &entry)
For an array containing RelationsObjects, update index and entry cache for entire contents.
static const int c_NDurabilityTypes
Number of Durability Types.
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.
static std::string defaultRelationName()
Return the default storage name for a relation between the given types.
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.
DataStore & operator=(const DataStore &)=delete
no assignment operator
bool requireInput(const StoreAccessorBase &accessor)
Produce ERROR message if no entry of the given type is registered in the DataStore.
EDurability
Durability types.
@ c_Persistent
Object is available during entire execution time.
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
Belle2::StoreEntry StoreEntry
Wraps a stored array/object, stored under unique (name, durability) key.
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...
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.
std::string currentID() const
returns ID of current DataStore.
static DataStore & Instance()
Instance of singleton Store.
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.
void setInitializeActive(bool active)
Setter for m_initializeActive.
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 bool s_DoCleanup
Global flag to to decide if we can do normal cleanup.
void reset()
Clears contents of the datastore (all durabilities)
StoreEntry * getEntry(const StoreAccessorBase &accessor)
Check whether an entry with the correct type is registered in the DataStore map and return it.
void invalidateData(EDurability durability)
Clears all registered StoreEntry objects of a specified durability, invalidating all objects.
static std::string arrayName(const std::string &name)
Return the storage name for an object of the given type and name.
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 createObject(TObject *object, bool replace, const StoreAccessorBase &accessor)
Create a new object/array in the DataStore or add an existing one.
TObject ** getObject(const StoreAccessorBase &accessor)
Get a pointer to a pointer of an object in the DataStore.
static std::string arrayName(const TClass *t, const std::string &name)
Return the storage name for an object of the given TClass and name.
bool m_initializeActive
True if modules are currently being initialized.
bool registerEntry(const std::string &name, EDurability durability, TClass *objClass, bool array, EStoreFlags storeFlags)
Register an entry in the DataStore map.
bool optionalInput(const StoreAccessorBase &accessor)
Register the given object/array as an optional input.
DataStore(const DataStore &)=delete
no copy constructor
SwitchableDataStoreContents m_storeEntryMap
Maps (name, durability) key to StoreEntry objects.
void replaceData(const StoreAccessorBase &from, const StoreAccessorBase &to)
For two StoreAccessors of same type, move all data in 'from' into 'to', discarding previous contents ...
std::map< std::string, StoreEntry > StoreEntryMap
Map for StoreEntries.
DependencyMap & getDependencyMap()
Return map of dependencies between modules.
Collect information about the dependencies between modules.
base class for RelationVector<T>
Class for type safe access to objects that are referred to in relations.
Base class for StoreObjPtr and StoreArray for easier common treatment.
ADD_BITMASK_OPERATORS(DataStore::EStoreFlags)
Add bitmask operators to DataStore::EStoreFlags.
Abstract base class for different kinds of events.
TObject * object
Pointer to the object.
Wraps a stored array/object, stored under unique (name, durability) key.