Belle II Software  release-05-02-19
DataStore.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Heck *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <framework/datastore/DataStore.h>
12 
13 #include <framework/logging/Logger.h>
14 #include <framework/datastore/RelationEntry.h>
15 #include <framework/datastore/DependencyMap.h>
16 #include <framework/dataobjects/RelationContainer.h>
17 #include <framework/datastore/RelationIndex.h>
18 #include <framework/datastore/RelationIndexManager.h>
19 #include <framework/datastore/RelationsObject.h>
20 #include <framework/datastore/StoreAccessorBase.h>
21 
22 #include <TClonesArray.h>
23 #include <TClass.h>
24 
25 #include <unordered_map>
26 #include <algorithm>
27 #include <cstdlib>
28 
29 using namespace std;
30 using namespace Belle2;
31 
32 namespace {
38  void cleanDataStore()
39  {
40  DataStore::Instance().reset();
41  }
42 
46  void fixAbsorbObjects(TClonesArray* from, TClonesArray* to)
47  {
48  to->AbsorbObjects(from, 0, from->GetEntriesFast() - 1);
49  }
50 }
51 
52 bool DataStore::s_DoCleanup = false;
53 
54 DataStore& DataStore::Instance()
55 {
56  static DataStore instance;
57  return instance;
58 }
59 
60 
61 DataStore::DataStore() : m_initializeActive(true), m_dependencyMap(new DependencyMap)
62 {
63 }
64 
66 {
67  if (s_DoCleanup) {
68  //release all memory in data store
69  reset();
70  }
71  delete m_dependencyMap;
72 }
73 
75 {
76  B2DEBUG(31, "DataStore::reset(): Removing all elements from DataStore");
77  m_initializeActive = true;
79 
80  for (int i = 0; i < c_NDurabilityTypes; i++)
81  reset((EDurability)i);
82 
84 }
85 
86 void DataStore::reset(EDurability durability)
87 {
88  m_storeEntryMap.reset(durability);
89 
90  //invalidate any cached relations (expect RelationArrays to remain valid)
92 }
93 
95 {
96  m_initializeActive = active;
97 
98  static bool firstCall = true;
99  if (firstCall) {
100  atexit(cleanDataStore);
101  firstCall = false;
102  }
103 }
104 
105 TClass* DataStore::getTClassFromDefaultObjectName(const std::string& objectName)
106 {
107  // First look for an name without the namespace Belle2::
108  TClass* cl = TClass::GetClass(("Belle2::" + objectName).c_str());
109  if (not cl) {
110  // If this fails look for a name that already has the full namespace.
111  cl = TClass::GetClass(objectName.c_str());
112  }
113  return cl;
114 }
115 
116 TClass* DataStore::getTClassFromDefaultArrayName(const std::string& arrayName)
117 {
118  if (arrayName.empty()) {
119  return nullptr;
120  } else if ('s' == arrayName.back()) {
121  std::string objectName = arrayName.substr(0, arrayName.size() - 1);
123  } else {
124  return nullptr;
125  }
126 }
127 
128 std::string DataStore::defaultObjectName(const std::string& classname)
129 {
130  const static string gfclass = "genfit::Track";
131  const static string gfobjectname = "GF2Track";
132  if (classname == gfclass)
133  return gfobjectname;
134  //Strip qualifiers like namespaces
135  size_t colon = classname.rfind(':');
136  if (colon != std::string::npos) {
137  return classname.substr(colon + 1);
138  }
139  return classname;
140 }
141 
142 
143 std::string DataStore::defaultObjectName(const TClass* t)
144 {
145  B2ASSERT("Cannot deduce default object name from null pointer TClass", t);
146  const std::string s = defaultObjectName(t->GetName());
147  return s;
148 }
149 
150 
151 std::string DataStore::objectName(const TClass* t, const std::string& name)
152 {
153  return ((name.empty()) ? defaultObjectName(t) : name);
154 }
155 
156 
157 std::string DataStore::defaultArrayName(const TClass* t)
158 {
159  const std::string s = defaultArrayName(defaultObjectName(t));
160  return s;
161 }
162 
163 
164 std::string DataStore::arrayName(const TClass* t, const std::string& name)
165 {
166  return ((name.empty()) ? defaultArrayName(t) : name);
167 }
168 
169 
170 bool DataStore::checkType(const StoreEntry& entry, const StoreAccessorBase& accessor) const
171 {
172  // Check whether the existing entry and the requested object are both arrays or both single objects
173  const char* entryType = (entry.isArray) ? "array" : "object";
174  if (entry.isArray != accessor.isArray()) {
175  B2FATAL("Existing entry '" << entry.name << "' is an " << entryType << " and the requested one an " << ((
176  accessor.isArray()) ? "array" : "object"));
177  }
178 
179  // Check whether the existing entry has the same type
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 " <<
183  accessor.getClass()->GetName());
184  }
185 
186  return true;
187 }
188 
189 
190 bool DataStore::registerEntry(const std::string& name, EDurability durability,
191  TClass* objClass, bool array, EStoreFlags storeFlags)
192 {
193  const StoreAccessorBase accessor(name, durability, objClass, array);
194  // Check whether this method is called in the initialization phase
195  if (!m_initializeActive) {
196  B2ERROR("Attempt to register " << accessor.readableName() <<
197  " outside of the initialization phase. Please move calls to registerInDataStore() into your Module's initialize() function.");
198  return false;
199  }
200  const bool dontwriteout = storeFlags & c_DontWriteOut;
201 
202  //add to current module's outputs
203  m_dependencyMap->getCurrentModuleInfo().addEntry(name, DependencyMap::c_Output, (objClass == RelationContainer::Class()));
204 
205  // Check whether the map entry already exists
206  const auto& it = m_storeEntryMap[durability].find(name);
207  if (it != m_storeEntryMap[durability].end()) {
208  StoreEntry& entry = it->second;
209 
210  // Complain about existing entry
211  if (storeFlags & c_ErrorIfAlreadyRegistered) {
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.");
214  return false;
215  }
216 
217  // Check whether the types match
218  if (!checkType(entry, accessor)) return false;
219 
220  // Check whether the persistency type matches
221  if (entry.dontWriteOut != dontwriteout) {
222  B2WARNING("Existing " << accessor.readableName() << " has different persistency type than requested. Changing to " <<
223  (dontwriteout ? "c_DontWriteOut" : "c_WriteOut") << ".");
224  entry.dontWriteOut = dontwriteout;
225  }
226 
227  B2DEBUG(100, "An " << accessor.readableName() << " was registered once more.");
228  return true;
229  }
230 
231  // check reserved names
232  if (array and name == "ALL") {
233  B2ERROR("Creating an array with the reserved name 'ALL' is not allowed!");
234  return false;
235  }
236 
237  // Add the DataStore entry
238  m_storeEntryMap[durability][name] = StoreEntry(array, objClass, name, dontwriteout);
239 
240  B2DEBUG(100, "Successfully registered " << accessor.readableName());
241  return true;
242 }
243 
244 bool DataStore::registerRelation(const StoreAccessorBase& fromArray, const StoreAccessorBase& toArray, EDurability durability,
245  EStoreFlags storeFlags, const std::string& namedRelation)
246 {
247  if (!fromArray.isArray())
248  B2FATAL(fromArray.readableName() << " is not an array!");
249  if (!toArray.isArray())
250  B2FATAL(toArray.readableName() << " is not an array!");
251 
252  // check the the namedRelation only contains regular characters
253  if (!std::regex_match(namedRelation, m_regexNamedRelationCheck))
254  B2FATAL("Named Relations can only contain alphabetic characters, given was: " << namedRelation);
255 
256  const std::string& relName = relationName(fromArray.getName(), toArray.getName(), namedRelation);
257  /*
258  if ((fromArray.notWrittenOut() or toArray.notWrittenOut()) and !(storeFlags & c_DontWriteOut)) {
259  B2WARNING("You're trying to register a persistent relation " << relName << " from/to an array which is not written out (DataStore::c_DontWriteOut flag)! Relation will also not be saved!");
260  storeFlags |= c_DontWriteOut;
261  }
262  */
263 
264  if (fromArray.getDurability() > durability or toArray.getDurability() > durability) {
265  B2FATAL("Tried to create a relation '" << relName << "' with a durability larger than the StoreArrays it relates");
266  }
267 
268  return DataStore::Instance().registerEntry(relName, durability, RelationContainer::Class(), false, storeFlags);
269 }
270 
271 bool DataStore::hasRelation(const StoreAccessorBase& fromArray, const StoreAccessorBase& toArray, EDurability durability,
272  const std::string& namedRelation)
273 {
274  // check that the input makes sense
275  if (!fromArray.isArray())
276  B2FATAL(fromArray.readableName() << " is not an array!");
277  if (!toArray.isArray())
278  B2FATAL(toArray.readableName() << " is not an array!");
279 
280  // check the the namedRelation only contains regular characters
281  if (!std::regex_match(namedRelation, m_regexNamedRelationCheck))
282  B2FATAL("Named Relations can only contain alphabetic characters, given was: " << namedRelation);
283 
284  // get the internal relation name from the name provided
285  const std::string& realname = relationName(fromArray.getName(), toArray.getName(), namedRelation);
286 
287  // check whether the map entry exists
288  const auto& it = m_storeEntryMap[durability].find(realname);
289  if (it != m_storeEntryMap[durability].end()) return true;
290 
291  return false;
292 }
293 
295 {
296  const auto& it = m_storeEntryMap[accessor.getDurability()].find(accessor.getName());
297 
298  if (it != m_storeEntryMap[accessor.getDurability()].end() and checkType((it->second), accessor)) {
299  return &(it->second);
300  } else {
301  return nullptr;
302  }
303 }
304 
305 
306 TObject** DataStore::getObject(const StoreAccessorBase& accessor)
307 {
308  StoreEntry* entry = getEntry(accessor);
309  if (!entry) {
310  return nullptr;
311  }
312  return &(entry->ptr);
313 }
314 
315 
316 bool DataStore::createObject(TObject* object, bool replace, const StoreAccessorBase& accessor)
317 {
318  StoreEntry* entry = getEntry(accessor);
319  if (!entry) {
320  B2ERROR("No " << accessor.readableName() <<
321  " exists in the DataStore, did you forget to register it in your Module's initialize() function? Note: direct accesses to it will crash!");
322  return false;
323  }
324 
325  if (entry->ptr && !replace && object != entry->object) {
326  B2ERROR("An " << accessor.readableName() << " was already created in the DataStore.");
327  return false;
328  }
329 
330  if (object) {
331  if (object != entry->object) {
332  delete entry->object;
333  entry->object = object;
334  }
335  entry->ptr = entry->object;
336  } else {
337  entry->recreate();
338  }
339 
340  return true;
341 }
342 
344 {
345  StoreEntry* fromEntry = getEntry(from);
346  StoreEntry* toEntry = getEntry(to);
347  if (!fromEntry)
348  B2FATAL("No " << from.readableName() << " exists in the DataStore!");
349  if (!toEntry)
350  B2FATAL("No " << to.readableName() << " exists in the DataStore!");
351  if (from.isArray() != to.isArray() or from.getClass() != to.getClass())
352  B2FATAL("cannot replace " << to.readableName() << " with " << from.readableName() << " (incompatible types)!");
353 
354  if (!fromEntry->ptr) {
355  //since we don't need to move any data, just invalidate toEntry instead.
356  toEntry->ptr = nullptr;
357  } else if (fromEntry->isArray) {
358  if (!toEntry->ptr)
359  toEntry->ptr = toEntry->object;
360  toEntry->getPtrAsArray()->Delete();
361 
362  fixAbsorbObjects(fromEntry->getPtrAsArray(), toEntry->getPtrAsArray());
363  updateRelationsObjectCache(*toEntry);
364  } else if (fromEntry->objClass == RelationContainer::Class()) {
365  if (!toEntry->ptr)
366  toEntry->ptr = toEntry->object;
367  auto* fromRel = static_cast<RelationContainer*>(fromEntry->ptr);
368  auto* toRel = static_cast<RelationContainer*>(toEntry->ptr);
369 
370  toRel->elements().Delete();
371 
372  fixAbsorbObjects(&fromRel->elements(), &toRel->elements());
373 
374  //indices need a rebuild
375  fromRel->setModified(true);
376  toRel->setModified(true);
377  } else {
378  delete toEntry->object;
379 
380  toEntry->object = fromEntry->ptr->Clone();
381  toEntry->ptr = toEntry->object;
382 
383  fromEntry->ptr = nullptr;
384  }
385 }
386 
388 {
389  const TClonesArray* array = static_cast<TClonesArray*>(entry.ptr);
390  const int nEntries = array->GetEntriesFast();
391  for (int i = 0; i < nEntries; i++) {
392  auto* relobj = static_cast<RelationsObject*>(array->At(i));
393  relobj->m_cacheArrayIndex = i;
394  relobj->m_cacheDataStoreEntry = &entry;
395  }
396 }
397 
398 bool DataStore::findStoreEntry(const TObject* object, DataStore::StoreEntry*& entry, int& index)
399 {
400  if (!entry or index < 0) {
401  //usually entry/index should be passed for RelationsObject,
402  //but there are exceptions -> let's check again
403  const auto* relObj = dynamic_cast<const RelationsObject*>(object);
404  if (relObj) {
405  entry = relObj->m_cacheDataStoreEntry;
406  index = relObj->m_cacheArrayIndex;
407  }
408  }
409  // check whether the cached information is (still) valid
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");
417  }
418  entry = nullptr;
419  index = -1;
420 
421  //searching for nullptr should be safe
422  if (!object)
423  return false;
424 
425  // search for the object and set the entry and index
426  const TClass* objectClass = object->IsA();
427  for (auto& mapEntry : m_storeEntryMap[c_Event]) {
428  if (mapEntry.second.ptr && mapEntry.second.isArray) {
429  const TClass* arrayClass = mapEntry.second.objClass;
430  if (arrayClass != objectClass)
431  continue;
432 
433  const TClonesArray* array = static_cast<TClonesArray*>(mapEntry.second.ptr);
434  if (object == array->Last()) {
435  //quickly find entry if it's at the end of the array
436  index = array->GetLast();
437  } else {
438  if (arrayClass->InheritsFrom(RelationsObject::Class())) {
439  //update cache for entire array
440  updateRelationsObjectCache(mapEntry.second);
441 
442  //if found, m_cacheArrayIndex is now correct, otherwise still -1
443  StoreEntry* objEntry = static_cast<const RelationsObject*>(object)->m_cacheDataStoreEntry;
444  index = static_cast<const RelationsObject*>(object)->m_cacheArrayIndex;
445  if (index >= 0 and objEntry) {
446  //if the cache of 'object' is filled, make sure to also set entry!
447  entry = objEntry;
448  return true;
449  }
450  } else {
451  //not a RelationsObject, so no caching
452  index = array->IndexOf(object);
453  }
454  }
455 
456  if (index >= 0) {
457  entry = &mapEntry.second;
458  return true;
459  }
460  }
461  }
462  return false;
463 }
464 
465 const std::vector<std::string>& DataStore::getArrayNames(const std::string& name, const TClass* arrayClass,
466  EDurability durability) const
467 {
468  static vector<string> arrayNames;
469  arrayNames.clear();
470  if (name.empty()) {
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);
475  } else {
476  const std::string& result = defaultArrayName(arrayClass->GetName());
477  classToArrayName[arrayClass] = result;
478  arrayNames.emplace_back(result);
479  }
480  } else if (name == "ALL") {
481  for (auto& mapEntry : m_storeEntryMap[durability]) {
482  if (mapEntry.second.object and mapEntry.second.isArray and mapEntry.second.objClass->InheritsFrom(arrayClass)) {
483  arrayNames.emplace_back(mapEntry.second.name);
484  }
485  }
486  } else {
487  arrayNames.emplace_back(name);
488  }
489  return arrayNames;
490 }
491 
492 void DataStore::addRelation(const TObject* fromObject, StoreEntry*& fromEntry, int& fromIndex, const TObject* toObject,
493  StoreEntry*& toEntry, int& toIndex, float weight, const std::string& namedRelation)
494 {
495  if (!fromObject or !toObject)
496  return;
497 
498  // get entry from which the relation points
499  if (!findStoreEntry(fromObject, fromEntry, fromIndex)) {
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.");
502  }
503 
504  // get entry to which the relation points
505  if (!findStoreEntry(toObject, toEntry, toIndex)) {
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.");
508  }
509 
510  // get the relations from -> to
511  const string& relationsName = relationName(fromEntry->name, toEntry->name, namedRelation);
512  const StoreEntryIter& it = m_storeEntryMap[c_Event].find(relationsName);
513  if (it == m_storeEntryMap[c_Event].end()) {
514  B2FATAL("No relation '" << relationsName <<
515  "' found. Please register it (using StoreArray::registerRelationTo()) before trying to add relations.");
516  }
517  StoreEntry* entry = &(it->second);
518 
519  // auto create relations if needed (both if null pointer, or uninitialised object read from TTree)
520  if (!entry->ptr)
521  entry->recreate();
522  auto* relContainer = static_cast<RelationContainer*>(entry->ptr);
523  if (relContainer->isDefaultConstructed()) {
524  relContainer->setFromName(fromEntry->name);
525  relContainer->setFromDurability(c_Event);
526  relContainer->setToName(toEntry->name);
527  relContainer->setToDurability(c_Event);
528  }
529 
530  // add relation
531  // cppcheck-suppress constVariable ; no, this can obviously not be const, we modify it in the next line, admittedly weirdly
532  TClonesArray& relations = relContainer->elements();
533  new(relations.AddrAt(relations.GetLast() + 1)) RelationElement(fromIndex, toIndex, weight);
534 
535  std::shared_ptr<RelationIndexContainer<TObject, TObject>> relIndex =
536  RelationIndexManager::Instance().getIndexIfExists<TObject, TObject>(relationsName, c_Event);
537  if (relIndex) {
538  // add it to index (so we avoid expensive rebuilding later)
539  relIndex->index().emplace(fromIndex, toIndex, fromObject, toObject, weight);
540  } else {
541  //mark for rebuilding later on
542  relContainer->setModified(true);
543  }
544 }
545 
547  int& index, const TClass* withClass, const std::string& withName, const std::string& namedRelation)
548 {
549  if (searchSide == c_BothSides) {
550  auto result = getRelationsWith(c_ToSide, object, entry, index, withClass, withName, namedRelation);
551  const auto& fromResult = getRelationsWith(c_FromSide, object, entry, index, withClass, withName, namedRelation);
552  result.add(fromResult);
553  return result;
554  }
555 
556  std::vector<RelationEntry> result;
557 
558  // get StoreEntry for 'object'
559  if (!findStoreEntry(object, entry, index)) return RelationVectorBase();
560 
561  // get names of store arrays to search
562  const std::vector<string>& names = getArrayNames(withName, withClass);
563  vector<string> relationNames;
564 
565  // loop over found store arrays
566  for (const std::string& name : names) {
567  // get the relations from -> to
568  const string& relationsName = (searchSide == c_ToSide) ? relationName(entry->name, name, namedRelation) : relationName(name,
569  entry->name, namedRelation);
570  RelationIndex<TObject, TObject> relIndex(relationsName, c_Event);
571  if (!relIndex)
572  continue;
573 
574  const size_t prevsize = result.size();
575 
576  //get relations with object
577  if (searchSide == c_ToSide) {
578  for (const auto& rel : relIndex.getElementsFrom(object)) {
579  auto* const toObject = const_cast<TObject*>(rel.to);
580  if (toObject)
581  result.emplace_back(toObject, rel.weight);
582  }
583  } else {
584  for (const auto& rel : relIndex.getElementsTo(object)) {
585  auto* const fromObject = const_cast<TObject*>(rel.from);
586  if (fromObject)
587  result.emplace_back(fromObject, rel.weight);
588  }
589  }
590 
591  if (result.size() != prevsize)
592  relationNames.push_back(relationsName);
593  }
594 
595  return RelationVectorBase(entry->name, index, result, relationNames);
596 }
597 
598 RelationEntry DataStore::getRelationWith(ESearchSide searchSide, const TObject* object, DataStore::StoreEntry*& entry, int& index,
599  const TClass* withClass, const std::string& withName, const std::string& namedRelation)
600 {
601  if (searchSide == c_BothSides) {
602  RelationEntry result = getRelationWith(c_ToSide, object, entry, index, withClass, withName, namedRelation);
603  if (!result.object) {
604  result = getRelationWith(c_FromSide, object, entry, index, withClass, withName, namedRelation);
605  }
606  return result;
607  }
608 
609  // get StoreEntry for 'object'
610  if (!findStoreEntry(object, entry, index)) return RelationEntry(nullptr);
611 
612  // get names of store arrays to search
613  const std::vector<string>& names = getArrayNames(withName, withClass);
614 
615  // loop over found store arrays
616  for (const std::string& name : names) {
617  // get the relations from -> to
618  const string& relationsName = (searchSide == c_ToSide) ? relationName(entry->name, name, namedRelation) : relationName(name,
619  entry->name, namedRelation);
620  RelationIndex<TObject, TObject> relIndex(relationsName, c_Event);
621  if (!relIndex)
622  continue;
623 
624  // get first element
625  if (searchSide == c_ToSide) {
626  const RelationIndex<TObject, TObject>::Element* element = relIndex.getFirstElementFrom(object);
627  if (element && element->to) {
628  return RelationEntry(const_cast<TObject*>(element->to), element->weight);
629  }
630  } else {
631  const RelationIndex<TObject, TObject>::Element* element = relIndex.getFirstElementTo(object);
632  if (element && element->from) {
633  return RelationEntry(const_cast<TObject*>(element->from), element->weight);
634  }
635  }
636  }
637 
638  return RelationEntry(nullptr);
639 }
640 
641 std::vector<std::string> DataStore::getListOfRelatedArrays(const StoreAccessorBase& array) const
642 {
643  std::vector<std::string> arrays;
644  if (!array.isArray()) {
645  B2ERROR("getListOfRelatedArrays(): " << array.readableName() << " is not an array!");
646  return arrays;
647  }
648 
649  //loop over all arrays
650  EDurability durability = array.getDurability();
651  for (auto& mapEntry : m_storeEntryMap[durability]) {
652  if (mapEntry.second.isArray) {
653  const std::string& name = mapEntry.second.name;
654 
655  //check both from & to 'array'
656  for (int searchSide = 0; searchSide < c_BothSides; searchSide++) {
657  const string& relationsName = (searchSide == c_ToSide) ? relationName(array.getName(), name) : relationName(name, array.getName());
658  const StoreEntryConstIter& it = m_storeEntryMap[durability].find(relationsName);
659  if (it != m_storeEntryMap[durability].end())
660  arrays.emplace_back(name);
661  }
662  }
663  }
664 
665  return arrays;
666 }
667 std::vector<std::string> DataStore::getListOfArrays(const TClass* arrayClass, EDurability durability) const
668 {
669  return getArrayNames("ALL", arrayClass, durability);
670 }
671 
672 std::vector<std::string> DataStore::getListOfObjects(const TClass* objClass, EDurability durability) const
673 {
674  vector<string> list;
676  for (const auto& entrypair : map) {
677  if (!entrypair.second.isArray) {
678  const TObject* obj = entrypair.second.object;
679  if (dynamic_cast<const RelationContainer*>(obj))
680  continue; //ignore relations in list
681 
682  if (obj and obj->IsA()->InheritsFrom(objClass))
683  list.emplace_back(entrypair.first);
684  }
685  }
686  return list;
687 }
688 
690 {
691  B2DEBUG(100, "Invalidating objects for durability " << durability);
692  m_storeEntryMap.invalidateData(durability);
694 }
695 
697 {
698  if (m_initializeActive) {
700  (accessor.getClass() == RelationContainer::Class()));
701  } else {
702  B2FATAL("Attempt to require input " << accessor.readableName() <<
703  " outside of the initialization phase. Please move isRequired() calls into your Module's initialize() function.");
704  }
705 
706  if (!getEntry(accessor)) {
707  B2ERROR("The required " << accessor.readableName() << " does not exist. Maybe you forgot the module that registers it?");
708  return false;
709  }
710  return true;
711 }
712 
714 {
715  if (m_initializeActive) {
717  (accessor.getClass() == RelationContainer::Class()));
718  }
719 
720  return (getEntry(accessor) != nullptr);
721 }
722 
723 bool DataStore::requireRelation(const StoreAccessorBase& fromArray, const StoreAccessorBase& toArray, EDurability durability,
724  std::string const& namedRelation)
725 {
726  if (!m_initializeActive) {
727  B2FATAL("Attempt to require relation " << fromArray.readableName() << " -> " << toArray.readableName() <<
728  " outside of the initialization phase. Please move requireRelationTo() calls into your Module's initialize() function.");
729  }
730 
731  if (!fromArray.isArray())
732  B2FATAL(fromArray.readableName() << " is not an array!");
733  if (!toArray.isArray())
734  B2FATAL(toArray.readableName() << " is not an array!");
735 
736  const std::string& relName = relationName(fromArray.getName(), toArray.getName(), namedRelation);
737  return DataStore::Instance().requireInput(StoreAccessorBase(relName, durability, RelationContainer::Class(), false));
738 }
739 
740 bool DataStore::optionalRelation(const StoreAccessorBase& fromArray, const StoreAccessorBase& toArray, EDurability durability,
741  std::string const& namedRelation)
742 {
743  if (!fromArray.isArray())
744  B2FATAL(fromArray.readableName() << " is not an array!");
745  if (!toArray.isArray())
746  B2FATAL(toArray.readableName() << " is not an array!");
747 
748  const std::string& relName = relationName(fromArray.getName(), toArray.getName(), namedRelation);
749  return DataStore::Instance().optionalInput(StoreAccessorBase(relName, durability, RelationContainer::Class(), false));
750 }
751 
752 
753 void DataStore::createNewDataStoreID(const std::string& id)
754 {
756 }
757 
758 std::string DataStore::currentID() const
759 {
760  return m_storeEntryMap.currentID();
761 }
762 
763 void DataStore::switchID(const std::string& id)
764 {
765  if (id == m_storeEntryMap.currentID())
766  return;
767 
768  //remember to clear caches
770 
772 }
773 
774 void DataStore::copyEntriesTo(const std::string& id, const std::vector<std::string>& entrylist_event)
775 {
776  m_storeEntryMap.copyEntriesTo(id, entrylist_event);
777 }
778 
779 void DataStore::copyContentsTo(const std::string& id, const std::vector<std::string>& entrylist_event)
780 {
781  m_storeEntryMap.copyContentsTo(id, entrylist_event);
782 }
783 
784 
785 DataStore::SwitchableDataStoreContents::SwitchableDataStoreContents():
786  m_entries(1)
787 {
788  m_idToIndexMap[""] = 0;
789 }
790 
792 {
793  //does this id already exist?
794  if (m_idToIndexMap.count(id) > 0)
795  return;
796 
797  copyEntriesTo(id);
798  //copy actual contents, fixing pointers
799  copyContentsTo(id);
800 }
801 void DataStore::SwitchableDataStoreContents::copyEntriesTo(const std::string& id, const std::vector<std::string>& entrylist_event)
802 {
803  int targetidx;
804  if (m_idToIndexMap.count(id) == 0) {
805  //new DataStore & full copy
806  if (!entrylist_event.empty())
807  B2FATAL("entrlylist_event given for new DS id. This shouldn't happen, report to framework author.");
808  targetidx = m_entries.size();
809  m_idToIndexMap[id] = targetidx;
810 
811  //copy entries
812  m_entries.push_back(m_entries[m_currentIdx]);
813  } else if (!entrylist_event.empty()) {
814  //copy only given entries (in c_Event)
815  targetidx = m_idToIndexMap.at(id);
816  for (const auto& entryname : entrylist_event) {
817  if (m_entries[m_currentIdx][c_Event].count(entryname) == 0)
818  continue;
819  if (m_entries[targetidx][c_Event].count(entryname) != 0) {
820  B2WARNING("Independent path: entry '" << entryname << "' already exists in DataStore '" << id <<
821  "'! This will likely break something.");
822  }
823  m_entries[targetidx][c_Event][entryname] = m_entries[m_currentIdx][c_Event][entryname];
824  }
825  } else {
826  B2FATAL("no entrlylist_event given, not new DS id. This shouldn't happen, report to framework author.");
827  }
828 
829  //fix duplicate pointers
830  for (int iDurability = 0; iDurability < c_NDurabilityTypes; iDurability++) {
831  for (auto& entrypair : m_entries[targetidx][iDurability]) {
832  if (not entrypair.second.object)
833  B2FATAL("createNewDataStoreID(): object '" << entrypair.first << " already null (this should never happen).");
834  if (!entrylist_event.empty()) {
835  //skip all entries of other durabilities
836  if (iDurability != c_Event)
837  continue;
838  //skip all entries not found in entrylist_event
839  if (std::find(entrylist_event.begin(), entrylist_event.end(), entrypair.first) == entrylist_event.end())
840  continue;
841  }
842 
843  entrypair.second.object = nullptr; //remove duplicate ownership
844  entrypair.second.ptr = nullptr;
845  }
846  }
847 }
848 
849 void DataStore::SwitchableDataStoreContents::copyContentsTo(const std::string& id, const std::vector<std::string>& entrylist_event)
850 {
851  int targetidx = m_idToIndexMap.at(id);
852  auto& targetMaps = m_entries[targetidx];
853  const auto& sourceMaps = m_entries[m_currentIdx];
854 
855  for (int iDurability = 0; iDurability < c_NDurabilityTypes; iDurability++) {
856  for (const auto& entrypair : sourceMaps[iDurability]) {
857  const StoreEntry& fromEntry = entrypair.second;
858  //does this exist in target?
859  if (targetMaps[iDurability].count(fromEntry.name) == 0) {
860  continue;
861  }
862 
863  if (!entrylist_event.empty()) {
864  //skip all entries of other durabilities
865  if (iDurability != c_Event)
866  continue;
867  //skip all entries not found in entrylist_event
868  if (std::find(entrylist_event.begin(), entrylist_event.end(), fromEntry.name) == entrylist_event.end())
869  continue;
870  }
871 
872  StoreEntry& target = targetMaps[iDurability][fromEntry.name];
873 
874  //copy contents into target object
875  if (not fromEntry.ptr) {
876  if (!target.object)
877  target.recoverFromNullObject();
878  target.ptr = nullptr;
879  } else {
880  //TODO there is some optimisation opportunity here, e.g. by only cloning the entries of a TClonesArray instead of the array itself
881  delete target.object;
882  target.object = fromEntry.object->Clone();
883  target.ptr = target.object;
884  }
885  }
886  }
887 
888 }
889 
891 {
892  //switch
893  m_currentID = id;
894  m_currentIdx = m_idToIndexMap.at(id);
895 
896  if ((unsigned int)m_currentIdx >= m_entries.size())
897  B2FATAL("out of bounds in SwitchableDataStoreContents::switchID(): " << m_currentIdx << " >= size " << m_entries.size());
898 }
899 
901 {
902  for (int i = 0; i < c_NDurabilityTypes; i++)
903  reset((EDurability)i);
904 
905  m_entries.clear();
906  m_entries.resize(1);
907  m_idToIndexMap.clear();
908  m_idToIndexMap[""] = 0;
909  m_currentID = "";
910  m_currentIdx = 0;
911 }
912 
914 {
915  for (auto& map : m_entries) {
916  for (auto& mapEntry : map[durability])
917  delete mapEntry.second.object;
918  map[durability].clear();
919  }
920 }
921 
923 {
924  for (auto& map : m_entries)
925  for (auto& mapEntry : map[durability])
926  mapEntry.second.invalidate();
927 }
Belle2::DataStore::SwitchableDataStoreContents::currentID
const std::string & currentID() const
returns ID of current DataStore.
Definition: DataStore.h:587
Belle2::DataStore::c_BothSides
@ c_BothSides
Combination of c_FromSide and c_ToSide.
Definition: DataStore.h:81
Belle2::StoreEntry::object
TObject * object
The pointer to the actual object.
Definition: StoreEntry.h:41
Belle2::DataStore::registerRelation
bool registerRelation(const StoreAccessorBase &fromArray, const StoreAccessorBase &toArray, EDurability durability, EStoreFlags storeFlags, const std::string &namedRelation)
Register a relation in the DataStore map.
Definition: DataStore.cc:244
Belle2::DataStore::updateRelationsObjectCache
static void updateRelationsObjectCache(StoreEntry &entry)
For an array containing RelationsObjects, update index and entry cache for entire contents.
Definition: DataStore.cc:387
Belle2::RelationIndexManager::Instance
static RelationIndexManager & Instance()
Returns the singleton instance.
Definition: RelationIndexManager.cc:14
Belle2::DataStore::m_initializeActive
bool m_initializeActive
True if modules are currently being initialized.
Definition: DataStore.h:608
Belle2::DataStore::StoreEntryIter
StoreEntryMap::iterator StoreEntryIter
Iterator for a StoreEntry map.
Definition: DataStore.h:90
Belle2::DataStore::SwitchableDataStoreContents::createNewDataStoreID
void createNewDataStoreID(const std::string &id)
creates new datastore with given id, copying the registered objects/arrays from the current one.
Definition: DataStore.cc:791
Belle2::DataStore::SwitchableDataStoreContents::m_idToIndexMap
std::map< std::string, int > m_idToIndexMap
Maps DataStore ID to index in m_entries.
Definition: DataStore.h:596
Belle2::RelationIndex::getFirstElementTo
const Element * getFirstElementTo(const TO &to) const
Return a pointer to the first relation Element of the given object.
Definition: RelationIndex.h:222
Belle2::DependencyMap::clear
void clear()
Reset all collected data.
Definition: DependencyMap.h:62
Belle2::DataStore::getListOfArrays
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.
Definition: DataStore.cc:667
Belle2::StoreAccessorBase::getDurability
DataStore::EDurability getDurability() const
Return durability with which the object is saved in the DataStore.
Definition: StoreAccessorBase.h:133
Belle2::DataStore::currentID
std::string currentID() const
returns ID of current DataStore.
Definition: DataStore.cc:758
Belle2::StoreAccessorBase::getClass
TClass * getClass() const
The underlying object's type.
Definition: StoreAccessorBase.h:151
Belle2::DataStore::SwitchableDataStoreContents::copyEntriesTo
void copyEntriesTo(const std::string &id, const std::vector< std::string > &entrylist_event={})
copy entries (not contents) of current DataStore to the DataStore with given ID.
Definition: DataStore.cc:801
Belle2::DataStore::Instance
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
Belle2::StoreAccessorBase::readableName
std::string readableName() const
Convert this acessor into a readable string (for messages).
Definition: StoreAccessorBase.cc:20
Belle2::DataStore::arrayName
static std::string arrayName(const TClass *t, const std::string &name)
Return the storage name for an object of the given TClass and name.
Definition: DataStore.cc:164
Belle2::DataStore::StoreEntryMap
std::map< std::string, StoreEntry > StoreEntryMap
Map for StoreEntries.
Definition: DataStore.h:89
Belle2::DependencyMap
Collect information about the dependencies between modules.
Definition: DependencyMap.h:22
Belle2::DataStore::ESearchSide
ESearchSide
Which side of relations should be returned?
Definition: DataStore.h:78
Belle2::DataStore::setInitializeActive
void setInitializeActive(bool active)
Setter for m_initializeActive.
Definition: DataStore.cc:94
Belle2::DataStore::SwitchableDataStoreContents::reset
void reset(EDurability durability)
Frees memory occupied by data store items and removes all objects from the map.
Definition: DataStore.cc:913
Belle2::RelationContainer
Class to store relations between StoreArrays in the DataStore.
Definition: RelationContainer.h:35
Belle2::DataStore::EStoreFlags
EStoreFlags
Flags describing behaviours of objects etc.
Definition: DataStore.h:71
Belle2::DataStore::addRelation
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.
Definition: DataStore.cc:492
Belle2::RelationIndex
Provides access to fast ( O(log n) ) bi-directional lookups on a specified relation.
Definition: RelationIndex.h:84
Belle2::StoreEntry
Wraps a stored array/object, stored under unique (name, durability) key.
Definition: StoreEntry.h:15
Belle2::DataStore::getListOfRelatedArrays
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'.
Definition: DataStore.cc:641
Belle2::StoreAccessorBase::getName
const std::string & getName() const
Return name under which the object is saved in the DataStore.
Definition: StoreAccessorBase.h:130
Belle2::RelationIndex::getFirstElementFrom
const Element * getFirstElementFrom(const FROM &from) const
Return a pointer to the first relation Element of the given object.
Definition: RelationIndex.h:199
Belle2::DataStore::replaceData
void replaceData(const StoreAccessorBase &from, const StoreAccessorBase &to)
For two StoreAccessors of same type, move all data in 'from' into 'to', discarding previous contents ...
Definition: DataStore.cc:343
Belle2::RelationIndexManager::reset
void reset()
Reset the cache completely, that is clear all caches and don't even keep the Index objects around.
Definition: RelationIndexManager.h:89
Belle2::StoreAccessorBase
Base class for StoreObjPtr and StoreArray for easier common treatment.
Definition: StoreAccessorBase.h:29
Belle2::RelationIndex::getElementsTo
range_to getElementsTo(const TO *to) const
Return a range of all elements pointing to the given object.
Definition: RelationIndex.h:179
Belle2::DataStore::defaultObjectName
static std::string defaultObjectName()
Return the default storage name for an object of the given type.
Definition: DataStore.h:129
Belle2::DataStore::c_DontWriteOut
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
Definition: DataStore.h:73
Belle2::DependencyMap::c_Output
@ c_Output
registered output.
Definition: DependencyMap.h:28
Belle2::DataStore::getObject
TObject ** getObject(const StoreAccessorBase &accessor)
Get a pointer to a pointer of an object in the DataStore.
Definition: DataStore.cc:306
Belle2::DataStore::hasRelation
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.
Definition: DataStore.cc:271
Belle2::DataStore::getArrayNames
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.
Definition: DataStore.cc:465
Belle2::RelationVectorBase
base class for RelationVector<T>
Definition: RelationVector.h:34
Belle2::DataStore::optionalInput
bool optionalInput(const StoreAccessorBase &accessor)
Register the given object/array as an optional input.
Definition: DataStore.cc:713
Belle2::StoreEntry::isArray
bool isArray
Flag that indicates whether the object is a TClonesArray.
Definition: StoreEntry.h:32
Belle2::DataStore::m_dependencyMap
DependencyMap * m_dependencyMap
Collect information about the dependencies between modules.
Definition: DataStore.h:617
Belle2::DataStore::getStoreEntryMap
StoreEntryMap & getStoreEntryMap(EDurability durability)
Get a reference to the object/array map.
Definition: DataStore.h:321
Belle2::DataStore::createNewDataStoreID
void createNewDataStoreID(const std::string &id)
creates new datastore with given id, copying the registered objects/arrays from the current one.
Definition: DataStore.cc:753
Belle2::StoreEntry::name
std::string name
Name of the entry.
Definition: StoreEntry.h:46
Belle2::DataStore::s_DoCleanup
static bool s_DoCleanup
Global flag to to decide if we can do normal cleanup.
Definition: DataStore.h:102
Belle2::DataStore::getTClassFromDefaultArrayName
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...
Definition: DataStore.cc:116
Belle2::RelationEntry
Struct for relations.
Definition: RelationEntry.h:26
Belle2::DataStore::copyEntriesTo
void copyEntriesTo(const std::string &id, const std::vector< std::string > &entrylist_event={})
copy entries (not contents) of current DataStore to the DataStore with given ID.
Definition: DataStore.cc:774
Belle2::DataStore::m_regexNamedRelationCheck
const std::regex m_regexNamedRelationCheck
Regular expression to check that no special characters and no white spaces are in the string given fo...
Definition: DataStore.h:614
Belle2::RelationElement
Class to store a single element of a relation.
Definition: RelationElement.h:33
Belle2::RelationIndexContainer::Element
Element type for the index.
Definition: RelationIndexContainer.h:62
Belle2::DataStore::getListOfObjects
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.
Definition: DataStore.cc:672
Belle2::StoreEntry::recreate
void recreate()
Reset stored object to defaults, set ptr to new object.
Definition: StoreEntry.cc:61
Belle2::RelationIndex::getElementsFrom
range_from getElementsFrom(const FROM *from) const
Return a range of all elements pointing from the given object.
Definition: RelationIndex.h:157
Belle2::DataStore::getRelationsWith
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.
Definition: DataStore.cc:546
Belle2::DependencyMap::ModuleInfo::addEntry
void addEntry(const std::string &name, EEntryType type, bool isRelation)
Adds given entry/relation.
Definition: DependencyMap.cc:14
Belle2::DataStore::copyContentsTo
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.
Definition: DataStore.cc:779
Belle2::DataStore::requireRelation
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...
Definition: DataStore.cc:723
Belle2::DataStore::m_storeEntryMap
SwitchableDataStoreContents m_storeEntryMap
Maps (name, durability) key to StoreEntry objects.
Definition: DataStore.h:601
Belle2::RelationContainer::setFromName
void setFromName(const std::string &name)
Set name of the StoreArray we relate from.
Definition: RelationContainer.h:54
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::DataStore::SwitchableDataStoreContents::switchID
void switchID(const std::string &id)
switch to DataStore with given ID.
Definition: DataStore.cc:890
Belle2::RelationContainer::elements
TClonesArray & elements()
Get reference to the elements.
Definition: RelationContainer.h:79
Belle2::DataStore::SwitchableDataStoreContents::copyContentsTo
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.
Definition: DataStore.cc:849
Belle2::DataStore::c_NDurabilityTypes
const static int c_NDurabilityTypes
Number of Durability Types.
Definition: DataStore.h:65
Belle2::DataStore::c_ToSide
@ c_ToSide
Return relations/objects pointed to (from a given object).
Definition: DataStore.h:80
Belle2::StoreAccessorBase::isArray
bool isArray() const
Is this an accessor for an array?
Definition: StoreAccessorBase.h:154
Belle2::DataStore::defaultArrayName
static std::string defaultArrayName()
Return the default storage name for an array of the given type.
Definition: DataStore.h:159
Belle2::RelationsInterface::m_cacheArrayIndex
int m_cacheArrayIndex
Cache of the index in the TClonesArray to which this object belongs.
Definition: RelationsObject.h:434
Belle2::DataStore::SwitchableDataStoreContents::clear
void clear()
same as calling reset() for all durabilities + all non-default datastore IDs are removed.
Definition: DataStore.cc:900
Belle2::RelationIndexManager::getIndexIfExists
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.
Definition: RelationIndexManager.h:109
Belle2::DataStore::registerEntry
bool registerEntry(const std::string &name, EDurability durability, TClass *objClass, bool array, EStoreFlags storeFlags)
Register an entry in the DataStore map.
Definition: DataStore.cc:190
Belle2::DataStore::switchID
void switchID(const std::string &id)
switch to DataStore with given ID.
Definition: DataStore.cc:763
Belle2::RelationIndexManager::clear
void clear(DataStore::EDurability durability=DataStore::c_Event)
Clear the cache of RelationIndexContainers with the given durability.
Definition: RelationIndexManager.cc:19
Belle2::DataStore::SwitchableDataStoreContents::invalidateData
void invalidateData(EDurability durability)
Clears all registered StoreEntry objects of a specified durability, invalidating all objects.
Definition: DataStore.cc:922
Belle2::DataStore::findStoreEntry
bool findStoreEntry(const TObject *object, StoreEntry *&entry, int &index)
Find an object in an array in the data store.
Definition: DataStore.cc:398
Belle2::StoreEntry::getPtrAsArray
TClonesArray * getPtrAsArray() const
Return ptr cast to TClonesArray.
Definition: StoreEntry.cc:76
Belle2::DataStore::~DataStore
~DataStore()
Destructor.
Definition: DataStore.cc:65
Belle2::DataStore::StoreEntry
Belle2::StoreEntry StoreEntry
Wraps a stored array/object, stored under unique (name, durability) key.
Definition: DataStore.h:86
Belle2::DataStore::c_ErrorIfAlreadyRegistered
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
Definition: DataStore.h:74
Belle2::DependencyMap::getCurrentModuleInfo
ModuleInfo & getCurrentModuleInfo()
Get info for current module.
Definition: DependencyMap.h:56
Belle2::DataStore::relationName
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.
Definition: DataStore.h:182
Belle2::StoreEntry::ptr
TObject * ptr
The pointer to the returned object, either equal to 'object' or null, depending on wether the object ...
Definition: StoreEntry.h:44
Belle2::DataStore::getTClassFromDefaultObjectName
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.
Definition: DataStore.cc:105
Belle2::DataStore::objectName
static std::string objectName(const TClass *t, const std::string &name)
Return the storage name for an object of the given TClass and name.
Definition: DataStore.cc:151
Belle2::DependencyMap::c_Input
@ c_Input
required input.
Definition: DependencyMap.h:26
Belle2::DataStore::StoreEntryConstIter
StoreEntryMap::const_iterator StoreEntryConstIter
const_iterator for a StoreEntry map.
Definition: DataStore.h:91
Belle2::DataStore::createObject
bool createObject(TObject *object, bool replace, const StoreAccessorBase &accessor)
Create a new object/array in the DataStore or add an existing one.
Definition: DataStore.cc:316
Belle2::DataStore::optionalRelation
bool optionalRelation(const StoreAccessorBase &fromArray, const StoreAccessorBase &toArray, EDurability durability, std::string const &namedRelation)
Register the given relation as an optional input.
Definition: DataStore.cc:740
Belle2::DataStore::getRelationWith
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.
Definition: DataStore.cc:598
Belle2::StoreEntry::objClass
TClass * objClass
class of object.
Definition: StoreEntry.h:34
Belle2::StoreEntry::dontWriteOut
bool dontWriteOut
Flag that indicates whether the object should be written to the output by default.
Definition: StoreEntry.h:33
Belle2::DataStore::getEntry
StoreEntry * getEntry(const StoreAccessorBase &accessor)
Check whether an entry with the correct type is registered in the DataStore map and return it.
Definition: DataStore.cc:294
Belle2::DataStore::checkType
bool checkType(const StoreEntry &entry, const StoreAccessorBase &accessor) const
Check whether the given entry and the requested class match.
Definition: DataStore.cc:170
Belle2::DataStore::c_Event
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
Definition: DataStore.h:61
Belle2::DataStore::invalidateData
void invalidateData(EDurability durability)
Clears all registered StoreEntry objects of a specified durability, invalidating all objects.
Definition: DataStore.cc:689
Belle2::DependencyMap::c_OptionalInput
@ c_OptionalInput
optional input.
Definition: DependencyMap.h:27
Belle2::DataStore::reset
void reset()
Clears contents of the datastore (all durabilities)
Definition: DataStore.cc:74
Belle2::DataStore
In the store you can park objects that have to be accessed by various modules.
Definition: DataStore.h:53
Belle2::RelationsInterface
Defines interface for accessing relations of objects in StoreArray.
Definition: RelationsObject.h:102
Belle2::DataStore::c_FromSide
@ c_FromSide
Return relations/objects pointed from (to a given object).
Definition: DataStore.h:79
Belle2::DataStore::requireInput
bool requireInput(const StoreAccessorBase &accessor)
Produce ERROR message if no entry of the given type is registered in the DataStore.
Definition: DataStore.cc:696
Belle2::DataStore::EDurability
EDurability
Durability types.
Definition: DataStore.h:60