Belle II Software light-2406-ragdoll
StoreAccessorBase Class Reference

Base class for StoreObjPtr and StoreArray for easier common treatment. More...

#include <StoreAccessorBase.h>

Inheritance diagram for StoreAccessorBase:
Collaboration diagram for StoreAccessorBase:

Public Member Functions

 StoreAccessorBase (const std::string &name, DataStore::EDurability durability, TClass *objClass, bool isArray)
 Constructor to access an object or array in the DataStore.
 
virtual ~StoreAccessorBase ()
 Destructor.
 
bool registerInDataStore (DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
 Register the object/array in the DataStore.
 
bool registerInDataStore (const std::string &name, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
 Register the object/array in the DataStore.
 
bool isRequired (const std::string &name="")
 Ensure this array/object has been registered previously.
 
bool isOptional (const std::string &name="")
 Tell the DataStore about an optional input.
 
bool create (bool replace=false)
 Create a default object in the data store.
 
bool assign (TObject *object, bool replace=false)
 Assign 'object' to this accessor.
 
virtual void clear ()
 Clear contents of this object.
 
const std::string & getName () const
 Return name under which the object is saved in the DataStore.
 
DataStore::EDurability getDurability () const
 Return durability with which the object is saved in the DataStore.
 
AccessorParams getAccessorParams () const
 Return pair of name and durability under which stored object is saved.
 
virtual bool operator== (const StoreAccessorBase &other) const
 Check if two store accessors point to the same object/array.
 
virtual bool operator!= (const StoreAccessorBase &other) const
 Check if two store accessors point to a different object/array.
 
TClass * getClass () const
 The underlying object's type.
 
bool isArray () const
 Is this an accessor for an array?
 
bool notWrittenOut () const
 Returns true if this object/array should not be saved by output modules.
 
std::string readableName () const
 Convert this acessor into a readable string (for messages).
 

Protected Attributes

std::string m_name
 Store name under which this object/array is saved.
 
DataStore::EDurability m_durability
 Store durability under which the object/array is saved.
 
TClass * m_class
 The underlying object's type.
 
bool m_isArray
 Is this an accessor for an array?
 

Detailed Description

Base class for StoreObjPtr and StoreArray for easier common treatment.


Definition at line 27 of file StoreAccessorBase.h.

Constructor & Destructor Documentation

◆ StoreAccessorBase()

StoreAccessorBase ( const std::string &  name,
DataStore::EDurability  durability,
TClass *  objClass,
bool  isArray 
)
inline

Constructor to access an object or array in the DataStore.

Parameters
nameName under which the object is stored in the DataStore.
durabilityDecides durability map used for getting the accessed object.
objClassType of the object
isArraytrue if the entry in the DataStore is an array

Definition at line 37 of file StoreAccessorBase.h.

37 :
38 m_name(name), m_durability(durability), m_class(objClass), m_isArray(isArray) {}
DataStore::EDurability m_durability
Store durability under which the object/array is saved.
bool m_isArray
Is this an accessor for an array?
std::string m_name
Store name under which this object/array is saved.
bool isArray() const
Is this an accessor for an array?
TClass * m_class
The underlying object's type.

◆ ~StoreAccessorBase()

virtual ~StoreAccessorBase ( )
inlinevirtual

Destructor.

Virtual because this is a base class.

Definition at line 44 of file StoreAccessorBase.h.

44{}

Member Function Documentation

◆ assign()

bool assign ( TObject *  object,
bool  replace = false 
)

Assign 'object' to this accessor.

(takes ownership).

Parameters
objectThe object that should be put in the DataStore, should be of same type as the one used by this accessor.
replaceShould an existing object be replaced? (if existing and supplied object are equal, this has no effect)
Returns
True if the assignment succeeded. If false, assign() will delete 'object', do not use it afterwards.

Definition at line 33 of file StoreAccessorBase.cc.

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}
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
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
std::string readableName() const
Convert this acessor into a readable string (for messages).
TClass * getClass() const
The underlying object's type.

◆ clear()

◆ create()

bool create ( bool  replace = false)
inline

Create a default object in the data store.

This only works after registerInDataStore() has been called by this or another module.

Parameters
replaceShould an existing object be replaced?
Returns
True if the creation succeeded.

Definition at line 107 of file StoreAccessorBase.h.

108 {
109 return DataStore::Instance().createObject(0, replace, *this);
110 }

◆ getAccessorParams()

AccessorParams getAccessorParams ( ) const
inline

Return pair of name and durability under which stored object is saved.


Definition at line 134 of file StoreAccessorBase.h.

134{ return make_pair(m_name, m_durability);}

◆ getClass()

TClass * getClass ( ) const
inline

The underlying object's type.

Definition at line 149 of file StoreAccessorBase.h.

149{ return m_class; }

◆ getDurability()

DataStore::EDurability getDurability ( ) const
inline

Return durability with which the object is saved in the DataStore.

Definition at line 131 of file StoreAccessorBase.h.

131{ return m_durability; }

◆ getName()

const std::string & getName ( ) const
inline

Return name under which the object is saved in the DataStore.

Definition at line 128 of file StoreAccessorBase.h.

128{ return m_name; }

◆ isArray()

bool isArray ( ) const
inline

Is this an accessor for an array?

Definition at line 152 of file StoreAccessorBase.h.

152{ return m_isArray; }

◆ isOptional()

bool isOptional ( const std::string &  name = "")
inline

Tell the DataStore about an optional input.

Mainly useful for creating diagrams of module inputs and outputs.

Parameters
nameIf not empty, set non-default name for this object/array. This is permanent, so that e.g. after using registerInDataStore("myName") in initialize(), this object will continue refer to 'myName' in event().
Returns
True if the object/array exists.

Definition at line 93 of file StoreAccessorBase.h.

94 {
95 if (!name.empty())
96 m_name = name;
97 return DataStore::Instance().optionalInput(*this);
98 }
bool optionalInput(const StoreAccessorBase &accessor)
Register the given object/array as an optional input.
Definition: DataStore.cc:739

◆ isRequired()

bool isRequired ( const std::string &  name = "")
inline

Ensure this array/object has been registered previously.

Will cause an ERROR if it does not exist. This must be called in the initialization phase.

Parameters
nameIf not empty, set non-default name for this object/array. This is permanent, so that e.g. after using registerInDataStore("myName") in initialize(), this object will continue refer to 'myName' in event().
Returns
True if the object/array exists.

Definition at line 78 of file StoreAccessorBase.h.

79 {
80 if (!name.empty())
81 m_name = name;
82 return DataStore::Instance().requireInput(*this);
83 }
bool requireInput(const StoreAccessorBase &accessor)
Produce ERROR message if no entry of the given type is registered in the DataStore.
Definition: DataStore.cc:722

◆ notWrittenOut()

bool notWrittenOut ( ) const

Returns true if this object/array should not be saved by output modules.

See DataStore::c_DontWriteOut. Can be changed by re-registering it with/without the flag.

Definition at line 53 of file StoreAccessorBase.cc.

54{
56 if (!entry) {
57 B2ERROR("notWrittenOut(): " << readableName() << " doesn't seem to be registered");
58 return false;
59 }
60 return entry->dontWriteOut;
61}
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
Wraps a stored array/object, stored under unique (name, durability) key.
Definition: StoreEntry.h:22
bool dontWriteOut
Flag that indicates whether the object should be written to the output by default.
Definition: StoreEntry.h:40

◆ operator!=()

virtual bool operator!= ( const StoreAccessorBase other) const
inlinevirtual

Check if two store accessors point to a different object/array.

Definition at line 143 of file StoreAccessorBase.h.

144 {
145 return !(*this == other);
146 }

◆ operator==()

virtual bool operator== ( const StoreAccessorBase other) const
inlinevirtual

Check if two store accessors point to the same object/array.

Definition at line 137 of file StoreAccessorBase.h.

138 {
139 return getAccessorParams() == other.getAccessorParams();
140 }
AccessorParams getAccessorParams() const
Return pair of name and durability under which stored object is saved.

◆ readableName()

std::string readableName ( ) const

Convert this acessor into a readable string (for messages).

e.g. "object EventMetaData (durability: event)"

Definition at line 18 of file StoreAccessorBase.cc.

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}
@ 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
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.

