11#include <framework/datastore/DataStore.h>
12#include <framework/datastore/RelationVector.h>
13#include <framework/datastore/RelationEntry.h>
27 namespace _RelationsInterfaceImpl {
102 static_assert(std::is_same<TObject, BASE>::value,
103 "Using RelationsInterface<BASE> is no longer allowed. Please use RelationsObject as a base class.");
111 BASE(
std::forward<Args>(params)...),
120 BASE(relationsInterface),
130 if (
this != &relationsInterface)
131 this->BASE::operator=(relationsInterface);
155 void addRelationTo(
const TObject*
object,
float weight = 1.0,
const std::string& namedRelation =
"")
const
175 for (
unsigned int iRel = 0; iRel < fromRels.size(); iRel++) {
176 fromRels.object(iRel)->
addRelationTo(
this, fromRels.weight(iRel));
180 for (
unsigned int iRel = 0; iRel < toRels.size(); iRel++) {
181 this->
addRelationTo(toRels.object(iRel), toRels.weight(iRel));
213 const std::string& namedRelation =
"")
const
248 template <
class TO> TO*
getRelatedTo(
const std::string& name =
"",
const std::string& namedRelation =
"")
const
251 TO::Class(), name, namedRelation).
object);
263 template <
class FROM> FROM*
getRelatedFrom(
const std::string& name =
"",
const std::string& namedRelation =
"")
const
278 template <
class T> T*
getRelated(
const std::string& name =
"",
const std::string& namedRelation =
"")
const
281 T::Class(), name, namedRelation).
object);
298 const std::string& namedRelation =
"")
const
301 TO::Class(), name, namedRelation);
302 return std::make_pair(
static_cast<TO*
>(entry.
object), entry.
weight);
315 const std::string& namedRelation =
"")
const
318 FROM::Class(), name, namedRelation);
319 return std::make_pair(
static_cast<FROM*
>(entry.
object), entry.
weight);
332 const std::string& namedRelation =
"")
const
335 T::Class(), name, namedRelation);
336 return std::make_pair(
static_cast<T*
>(entry.
object), entry.
weight);
344 virtual std::string
getName()
const {
return ""; }
392#if defined(__CINT__) || defined(__ROOTCLING__) || defined(R__DICTIONARY_FILENAME)
400 return getRelationsTo<TObject>(name);
404 return getRelationsFrom<TObject>(name);
408 return getRelationsWith<TObject>(name);
410 TObject*
getRelatedTo(
const std::string& name,
const std::string& namedRelation =
"")
const {
return getRelatedTo<TObject>(name, namedRelation); }
411 TObject*
getRelatedFrom(
const std::string& name,
const std::string& namedRelation =
"")
const {
return getRelatedFrom<TObject>(name, namedRelation); }
412 TObject*
getRelated(
const std::string& name,
const std::string& namedRelation =
"")
const {
return getRelated<TObject>(name, namedRelation); }
In the store you can park objects that have to be accessed by various modules.
bool findStoreEntry(const TObject *object, StoreEntry *&entry, int &index)
Find an object in an array in the data store.
void addRelation(const TObject *fromObject, StoreEntry *&fromEntry, int &fromIndex, const TObject *toObject, StoreEntry *&toEntry, int &toIndex, float weight, const std::string &namedRelation)
Add a relation from an object in a store array to another object in a store array.
@ c_BothSides
Combination of c_FromSide and c_ToSide.
@ c_FromSide
Return relations/objects pointed from (to a given object).
@ c_ToSide
Return relations/objects pointed to (from a given object).
static DataStore & Instance()
Instance of singleton Store.
Belle2::RelationEntry getRelationWith(ESearchSide searchSide, const TObject *object, StoreEntry *&entry, int &index, const TClass *withClass, const std::string &withName, const std::string &namedRelation)
Get the first relation between an object and another object in a store array.
Class for type safe access to objects that are referred to in relations.
Defines interface for accessing relations of objects in StoreArray.
std::pair< FROM *, float > getRelatedFromWithWeight(const std::string &name="", const std::string &namedRelation="") const
Get first related object & weight of relation pointing from an array.
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
RelationsInterface(const RelationsInterface &relationsInterface)
Copy constructor.
std::string getArrayName() const
Get name of array this object is stored in, or "" if not found.
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
TO * getRelatedTo(const std::string &name="", const std::string &namedRelation="") const
Get the object to which this object has a relation.
void addRelationTo(const TObject *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (no caching, can be quite slow).
virtual std::string getInfoHTML() const
Return a short summary of this object's contents in HTML format.
virtual std::string getName() const
Return a short name that describes this object, e.g.
TClonesArray * getArrayPointer() const
Returns the pointer to the raw DataStore array holding this object (protected since these arrays are ...
ClassDef(RelationsInterface, 0)
defines interface for accessing relations of objects in StoreArray.
std::pair< TO *, float > getRelatedToWithWeight(const std::string &name="", const std::string &namedRelation="") const
Get first related object & weight of relation pointing to an array.
DataStore::StoreEntry * m_cacheDataStoreEntry
Cache of the data store entry to which this object belongs.
RelationsInterface(Args &&... params)
Constructor, forwards all arguments to BASE constructor.
RelationVector< FROM > getRelationsFrom(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from another store array to this object.
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
RelationVector< T > getRelationsWith(const std::string &name="", const std::string &namedRelation="") const
Get the relations between this object and another store array.
FROM * getRelatedFrom(const std::string &name="", const std::string &namedRelation="") const
Get the object from which this object has a relation.
int m_cacheArrayIndex
Cache of the index in the TClonesArray to which this object belongs.
std::pair< T *, float > getRelatedWithWeight(const std::string &name="", const std::string &namedRelation="") const
Get first related object & weight of relation pointing from/to an array.
std::string getInfo() const
Return a short summary of this object's contents in raw text format.
void copyRelations(const RelationsInterface< BASE > *sourceObj)
Copies all relations of sourceObj (pointing from or to sourceObj) to this object (including weights).
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
RelationsInterface()
template class cannot be removed without breaking ROOT I/O, so just disable it.
RelationsInterface & operator=(const RelationsInterface &relationsInterface)
Assignment operator.
RelationsInterface< TObject > RelationsObject
Provides interface for getting/adding relations to objects in StoreArrays.
std::string htmlToPlainText(const std::string &html)
See RelationsObject::getInfo()
Abstract base class for different kinds of events.
TObject * object
Pointer to the object.
float weight
Weight of the relation.
Wraps a stored array/object, stored under unique (name, durability) key.
TClonesArray * getPtrAsArray() const
Return ptr cast to TClonesArray.
std::string name
Name of the entry.