Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

TRefFinder.cpp

Go to the documentation of this file.
00001 #include "caf_util/TRefFinder.hpp" 
00002 
00003 namespace caf_util {
00004 
00005   using namespace std ;
00006   using namespace cafe ;
00007 
00008   TRefFinder::TRefFinder() : _trackBranch("Track"), _vertexBranch("PrimaryVertex"),
00009                                        _debug(0)
00010   {}
00011 
00012   const TMBTrack*  TRefFinder::FindTrack(Event &event, const TRef& ref) const {
00013     unsigned int id ;
00014     if ((id = ref.GetUniqueID()) == 0) {
00015       cout << "caf_util::TRefFinder::FindTrack ERROR: TRef has fUniqueID 0!" ;
00016       cout << " This could mean that TRef was never assign to an object or it was cleared" << std::endl;
00017       return 0 ;
00018     }
00019 
00020     TMBTrack* trk = (TMBTrack*) ref.GetObject() ;    
00021     if (_debug>2) 
00022       cout << "TRefFinder: for TRef with process ID " << ref.GetPID() 
00023            << " and unique ID " << ref.GetUniqueID() 
00024            << " the track pointer was found " << trk 
00025            << endl ;
00026 
00027     if (trk) return trk ;
00028     
00029     id &= 0xffffff ;
00030     if (_debug>1) 
00031       cout << "TRefFinder: track pointer is zero. Will try to find the track with ID " 
00032            << id << endl ;
00033 
00034     Collection<TMBTrack> from(event.getCollection<TMBTrack>(_trackBranch, _trvars));
00035     Collection<TMBTrack>::const_iterator it = from.begin();
00036     for(; it != from.end(); ++it) 
00037       if ( (it->GetUniqueID() & 0xffffff) == id ) break ;
00038     
00039     if (it != from.end()) return &(*it) ;
00040     cout << "caf_util::TRefFinder::FindTrack ERROR: Could not find any track with id " 
00041          << id << " TRef is not correct!" << endl ;
00042     return 0 ;
00043   }
00044 
00045 
00046   const TMBPrimaryVertex*  TRefFinder::FindVertex(Event &event, const TRef& ref) const {
00047     unsigned int id ;
00048     if ((id = ref.GetUniqueID()) == 0) {
00049       cout << "caf_util::TRefFinder::FindVertex ERROR: TRef has fUniqueID 0!" ;
00050       cout << " This could mean that TRef was never assign to an object or it was cleared" << std::endl;
00051       return 0 ;
00052     }
00053     
00054     TMBPrimaryVertex* vtx = (TMBPrimaryVertex*) ref.GetObject() ;
00055     if (vtx) return vtx ;
00056 
00057     id &= 0xffffff ;
00058     Collection<TMBPrimaryVertex> from(event.getCollection<TMBPrimaryVertex>(_vertexBranch,_vtxvars));
00059     Collection<TMBPrimaryVertex>::const_iterator it = from.begin();
00060     for(; it != from.end(); ++it) 
00061       if ( (it->GetUniqueID() & 0xffffff) == id ) break ;
00062     
00063     if (it != from.end()) return &(*it) ;
00064     cout << "caf_util::TRefFinder::FindVertex ERROR: Could not find any track with id " 
00065          << id << " TRef is not correct!" << endl ;
00066     return 0 ;
00067   }
00068 
00069 }
00070 ClassImp(caf_util::TRefFinder) ;

Generated on Tue Mar 28 10:13:05 2006 for CAF by doxygen 1.3.4