Changes to identifiers in DANA
From the DANA manual -
...
Every data object in DANA has a unique identifier attached to it.
This is done through its inheritance of the DObject class which has
a member named id of type oid_t (for object identifier type). The id
is used to uniquely identify an object within an event and can be used
by one data object to refer to another.
...
Example: A track is made up of detector hits. Each DTrackCandidate object
keeps a list of which DTrackHit objects were used to make it.
class DTrackCandidate:public DObject{
    public:
     HDCLASSDEF(DTrackCandidate);
     vector< oid_t> hitid; ///< ids of DTrackHit objects
     float x0,y0; ///< center of circle
     float z_vertex; ///< z coordinate of vertex
     float dphidz; ///< dphi/dz in radians per cm
     float q; ///< electric charge
     float p, p_trans; ///< total and transverse mom. in GeV/c
     float phi, theta; ///< theta and phi in radians
};
|
An identifier does not (explicitly) carry information about the
factory that created the object. This is a problem when a factory
can get its source objects from multiple places:
FindByID (templated)
Most often, you will know the class of the desired object and so
the templated FindByID method can be used. In the following example,
the pointer to a DTrackHit object is obtained using the oid_t id.
const DTrackHit* trackhit = loop-> FindByID< DTrackHit> (id);
This is the fastest way to search for the object pointer since
the method can restrict its search to only those factories that
provide the specified data type.
FindByID (non-templated)
If you have the id of an object, but don't know the specific
subclass of it, you can still obtain a pointer to it using the
non-templated version of FindByID. This version is slower and will
search through every object of every factory until it finds the
object with the given id.
const DObject* obj = loop-> FindByID(id);
FindOwner
If one wishes to obtain
a pointer to the factory that produced the object of the given id,
then use the FindOwner method. This method will return a pointer
to a DFactory_base object which must be dynamic_cast< > if one wishes
to use the methods of the subclass as shown if the following example:
DFactory_base *fac = loop-> FindOwner(id);
DFactory_TrackHit *fac_th = dynamic_cast< DFactory_TrackHit*> (fac);
The FindOwner method is overloaded to also accept a DObject pointer:
const DTrackHit* trackhit = loop-> FindByID< DTrackHit> (id);
DFactory_base *fac = loop-> FindOwner(trackhit);
DFactory_TrackHit *fac_th = dynamic_cast< DFactory_TrackHit*> (fac);
GetByID
Lower level methods are also provided in the DFactory and
DFactory_base classes and should be used if you already have
a pointer to the factory that you know produced the object
with the given id. Both provide a method called GetByID(oid_t).
The difference between the two is that the DFactory_base class
can only return a DObject pointer while the (template) class
DFactory can return a pointer to the subclass:
DFactory_base *fac = loop-> FindOwner(id);
DFactory_TrackHit *fac_th = dynamic_cast< DFactory_TrackHit*> (fac);
const DObject *obj = fac-> GetByID(id);
const DTrackHit *trackhit = fac_th-> GetByID(id);
|