|
| RelationsInterface () |
| template class cannot be removed without breaking ROOT I/O, so just disable it.
|
|
template<class ... Args> |
| RelationsInterface (Args &&... params) |
| Constructor, forwards all arguments to BASE constructor.
|
|
| RelationsInterface (const RelationsInterface &relationsInterface) |
| Copy constructor.
|
|
RelationsInterface & | operator= (const RelationsInterface &relationsInterface) |
| Assignment operator.
|
|
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).
|
|
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).
|
|
void | copyRelations (const RelationsInterface< BASE > *sourceObj) |
| Copies all relations of sourceObj (pointing from or to sourceObj) to this object (including weights).
|
|
template<class TO > |
RelationVector< TO > | getRelationsTo (const std::string &name="", const std::string &namedRelation="") const |
| Get the relations that point from this object to another store array.
|
|
template<class FROM > |
RelationVector< FROM > | getRelationsFrom (const std::string &name="", const std::string &namedRelation="") const |
| Get the relations that point from another store array to this object.
|
|
template<class T > |
RelationVector< T > | getRelationsWith (const std::string &name="", const std::string &namedRelation="") const |
| Get the relations between this object and another store array.
|
|
template<class TO > |
TO * | getRelatedTo (const std::string &name="", const std::string &namedRelation="") const |
| Get the object to which this object has a relation.
|
|
template<class FROM > |
FROM * | getRelatedFrom (const std::string &name="", const std::string &namedRelation="") const |
| Get the object from which this object has a relation.
|
|
template<class T > |
T * | getRelated (const std::string &name="", const std::string &namedRelation="") const |
| Get the object to or from which this object has a relation.
|
|
template<class TO > |
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.
|
|
template<class FROM > |
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.
|
|
template<class T > |
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.
|
|
virtual std::string | getName () const |
| Return a short name that describes this object, e.g.
|
|
virtual std::string | getInfoHTML () const |
| Return a short summary of this object's contents in HTML format.
|
|
std::string | getInfo () const |
| Return a short summary of this object's contents in raw text format.
|
|
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.
|
|
template<class BASE>
class Belle2::RelationsInterface< BASE >
Defines interface for accessing relations of objects in StoreArray.
- Note
- Please use the RelationsObject typedef instead of this class.
Your class then provides methods like addRelationTo or getRelationsTo for an easy handling of relations to and from objects of this class. Retrieving relations this way is handled using auto-generated indices, and so should not introduce a large overhead.
Retrieving relations
- Note
- Remember to use references or pointers when iterating over a StoreArray. Accessing relations through a copied object will not work.
You can either retrieve a vector of relations using getRelations...(),
for (
const CDCSimHit& simhit : particle->
getRelationsTo<CDCSimHit>()) {
}
A Class to store the Monte Carlo particle information.
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
or, for 1:1 relations, the first related object (or NULL) using getRelated...():
const CDCSimHit* simhit = cdcsimhits[i];
if (!mcpart) {
}
FROM * getRelatedFrom(const std::string &name="", const std::string &namedRelation="") const
Get the object from which this object has a relation.
Weigths are available when looping over the RelationVector returned by getRelations(), as in this example:
for (
unsigned int iHit = 0; iHit < cdcRelations.
size(); iHit++) {
const CDCSimHit *simhit = cdcRelations[iHit];
float weight = cdcRelations.
weight(iHit);
}
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
float weight(int index) const
Get weight with index.
or for at most one relation, using getRelatedWithWeight(), getRelatedFromWithWeight(), and getRelatedToWithWeight().
Adding relations
Creating new relations is also fairly straightforward:
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).
Note that you'll have to register the relation in your module's initialize() function:
Accessor to arrays stored in the data store.
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
Definition at line 100 of file RelationsObject.h.
Copies all relations of sourceObj (pointing from or to sourceObj) to this object (including weights).
Useful if you want to make a complete copy of a StoreArray object to make modifications to it, but retain all information on linked objects.
Note: this only works if sourceObj inherits from the same base (e.g. RelationsObject), and only for related objects that also inherit from the same base.
Definition at line 170 of file RelationsObject.h.
171 {
172 if (!sourceObj)
173 return;
174 auto fromRels = sourceObj->getRelationsFrom<RelationsInterface<BASE>>("ALL");
175 for (unsigned int iRel = 0; iRel < fromRels.size(); iRel++) {
176 fromRels.object(iRel)->addRelationTo(this, fromRels.weight(iRel));
177 }
178
179 auto toRels = sourceObj->getRelationsTo<RelationsInterface<BASE>>("ALL");
180 for (unsigned int iRel = 0; iRel < toRels.size(); iRel++) {
181 this->
addRelationTo(toRels.object(iRel), toRels.weight(iRel));
182 }
183 }
virtual std::string getInfoHTML |
( |
| ) |
const |
|
inlinevirtual |
Return a short summary of this object's contents in HTML format.
Reimplement this in your own class to provide useful output for display or debugging purposes. For example, you might do something like:
std::stringstream out;
out << "<b>PDG</b>: " << m_pdg << "<br>";
out <<
"<b>Covariance Matrix</b>: " <<
HTML::getString(getCovariance5()) <<
"<br>";
return out.str();
std::string getString(const TMatrixFBase &matrix, int precision=2, bool color=true)
get HTML table representing a matrix.
- See also
- Particle::getInfoHTML() for a more complex example.
-
HTML for some utility functions.
-
Use getInfo() to get a raw text version of this output.
Reimplemented in Particle, Cluster, MCParticle, PIDLikelihood, SoftwareTriggerResult, Track, TrackFitResult, and TRGSummary.
Definition at line 362 of file RelationsObject.h.