10#include <framework/database/DBAccessorBase.h>
12#include <framework/utilities/ArrayIterator.h>
14#include <TClonesArray.h>
38 explicit DBArray(
const std::string& name =
"",
bool required =
true):
42 inline int getEntries()
const {
return isValid() ? getObject<TClonesArray>()->GetEntriesFast() : 0;}
54 throw std::out_of_range(
"Out-of-range access in DBArray::operator[], for " +
getName() +
": Object not valid");
57 TObject* obj = getObject<TClonesArray>()->At(i);
59 throw std::out_of_range(
"Out-of-range access in DBArray::operator[], for " +
getName() +
", index " + std::to_string(i));
60 return static_cast<T*
>(obj);
69 template<
class KEY>
const T*
getByKey(KEY(T::*method)(
void)
const, KEY key)
const
71 const TClonesArray& array = *getObject<TClonesArray>();
73 T* obj =
static_cast<T*
>(array.At(i));
74 if ((*obj.*method)() == key) {
Base class for DBObjPtr and DBArray for easier common treatment.
const std::string & getName() const
Return name under which the object is saved in the DBStore.
bool isValid() const
Check whether a valid object was obtained from the database.
Class for accessing arrays of objects in the database.
const_iterator begin() const
Return const_iterator to first entry.
const T * operator[](int i) const
Access to the stored objects.
DBArray(const std::string &name="", bool required=true)
Constructor to access an array of objects in the DBStore.
const T * getByKey(KEY(T::*method)(void) const, KEY key) const
Access object by key instead of by index.
int getEntries() const
Get the number of objects in the array.
const_iterator end() const
Return const_iterator to last entry +1.
ObjArrayIterator< const TClonesArray, const T > const_iterator
STL-like const_iterator over the T objects (not T* ).
Singleton class to cache database objects.
Optimizes class to iterate over TObjArray and classes inheriting from it.
Optional DBArray: This class behaves the same as the DBArray except that it will not raise errors whe...
OptionalDBArray(const std::string &name="")
Construct a new Array with a given name or with the default name which is identical to the class name...
Abstract base class for different kinds of events.