◆ registerInDataStore() [1/2]

bool registerInDataStore ( const std::string &  name,
DataStore::EStoreFlags  storeFlags = DataStore::c_WriteOut 
)
inline

Register the object/array in the DataStore.

This must be called in the initialization phase.

Parameters
nameIf not empty, set non-default name for this object/array. This is permanent, so that e.g. after using registerInDataStore("myName") in initialize(), this object will continue refer to 'myName' in event().
storeFlagsORed combination of DataStore::EStoreFlags.
Returns
True if the registration succeeded.

Definition at line 64 of file StoreAccessorBase.h.

65 {
66 if (!name.empty())
67 m_name = name;
69 }
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

◆ registerInDataStore() [2/2]

bool registerInDataStore ( DataStore::EStoreFlags  storeFlags = DataStore::c_WriteOut)
inline

Register the object/array in the DataStore.

This must be called in the initialization phase.

Parameters
storeFlagsORed combination of DataStore::EStoreFlags.
Returns
True if the registration succeeded.

Definition at line 52 of file StoreAccessorBase.h.

53 {
55 }

Member Data Documentation

◆ m_class

TClass* m_class
protected

The underlying object's type.

Definition at line 172 of file StoreAccessorBase.h.

◆ m_durability

DataStore::EDurability m_durability
protected

Store durability under which the object/array is saved.

Definition at line 169 of file StoreAccessorBase.h.

◆ m_isArray

bool m_isArray
protected

Is this an accessor for an array?

Definition at line 175 of file StoreAccessorBase.h.

◆ m_name

std::string m_name
protected

Store name under which this object/array is saved.

Definition at line 166 of file StoreAccessorBase.h.


The documentation for this class was generated from the following files: