CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DataFormats/TrackerRecHit2D/interface/OmniClusterRef.h

Go to the documentation of this file.
00001 #ifndef TrackerRecHit2D_OmniClusterRef_H
00002 #define TrackerRecHit2D_OmniClusterRef_H
00003 
00004 #include "DataFormats/Common/interface/RefCoreWithIndex.h"
00005 
00006 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
00007 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
00008 #include "DataFormats/Common/interface/DetSetVector.h"
00009 #include "DataFormats/Common/interface/DetSetVectorNew.h"
00010 #include "DataFormats/Common/interface/RefGetter.h"
00011 
00012 class OmniClusterRef {
00013 
00014   static const unsigned int kInvalid = 0x80000000; // bit 31 on
00015   static const unsigned int kIsStrip = 0x20000000; // bit 29 on
00016   static const unsigned int kIsRegional = 0x60000000; // bit 30 and 29 on
00017 
00018 public:
00019   typedef edm::Ref<edmNew::DetSetVector<SiPixelCluster>,SiPixelCluster > ClusterPixelRef;
00020   typedef edm::Ref<edmNew::DetSetVector<SiStripCluster>,SiStripCluster > ClusterStripRef;
00021   typedef edm::Ref< edm::LazyGetter<SiStripCluster>, SiStripCluster, edm::FindValue<SiStripCluster> >  ClusterRegionalRef;
00022   
00023   OmniClusterRef() : me(edm::RefCore(),kInvalid) {}
00024   explicit OmniClusterRef(ClusterPixelRef const & ref) : me(ref.refCore(), (ref.isNonnull() ? ref.key() : kInvalid) ){}
00025   explicit OmniClusterRef(ClusterStripRef const & ref) : me(ref.refCore(), (ref.isNonnull() ? ref.key() | kIsStrip : kInvalid) ){}
00026   explicit OmniClusterRef(ClusterRegionalRef const & ref) : me(ref.refCore(), (ref.isNonnull() ? ref.key() | kIsRegional : kInvalid)){}
00027   
00028   ClusterPixelRef cluster_pixel()  const { 
00029     return (isPixel() && isValid()) ?  ClusterPixelRef(me.toRefCore(),index()) : ClusterPixelRef();
00030   }
00031 
00032   ClusterStripRef cluster_strip()  const { 
00033     return isNonRegionalStrip() ? ClusterStripRef(me.toRefCore(),index()) : ClusterStripRef();
00034   }
00035   
00036   ClusterRegionalRef cluster_regional()  const { 
00037     return isRegional() ?  ClusterRegionalRef(me.toRefCore(),index()) : ClusterRegionalRef();
00038   }
00039   
00040 
00041   SiStripCluster const & stripCluster() const {
00042     return isRegional() ?  *ClusterRegionalRef(me.toRefCore(),index()) :  *ClusterStripRef(me.toRefCore(),index());
00043   }
00044   
00045   bool operator==(OmniClusterRef const & lh) const { 
00046     return rawIndex() == lh.rawIndex(); // in principle this is enough!
00047   }
00048 
00049   bool operator<(OmniClusterRef const & lh) const { 
00050     return rawIndex() < lh.rawIndex(); // in principle this is enough!
00051   }
00052   
00053 public:
00054   // edm Ref interface
00055   /* auto */ edm::ProductID id() const { return me.id();}
00056   unsigned int key() const { return index();}
00057 
00058 
00059   unsigned int rawIndex() const { return me.index();}
00060   
00061   unsigned int index() const { return rawIndex() & (~kIsRegional);}
00062   
00063 
00064   bool isValid() const { return !(rawIndex() & kInvalid); }
00065   bool isPixel() const { return !isStrip(); } //NOTE: non-valid will also show up as a pixel
00066   bool isStrip() const { return rawIndex() & kIsStrip; }
00067   bool isRegional() const { return (rawIndex() & kIsRegional)==kIsRegional; }
00068   bool isNonRegionalStrip() const {return (rawIndex() & kIsRegional)==kIsStrip;}
00069 
00070   edm::RefCoreWithIndex me;
00071  
00072   
00073 };
00074 
00075 #endif // TrackerRecHit2D_OmniClusterRef_H
00076