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>
46 void fixAbsorbObjects(TClonesArray* from, TClonesArray* to)
48 to->AbsorbObjects(from, 0, from->GetEntriesFast() - 1);
76 B2DEBUG(31,
"DataStore::reset(): Removing all elements from DataStore");
98 static bool firstCall =
true;
100 atexit(cleanDataStore);
108 TClass* cl = TClass::GetClass((
"Belle2::" +
objectName).c_str());
130 const static string gfclass =
"genfit::Track";
131 const static string gfobjectname =
"GF2Track";
132 if (classname == gfclass)
135 size_t colon = classname.rfind(
':');
136 if (colon != std::string::npos) {
137 return classname.substr(colon + 1);
145 B2ASSERT(
"Cannot deduce default object name from null pointer TClass", t);
173 const char* entryType = (entry.
isArray) ?
"array" :
"object";
175 B2FATAL(
"Existing entry '" << entry.
name <<
"' is an " << entryType <<
" and the requested one an " << ((
176 accessor.
isArray()) ?
"array" :
"object"));
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 " <<
191 TClass* objClass,
bool array,
EStoreFlags storeFlags)
196 B2ERROR(
"Attempt to register " << accessor.
readableName() <<
197 " outside of the initialization phase. Please move calls to registerInDataStore() into your Module's initialize() function.");
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.");
218 if (!
checkType(entry, accessor))
return false;
222 B2WARNING(
"Existing " << accessor.
readableName() <<
" has different persistency type than requested. Changing to " <<
223 (dontwriteout ?
"c_DontWriteOut" :
"c_WriteOut") <<
".");
227 B2DEBUG(100,
"An " << accessor.
readableName() <<
" was registered once more.");
232 if (array and name ==
"ALL") {
233 B2ERROR(
"Creating an array with the reserved name 'ALL' is not allowed!");
240 B2DEBUG(100,
"Successfully registered " << accessor.
readableName());
245 EStoreFlags storeFlags,
const std::string& namedRelation)
248 B2FATAL(fromArray.
readableName() <<
" is not an array!");
254 B2FATAL(
"Named Relations can only contain alphabetic characters, given was: " << namedRelation);
265 B2FATAL(
"Tried to create a relation '" << relName <<
"' with a durability larger than the StoreArrays it relates");
272 const std::string& namedRelation)
276 B2FATAL(fromArray.
readableName() <<
" is not an array!");
282 B2FATAL(
"Named Relations can only contain alphabetic characters, given was: " << namedRelation);
299 return &(it->second);
312 return &(entry->
ptr);
321 " exists in the DataStore, did you forget to register it in your Module's initialize() function? Note: direct accesses to it will crash!");
325 if (entry->
ptr && !replace &&
object != entry->
object) {
326 B2ERROR(
"An " << accessor.
readableName() <<
" was already created in the DataStore.");
331 if (
object != entry->
object) {
348 B2FATAL(
"No " << from.
readableName() <<
" exists in the DataStore!");
350 B2FATAL(
"No " << to.
readableName() <<
" exists in the DataStore!");
354 if (!fromEntry->
ptr) {
356 toEntry->
ptr =
nullptr;
357 }
else if (fromEntry->
isArray) {
364 }
else if (fromEntry->
objClass == RelationContainer::Class()) {
372 fixAbsorbObjects(&fromRel->elements(), &toRel->elements());
375 fromRel->setModified(
true);
376 toRel->setModified(
true);
380 toEntry->
object = fromEntry->
ptr->Clone();
383 fromEntry->
ptr =
nullptr;
389 const TClonesArray* array =
static_cast<TClonesArray*
>(entry.
ptr);
390 const int nEntries = array->GetEntriesFast();
391 for (
int i = 0; i < nEntries; i++) {
394 relobj->m_cacheDataStoreEntry = &entry;
400 if (!entry or index < 0) {
405 entry = relObj->m_cacheDataStoreEntry;
406 index = relObj->m_cacheArrayIndex;
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");
426 const TClass* objectClass =
object->IsA();
428 if (mapEntry.second.ptr && mapEntry.second.isArray) {
429 const TClass* arrayClass = mapEntry.second.
objClass;
430 if (arrayClass != objectClass)
433 const TClonesArray* array =
static_cast<TClonesArray*
>(mapEntry.second.ptr);
434 if (
object == array->Last()) {
436 index = array->GetLast();
438 if (arrayClass->InheritsFrom(RelationsObject::Class())) {
444 index =
static_cast<const RelationsObject*
>(object)->m_cacheArrayIndex;
445 if (index >= 0 and objEntry) {
452 index = array->IndexOf(
object);
457 entry = &mapEntry.second;
468 static vector<string> arrayNames;
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);
477 classToArrayName[arrayClass] = result;
478 arrayNames.emplace_back(result);
480 }
else if (name ==
"ALL") {
482 if (mapEntry.second.object and mapEntry.second.isArray and mapEntry.second.objClass->InheritsFrom(arrayClass)) {
483 arrayNames.emplace_back(mapEntry.second.name);
487 arrayNames.emplace_back(name);
493 StoreEntry*& toEntry,
int& toIndex,
float weight,
const std::string& namedRelation)
495 if (!fromObject or !toObject)
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.");
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.");
514 B2FATAL(
"No relation '" << relationsName <<
515 "' found. Please register it (using StoreArray::registerRelationTo()) before trying to add relations.");
523 if (relContainer->isDefaultConstructed()) {
525 relContainer->setFromDurability(
c_Event);
526 relContainer->setToName(toEntry->
name);
527 relContainer->setToDurability(
c_Event);
531 TClonesArray& relations = relContainer->elements();
532 new (relations.AddrAt(relations.GetLast() + 1))
RelationElement(fromIndex, toIndex, weight);
534 std::shared_ptr<RelationIndexContainer<TObject, TObject>> relIndex =
538 relIndex->index().emplace(fromIndex, toIndex, fromObject, toObject, weight);
541 relContainer->setModified(
true);
546 int& index,
const TClass* withClass,
const std::string& withName,
const std::string& namedRelation)
551 result.add(fromResult);
555 std::vector<RelationEntry> result;
561 const std::vector<string>& names =
getArrayNames(withName, withClass);
562 vector<string> relationNames;
565 for (
const std::string& name : names) {
568 entry->
name, namedRelation);
573 const size_t prevsize = result.size();
578 auto*
const toObject =
const_cast<TObject*
>(rel.to);
580 result.emplace_back(toObject, rel.weight);
584 auto*
const fromObject =
const_cast<TObject*
>(rel.from);
586 result.emplace_back(fromObject, rel.weight);
590 if (result.size() != prevsize)
591 relationNames.push_back(relationsName);
598 const TClass* withClass,
const std::string& withName,
const std::string& namedRelation)
602 if (!result.object) {
612 const std::vector<string>& names =
getArrayNames(withName, withClass);
615 for (
const std::string& name : names) {
618 entry->
name, namedRelation);
626 if (element && element->
to) {
631 if (element && element->
from) {
642 std::vector<std::string> arrays;
644 B2ERROR(
"getListOfRelatedArrays(): " << array.
readableName() <<
" is not an array!");
651 if (mapEntry.second.isArray) {
652 const std::string& name = mapEntry.second.name;
655 for (
int searchSide = 0; searchSide <
c_BothSides; searchSide++) {
659 arrays.emplace_back(name);
675 for (
const auto& entrypair : map) {
676 if (!entrypair.second.isArray) {
677 const TObject* obj = entrypair.second.object;
681 if (obj and obj->IsA()->InheritsFrom(objClass))
682 list.emplace_back(entrypair.first);
692 for (
const auto& entrypair : map) {
693 if (!entrypair.second.isArray) {
694 const TObject* obj = entrypair.second.object;
696 list.emplace_back(entrypair.first);
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));
709 list.insert(std::end(list), std::begin(mergeContent), std::end(mergeContent));
711 list.insert(std::end(list), std::begin(mergeContent), std::end(mergeContent));
717 B2DEBUG(100,
"Invalidating objects for durability " << durability);
726 (accessor.
getClass() == RelationContainer::Class()));
728 B2FATAL(
"Attempt to require input " << accessor.
readableName() <<
729 " outside of the initialization phase. Please move isRequired() calls into your Module's initialize() function.");
733 B2ERROR(
"The required " << accessor.
readableName() <<
" does not exist. Maybe you forgot the module that registers it?");
743 (accessor.
getClass() == RelationContainer::Class()));
746 return (
getEntry(accessor) !=
nullptr);
750 std::string
const& namedRelation)
754 " outside of the initialization phase. Please move requireRelationTo() calls into your Module's initialize() function.");
758 B2FATAL(fromArray.
readableName() <<
" is not an array!");
767 std::string
const& namedRelation)
770 B2FATAL(fromArray.
readableName() <<
" is not an array!");
821DataStore::SwitchableDataStoreContents::SwitchableDataStoreContents():
824 m_idToIndexMap[
""] = 0;
841 if (m_idToIndexMap.count(
id) > 0)
844 int targetidx = m_entries.size();
845 m_idToIndexMap[id] = targetidx;
853 std::vector<std::string> entrylist;
854 if (entrylist_event.size() == 1 and entrylist_event.at(0) ==
"ALL") {
857 entrylist = entrylist_event;
862 if (std::find(entrylist.begin(), entrylist.end(),
"EventMetaData") == entrylist.end()) {
863 entrylist.push_back(
"EventMetaData");
864 B2INFO(
"It is required to merge the 'EventMetaData' for consistency. Added.");
869 std::vector<std::string> skipEntries;
872 if (m_idToIndexMap.count(
id) == 0) {
874 if (!entrylist.empty())
875 B2FATAL(
"entrlylist_event given for new DS id. This shouldn't happen, report to framework author.");
876 targetidx = m_entries.size();
877 m_idToIndexMap[id] = targetidx;
880 m_entries.push_back(m_entries[m_currentIdx]);
881 }
else if (!entrylist.empty()) {
882 targetidx = m_idToIndexMap.at(
id);
885 if (m_entries[targetidx][
c_Event].count(
"MergedArrayIndices") != 0) {
886 B2FATAL(
"MergedArrayIndices already exists. This should not happen.");
888 m_entries[targetidx][
c_Event][
"MergedArrayIndices"] =
StoreEntry(
false, EventExtraInfo::Class(),
"MergedArrayIndices",
false);
890 for (std::string& entryname : entrylist) {
892 if (m_entries[m_currentIdx][
c_Event].count(entryname) == 0) {
895 if (m_entries[targetidx][
c_Event].count(entryname) != 0) {
898 if (m_entries[targetidx][
c_Event][entryname].isArray
899 or m_entries[targetidx][
c_Event][entryname].objClass == RelationContainer::Class()) {
903 if (m_entries[targetidx][
c_Event].count(entryname +
"_indepPath") != 0) {
904 B2FATAL(entryname +
"_indepPath already exists. This should not happen.");
906 m_entries[targetidx][
c_Event][entryname +
"_indepPath"] =
StoreEntry(
false, m_entries[targetidx][
c_Event][entryname].objClass,
907 entryname +
"_indepPath", m_entries[targetidx][
c_Event][entryname].dontWriteOut);
909 skipEntries.push_back(entryname);
912 B2WARNING(
"Independent path: entry '" << entryname <<
"' already exists in DataStore '" <<
id <<
913 "'! This will likely break something.");
916 m_entries[targetidx][
c_Event][entryname] = m_entries[m_currentIdx][
c_Event][entryname];
920 B2FATAL(
"no entrlylist_event given, not new DS id. This shouldn't happen, report to framework author.");
925 for (
auto& entrypair : m_entries[targetidx][iDurability]) {
926 if (not entrypair.second.object)
927 B2FATAL(
"createNewDataStoreID(): object '" << entrypair.first <<
" already null (this should never happen).");
928 if (!entrylist.empty()) {
933 if (std::find(entrylist.begin(), entrylist.end(), entrypair.first) == entrylist.end())
936 if (std::find(skipEntries.begin(), skipEntries.end(), entrypair.first) != skipEntries.end())
940 entrypair.second.object =
nullptr;
941 entrypair.second.ptr =
nullptr;
948 int targetidx = m_idToIndexMap.at(
id);
949 auto& targetMaps = m_entries[targetidx];
950 const auto& sourceMaps = m_entries[m_currentIdx];
953 for (
const auto& entrypair : sourceMaps[iDurability]) {
954 const StoreEntry& fromEntry = entrypair.second;
956 if (targetMaps[iDurability].count(fromEntry.
name) == 0) {
960 if (!entrylist_event.empty()) {
965 if (std::find(entrylist_event.begin(), entrylist_event.end(), fromEntry.
name) == entrylist_event.end())
972 if (not fromEntry.
ptr) {
974 target.recoverFromNullObject();
975 target.ptr =
nullptr;
978 delete target.object;
979 target.object = fromEntry.
object->Clone();
980 target.ptr = target.object;
989 if (entrylist_event.empty()) {
990 B2WARNING(
"Nothing to merge. Returning.");
994 std::vector<std::string> entrylist;
995 if (entrylist_event.size() == 1 and entrylist_event.at(0) ==
"ALL") {
998 entrylist = entrylist_event;
1001 int targetidx = m_idToIndexMap.at(
id);
1002 auto& targetMaps = m_entries[targetidx];
1003 const auto& sourceMaps = m_entries[m_currentIdx];
1006 if (targetMaps[
c_Event].count(
"MergedArrayIndices") == 0) {
1007 B2FATAL(
"Did not find MergedArrayIndices in target. This should not happen.");
1014 for (std::string nextEntry : entrylist) {
1015 for (
const auto& entrypair : sourceMaps[
c_Event]) {
1016 const StoreEntry& fromEntry = entrypair.second;
1017 if (fromEntry.
name != nextEntry) {
1022 if (targetMaps[
c_Event].count(fromEntry.
name) == 0) {
1029 if (!fromEntry.
ptr) {
1030 if (!target.object) {
1031 target.recoverFromNullObject();
1032 target.ptr =
nullptr;
1035 if (target.isArray) {
1036 arrayIndices->
addExtraInfo(target.name, target.getPtrAsArray()->GetEntriesFast());
1041 if (target.isArray) {
1043 target.object = fromEntry.
object->Clone();
1044 target.ptr = target.object;
1048 if (target.objClass != fromEntry.
objClass) {
1049 B2FATAL(
"Cannot merge StoreArrays " << target.name <<
"as they are of different classes.");
1052 arrayIndices->
addExtraInfo(target.name, target.getPtrAsArray()->GetEntriesFast());
1062 TClonesArray* fromArr =
static_cast<TClonesArray*
>(fromEntry.
getPtrAsArray()->Clone());
1063 fixAbsorbObjects(fromArr, target.getPtrAsArray());
1071 target.object = fromEntry.
object->Clone();
1072 target.ptr = target.object;
1075 if (fromEntry.
objClass == RelationContainer::Class()) {
1077 if (fromRelContainer->isDefaultConstructed()) {
1081 if (fromRelContainer->getEntries() == 0) {
1085 const std::string& fromName = fromRelContainer->
getFromName();
1086 const std::string& toName = fromRelContainer->getToName();
1090 B2WARNING(
"Skipping merging of relation " << fromEntry.
name
1091 <<
". The StoreArrays " << fromName <<
" and " << toName <<
" have to be merged before.");
1093 targetRelContainer->Clear();
1098 if (targetRelContainer->isDefaultConstructed()) {
1099 targetRelContainer->setFromName(fromName);
1100 targetRelContainer->setFromDurability(
c_Event);
1101 targetRelContainer->setToName(toName);
1102 targetRelContainer->setToDurability(
c_Event);
1106 TClonesArray& relations = targetRelContainer->elements();
1112 for (
int i = 0; i < fromRelContainer->getEntries(); i++) {
1116 for (
size_t rel_idx = 0; rel_idx < rel.
getSize(); rel_idx++) {
1119 new (relations.AddrAt(relations.GetLast() + 1))
RelationElement(fromIndex, toIndex, weight);
1124 targetRelContainer->setModified(
true);
1128 std::string nameRenamed = fromEntry.
name +
"_indepPath";
1129 if (targetMaps[
c_Event].count(nameRenamed) == 0) {
1130 B2FATAL(
"Did not find " << nameRenamed <<
" in target. This should not happen.");
1134 target_renamed.
ptr = target_renamed.
object;
1148 m_currentIdx = m_idToIndexMap.at(
id);
1150 if ((
unsigned int)m_currentIdx >= m_entries.size())
1151 B2FATAL(
"out of bounds in SwitchableDataStoreContents::switchID(): " << m_currentIdx <<
" >= size " << m_entries.size());
1160 m_entries.resize(1);
1161 m_idToIndexMap.clear();
1162 m_idToIndexMap[
""] = 0;
1169 for (
auto& map : m_entries) {
1170 for (
auto& mapEntry : map[durability]) {
1171 delete mapEntry.second.object;
1173 map[durability].clear();
1179 for (
auto& map : m_entries)
1180 for (
auto& mapEntry : map[durability])
1181 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 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?
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.
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.
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 wether 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.