00001 //-------------------------------------------------------------------------- 00002 // File and Version Information: 00003 // $Id: TrkFundHit.cxx,v 1.4 2011/02/17 11:53:41 zhangy Exp $ 00004 // 00005 // Description: 00006 // 00007 // Environment: 00008 // Software developed for the BaBar Detector at the SLAC B-Factory. 00009 // 00010 // Author(s): Steve Schaffner 00011 // 00012 // We may want to inline some of these functions some day. 00013 // 00014 // Revision History: 00015 // 20000523 M. Kelsey -- Add concrete printAll() implementation which 00016 // calls through to subclass print(), then dumps HOT list. 00017 //------------------------------------------------------------------------ 00018 #include "TrkBase/TrkFundHit.h" 00019 #include "TrkBase/TrkHitOnTrk.h" 00020 #include "TrkBase/TrkHitOnTrkIter.h" 00021 #include "TrkBase/TrkPredicates.h" 00022 #include <assert.h> 00023 #include <algorithm> 00024 #include <iostream> 00025 // Remove!: 00026 // MHK Restore, for use in printAll() 00027 #include "TrkBase/TrkRecoTrk.h" 00028 using std::endl; 00029 using std::ostream; 00030 00031 int debug_nHit = 0; 00032 00033 TrkFundHit::TrkFundHit() { 00034 //std::cout << " @ TrkFundHit constructor: " << ++debug_nHit << " addr: " << this << std::endl; 00035 } 00036 00037 TrkFundHit::~TrkFundHit() 00038 { 00039 //std::cout << " @ ~TrkFundHit() : " << --debug_nHit << " addr: " << this << std::endl; 00040 // hitlist cleanup done in derived classes 00041 } 00042 00043 TrkFundHit::TrkFundHit(const TrkFundHit& ) 00044 { 00045 assert(_hitList.empty()); 00046 //std::cout << " @ TrkFundHit copy constructor : " << ++debug_nHit << " addr: " << this << std::endl; 00047 } 00048 00049 TrkFundHit& 00050 TrkFundHit::operator= (const TrkFundHit& x) 00051 { 00052 //std::cout << " @ TrkFundHit operator= : " << debug_nHit << " addr: " << this << std::endl; 00053 assert(_hitList.empty()); 00054 return *this; 00055 } 00056 00057 const TrkHitOnTrk* 00058 TrkFundHit::setUsedHit(const TrkHitOnTrk *hit) 00059 { 00060 // if (hitList->contains(hit)) { 00061 // return; 00062 // } 00063 //FIXME: check hot corresponds to this hit?? 00064 // std::cout << "TrkFundHit setUsedHit "<<((MdcHit*)(hit->hit()))->layernumber()<<" "<<((MdcHit*)(hit->hit()))->wirenumber()<<endl; 00065 // this->printAll(std::cout);//yzhang debug 00066 _hitList.push_back(hit); 00067 // std::cout << "after push_bak " << std::endl;//yzhang debug 00068 // printAll(std::cout);//yzhang debug 00069 00070 return hit; 00071 } 00072 00073 // return hit if on list, return 0 if not on list... 00074 const TrkHitOnTrk * 00075 TrkFundHit::setUnusedHit(const TrkHitOnTrk *hit) 00076 { 00077 //std::cout << " @ setUnusedHit() : " << debug_nHit << " addr: " << this << std::endl; 00078 if (_hitList.empty()) return 0; 00079 std::vector<const TrkHitOnTrk*>::iterator i=std::find(_hitList.begin(),_hitList.end(),hit); 00080 if (i==_hitList.end()) return 0; 00081 assert(*i==hit); 00082 // std::cout << "TrkFundHit setUnusedHit "<<((MdcHit*)(hit->hit()))->layernumber()<<" "<<((MdcHit*)(hit->hit()))->wirenumber()<<endl; 00083 //this->printAll(std::cout);//yzhang debug 00084 _hitList.erase(i); 00085 return hit; 00086 } 00087 00088 int 00089 TrkFundHit::nUsedHits() const 00090 { 00091 return _hitList.size(); 00092 } 00093 00094 const TrkHitOnTrk* 00095 TrkFundHit::getHitOnTrack(const TrkRecoTrk *trk) const 00096 { 00097 hot_iterator i = std::find_if(begin(), end(), 00098 std::bind2nd(TrkBase::Predicates::isHotOnTrack(),trk)); 00099 return (i==end()?0:i.get()); 00100 } 00101 00102 void 00103 TrkFundHit::printAll(ostream& os) const 00104 { 00105 // print(os); // Call through to get subclass info 00106 os << " used by " << nUsedHits() << " HOTs" << endl; 00107 if (usedHit()) { 00108 for (hot_iterator i=begin(); i != end(); ++i) { 00109 i->printAll(os);//yzhang debug 00110 // os << "\ttrack " << i->parentTrack()->id() << ": "; 00111 // i->print(os); // NOTE: includes endl! 00112 //yzhang debug 00113 std::cout << " parentTrack" << std::endl;//yzhang debug 00114 i->parentTrack()->printAll(std::cout); 00115 //zhangy debug 00116 } 00117 os << endl; 00118 } 00119 }