Belle II Software development
StoreAccessorBase.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <framework/datastore/StoreAccessorBase.h>
10#include <framework/logging/Logger.h>
11
12#include <TClass.h>
13#include <TClonesArray.h>
14#include <TObject.h>
15
16using namespace Belle2;
17
19{
20 std::string str(isArray() ? "array" : "object");
21 str += " '" + getName() + "' (durability: ";
22 switch (getDurability()) {
24 str += "event";
25 break;
27 str += "persistent";
28 break;
29 }
30 return str + ")";
31}
32
33bool StoreAccessorBase::assign(TObject* object, bool replace)
34{
35 if (not object)
36 return false;
37
38 bool success = false;
39 const bool objIsArray = (object->IsA() == TClonesArray::Class());
40 TClass* objClass = objIsArray ? (static_cast<TClonesArray*>(object))->GetClass() : object->IsA();
41 if (objIsArray != isArray()) {
42 B2ERROR("Cannot assign an object to an array (or vice versa); while assigning to " << readableName());
43 } else if (objClass != getClass()) {
44 B2ERROR("Cannot assign() an object of type '" << objClass->GetName() << "' to " << readableName() << " of type '" <<
45 getClass()->GetName() << "'!");
46 } else {
47 success = DataStore::Instance().createObject(object, replace, *this);
48 }
49 if (!success)
50 delete object;
51 return success;
52}
54{
56 if (!entry) {
57 B2ERROR("notWrittenOut(): " << readableName() << " doesn't seem to be registered");
58 return false;
59 }
60 return entry->dontWriteOut;
61}
@ c_Persistent
Object is available during entire execution time.
Definition DataStore.h:60
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
Definition DataStore.h:59
Belle2::StoreEntry StoreEntry
Wraps a stored array/object, stored under unique (name, durability) key.
Definition DataStore.h:84
static DataStore & Instance()
Instance of singleton Store.
Definition DataStore.cc:53
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:293
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:315
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.
bool notWrittenOut() const
Returns true if this object/array should not be saved by output modules.
std::string readableName() const
Convert this accessor into a readable string (for messages).
bool assign(TObject *object, bool replace=false)
Assign 'object' to this accessor.
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.
bool dontWriteOut
Flag that indicates whether the object should be written to the output by default.
Definition StoreEntry.h:40