Belle II Software light-2406-ragdoll
StoreEntry Struct Reference

Wraps a stored array/object, stored under unique (name, durability) key. More...

#include <StoreEntry.h>

Collaboration diagram for StoreEntry:

Public Member Functions

 StoreEntry (bool isArray, TClass *cl, std::string name, bool dontWriteOut)
 useful constructor, creates 'object', but leaves 'ptr' NULL.
 
void invalidate ()
 invalidate entry for next event.
 
void resetForGetEntry ()
 Reset stored object to defaults, or nullptr.
 
void recoverFromNullObject ()
 Recreate object if null.
 
void recreate ()
 Reset stored object to defaults, set ptr to new object.
 
TClonesArray * getPtrAsArray () const
 Return ptr cast to TClonesArray.
 

Public Attributes

bool isArray
 Flag that indicates whether the object is a TClonesArray.
 
bool dontWriteOut
 Flag that indicates whether the object should be written to the output by default.
 
TClass * objClass
 class of object.
 
TObject * object
 The pointer to the actual object.
 
TObject * ptr
 The pointer to the returned object, either equal to 'object' or null, depending on wether the object was created in the current event.
 
std::string name
 Name of the entry.
 

Detailed Description

Wraps a stored array/object, stored under unique (name, durability) key.

See DataStore::m_storeEntryMap.

Definition at line 22 of file StoreEntry.h.

Constructor & Destructor Documentation

◆ StoreEntry() [1/2]

StoreEntry ( )
inline

Definition at line 23 of file StoreEntry.h.

23: isArray(false), dontWriteOut(false), objClass(nullptr), object(nullptr), ptr(nullptr), name() {};
TObject * ptr
The pointer to the returned object, either equal to 'object' or null, depending on wether the object ...
Definition: StoreEntry.h:51
bool dontWriteOut
Flag that indicates whether the object should be written to the output by default.
Definition: StoreEntry.h:40
TObject * object
The pointer to the actual object.
Definition: StoreEntry.h:48
bool isArray
Flag that indicates whether the object is a TClonesArray.
Definition: StoreEntry.h:39
std::string name
Name of the entry.
Definition: StoreEntry.h:53
TClass * objClass
class of object.
Definition: StoreEntry.h:41

◆ StoreEntry() [2/2]

StoreEntry ( bool  isArray,
TClass *  cl,
std::string  name,
bool  dontWriteOut 
)

useful constructor, creates 'object', but leaves 'ptr' NULL.

Definition at line 19 of file StoreEntry.cc.

19 :
20 isArray(isArray_),
21 dontWriteOut(dontWriteOut_),
22 objClass(cl),
23 object(nullptr),
24 ptr(nullptr),
25 name(std::move(name_))
26{
28}
void recoverFromNullObject()
Recreate object if null.
Definition: StoreEntry.cc:30

Member Function Documentation

◆ getPtrAsArray()

TClonesArray * getPtrAsArray ( ) const

Return ptr cast to TClonesArray.

If this is not an array, return null.

Definition at line 83 of file StoreEntry.cc.

84{
85 if (!isArray)
86 return nullptr;
87 return static_cast<TClonesArray*>(ptr);
88}

◆ invalidate()

void invalidate ( )

invalidate entry for next event.

(ptr will be null afterwards, memory may be reused.)

Definition at line 77 of file StoreEntry.cc.

78{
79 recreate();
80 ptr = nullptr;
81}
void recreate()
Reset stored object to defaults, set ptr to new object.
Definition: StoreEntry.cc:68

◆ recoverFromNullObject()

void recoverFromNullObject ( )

Recreate object if null.

Used to recover from temporary invalid states after reading empty branches.

Definition at line 30 of file StoreEntry.cc.

31{
32 if (object)
33 return;
34 if (isArray) {
35 object = new TClonesArray(objClass);
36 } else {
37 // Oh dear, where to begin. So we want to create a new object of the class
38 // we have and we require this class to be inheriting from TObject. Fine,
39 // but there could be classes with multiple inheritance where the TObject
40 // is not the first base class. In this case the memory layout puts the
41 // TObject not at the beginning of the instance but at an offset. The
42 // compiler knows this so a static_cast<> or c-style cast from one to the
43 // other will correctly modify the pointing address to point to the start
44 // of TObject, but TClass::New() gives us a void* pointer so the compiler
45 // doesn't know about that. So to be on the safe side we have to manually
46 // fix the pointer address using the BaseClassOffset from TClass. And since
47 // pointer arithmetic on void* is forbidden we have to go to char* first.
48 auto* rawPtr = reinterpret_cast<char*>(objClass->New());
49 int offset = objClass->GetBaseClassOffset(TObject::Class());
50 if (offset < 0) B2FATAL("Class " << objClass->GetName() << " does not inherit from TObject");
51 object = reinterpret_cast<TObject*>(rawPtr + offset);
52 }
53}

◆ recreate()

void recreate ( )

Reset stored object to defaults, set ptr to new object.

More or less equivalent to delete object; object = new X;, but optimized.

Definition at line 68 of file StoreEntry.cc.

69{
71 if (object == nullptr)
73
74 ptr = object;
75}
void resetForGetEntry()
Reset stored object to defaults, or nullptr.
Definition: StoreEntry.cc:55

◆ resetForGetEntry()

void resetForGetEntry ( )

Reset stored object to defaults, or nullptr.

Only useful for input modules (before GetEntry()).

Definition at line 55 of file StoreEntry.cc.

56{
57 if (isArray) {
58 static_cast<TClonesArray*>(object)->Delete();
59 } else if (object->IsA() == RelationContainer::Class()) {
60 static_cast<RelationContainer*>(object)->Clear();
61 } else {
62 //we don't know anything about object, so we just delete it here (and recreate later)
63 delete object;
64 object = nullptr;
65 }
66}
Class to store relations between StoreArrays in the DataStore.

Member Data Documentation

◆ dontWriteOut

bool dontWriteOut

Flag that indicates whether the object should be written to the output by default.

Definition at line 40 of file StoreEntry.h.

◆ isArray

bool isArray

Flag that indicates whether the object is a TClonesArray.

Definition at line 39 of file StoreEntry.h.

◆ name

std::string name

Name of the entry.

Equal to the key in the map.

Definition at line 53 of file StoreEntry.h.

◆ objClass

TClass* objClass

class of object.

If isArray==true, class of array objects

Definition at line 41 of file StoreEntry.h.

◆ object

TObject* object

The pointer to the actual object.

Associated memory may exceed object durability, and is kept until the object is replaced. In normal use, this should never be null. Temporary exceptions are allowed for input modules.

Definition at line 48 of file StoreEntry.h.

◆ ptr

TObject* ptr

The pointer to the returned object, either equal to 'object' or null, depending on wether the object was created in the current event.

Definition at line 51 of file StoreEntry.h.


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