Belle II Software  release-05-02-19
PyDBArray.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2012-2017 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <framework/pybasf2/PyDBArray.h>
12 #include <framework/datastore/DataStore.h>
13 
14 #include <TClonesArray.h>
15 #include <TClass.h>
16 
17 using namespace Belle2;
18 
19 namespace {
22  TClass* getDefaultClass(const std::string& name)
23  {
24  // First look for an name without the namespace Belle2::
25  // For arrays the default name is the class name + 's' so lets strip it.
26  TClass* cl = TClass::GetClass(("Belle2::" + name.substr(0, name.size() - 1)).c_str());
27  if (!cl) {
28  // If this fails look for a name that already has the full namespace.
29  cl = TClass::GetClass(name.c_str());
30  }
31  if (!cl) return TObject::Class();
32  return cl;
33  }
34 }
35 
36 const TObject* PyDBArray::_get(int i) const
37 {
38  return getObject<TClonesArray>()->At(i);
39 }
40 
42 {
43  return isValid() ? (getObject<TClonesArray>()->GetEntriesFast()) : 0;
44 }
45 
46 PyDBArray::PyDBArray(const std::string& name, bool required): PyDBArray(name, getDefaultClass(name), required) {}
47 
48 PyDBArray::PyDBArray(const TClass* objClass, bool required): PyDBArray(DataStore::defaultArrayName(objClass), objClass, required) {}
49 
50 PyDBArray::PyDBArray(const std::string& name, const TClass* objClass, bool required): DBAccessorBase(name, objClass, true,
51  required) {}
Belle2::PyDBArray::getEntries
int getEntries() const
Get the number of entries.
Definition: PyDBArray.cc:41
Belle2::DBAccessorBase
Base class for DBObjPtr and DBArray for easier common treatment.
Definition: DBAccessorBase.h:28
Belle2::PyDBArray::_get
const TObject * _get(int i) const
Element access.
Definition: PyDBArray.cc:36
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::DBAccessorBase::isValid
bool isValid() const
Check whether a valid object was obtained from the database.
Definition: DBAccessorBase.h:75
Belle2::PyDBArray
Class to access a DB Array from Python.
Definition: PyDBArray.h:43
Belle2::DataStore
In the store you can park objects that have to be accessed by various modules.
Definition: DataStore.h:53
Belle2::PyDBArray::PyDBArray
PyDBArray(const std::string &name, bool required=true)
Construct the array from the name of the payload.
Definition: PyDBArray.cc:46