8#include <framework/pybasf2/PyStoreArray.h>
10#include <framework/logging/Logger.h>
11#include <framework/datastore/DataStore.h>
12#include <framework/datastore/StoreAccessorBase.h>
14#include "TClonesArray.h"
22 T* replaceNullPtr(T* value, T* fallback)
24 return value ? value : fallback;
36 for (
const auto& n :
list(durability))
57 const std::string& name,
59 m_storeAccessor(name, durability, objClass, true)
73 B2ERROR(
"Cannot register PyStoreArray '" << name <<
"' with unknown TClass. Please supply one to the PyStoreArray constructor.");
95 std::string
const& namedRelation)
const
106 std::string
const& namedRelation)
const
116 std::string
const& namedRelation)
const
126 const std::string& namedRelation)
const
136 const std::string& namedRelation)
const
139 this->m_storeAccessor,
147 return objClass and objClass != TObject::Class();
184 B2ERROR(
"Cannot create an object in invalid PyStoreArray.");
205 B2ERROR(
"Cannot create unregistered PyStoreArray.");
210 if (
isValid() and not replace)
return true;
213 B2ERROR(
"Cannot create PyStoreArray with unknown TClass.");
In the store you can park objects that have to be accessed by various modules.
EStoreFlags
Flags describing behaviours of objects etc.
bool registerRelation(const StoreAccessorBase &fromArray, const StoreAccessorBase &toArray, EDurability durability, EStoreFlags storeFlags, const std::string &namedRelation)
Register a relation in the DataStore map.
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.
EDurability
Durability types.
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...
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.
StoreEntry * getEntry(const StoreAccessorBase &accessor)
Check whether an entry with the correct type is registered in the DataStore map and return it.
A (simplified) python wrapper for StoreArray.
StoreAccessorBase m_storeAccessor
Store accessor to retrieve the object.
static void printList(DataStore::EDurability durability=DataStore::EDurability::c_Event)
Print list of available arrays for given durability.
bool hasRelationFrom(const PyStoreArray &fromArray, DataStore::EDurability durability=DataStore::c_Event, const std::string &namedRelation="") const
Check for the existence of a relation from the provided toArray (to this Pystorearray)
void ensureAttached() const
Ensure that contained TClonesArray has been attached to a memory location on the DataStore.
bool hasValidClass() const
Check whether a TClass of the objects in this PyStoreArray could be determined.
bool isValid() const
Check whether the array was registered and created.
bool isRequired(const std::string &name="")
Ensure this array has been registered previously.
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
PyStoreArray(const std::string &name, DataStore::EDurability durability=DataStore::EDurability::c_Event)
constructor.
bool optionalRelationTo(const PyStoreArray &toArray, DataStore::EDurability durability=DataStore::c_Event, std::string const &namedRelation="") const
Tell the data store about a relation that we could make use of.
bool hasRelationTo(const PyStoreArray &toArray, DataStore::EDurability durability=DataStore::c_Event, const std::string &namedRelation="") const
Check for the existence of a relation to the provided toArray (from this Pystorearray)
TObject * operator[](int i) const
returns object at index i, or null pointer if out of range (+error)
bool registerRelationTo(const PyStoreArray &toArray, DataStore::EDurability durability=DataStore::EDurability::c_Event, DataStore::EStoreFlags storeFlags=DataStore::EStoreFlags::c_WriteOut, std::string const &namedRelation="") const
Register a relation to the given PyStoreArray.
bool registerInDataStore(DataStore::EStoreFlags storeFlags)
Register the array in the data store.
TObject * appendNew()
Construct a new object of the array's type at the end of the array.
int getEntries() const
returns number of entries for current event.
void ensureCreated()
Ensure that contained TClonesArray has been created on the DataStore.
StoreEntry * m_storeEntry
Pointer to the DataStore entry - serves as an internal cache omitting repeated look up from the DataS...
TClonesArray * getPtr()
Raw access to the underlying TClonesArray.
bool requireRelationTo(const PyStoreArray &toArray, DataStore::EDurability durability=DataStore::c_Event, std::string const &namedRelation="") const
Produce error if no relation from this array to 'toArray' has been registered.
void attach() const
Lookup the store entry and cache a pointer to it.
bool create(bool replace=false)
Create constructed TClonesArray in the DataStore.
TIter __iter__() const
Allow iteration using for in Python.
static std::vector< std::string > list(DataStore::EDurability durability=DataStore::EDurability::c_Event)
Return list of available arrays for given durability.
const std::string & getName() const
Return name under which the object is saved 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.
std::string readableName() const
Convert this acessor into a readable string (for messages).
TClass * getClass() const
The underlying object's type.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
bool create(bool replace=false)
Create a default object in the data store.
Abstract base class for different kinds of events.
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.