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 " <<
190 TClass* objClass,
bool array,
EStoreFlags storeFlags)
195 B2ERROR(
"Attempt to register " << accessor.
readableName() <<
196 " outside of the initialization phase. Please move calls to registerInDataStore() into your Module's initialize() function.");
211 B2ERROR(
"An " << accessor.
readableName() <<
" of type " << entry.
object->ClassName() <<
212 " 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.");
217 if (!
checkType(entry, accessor))
return false;
221 B2WARNING(
"Existing " << accessor.
readableName() <<
" has different persistency type than requested. Changing to " <<
222 (dontwriteout ?
"c_DontWriteOut" :
"c_WriteOut") <<
".");
226 B2DEBUG(100,
"An " << accessor.
readableName() <<
" was registered once more.");
231 if (array and name ==
"ALL") {
232 B2ERROR(
"Creating an array with the reserved name 'ALL' is not allowed!");
239 B2DEBUG(100,
"Successfully registered " << accessor.
readableName());
244 EStoreFlags storeFlags,
const std::string& namedRelation)
247 B2FATAL(fromArray.
readableName() <<
" is not an array!");
253 B2FATAL(
"Named Relations can only contain alphabetic characters, given was: " << namedRelation);
264 B2FATAL(
"Tried to create a relation '" << relName <<
"' with a durability larger than the StoreArrays it relates");
271 const std::string& namedRelation)
275 B2FATAL(fromArray.
readableName() <<
" is not an array!");
281 B2FATAL(
"Named Relations can only contain alphabetic characters, given was: " << namedRelation);
298 return &(it->second);
311 return &(entry->
ptr);
320 " exists in the DataStore, did you forget to register it in your Module's initialize() function? Note: direct accesses to it will crash!");
324 if (entry->
ptr && !replace &&
object != entry->
object) {
325 B2ERROR(
"An " << accessor.
readableName() <<
" was already created in the DataStore.");
330 if (
object != entry->
object) {
347 B2FATAL(
"No " << from.
readableName() <<
" exists in the DataStore!");
349 B2FATAL(
"No " << to.
readableName() <<
" exists in the DataStore!");
353 if (!fromEntry->
ptr) {
355 toEntry->
ptr =
nullptr;
356 }
else if (fromEntry->
isArray) {
363 }
else if (fromEntry->
objClass == RelationContainer::Class()) {
371 fixAbsorbObjects(&fromRel->elements(), &toRel->elements());
374 fromRel->setModified(
true);
375 toRel->setModified(
true);
379 toEntry->
object = fromEntry->
ptr->Clone();
382 fromEntry->
ptr =
nullptr;
388 const TClonesArray* array =
static_cast<TClonesArray*
>(entry.
ptr);
389 const int nEntries = array->GetEntriesFast();
390 for (
int i = 0; i < nEntries; i++) {
393 relobj->m_cacheDataStoreEntry = &entry;
399 if (!entry or index < 0) {
404 entry = relObj->m_cacheDataStoreEntry;
405 index = relObj->m_cacheArrayIndex;
409 if (entry && entry->
ptr && (index >= 0)) {
410 const TClonesArray* array =
static_cast<TClonesArray*
>(entry->
ptr);
411 if (array->At(index) == object)
return true;
412 B2INFO(
"findStoreEntry: cached index invalid, probably harmless but odd : " << entry->
name <<
" idx " << index);
413 index = array->IndexOf(
object);
414 if (index >= 0)
return true;
415 B2INFO(
"findStoreEntry: cached entry was also wrong");
425 const TClass* objectClass =
object->IsA();
427 if (mapEntry.second.ptr && mapEntry.second.isArray) {
428 const TClass* arrayClass = mapEntry.second.objClass;
429 if (arrayClass != objectClass)
432 const TClonesArray* array =
static_cast<TClonesArray*
>(mapEntry.second.ptr);
433 if (
object == array->Last()) {
435 index = array->GetLast();
437 if (arrayClass->InheritsFrom(RelationsObject::Class())) {
443 index =
static_cast<const RelationsObject*
>(object)->m_cacheArrayIndex;
444 if (index >= 0 and objEntry) {
451 index = array->IndexOf(
object);
456 entry = &mapEntry.second;
467 static vector<string> arrayNames;
470 static std::unordered_map<const TClass*, string> classToArrayName;
471 const auto& it = classToArrayName.find(arrayClass);
472 if (it != classToArrayName.end()) {
473 arrayNames.emplace_back(it->second);
476 classToArrayName[arrayClass] = result;
477 arrayNames.emplace_back(result);
479 }
else if (name ==
"ALL") {
481 if (mapEntry.second.object and mapEntry.second.isArray and mapEntry.second.objClass->InheritsFrom(arrayClass)) {
482 arrayNames.emplace_back(mapEntry.second.name);
486 arrayNames.emplace_back(name);
492 StoreEntry*& toEntry,
int& toIndex,
float weight,
const std::string& namedRelation)
494 if (!fromObject or !toObject)
499 B2FATAL(
"Couldn't find from-side entry for relation between " << fromObject->ClassName() <<
" and " << toObject->ClassName() <<
500 ". Please make sure the object is part of a StoreArray before adding a relation.");
505 B2FATAL(
"Couldn't find to-side entry for relation between " << fromObject->ClassName() <<
" and " << toObject->ClassName() <<
506 ". Please make sure the object is part of a StoreArray before adding a relation.");
513 B2FATAL(
"No relation '" << relationsName <<
514 "' found. Please register it (using StoreArray::registerRelationTo()) before trying to add relations.");
522 if (relContainer->isDefaultConstructed()) {
524 relContainer->setFromDurability(
c_Event);
525 relContainer->setToName(toEntry->
name);
526 relContainer->setToDurability(
c_Event);
530 TClonesArray& relations = relContainer->elements();
531 new (relations.AddrAt(relations.GetLast() + 1))
RelationElement(fromIndex, toIndex, weight);
533 std::shared_ptr<RelationIndexContainer<TObject, TObject>> relIndex =
537 relIndex->index().emplace(fromIndex, toIndex, fromObject, toObject, weight);
540 relContainer->setModified(
true);
545 int& index,
const TClass* withClass,
const std::string& withName,
const std::string& namedRelation)
550 result.add(fromResult);
554 std::vector<RelationEntry> result;
560 const std::vector<string>& names =
getArrayNames(withName, withClass);
561 vector<string> relationNames;
564 for (
const std::string& name : names) {
567 entry->
name, namedRelation);
572 const size_t prevsize = result.size();
577 auto*
const toObject =
const_cast<TObject*
>(rel.to);
579 result.emplace_back(toObject, rel.weight);
583 auto*
const fromObject =
const_cast<TObject*
>(rel.from);
585 result.emplace_back(fromObject, rel.weight);
589 if (result.size() != prevsize)
590 relationNames.push_back(relationsName);
597 const TClass* withClass,
const std::string& withName,
const std::string& namedRelation)
601 if (!result.object) {
611 const std::vector<string>& names =
getArrayNames(withName, withClass);
614 for (
const std::string& name : names) {
617 entry->
name, namedRelation);
625 if (element && element->to) {
626 return RelationEntry(
const_cast<TObject*
>(element->to), element->weight);
630 if (element && element->from) {
631 return RelationEntry(
const_cast<TObject*
>(element->from), element->weight);
641 std::vector<std::string> arrays;
643 B2ERROR(
"getListOfRelatedArrays(): " << array.
readableName() <<
" is not an array!");
650 if (mapEntry.second.isArray) {
651 const std::string& name = mapEntry.second.name;
654 for (
int searchSide = 0; searchSide <
c_BothSides; searchSide++) {
658 arrays.emplace_back(name);
674 for (
const auto& entrypair : map) {
675 if (!entrypair.second.isArray) {
676 const TObject* obj = entrypair.second.object;
680 if (obj and obj->IsA()->InheritsFrom(objClass))
681 list.emplace_back(entrypair.first);
691 for (
const auto& entrypair : map) {
692 if (!entrypair.second.isArray) {
693 const TObject* obj = entrypair.second.object;
695 list.emplace_back(entrypair.first);
704 std::vector<string> list;
705 std::vector<std::string> mergeContent =
getListOfObjects(TObject::Class(), durability);
706 list.insert(std::end(list), std::begin(mergeContent), std::end(mergeContent));
708 list.insert(std::end(list), std::begin(mergeContent), std::end(mergeContent));
710 list.insert(std::end(list), std::begin(mergeContent), std::end(mergeContent));
716 B2DEBUG(100,
"Invalidating objects for durability " << durability);
725 (accessor.
getClass() == RelationContainer::Class()));
727 B2FATAL(
"Attempt to require input " << accessor.
readableName() <<
728 " outside of the initialization phase. Please move isRequired() calls into your Module's initialize() function.");
732 B2ERROR(
"The required " << accessor.
readableName() <<
" does not exist. Maybe you forgot the module that registers it?");
742 (accessor.
getClass() == RelationContainer::Class()));
745 return (
getEntry(accessor) !=
nullptr);
749 std::string
const& namedRelation)
753 " outside of the initialization phase. Please move requireRelationTo() calls into your Module's initialize() function.");
757 B2FATAL(fromArray.
readableName() <<
" is not an array!");
766 std::string
const& namedRelation)
769 B2FATAL(fromArray.
readableName() <<
" is not an array!");
820DataStore::SwitchableDataStoreContents::SwitchableDataStoreContents():
823 m_idToIndexMap[
""] = 0;
840 if (m_idToIndexMap.count(
id) > 0)
843 int targetidx = m_entries.size();
844 m_idToIndexMap[id] = targetidx;
852 std::vector<std::string> entrylist;
853 if (entrylist_event.size() == 1 and entrylist_event.at(0) ==
"ALL") {
856 entrylist = entrylist_event;
861 if (std::find(entrylist.begin(), entrylist.end(),
"EventMetaData") == entrylist.end()) {
862 entrylist.push_back(
"EventMetaData");
863 B2INFO(
"It is required to merge the 'EventMetaData' for consistency. Added.");
868 std::vector<std::string> skipEntries;
871 if (m_idToIndexMap.count(
id) == 0) {
873 if (!entrylist.empty())
874 B2FATAL(
"entrlylist_event given for new DS id. This shouldn't happen, report to framework author.");
875 targetidx = m_entries.size();
876 m_idToIndexMap[id] = targetidx;
879 m_entries.push_back(m_entries[m_currentIdx]);
880 }
else if (!entrylist.empty()) {
881 targetidx = m_idToIndexMap.at(
id);
884 if (m_entries[targetidx][
c_Event].count(
"MergedArrayIndices") != 0) {
885 B2FATAL(
"MergedArrayIndices already exists. This should not happen.");
887 m_entries[targetidx][
c_Event][
"MergedArrayIndices"] =
StoreEntry(
false, EventExtraInfo::Class(),
"MergedArrayIndices",
false);
889 for (std::string& entryname : entrylist) {
891 if (m_entries[m_currentIdx][
c_Event].count(entryname) == 0) {
894 if (m_entries[targetidx][
c_Event].count(entryname) != 0) {
897 if (m_entries[targetidx][
c_Event][entryname].isArray
898 or m_entries[targetidx][
c_Event][entryname].objClass == RelationContainer::Class()) {
902 if (m_entries[targetidx][
c_Event].count(entryname +
"_indepPath") != 0) {
903 B2FATAL(entryname +
"_indepPath already exists. This should not happen.");
905 m_entries[targetidx][
c_Event][entryname +
"_indepPath"] =
StoreEntry(
false, m_entries[targetidx][
c_Event][entryname].objClass,
906 entryname +
"_indepPath", m_entries[targetidx][
c_Event][entryname].dontWriteOut);
908 skipEntries.push_back(entryname);
911 B2WARNING(
"Independent path: entry '" << entryname <<
"' already exists in DataStore '" <<
id <<
912 "'! This will likely break something.");
915 m_entries[targetidx][
c_Event][entryname] = m_entries[m_currentIdx][
c_Event][entryname];
919 B2FATAL(
"no entrlylist_event given, not new DS id. This shouldn't happen, report to framework author.");
924 for (
auto& entrypair : m_entries[targetidx][iDurability]) {
925 if (not entrypair.second.object)
926 B2FATAL(
"createNewDataStoreID(): object '" << entrypair.first <<
" already null (this should never happen).");
927 if (!entrylist.empty()) {
932 if (std::find(entrylist.begin(), entrylist.end(), entrypair.first) == entrylist.end())
935 if (std::find(skipEntries.begin(), skipEntries.end(), entrypair.first) != skipEntries.end())
939 entrypair.second.object =
nullptr;
940 entrypair.second.ptr =
nullptr;
947 int targetidx = m_idToIndexMap.at(
id);
948 auto& targetMaps = m_entries[targetidx];
949 const auto& sourceMaps = m_entries[m_currentIdx];
952 for (
const auto& entrypair : sourceMaps[iDurability]) {
953 const StoreEntry& fromEntry = entrypair.second;
955 if (targetMaps[iDurability].count(fromEntry.
name) == 0) {
959 if (!entrylist_event.empty()) {
964 if (std::find(entrylist_event.begin(), entrylist_event.end(), fromEntry.
name) == entrylist_event.end())
971 if (not fromEntry.
ptr) {
973 target.recoverFromNullObject();
974 target.ptr =
nullptr;
977 delete target.object;
978 target.object = fromEntry.
object->Clone();
979 target.ptr = target.object;
988 if (entrylist_event.empty()) {
989 B2WARNING(
"Nothing to merge. Returning.");
993 std::vector<std::string> entrylist;
994 if (entrylist_event.size() == 1 and entrylist_event.at(0) ==
"ALL") {
997 entrylist = entrylist_event;
1000 int targetidx = m_idToIndexMap.at(
id);
1001 auto& targetMaps = m_entries[targetidx];
1002 const auto& sourceMaps = m_entries[m_currentIdx];
1005 if (targetMaps[
c_Event].count(
"MergedArrayIndices") == 0) {
1006 B2FATAL(
"Did not find MergedArrayIndices in target. This should not happen.");
1013 for (std::string nextEntry : entrylist) {
1014 for (
const auto& entrypair : sourceMaps[
c_Event]) {
1015 const StoreEntry& fromEntry = entrypair.second;
1016 if (fromEntry.
name != nextEntry) {
1021 if (targetMaps[
c_Event].count(fromEntry.
name) == 0) {
1028 if (!fromEntry.
ptr) {
1029 if (!target.object) {
1030 target.recoverFromNullObject();
1031 target.ptr =
nullptr;
1034 if (target.isArray) {
1035 arrayIndices->
addExtraInfo(target.name, target.getPtrAsArray()->GetEntriesFast());
1040 if (target.isArray) {
1042 target.object = fromEntry.
object->Clone();
1043 target.ptr = target.object;
1047 if (target.objClass != fromEntry.
objClass) {
1048 B2FATAL(
"Cannot merge StoreArrays " << target.name <<
"as they are of different classes.");
1051 arrayIndices->
addExtraInfo(target.name, target.getPtrAsArray()->GetEntriesFast());
1061 TClonesArray* fromArr =
static_cast<TClonesArray*
>(fromEntry.
getPtrAsArray()->Clone());
1062 fixAbsorbObjects(fromArr, target.getPtrAsArray());
1070 target.object = fromEntry.
object->Clone();
1071 target.ptr = target.object;
1074 if (fromEntry.
objClass == RelationContainer::Class()) {
1076 if (fromRelContainer->isDefaultConstructed()) {
1080 if (fromRelContainer->getEntries() == 0) {
1084 const std::string& fromName = fromRelContainer->
getFromName();
1085 const std::string& toName = fromRelContainer->getToName();
1089 B2WARNING(
"Skipping merging of relation " << fromEntry.
name
1090 <<
". The StoreArrays " << fromName <<
" and " << toName <<
" have to be merged before.");
1092 targetRelContainer->Clear();
1097 if (targetRelContainer->isDefaultConstructed()) {
1098 targetRelContainer->setFromName(fromName);
1099 targetRelContainer->setFromDurability(
c_Event);
1100 targetRelContainer->setToName(toName);
1101 targetRelContainer->setToDurability(
c_Event);
1105 TClonesArray& relations = targetRelContainer->elements();
1111 for (
int i = 0; i < fromRelContainer->getEntries(); i++) {
1115 for (
size_t rel_idx = 0; rel_idx < rel.
getSize(); rel_idx++) {
1118 new (relations.AddrAt(relations.GetLast() + 1))
RelationElement(fromIndex, toIndex, weight);
1123 targetRelContainer->setModified(
true);
1127 std::string nameRenamed = fromEntry.
name +
"_indepPath";
1128 if (targetMaps[
c_Event].count(nameRenamed) == 0) {
1129 B2FATAL(
"Did not find " << nameRenamed <<
" in target. This should not happen.");
1133 target_renamed.
ptr = target_renamed.
object;
1147 m_currentIdx = m_idToIndexMap.at(
id);
1149 if ((
unsigned int)m_currentIdx >= m_entries.size())
1150 B2FATAL(
"out of bounds in SwitchableDataStoreContents::switchID(): " << m_currentIdx <<
" >= size " << m_entries.size());
1159 m_entries.resize(1);
1160 m_idToIndexMap.clear();
1161 m_idToIndexMap[
""] = 0;
1168 for (
auto& map : m_entries) {
1169 for (
auto& mapEntry : map[durability]) {
1170 delete mapEntry.second.object;
1172 map[durability].clear();
1178 for (
auto& map : m_entries)
1179 for (
auto& mapEntry : map[durability])
1180 mapEntry.second.invalidate();
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.
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.
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.
In the store you can park objects that have to be accessed by various modules.
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'.
std::vector< std::string > getListOfRelations(EDurability durability) const
Returns a list of names of StoreObjPtr-objects whose class is (or inherits from) RelationContainer.
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.
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_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).
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.
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.
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.
ModuleInfo & getCurrentModuleInfo()
Get info for current module.
void clear()
Reset all collected data.
Class to store relations between StoreArrays in the DataStore.
const std::string & getFromName() const
Get name of the StoreArray we relate from.
void setFromName(const std::string &name)
Set 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.
range_to getElementsTo(const TO *to) const
Return a range of all elements pointing to the given object.
base class for RelationVector<T>
Defines interface for accessing relations of objects in StoreArray.
int m_cacheArrayIndex
Cache of the index in the TClonesArray to which this object belongs.
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?
Abstract base class for different kinds of events.
void addEntry(const std::string &name, EEntryType type, bool isRelation)
Adds given entry/relation.
Element type for the index.
Wraps a stored array/object, stored under unique (name, durability) key.
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.