9#include <framework/datastore/DataStore.h>
11#include <framework/logging/Logger.h>
12#include <framework/datastore/RelationEntry.h>
13#include <framework/datastore/DependencyMap.h>
14#include <framework/dataobjects/RelationContainer.h>
15#include <framework/datastore/RelationIndex.h>
16#include <framework/datastore/RelationIndexManager.h>
17#include <framework/datastore/RelationsObject.h>
18#include <framework/datastore/StoreAccessorBase.h>
19#include <framework/dataobjects/EventExtraInfo.h>
21#include <TClonesArray.h>
24#include <unordered_map>
45 void fixAbsorbObjects(TClonesArray* from, TClonesArray* to)
47 to->AbsorbObjects(from, 0, from->GetEntriesFast() - 1);
75 B2DEBUG(31,
"DataStore::reset(): Removing all elements from DataStore");
97 static bool firstCall =
true;
99 atexit(cleanDataStore);
107 TClass* cl = TClass::GetClass((
"Belle2::" +
objectName).c_str());
129 const static string gfclass =
"genfit::Track";
130 const static string gfobjectname =
"GF2Track";
131 if (classname == gfclass)
134 size_t colon = classname.rfind(
':');
135 if (colon != std::string::npos) {
136 return classname.substr(colon + 1);
144 B2ASSERT(
"Cannot deduce default object name from null pointer TClass", t);
172 const char* entryType = (entry.
isArray) ?
"array" :
"object";
174 B2FATAL(
"Existing entry '" << entry.
name <<
"' is an " << entryType <<
" and the requested one an " << ((
175 accessor.
isArray()) ?
"array" :
"object"));
179 const TClass* entryClass = entry.
objClass;
180 if (!entryClass->InheritsFrom(accessor.
getClass())) {
181 B2FATAL(
"Existing " << accessor.
readableName() <<
" of type " << entryClass->GetName() <<
" doesn't match requested type " <<
188 TClass* objClass,
bool array,
EStoreFlags storeFlags)
193 B2ERROR(
"Attempt to register " << accessor.
readableName() <<
194 " outside of the initialization phase. Please move calls to registerInDataStore() into your Module's initialize() function.");
209 B2ERROR(
"An " << accessor.
readableName() <<
" of type " << entry.
object->ClassName() <<
210 " 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.");
219 B2WARNING(
"Existing " << accessor.
readableName() <<
" has different persistency type than requested. Changing to " <<
220 (dontwriteout ?
"c_DontWriteOut" :
"c_WriteOut") <<
".");
224 B2DEBUG(100,
"An " << accessor.
readableName() <<
" was registered once more.");
229 if (array and name ==
"ALL") {
230 B2ERROR(
"Creating an array with the reserved name 'ALL' is not allowed!");
237 B2DEBUG(100,
"Successfully registered " << accessor.
readableName());
242 EStoreFlags storeFlags,
const std::string& namedRelation)
245 B2FATAL(fromArray.
readableName() <<
" is not an array!");
251 B2FATAL(
"Named Relations can only contain alphabetic characters, given was: " << namedRelation);
262 B2FATAL(
"Tried to create a relation '" << relName <<
"' with a durability larger than the StoreArrays it relates");
269 const std::string& namedRelation)
273 B2FATAL(fromArray.
readableName() <<
" is not an array!");
279 B2FATAL(
"Named Relations can only contain alphabetic characters, given was: " << namedRelation);
297 return &(it->second);
310 return &(entry->
ptr);
319 " exists in the DataStore, did you forget to register it in your Module's initialize() function? Note: direct accesses to it will crash!");
323 if (entry->
ptr && !replace &&
object != entry->
object) {
324 B2ERROR(
"An " << accessor.
readableName() <<
" was already created in the DataStore.");
329 if (
object != entry->
object) {
346 B2FATAL(
"No " << from.
readableName() <<
" exists in the DataStore!");
348 B2FATAL(
"No " << to.
readableName() <<
" exists in the DataStore!");
352 if (!fromEntry->
ptr) {
354 toEntry->
ptr =
nullptr;
355 }
else if (fromEntry->
isArray) {
362 }
else if (fromEntry->
objClass == RelationContainer::Class()) {
370 fixAbsorbObjects(&fromRel->elements(), &toRel->elements());
373 fromRel->setModified(
true);
374 toRel->setModified(
true);
378 toEntry->
object = fromEntry->
ptr->Clone();
381 fromEntry->
ptr =
nullptr;
387 const TClonesArray* array =
static_cast<TClonesArray*
>(entry.
ptr);
388 const int nEntries = array->GetEntriesFast();
389 for (
int i = 0; i < nEntries; i++) {
391 relobj->m_cacheArrayIndex = i;
392 relobj->m_cacheDataStoreEntry = &entry;
398 if (!entry or index < 0) {
403 entry = relObj->m_cacheDataStoreEntry;
404 index = relObj->m_cacheArrayIndex;
408 if (entry && entry->
ptr && (index >= 0)) {
409 const TClonesArray* array =
static_cast<TClonesArray*
>(entry->
ptr);
410 if (array->At(index) ==
object)
return true;
411 B2INFO(
"findStoreEntry: cached index invalid, probably harmless but odd : " << entry->
name <<
" idx " << index);
412 index = array->IndexOf(
object);
413 if (index >= 0)
return true;
414 B2INFO(
"findStoreEntry: cached entry was also wrong");
424 const TClass* objectClass =
object->IsA();
426 if (mapEntry.second.ptr && mapEntry.second.isArray) {
427 const TClass* arrayClass = mapEntry.second.objClass;
428 if (arrayClass != objectClass)
431 const TClonesArray* array =
static_cast<TClonesArray*
>(mapEntry.second.ptr);
432 if (
object == array->Last()) {
434 index = array->GetLast();
436 if (arrayClass->InheritsFrom(RelationsObject::Class())) {
442 index =
static_cast<const RelationsObject*
>(object)->m_cacheArrayIndex;
443 if (index >= 0 and objEntry) {
450 index = array->IndexOf(
object);
455 entry = &mapEntry.second;
466 static vector<string> arrayNames;
469 static std::unordered_map<const TClass*, string> classToArrayName;
470 const auto& it = classToArrayName.find(arrayClass);
471 if (it != classToArrayName.end()) {
472 arrayNames.emplace_back(it->second);
475 classToArrayName[arrayClass] = result;
476 arrayNames.emplace_back(result);
478 }
else if (name ==
"ALL") {
480 if (mapEntry.second.object and mapEntry.second.isArray and mapEntry.second.objClass->InheritsFrom(arrayClass)) {
481 arrayNames.emplace_back(mapEntry.second.name);
485 arrayNames.emplace_back(name);
491 StoreEntry*& toEntry,
int& toIndex,
float weight,
const std::string& namedRelation)
493 if (!fromObject or !toObject)
498 B2FATAL(
"Couldn't find from-side entry for relation between " << fromObject->ClassName() <<
" and " << toObject->ClassName() <<
499 ". Please make sure the object is part of a StoreArray before adding a relation.");
504 B2FATAL(
"Couldn't find to-side entry for relation between " << fromObject->ClassName() <<
" and " << toObject->ClassName() <<
505 ". Please make sure the object is part of a StoreArray before adding a relation.");
512 B2FATAL(
"No relation '" << relationsName <<
513 "' found. Please register it (using StoreArray::registerRelationTo()) before trying to add relations.");
521 if (relContainer->isDefaultConstructed()) {
522 relContainer->setFromName(fromEntry->
name);
523 relContainer->setFromDurability(
c_Event);
524 relContainer->setToName(toEntry->
name);
525 relContainer->setToDurability(
c_Event);
529 TClonesArray& relations = relContainer->
elements();
530 new (relations.AddrAt(relations.GetLast() + 1))
RelationElement(fromIndex, toIndex, weight);
532 std::shared_ptr<RelationIndexContainer<TObject, TObject>> relIndex =
536 relIndex->index().emplace(fromIndex, toIndex, fromObject, toObject, weight);
539 relContainer->setModified(
true);
544 int& index,
const TClass* withClass,
const std::string& withName,
const std::string& namedRelation)
549 result.add(fromResult);
553 std::vector<RelationEntry> result;
559 const std::vector<string>& names =
getArrayNames(withName, withClass);
560 vector<string> relationNames;
563 for (
const std::string& name : names) {
566 entry->
name, namedRelation);
571 const size_t prevsize = result.size();
576 auto*
const toObject =
const_cast<TObject*
>(rel.to);
578 result.emplace_back(toObject, rel.weight);
582 auto*
const fromObject =
const_cast<TObject*
>(rel.from);
584 result.emplace_back(fromObject, rel.weight);
588 if (result.size() != prevsize)
589 relationNames.push_back(relationsName);
596 const TClass* withClass,
const std::string& withName,
const std::string& namedRelation)
600 if (!result.object) {
610 const std::vector<string>& names =
getArrayNames(withName, withClass);
613 for (
const std::string& name : names) {
616 entry->
name, namedRelation);
624 if (element && element->
to) {
629 if (element && element->
from) {
640 std::vector<std::string> arrays;
641 if (!array.isArray()) {
642 B2ERROR(
"getListOfRelatedArrays(): " << array.readableName() <<
" is not an array!");
649 if (mapEntry.second.isArray) {
650 const std::string& name = mapEntry.second.name;
653 for (
int searchSide = 0; searchSide <
c_BothSides; searchSide++) {
657 arrays.emplace_back(name);
673 for (
const auto& entrypair : map) {
674 if (!entrypair.second.isArray) {
675 const TObject* obj = entrypair.second.object;
679 if (obj and obj->IsA()->InheritsFrom(objClass))
680 list.emplace_back(entrypair.first);
690 for (
const auto& entrypair : map) {
691 if (!entrypair.second.isArray) {
692 const TObject* obj = entrypair.second.object;
694 list.emplace_back(entrypair.first);
703 std::vector<string> list;
704 std::vector<std::string> mergeContent =
getListOfObjects(TObject::Class(), durability);
705 list.insert(std::end(list), std::begin(mergeContent), std::end(mergeContent));
707 list.insert(std::end(list), std::begin(mergeContent), std::end(mergeContent));
709 list.insert(std::end(list), std::begin(mergeContent), std::end(mergeContent));
715 B2DEBUG(100,
"Invalidating objects for durability " << durability);
724 (accessor.
getClass() == RelationContainer::Class()));
726 B2FATAL(
"Attempt to require input " << accessor.
readableName() <<
727 " outside of the initialization phase. Please move isRequired() calls into your Module's initialize() function.");
731 B2ERROR(
"The required " << accessor.
readableName() <<
" does not exist. Maybe you forgot the module that registers it?");
741 (accessor.
getClass() == RelationContainer::Class()));
744 return (
getEntry(accessor) !=
nullptr);
748 std::string
const& namedRelation)
752 " outside of the initialization phase. Please move requireRelationTo() calls into your Module's initialize() function.");
756 B2FATAL(fromArray.
readableName() <<
" is not an array!");
765 std::string
const& namedRelation)
768 B2FATAL(fromArray.
readableName() <<
" is not an array!");
819DataStore::SwitchableDataStoreContents::SwitchableDataStoreContents():
822 m_idToIndexMap[
""] = 0;
851 std::vector<std::string> entrylist;
852 if (entrylist_event.size() == 1 and entrylist_event.at(0) ==
"ALL") {
855 entrylist = entrylist_event;
860 if (std::find(entrylist.begin(), entrylist.end(),
"EventMetaData") == entrylist.end()) {
861 entrylist.push_back(
"EventMetaData");
862 B2INFO(
"It is required to merge the 'EventMetaData' for consistency. Added.");
867 std::vector<std::string> skipEntries;
872 if (!entrylist.empty())
873 B2FATAL(
"entrlylist_event given for new DS id. This shouldn't happen, report to framework author.");
879 }
else if (!entrylist.empty()) {
884 B2FATAL(
"MergedArrayIndices already exists. This should not happen.");
886 m_entries[targetidx][
c_Event][
"MergedArrayIndices"] =
StoreEntry(
false, EventExtraInfo::Class(),
"MergedArrayIndices",
false);
888 for (std::string& entryname : entrylist) {
897 or
m_entries[targetidx][
c_Event][entryname].objClass == RelationContainer::Class()) {
902 B2FATAL(entryname +
"_indepPath already exists. This should not happen.");
905 entryname +
"_indepPath",
m_entries[targetidx][
c_Event][entryname].dontWriteOut);
907 skipEntries.push_back(entryname);
910 B2WARNING(
"Independent path: entry '" << entryname <<
"' already exists in DataStore '" <<
id <<
911 "'! This will likely break something.");
918 B2FATAL(
"no entrlylist_event given, not new DS id. This shouldn't happen, report to framework author.");
923 for (
auto& entrypair :
m_entries[targetidx][iDurability]) {
924 if (not entrypair.second.object)
925 B2FATAL(
"createNewDataStoreID(): object '" << entrypair.first <<
" already null (this should never happen).");
926 if (!entrylist.empty()) {
931 if (std::find(entrylist.begin(), entrylist.end(), entrypair.first) == entrylist.end())
934 if (std::find(skipEntries.begin(), skipEntries.end(), entrypair.first) != skipEntries.end())
938 entrypair.second.object =
nullptr;
939 entrypair.second.ptr =
nullptr;
951 for (
const auto& entrypair : sourceMaps[iDurability]) {
952 const StoreEntry& fromEntry = entrypair.second;
954 if (targetMaps[iDurability].count(fromEntry.
name) == 0) {
958 if (!entrylist_event.empty()) {
963 if (std::find(entrylist_event.begin(), entrylist_event.end(), fromEntry.
name) == entrylist_event.end())
970 if (not fromEntry.
ptr) {
972 target.recoverFromNullObject();
973 target.ptr =
nullptr;
976 delete target.object;
977 target.object = fromEntry.
object->Clone();
978 target.ptr = target.object;
987 if (entrylist_event.empty()) {
988 B2WARNING(
"Nothing to merge. Returning.");
992 std::vector<std::string> entrylist;
993 if (entrylist_event.size() == 1 and entrylist_event.at(0) ==
"ALL") {
996 entrylist = entrylist_event;
1000 auto& targetMaps =
m_entries[targetidx];
1004 if (targetMaps[
c_Event].count(
"MergedArrayIndices") == 0) {
1005 B2FATAL(
"Did not find MergedArrayIndices in target. This should not happen.");
1012 for (std::string nextEntry : entrylist) {
1013 for (
const auto& entrypair : sourceMaps[
c_Event]) {
1014 const StoreEntry& fromEntry = entrypair.second;
1015 if (fromEntry.
name != nextEntry) {
1020 if (targetMaps[
c_Event].count(fromEntry.
name) == 0) {
1027 if (!fromEntry.
ptr) {
1028 if (!target.object) {
1029 target.recoverFromNullObject();
1030 target.ptr =
nullptr;
1033 if (target.isArray) {
1034 arrayIndices->
addExtraInfo(target.name, target.getPtrAsArray()->GetEntriesFast());
1039 if (target.isArray) {
1041 target.object = fromEntry.
object->Clone();
1042 target.ptr = target.object;
1046 if (target.objClass != fromEntry.
objClass) {
1047 B2FATAL(
"Cannot merge StoreArrays " << target.name <<
"as they are of different classes.");
1050 arrayIndices->
addExtraInfo(target.name, target.getPtrAsArray()->GetEntriesFast());
1060 TClonesArray* fromArr =
static_cast<TClonesArray*
>(fromEntry.
getPtrAsArray()->Clone());
1061 fixAbsorbObjects(fromArr, target.getPtrAsArray());
1069 target.object = fromEntry.
object->Clone();
1070 target.ptr = target.object;
1073 if (fromEntry.
objClass == RelationContainer::Class()) {
1075 if (fromRelContainer->isDefaultConstructed()) {
1079 if (fromRelContainer->getEntries() == 0) {
1083 const std::string& fromName = fromRelContainer->
getFromName();
1084 const std::string& toName = fromRelContainer->getToName();
1088 B2WARNING(
"Skipping merging of relation " << fromEntry.
name
1089 <<
". The StoreArrays " << fromName <<
" and " << toName <<
" have to be merged before.");
1091 targetRelContainer->Clear();
1096 if (targetRelContainer->isDefaultConstructed()) {
1097 targetRelContainer->setFromName(fromName);
1098 targetRelContainer->setFromDurability(
c_Event);
1099 targetRelContainer->setToName(toName);
1100 targetRelContainer->setToDurability(
c_Event);
1104 TClonesArray& relations = targetRelContainer->
elements();
1110 for (
int i = 0; i < fromRelContainer->getEntries(); i++) {
1114 for (
size_t rel_idx = 0; rel_idx < rel.
getSize(); rel_idx++) {
1117 new (relations.AddrAt(relations.GetLast() + 1))
RelationElement(fromIndex, toIndex, weight);
1122 targetRelContainer->setModified(
true);
1126 std::string nameRenamed = fromEntry.
name +
"_indepPath";
1127 if (targetMaps[
c_Event].count(nameRenamed) == 0) {
1128 B2FATAL(
"Did not find " << nameRenamed <<
" in target. This should not happen.");
1132 target_renamed.
ptr = target_renamed.
object;
1149 B2FATAL(
"out of bounds in SwitchableDataStoreContents::switchID(): " <<
m_currentIdx <<
" >= size " <<
m_entries.size());
1168 for (
const auto& mapEntry : map[durability]) {
1169 delete mapEntry.second.object;
1171 map[durability].clear();
1178 for (
auto& mapEntry : map[durability])
1179 mapEntry.second.invalidate();
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.
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.
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 reset(EDurability durability)
Frees memory occupied by data store items and removes all objects from the map.
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.
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'.
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.
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.
static 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_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.
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).
static std::vector< std::string > getListOfRelations(EDurability durability)
Returns a list of names of StoreObjPtr-objects whose class is (or inherits from) RelationContainer.
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.
static std::vector< std::string > getListOfObjects(const TClass *objClass, EDurability durability)
Returns a list of names of StoreObjPtr-objects whose class is (or inherits from) objClass.
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.
bool requireInput(const StoreAccessorBase &accessor)
Produce ERROR message if no entry of the given type is registered in the DataStore.
EDurability
Durability types.
@ 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...
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(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)
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.
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.
static void checkType(const StoreEntry &entry, const StoreAccessorBase &accessor)
Check whether the given entry and the requested class match; if not, a B2FATAL is raised.
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.
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.
Collect information about the dependencies between modules.
@ c_Output
registered output.
@ c_OptionalInput
optional input.
Class to store relations between StoreArrays in the DataStore.
const std::string & getFromName() const
Get name of the StoreArray we relate from.
TClonesArray & elements()
Get reference to the elements.
Class to store a single element of a relation.
index_type getFromIndex() const
Get index we point from.
index_type getToIndex(size_t n=0) const
Get nth index we point to.
size_t getSize() const
Get number of indices we points to.
weight_type getWeight(size_t n=0) const
Get nth weight we point to.
std::shared_ptr< RelationIndexContainer< FROM, TO > > getIndexIfExists(const std::string &name, DataStore::EDurability durability) const
if the index exists in the cache, it is returned; otherwise NULL.
static RelationIndexManager & Instance()
Returns the singleton instance.
void clear(DataStore::EDurability durability=DataStore::c_Event)
Clear the cache of RelationIndexContainers with the given durability.
void reset()
Reset the cache completely, that is clear all caches and don't even keep the Index objects around.
Provides access to fast ( O(log n) ) bi-directional lookups on a specified relation.
const Element * getFirstElementFrom(const FROM &from) const
Return a pointer to the first relation Element of the given object.
range_from getElementsFrom(const FROM *from) const
Return a range of all elements pointing from the given object.
const Element * getFirstElementTo(const TO &to) const
Return a pointer to the first relation Element of the given object.
RelationIndexContainer< FROM, TO >::Element Element
Struct representing a single element in the index.
range_to getElementsTo(const TO *to) const
Return a range of all elements pointing to the given object.
base class for RelationVector<T>
Base class for StoreObjPtr and StoreArray for easier common treatment.
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.
std::string readableName() const
Convert this accessor into a readable string (for messages).
TClass * getClass() const
The underlying object's type.
bool isArray() const
Is this an accessor for an array?
RelationsInterface< TObject > RelationsObject
Provides interface for getting/adding relations to objects in StoreArrays.
Abstract base class for different kinds of events.
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.
TObject * ptr
The pointer to the returned object, either equal to 'object' or null, depending on whether the object...
TClonesArray * getPtrAsArray() const
Return ptr cast to TClonesArray.
bool dontWriteOut
Flag that indicates whether the object should be written to the output by default.
TObject * object
The pointer to the actual object.
bool isArray
Flag that indicates whether the object is a TClonesArray.
std::string name
Name of the entry.
void recreate()
Reset stored object to defaults, set ptr to new object.
TClass * objClass
class of object.