 |
Belle II Software
release-05-02-19
|
12 #include <framework/database/DBAccessorBase.h>
14 #include <framework/utilities/ArrayIterator.h>
16 #include <TClonesArray.h>
28 template<
class T>
class DBArray:
public DBAccessorBase {
31 typedef ObjArrayIterator<const TClonesArray, const T>
const_iterator;
40 explicit DBArray(
const std::string& name =
"",
bool required =
true):
41 DBAccessorBase(DBStore::arrayName<T>(name), T::Class(), true, required) {}
44 inline int getEntries()
const {
return isValid() ? getObject<TClonesArray>()->GetEntriesFast() : 0;}
56 throw std::out_of_range(
"Out-of-range access in DBArray::operator[], for " +
getName() +
": Object not valid");
59 TObject* obj = getObject<TClonesArray>()->At(i);
61 throw std::out_of_range(
"Out-of-range access in DBArray::operator[], for " +
getName() +
", index " + std::to_string(i));
62 return static_cast<T*
>(obj);
71 template<
class KEY>
const T*
getByKey(KEY(T::*method)(
void)
const, KEY key)
const
73 const TClonesArray& array = *getObject<TClonesArray>();
75 T* obj =
static_cast<T*
>(array.At(i));
76 if ((*obj.*method)() == key) {
99 template<
class T>
class OptionalDBArray:
public DBArray<T> {
const_iterator end() const
Return const_iterator to last entry +1.
int getEntries() const
Get the number of objects in the array.
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.
DBArray(const std::string &name="", bool required=true)
Constructor to access an array of objects in the DBStore.
const T * operator[](int i) const
Access to the stored objects.
ObjArrayIterator< const TClonesArray, const T > const_iterator
STL-like const_iterator over the T objects (not T* ).
const_iterator begin() const
Return const_iterator to first entry.
const T * getByKey(KEY(T::*method)(void) const, KEY key) const
Access object by key instead of by index.
bool isValid() const
Check whether a valid object was obtained from the database.
const std::string & getName() const
Return name under which the object is saved in the DBStore.
DBAccessorBase(const std::string &name, const TClass *objClass, bool isArray, bool isRequired)
Constructor to access an object in the DBStore.