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, CDCDedxHit, CDCDedxLikelihood, CDCDedxTrack, CDCRawHit, CDCRawHitWaveForm, CDCTrigger3DFinderInfo, 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, KLMMuonIDDNNInputVariable, KLMScintillatorFirmwareFitResult, KLMTrgFittedTrack, KLMTrgSummary, KLMTriggerHit, KLMTriggerTrack, Kink, 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.
|
|
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.
|
|
|
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...(),
}
A Class to store the Monte Carlo particle information.
or, for 1:1 relations, the first related object (or NULL) using getRelated...():
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:
particle->addRelationTo(someOtherObject)
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.
◆ RelationsInterface() [1/3]
template class cannot be removed without breaking ROOT I/O, so just disable it.
Default constructor.
Definition at line 107 of file RelationsObject.h.
DataStore::StoreEntry * m_cacheDataStoreEntry
Cache of the data store entry to which this object belongs.
int m_cacheArrayIndex
Cache of the index in the TClonesArray to which this object belongs.
◆ RelationsInterface() [2/3]
Constructor, forwards all arguments to BASE constructor.
Definition at line 110 of file RelationsObject.h.
110 :
111 BASE(std::forward<Args>(params)...),
◆ RelationsInterface() [3/3]
Copy constructor.
Cached values are cleared.
- Parameters
-
relationsInterface | The object that should be copied. |
Definition at line 119 of file RelationsObject.h.
119 :
120 BASE(relationsInterface),
◆ 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.
143 {
144 if (object)
146 object, object->m_cacheDataStoreEntry, object->m_cacheArrayIndex, weight, namedRelation);
147 }
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.
static DataStore & Instance()
Instance of singleton Store.
◆ 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.
156 {
157 StoreEntry* toEntry = nullptr;
158 int toIndex = -1;
160 }
◆ 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.
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 }
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).
◆ getArrayIndex()
int getArrayIndex |
( |
| ) |
const |
|
inline |
Returns this object's array index (in StoreArray), or -1 if not found.
Definition at line 385 of file RelationsObject.h.
386 {
389 }
bool findStoreEntry(const TObject *object, StoreEntry *&entry, int &index)
Find an object in an array in the data store.
◆ getArrayName()
std::string getArrayName |
( |
| ) |
const |
|
inline |
Get name of array this object is stored in, or "" if not found.
Definition at line 377 of file RelationsObject.h.
378 {
381 }
std::string name
Name of the entry.
◆ getArrayPointer()
TClonesArray * getArrayPointer |
( |
| ) |
const |
|
inlineprotected |
Returns the pointer to the raw DataStore array holding this object (protected since these arrays are easy to misuse).
Definition at line 418 of file RelationsObject.h.
419 {
422 return nullptr;
424 }
TClonesArray * getPtrAsArray() const
Return ptr cast to TClonesArray.
◆ 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.
371 {
373 }
virtual std::string getInfoHTML() const
Return a short summary of this object's contents in HTML format.
std::string htmlToPlainText(const std::string &html)
See RelationsObject::getInfo()
◆ 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 Particle, Cluster, MCParticle, PIDLikelihood, SoftwareTriggerResult, Track, TrackFitResult, TRGSummary, and RecoTrack.
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.
279 {
281 T::Class(), name, namedRelation).
object);
282 }
@ c_BothSides
Combination of c_FromSide and c_ToSide.
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.
TObject * object
Pointer to the object.
◆ 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.
264 {
267 }
@ c_FromSide
Return relations/objects pointed from (to a given object).
◆ 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.
316 {
318 FROM::Class(), name, namedRelation);
319 return std::make_pair(static_cast<FROM*>(entry.object), entry.weight);
320 }
◆ 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.
249 {
251 TO::Class(), name, namedRelation).
object);
252 }
@ c_ToSide
Return relations/objects pointed to (from a given object).
◆ 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.
299 {
301 TO::Class(), name, namedRelation);
302 return std::make_pair(static_cast<TO*>(entry.object), entry.weight);
303 }
◆ 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.
333 {
335 T::Class(), name, namedRelation);
336 return std::make_pair(static_cast<T*>(entry.object), entry.weight);
337 }
◆ 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.
214 {
217 }
RelationVector< T > getRelationsWith(const std::string &name="", const std::string &namedRelation="") const
Get the relations between this object and another store array.
◆ 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.
129 {
130 if (this != &relationsInterface)
131 this->BASE::operator=(relationsInterface);
132 return *this;
133 }
◆ DataStore
◆ m_cacheArrayIndex
Cache of the index in the TClonesArray to which this object belongs.
Definition at line 432 of file RelationsObject.h.
◆ m_cacheDataStoreEntry
Cache of the data store entry to which this object belongs.
Definition at line 429 of file RelationsObject.h.
The documentation for this class was generated from the following file: