From 48a67276d4984cd331ce249189fdd75fed8498d8 Mon Sep 17 00:00:00 2001 From: "Stephen A. Wood" <saw@jlab.org> Date: Tue, 1 May 2012 09:20:22 -0400 Subject: [PATCH] Move Compare method from THcHodoscopeHit to ThcRawHit since it should work for any derived class. --- src/THcHodoscopeHit.cxx | 2 ++ src/THcHodoscopeHit.h | 4 ++-- src/THcRawHit.cxx | 21 +++++++++++++++++++++ src/THcRawHit.h | 6 ++++-- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/THcHodoscopeHit.cxx b/src/THcHodoscopeHit.cxx index 1a34c8b..9e3ea84 100644 --- a/src/THcHodoscopeHit.cxx +++ b/src/THcHodoscopeHit.cxx @@ -38,6 +38,7 @@ Int_t THcHodoscopeHit::GetData(Int_t signal) { return(-1); // Actually should throw exception } +#if 0 Int_t THcHodoscopeHit::Compare(const TObject* obj) const { // Compare to sort by plane and counter @@ -57,6 +58,7 @@ Int_t THcHodoscopeHit::Compare(const TObject* obj) const else return 1; } } +#endif //_____________________________________________________________________________ THcHodoscopeHit& THcHodoscopeHit::operator=( const THcHodoscopeHit& rhs ) { diff --git a/src/THcHodoscopeHit.h b/src/THcHodoscopeHit.h index f8ce97b..0bac2d1 100644 --- a/src/THcHodoscopeHit.h +++ b/src/THcHodoscopeHit.h @@ -20,8 +20,8 @@ class THcHodoscopeHit : public THcRawHit { void SetData(Int_t signal, Int_t data); Int_t GetData(Int_t signal); - virtual Bool_t IsSortable () const {return kTRUE; } - virtual Int_t Compare(const TObject* obj) const; + // virtual Bool_t IsSortable () const {return kTRUE; } + // virtual Int_t Compare(const TObject* obj) const; Int_t fADC_pos; Int_t fADC_neg; diff --git a/src/THcRawHit.cxx b/src/THcRawHit.cxx index daa5138..3e37972 100644 --- a/src/THcRawHit.cxx +++ b/src/THcRawHit.cxx @@ -13,6 +13,27 @@ //THcRawHit::~THcRawHit() //{} +Int_t THcRawHit::Compare(const TObject* obj) const +{ + // Compare to sort by plane and counter + + const THcRawHit* hit = dynamic_cast<const THcRawHit*>(obj); + + if(!hit) return -1; + Int_t p1 = fPlane; + Int_t p2 = hit->fPlane; + if(p1 < p2) return -1; + else if(p1 > p2) return 1; + else { + Int_t c1 = fCounter; + Int_t c2 = hit->fCounter; + if(c1 < c2) return -1; + else if (c1 == c2) return 0; + else return 1; + } +} + + ClassImp(THcRawHit) //_____________________________________________________________________________ diff --git a/src/THcRawHit.h b/src/THcRawHit.h index 921939e..7372463 100644 --- a/src/THcRawHit.h +++ b/src/THcRawHit.h @@ -29,8 +29,10 @@ public: virtual Int_t GetData(Int_t signal) {return 0;}; // Derived objects must be sortable and supply Compare method - virtual Bool_t IsSortable () const {return kFALSE; } - virtual Int_t Compare(const TObject* obj) const {return 0;} + // virtual Bool_t IsSortable () const {return kFALSE; } + // virtual Int_t Compare(const TObject* obj) const {return 0;} + virtual Bool_t IsSortable () const {return kTRUE; } + virtual Int_t Compare(const TObject* obj) const; Int_t fPlane; Int_t fCounter; -- GitLab