Belle II Software light-2406-ragdoll
PyDBArray.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <framework/pybasf2/PyDBArray.h>
10#include <framework/datastore/DataStore.h>
11
12#include <TClonesArray.h>
13#include <TClass.h>
14
15using namespace Belle2;
16
17namespace {
20 TClass* getDefaultClass(const std::string& name)
21 {
22 // First look for an name without the namespace Belle2::
23 // For arrays the default name is the class name + 's' so lets strip it.
24 TClass* cl = TClass::GetClass(("Belle2::" + name.substr(0, name.size() - 1)).c_str());
25 if (!cl) {
26 // If this fails look for a name that already has the full namespace.
27 cl = TClass::GetClass(name.c_str());
28 }
29 if (!cl) return TObject::Class();
30 return cl;
31 }
32}
33
34const TObject* PyDBArray::_get(int i) const
35{
36 return getObject<TClonesArray>()->At(i);
37}
38
40{
41 return isValid() ? (getObject<TClonesArray>()->GetEntriesFast()) : 0;
42}
43
44PyDBArray::PyDBArray(const std::string& name, bool required): PyDBArray(name, getDefaultClass(name), required) {}
45
46PyDBArray::PyDBArray(const TClass* objClass, bool required): PyDBArray(DataStore::defaultArrayName(objClass), objClass, required) {}
47
48PyDBArray::PyDBArray(const std::string& name, const TClass* objClass, bool required): DBAccessorBase(name, objClass, true,
49 required) {}
50
52{
53 PyObject* list = PyList_New(0);
54 // Currently, the boundaries are defined only as unsigned int.
55 // If in the future this will change, this method has to be updated accordingly.
56 for (auto boundary : getIntraRunBoundaries())
57 PyList_Append(list, PyLong_FromUnsignedLong(boundary));
58 return list;
59}
Base class for DBObjPtr and DBArray for easier common treatment.
const std::vector< unsigned int > getIntraRunBoundaries() const
Get the intra-run boundaries, if any.
In the store you can park objects that have to be accessed by various modules.
Definition: DataStore.h:51
Class to access a DB Array from Python.
Definition: PyDBArray.h:43
PyObject * getIntraRunBoundariesList() const
Get the intra-run boundaries, if any, as a python list.
Definition: PyDBArray.cc:51
PyDBArray(const std::string &name, bool required=true)
Construct the array from the name of the payload.
Definition: PyDBArray.cc:44
bool isValid() const
Check whether a valid object was obtained from the database.
const TObject * _get(int i) const
Element access.
Definition: PyDBArray.cc:34
int getEntries() const
Get the number of entries.
Definition: PyDBArray.cc:39
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24