Defines interface for accessing relations of objects in StoreArray.
More...
#include <RelationsObject.h>
Inherits BASE.
Inherited by FBDTClassifier< 9 >, PXD2TrackBase< Belle2::PXD::Track_t >, ARICHAeroHit, ARICHHit, ARICHInfo, ARICHLikelihood, ARICHPhoton, ARICHTrack, AWESOMESimHit, BKLMHit1d, BKLMTrack, BelleTrkExtra, BremHit, Btube, CDCDedxLikelihood, CDCDedxTrack, CDCRawHit, CDCRawHitWaveForm, CDCTriggerFinderClone, CDCTriggerHoughCluster, CDCTriggerSegmentHit, Cluster, ContinuumSuppression, CsiDigiHit, DigitBase, DirectedNodeNetworkContainer, ECLCNNPid, ECLCalDigit, ECLCluster, ECLConnectedRegion, ECLDebugHit, ECLDigit, ECLDsp, ECLEnergyCloseToTrack, ECLHitAssignment, ECLLocalMaximum, ECLPidLikelihood, ECLPureCsIInfo, ECLShower, ECLTrig, ECLTriggerCell, EKLMAlignmentHit, EventKinematics, EventShapeContainer, ExtHit, FBDTClassifier< Ndims >, FlavorTaggerInfo, FlavorTaggerInfoMap, Helix, KLMCluster, KLMClusterShape, KLMDigitEventInfo, KLMDigitRaw, KLMHit2d, KLMMuidHit, KLMMuidLikelihood, KLMScintillatorFirmwareFitResult, KLMTrgFittedTrack, KLMTrgSummary, KLMTriggerHit, KLMTriggerTrack, KlId, MCParticle, MCParticleTrajectory, OverlapNetwork, PIDLikelihood, PXD2TrackBase< T >, PXDCluster, PXDEnergyDepositionEvent, PXDNeutronFluxEvent, PXDOccupancyEvent, PXDRawAdc, PXDRawHit, PXDRawROIs, Particle, ROIid, RecoHitInformation, RecoTrack, RestOfEvent, SVDCluster, SVDDAQDiagnostic, SVDEnergyDepositionEvent, SVDNeutronFluxEvent, SVDOccupancyEvent, SVDRecoDigit, SVDRecoTimeBase, SVDTransparentDigit, Sector, SectorFriendship, SimClockState, SimHitBase, SoftwareTriggerResult, SpacePoint, SpacePointTrackCand, StringWrapper, TOPAsicMask, TOPAssociatedPDF, TOPBarHit, TOPInterimFEInfo, TOPLikelihood, TOPLikelihoodScanResult, TOPPDFCollection, TOPPixelLikelihood, TOPProductionEventDebug, TOPProductionHitDebug, TOPPull, TOPRawDigit, TOPRawWaveform, TOPRecBunch, TOPSimCalPulse, TOPSimPhoton, TOPSlowData, TOPTemplateFitResult, TOPTimeZero, TOPTriggerDigit, TRGECLCluster, TRGGRLInnerTrack, TRGGRLMATCH, TRGGRLMATCHKLM, TRGGRLPHOTON, TRGGRLShortTrack, TRGSummary, TRGTOPCombinedT0Decision, TRGTOPSlotTiming, TRGTOPTimeStamp, TRGTOPTimeStampsSlot, TRGTOPTimingISim, TRGTOPTimingISimSlot, TRGTOPUnpackerStore, TRGTOPWaveFormTimeStamp, TRGTOPWaveFormTimeStampsSlot, TRGTiming, TagVertex, TauPairDecay, Track, TrackClusterSeparation, StoreWrapper< T >, TrackFitResult, V0, VXDDedxLikelihood, VXDDedxTrack, VXDIntercept, and VXDTrueHit.
|
| RelationsInterface () |
| template class cannot be removed without breaking ROOT I/O, so just disable it. More...
|
|
template<class ... Args> |
| RelationsInterface (Args &&... params) |
| Constructor, forwards all arguments to BASE constructor.
|
|
| RelationsInterface (const RelationsInterface &relationsInterface) |
| Copy constructor. More...
|
|
RelationsInterface & | operator= (const RelationsInterface &relationsInterface) |
| Assignment operator. More...
|
|
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). More...
|
|
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). More...
|
|
void | copyRelations (const RelationsInterface< BASE > *sourceObj) |
| Copies all relations of sourceObj (pointing from or to sourceObj) to this object (including weights). More...
|
|
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. More...
|
|
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. More...
|
|
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. More...
|
|
template<class TO > |
TO * | getRelatedTo (const std::string &name="", const std::string &namedRelation="") const |
| Get the object to which this object has a relation. More...
|
|
template<class FROM > |
FROM * | getRelatedFrom (const std::string &name="", const std::string &namedRelation="") const |
| Get the object from which this object has a relation. More...
|
|
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. More...
|
|
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. More...
|
|
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. More...
|
|
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. More...
|
|
virtual std::string | getName () const |
| Return a short name that describes this object, e.g. More...
|
|
virtual std::string | getInfoHTML () const |
| Return a short summary of this object's contents in HTML format. More...
|
|
std::string | getInfo () const |
| Return a short summary of this object's contents in raw text format. More...
|
|
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.
|
|
|
TClonesArray * | getArrayPointer () const |
| Returns the pointer to the raw DataStore array holding this object (protected since these arrays are easy to misuse).
|
|
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...(),
const MCParticle* particle = particles[i];
for (const CDCSimHit& simhit : particle->getRelationsTo<CDCSimHit>()) {
}
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:
const MCParticle* particle = particles[i];
RelationVector<CDCSimHit> cdcRelations = particle->getRelationsTo<CDCSimHit>();
for (unsigned int iHit = 0; iHit < cdcRelations.size(); iHit++) {
const CDCSimHit *simhit = cdcRelations[iHit];
float weight = cdcRelations.weight(iHit);
}
or for at most one relation, using getRelatedWithWeight(), getRelatedFromWithWeight(), and getRelatedToWithWeight().
Adding relations
Creating new relations is also fairly straightforward:
particle->addRelationTo(someOtherObject)
Note that you'll have to register the relation in your module's initialize() function:
StoreArray<MCParticle> mcparticles;
StoreArray<SomethingOtherClass> otherArray;
mcparticles.registerRelationTo(otherArray);
Definition at line 100 of file RelationsObject.h.
◆ RelationsInterface() [1/2]
template class cannot be removed without breaking ROOT I/O, so just disable it.
Default constructor.
Definition at line 107 of file RelationsObject.h.
◆ RelationsInterface() [2/2]
Copy constructor.
Cached values are cleared.
- Parameters
-
relationsInterface | The object that should be copied. |
Definition at line 119 of file RelationsObject.h.
◆ addRelationTo() [1/2]
void addRelationTo |
( |
const RelationsInterface< BASE > * |
object, |
|
|
float |
weight = 1.0 , |
|
|
const std::string & |
namedRelation = "" |
|
) |
| const |
|
inline |
Add a relation from this object to another object (with caching).
- Parameters
-
object | The object to which the relation should point. |
weight | The weight of the relation. |
namedRelation | Additional name for the relation, or "" for the default naming |
Definition at line 142 of file RelationsObject.h.
◆ addRelationTo() [2/2]
void addRelationTo |
( |
const TObject * |
object, |
|
|
float |
weight = 1.0 , |
|
|
const std::string & |
namedRelation = "" |
|
) |
| const |
|
inline |
Add a relation from this object to another object (no caching, can be quite slow).
- Parameters
-
object | The object to which the relation should point. |
weight | The weight of the relation. |
namedRelation | Additional name for the relation, or "" for the default naming |
Definition at line 155 of file RelationsObject.h.
◆ copyRelations()
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.
◆ getInfo()
std::string getInfo |
( |
| ) |
const |
|
inline |
Return a short summary of this object's contents in raw text format.
Returns the contents of getInfoHTML() while translating line-breaks etc.
- Note
- : You don't need to implement this function (it's not virtual), getInfoHTML() is enough.
Definition at line 370 of file RelationsObject.h.
◆ getInfoHTML()
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 RecoTrack, TRGSummary, TrackFitResult, Track, SoftwareTriggerResult, PIDLikelihood, MCParticle, Cluster, and Particle.
Definition at line 362 of file RelationsObject.h.
◆ getName()
virtual std::string getName |
( |
| ) |
const |
|
inlinevirtual |
◆ getRelated()
T* getRelated |
( |
const std::string & |
name = "" , |
|
|
const std::string & |
namedRelation = "" |
|
) |
| const |
|
inline |
Get the object to or from which this object has a relation.
- Template Parameters
-
T | The class of objects to or from which the relation points. |
- Parameters
-
name | The name of the store array to or from which the relation points. If empty the default store array name for class T will be used. If the special name "ALL" is given all store arrays containing objects of type T are considered. |
namedRelation | Additional name for the relation, or "" for the default naming |
- Returns
- The first related object or a null pointer.
Definition at line 278 of file RelationsObject.h.
◆ getRelatedFrom()
FROM* getRelatedFrom |
( |
const std::string & |
name = "" , |
|
|
const std::string & |
namedRelation = "" |
|
) |
| const |
|
inline |
Get the object from which this object has a relation.
- Template Parameters
-
FROM | The class of objects from which the relation points. |
- Parameters
-
name | The name of the store array from which the relation points. If empty the default store array name for class FROM will be used. If the special name "ALL" is given all store arrays containing objects of type FROM are considered. |
namedRelation | Additional name for the relation, or "" for the default naming |
- Returns
- The first related object or a null pointer.
Definition at line 263 of file RelationsObject.h.
◆ getRelatedFromWithWeight()
std::pair<FROM*, float> getRelatedFromWithWeight |
( |
const std::string & |
name = "" , |
|
|
const std::string & |
namedRelation = "" |
|
) |
| const |
|
inline |
Get first related object & weight of relation pointing from an array.
- Template Parameters
-
FROM | The class of objects from which the relation points. |
- Parameters
-
name | The name of the store array from which the relation points. If empty the default store array name for class FROM will be used. If the special name "ALL" is given all store arrays containing objects of type FROM are considered. |
namedRelation | Additional name for the relation, or "" for the default naming |
- Returns
- Pair of first related object and the relation weight, or (NULL, 1.0) if none found.
Definition at line 314 of file RelationsObject.h.
◆ getRelatedTo()
TO* getRelatedTo |
( |
const std::string & |
name = "" , |
|
|
const std::string & |
namedRelation = "" |
|
) |
| const |
|
inline |
Get the object to which this object has a relation.
- Template Parameters
-
TO | The class of objects to which the relation points. |
- Parameters
-
name | The name of the store array to which the relation points. If empty the default store array name for class TO will be used. If the special name "ALL" is given all store arrays containing objects of type TO are considered. |
namedRelation | Additional name for the relation, or "" for the default naming |
- Returns
- The first related object or a null pointer.
Definition at line 248 of file RelationsObject.h.
◆ getRelatedToWithWeight()
std::pair<TO*, float> getRelatedToWithWeight |
( |
const std::string & |
name = "" , |
|
|
const std::string & |
namedRelation = "" |
|
) |
| const |
|
inline |
Get first related object & weight of relation pointing to an array.
- Template Parameters
-
TO | The class of objects to which the relation points. |
- Parameters
-
name | The name of the store array to which the relation points. If empty the default store array name for class TO will be used. If the special name "ALL" is given all store arrays containing objects of type TO are considered. |
namedRelation | Additional name for the relation, or "" for the default naming |
- Returns
- Pair of first related object and the relation weight, or (NULL, 1.0) if none found.
Definition at line 297 of file RelationsObject.h.
◆ getRelatedWithWeight()
std::pair<T*, float> getRelatedWithWeight |
( |
const std::string & |
name = "" , |
|
|
const std::string & |
namedRelation = "" |
|
) |
| const |
|
inline |
Get first related object & weight of relation pointing from/to an array.
- Template Parameters
-
T | The class of objects to or from which the relation points. |
- Parameters
-
name | The name of the store array to or from which the relation points. If empty the default store array name for class T will be used. If the special name "ALL" is given all store arrays containing objects of type T are considered. |
namedRelation | Additional name for the relation, or "" for the default naming |
- Returns
- Pair of first related object and the relation weight, or (NULL, 1.0) if none found.
Definition at line 331 of file RelationsObject.h.
◆ getRelationsFrom()
RelationVector<FROM> getRelationsFrom |
( |
const std::string & |
name = "" , |
|
|
const std::string & |
namedRelation = "" |
|
) |
| const |
|
inline |
Get the relations that point from another store array to this object.
- Template Parameters
-
FROM | The class of objects from which the relations point. |
- Parameters
-
name | The name of the store array from which the relations point. If empty the default store array name for class FROM will be used. If the special name "ALL" is given all store arrays containing objects of type FROM are considered. |
namedRelation | Additional name for the relation, or "" for the default naming |
- Returns
- A vector of relations.
Definition at line 212 of file RelationsObject.h.
◆ getRelationsTo()
RelationVector<TO> getRelationsTo |
( |
const std::string & |
name = "" , |
|
|
const std::string & |
namedRelation = "" |
|
) |
| const |
|
inline |
Get the relations that point from this object to another store array.
- Template Parameters
-
TO | The class of objects to which the relations point. |
- Parameters
-
name | The name of the store array to which the relations point. If empty the default store array name for class TO will be used. If the special name "ALL" is given all store arrays containing objects of type TO are considered. |
namedRelation | Additional name for the relation, or "" for the default naming |
- Returns
- A vector of relations.
Definition at line 197 of file RelationsObject.h.
◆ getRelationsWith()
RelationVector<T> getRelationsWith |
( |
const std::string & |
name = "" , |
|
|
const std::string & |
namedRelation = "" |
|
) |
| const |
|
inline |
Get the relations between this object and another store array.
Relations in both directions are returned.
- Template Parameters
-
T | The class of objects to or from which the relations point. |
- Parameters
-
name | The name of the store array to or from which the relations point. If empty the default store array name for class T will be used. If the special name "ALL" is given all store arrays containing objects of type T are considered. |
namedRelation | Additional name for the relation, or "" for the default naming |
- Returns
- A vector of relations.
Definition at line 230 of file RelationsObject.h.
◆ operator=()
Assignment operator.
cached values of 'this' are not touched, since position does not change.
- Parameters
-
relationsInterface | The object that should be assigned. |
Definition at line 128 of file RelationsObject.h.
The documentation for this class was generated from the following file: