Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

PlexPlaneId.h

Go to the documentation of this file.
00001 
00002 // $Id: PlexPlaneId.h,v 1.40 2005/08/26 18:47:03 rhatcher Exp $
00003 //
00004 // PlexPlaneId
00005 //
00006 // PlexPlaneId encapsulates plane number encoding
00007 //
00008 // Author:  R. Hatcher 2000.11.28
00009 //
00011 
00012 #ifndef PLEXPLANEID_H
00013 #define PLEXPLANEID_H
00014 
00015 #include <iosfwd>
00016 
00017 #include "Conventions/Detector.h"
00018 #include "Conventions/PlaneView.h"
00019 #include "Conventions/PlaneCoverage.h"
00020 
00021 class PlexPlaneId;
00022 std::ostream& operator<<(std::ostream& os, const PlexPlaneId& p);
00023 
00024 class PlexPlaneId {
00025 
00026  public:
00027 
00028    PlexPlaneId();
00029    PlexPlaneId(Detector::Detector_t detector,
00030                UInt_t plane, Bool_t isSteel=kFALSE,
00031                PlaneView::PlaneView_t view=PlaneView::kUnknown,
00032                PlaneCoverage::PlaneCoverage_t cover=PlaneCoverage::kUnknown);
00033 
00034    virtual ~PlexPlaneId() { ; } // no owned data members
00035 
00036    // use these three with caution as they work on the rawest level
00037    explicit PlexPlaneId(const UInt_t encoded);
00038    inline UInt_t            GetEncoded() const;
00039 
00040    const char              *AsString(Option_t *option="") const;
00041 
00042    Detector::Detector_t            GetDetector() const;
00043    UShort_t                        GetPlane() const;
00044    PlaneCoverage::PlaneCoverage_t  GetPlaneCoverage() const;
00045    PlaneView::PlaneView_t          GetPlaneView() const;
00046 
00047    Bool_t                          IsSteel() const;
00048    Bool_t                          IsVetoShield() const;
00049 
00050    Int_t                           GetVetoSection() const; // 1,2,3,4  0=!Veto
00051    Int_t                           GetSuperModule() const; // 0,1 for Far
00052    Bool_t                          IsNearSpect() const;
00053 
00054    virtual Bool_t                  IsValid() const; // !IsNull and Active has scint
00055    Bool_t                          IsNull() const;  // default nonsense value?
00056 
00057    UShort_t                        NumberOfStrips() const; 
00058 
00059    enum EPlaneType {
00060       kScintOrSteel,
00061       kScint,
00062       kSteel
00063    };
00064 
00065    // methods for iteration over planes
00066    // (may be problematic transitioning shield sections)
00067    PlexPlaneId  GetNext(EPlaneType ptype=PlexPlaneId::kScintOrSteel,
00068                         PlaneView::PlaneView_t view=PlaneView::kUnknown,
00069                         PlaneCoverage::PlaneCoverage_t cover=PlaneCoverage::kUnknown) const;
00070    PlexPlaneId  GetPrevious(EPlaneType ptype=PlexPlaneId::kScintOrSteel,
00071                             PlaneView::PlaneView_t view=PlaneView::kUnknown,
00072                             PlaneCoverage::PlaneCoverage_t cover=PlaneCoverage::kUnknown) const;
00073 
00074    // GetAdjoin() returns Previous() if dir<0, otherwise Next()
00075    PlexPlaneId  GetAdjoin(Int_t dir, 
00076                           EPlaneType ptype=PlexPlaneId::kScintOrSteel,
00077                           PlaneView::PlaneView_t view=PlaneView::kUnknown,
00078                           PlaneCoverage::PlaneCoverage_t cover=PlaneCoverage::kUnknown) const;
00079    PlexPlaneId  GetAdjoinScint(Int_t dir,
00080                                PlaneView::PlaneView_t view=PlaneView::kUnknown,
00081                                PlaneCoverage::PlaneCoverage_t cover=PlaneCoverage::kUnknown) const;
00082    PlexPlaneId  GetAdjoinSteel(Int_t dir,
00083                                PlaneView::PlaneView_t view=PlaneView::kUnknown,
00084                                PlaneCoverage::PlaneCoverage_t cover=PlaneCoverage::kUnknown) const;
00085 
00086    UShort_t     GetNumStrips() const;
00087    UShort_t     GetNumScintMdls() const;
00088 
00089    void Print(Option_t *option="") const;
00090 
00091    void SetDetector(Detector::Detector_t detector);
00092    void SetPlane(UInt_t plane,
00093                  PlaneView::PlaneView_t view=PlaneView::kUnknown,
00094                  PlaneCoverage::PlaneCoverage_t cover=PlaneCoverage::kUnknown);
00095 
00096    void SetPlaneCoverage(PlaneCoverage::PlaneCoverage_t coverage);
00097    void SetPlaneView(PlaneView::PlaneView_t view);
00098    
00099    void SetIsSteel(Bool_t isSteel);
00100 
00101    friend Bool_t operator< (const PlexPlaneId &lhs, const PlexPlaneId &rhs);
00102    friend Bool_t operator<=(const PlexPlaneId &lhs, const PlexPlaneId &rhs);
00103    friend Bool_t operator==(const PlexPlaneId &lhs, const PlexPlaneId &rhs);
00104    friend Bool_t operator!=(const PlexPlaneId &lhs, const PlexPlaneId &rhs);
00105    friend Bool_t operator> (const PlexPlaneId &lhs, const PlexPlaneId &rhs);
00106    friend Bool_t operator>=(const PlexPlaneId &lhs, const PlexPlaneId &rhs);
00107 
00108  protected:
00109 
00110    UInt_t   fEncoded;  // encoded value
00111 
00112  private:
00113 
00114    PlaneView::PlaneView_t
00115          DefaultPlaneView(Detector::Detector_t detector, UInt_t plane);
00116 
00117    PlaneCoverage::PlaneCoverage_t
00118          DefaultPlaneCoverage(Detector::Detector_t detector, UInt_t plane);
00119 
00120 public:
00121                                                              // blank
00122    inline static UInt_t LastPlaneFarSM0()    { return 248; } //   0 + [  1-248]
00123    inline static UInt_t LastPlaneFarSM1()    { return 485; } // 249 + [250-485]
00124    inline static UInt_t LastPlaneNearCalor() { return 120; } //   0 + [  1-120]
00125    inline static UInt_t LastPlaneNearSpect() { return 281; } //       [121-281] by 5
00126 
00127    // ugly public members for handling weird geometries
00128    //static Bool_t fgFarIsUV;          // far detector is organized as UV or VU
00129    static Bool_t fgCalDetCosmicsAView; // either A or B view
00130 
00131    ClassDef(PlexPlaneId,4)
00132 };
00133 
00134 #ifndef __CINT__
00135 //==========================================================================
00136 // Implementation details 
00137 //==========================================================================
00138 //
00139 // The details of the encoding of PlexPlaneId and PlexStripEndId
00140 // are here in PlexPlaneId.h; this is so that the compiler can
00141 // inline the code.  Users should NOT rely on intimate knowledge of
00142 // these details.
00143 //
00144 //    MSB                          LSB
00145 //     3         2         1         0
00146 //    10987654321098765432109876543210
00147 //    ddddppppppppppSvvvccssssssssxxee  PlexStripEndId
00148 //    ddddppppppppppSvvvccmmmmmmmm----  PlexScintMdlId
00149 //
00150 // detector    dddd       0:15   (0=unknown,1=near,2=far,3=caldet,4=test)
00151 // plane       pppppppppp 0:1023
00152 // issteel     S          0:1    (0=active,1=steel)
00153 // view        vvv        0:7    (X,Y,U,V,A,B,unknown)
00154 // coverage    cc         0:3    (noact,nearpart,nearful,complete)
00155 //                                unknown->complete
00156 //                               (use high-order bit to get 4:11)
00157 // module      mmmmmmmm   0:255
00158 // strip       ssssssss   0:255
00159 // subpart     xx         0:3    (unknown,-,+,whole)
00160 // stripend    ee         0:3    (unknown,-,+,whole)
00161 //
00162 const UInt_t defaultPlexPlaneId    = 0xffffffff;
00163 const UInt_t defaultPlexStripEndId = defaultPlexPlaneId;
00164 const UInt_t defaultPlexScintMdlId = defaultPlexPlaneId;
00165 
00166 const UInt_t maskPlexIdDetector     = 0x70000000;
00167 const UInt_t shftPlexIdDetector     = 28;
00168 const UInt_t maskPlexIdPlane        = 0x0FFC0000;
00169 const UInt_t shftPlexIdPlane        = 18;
00170 const UInt_t maskPlexIdIsSteel      = 0x00020000;
00171 const UInt_t maskPlexIdView         = 0x0001C000;
00172 const UInt_t shftPlexIdView         = 14;
00173 const UInt_t bitsPlexIdView         = 3;
00174 const UInt_t maskPlexIdCoverage     = 0x00003000;
00175 const UInt_t shftPlexIdCoverage     = 12;
00176 const UInt_t bitsPlexIdCoverage     = 2;
00177 const UInt_t maskPlexIdStrip        = 0x00000FF0;
00178 const UInt_t shftPlexIdStrip        = 4;
00179 const UInt_t bitsPlexIdStrip        = 8; // used for Build18BitPlnStripKey
00180 const UInt_t maskPlexIdScintMdl     = maskPlexIdStrip;
00181 const UInt_t shftPlexIdScintMdl     = shftPlexIdStrip;
00182 const UInt_t maskPlexIdSubPart      = 0x0000000C;
00183 const UInt_t shftPlexIdSubPart      = 2;
00184 const UInt_t maskPlexIdEnd          = 0x00000003;
00185 const UInt_t shftPlexIdEnd          = 0;
00186            
00187 const UInt_t zeroPlexIdStripInfo =
00188    ~(maskPlexIdStrip|maskPlexIdSubPart|maskPlexIdEnd);
00189 
00190 // used to test if Far Detector Veto Shield'ness
00191 // veto shield planes are all >= 512
00192 const UInt_t maskPlexIdIsVetoShield = (512 << shftPlexIdPlane);
00193 // each "section" of VetoShield is assigned a range of 64 plane #'s
00194 const UInt_t shftPlexIdVetoSection = 6;
00195 const UInt_t maskPlexIdIsFar =
00196    (Detector::kFar << shftPlexIdDetector);
00197 const UInt_t setPlexIdVSView       = (1 << bitsPlexIdView);
00198 const UInt_t setPlexIdVSCoverage   = (1 << bitsPlexIdCoverage);
00199 const UInt_t setPlexIdVSCoverage2  = (setPlexIdVSCoverage << 1);
00200 const UInt_t maskPlexIdVSCoverage2 = 0x80000000;
00201 
00202 const UInt_t maskPlexIdIsNear =
00203    (Detector::kNear << shftPlexIdDetector);
00204 
00205 //==========================================================================
00206 //
00207 // Be careful of order of inlines so as not to have one depend on
00208 // another that comes later.
00209 //
00210 //==========================================================================
00211 
00212 inline Bool_t operator< (const PlexPlaneId &lhs, const PlexPlaneId &rhs)
00213 { return (lhs.fEncoded&zeroPlexIdStripInfo) <  (rhs.fEncoded&zeroPlexIdStripInfo); }
00214 
00215 inline Bool_t operator<=(const PlexPlaneId &lhs, const PlexPlaneId &rhs)
00216 { return (lhs.fEncoded&zeroPlexIdStripInfo) <= (rhs.fEncoded&zeroPlexIdStripInfo); }
00217 
00218 inline Bool_t operator==(const PlexPlaneId &lhs, const PlexPlaneId &rhs)
00219 { return (lhs.fEncoded&zeroPlexIdStripInfo) == (rhs.fEncoded&zeroPlexIdStripInfo); }
00220 
00221 inline Bool_t operator!=(const PlexPlaneId &lhs, const PlexPlaneId &rhs)
00222 { return (lhs.fEncoded&zeroPlexIdStripInfo) != (rhs.fEncoded&zeroPlexIdStripInfo); }
00223 
00224 inline Bool_t operator> (const PlexPlaneId &lhs, const PlexPlaneId &rhs)
00225 { return (lhs.fEncoded&zeroPlexIdStripInfo) >  (rhs.fEncoded&zeroPlexIdStripInfo); }
00226 
00227 inline Bool_t operator>=(const PlexPlaneId &lhs, const PlexPlaneId &rhs)
00228 { return (lhs.fEncoded&zeroPlexIdStripInfo) >= (rhs.fEncoded&zeroPlexIdStripInfo); }
00229 
00230 inline PlexPlaneId::PlexPlaneId() : fEncoded(defaultPlexPlaneId) { ; }
00231 inline PlexPlaneId::PlexPlaneId(const UInt_t encoded) : fEncoded(encoded) { ; }
00232 
00233 inline UInt_t PlexPlaneId::GetEncoded() const
00234 { return fEncoded & zeroPlexIdStripInfo; }
00235 
00236 inline Detector::Detector_t PlexPlaneId::GetDetector() const
00237 { 
00238    Int_t bitField = ( fEncoded & maskPlexIdDetector ) >> shftPlexIdDetector;
00239    return (Detector::Detector_t) bitField;   
00240 }
00241 
00242 inline UShort_t PlexPlaneId::GetPlane() const
00243 {
00244    return ( fEncoded & maskPlexIdPlane ) >> shftPlexIdPlane;
00245 }
00246 
00247 inline Bool_t PlexPlaneId::IsSteel() const
00248 {
00249    //if (IsVetoShield()) return false;  // only if sharing steel bit
00250    return ( fEncoded & maskPlexIdIsSteel );
00251 }
00252 
00253 inline Bool_t PlexPlaneId::IsNull() const
00254 { 
00255   // test if plane # = all bits on as signal of invalid value
00256   return ( fEncoded & maskPlexIdPlane ) == maskPlexIdPlane;
00257 }
00258 
00259 inline Bool_t PlexPlaneId::IsVetoShield() const
00260 {
00261    if ( IsNull() ) return false;
00262    switch (GetDetector()) {
00263    case Detector::kFar:
00264        return ( fEncoded & maskPlexIdIsVetoShield );
00265    case Detector::kCalDet:
00266        return ( GetPlane() > 60 );
00267    default:
00268        return false;
00269    }
00270 }
00271 
00272 inline Int_t PlexPlaneId::GetVetoSection() const
00273 {
00274    // return section # (1,2,3,4) or 0 if not part of VetoShield
00275    if ( ! IsVetoShield() ) return 0;
00276    if ( Detector::kCalDet == GetDetector() ) return 1;
00277    UShort_t plane = GetPlane();
00278    return ( ( ( plane >> shftPlexIdVetoSection ) & 0x03 ) + 1  );
00279 }
00280 
00281 inline Int_t PlexPlaneId::GetSuperModule() const
00282 {
00283    // return supermodule # (0,1 if Far, else 0)
00284    if ( ! ( fEncoded & maskPlexIdIsFar ) ) return  0;
00285    UShort_t plane = GetPlane();
00286    if      ( plane <= LastPlaneFarSM0() )  return  0;
00287    else if ( plane <= LastPlaneFarSM1() )  return  1;
00288    else                                    return -1;
00289 }
00290 
00291 inline Bool_t PlexPlaneId::IsNearSpect() const
00292 {
00293    // return true if part of NearDet spectrometer region
00294    if ( ! ( fEncoded & maskPlexIdIsNear ) ) return false;
00295    UShort_t plane = GetPlane();
00296    return ( plane > LastPlaneNearCalor() );
00297 }
00298 
00299 inline PlaneCoverage::PlaneCoverage_t PlexPlaneId::GetPlaneCoverage() const
00300 {
00301    Int_t bitField = ( fEncoded & maskPlexIdCoverage ) >> shftPlexIdCoverage;
00302    if (GetDetector()==Detector::kFar && IsVetoShield()) {
00303      if ( fEncoded & maskPlexIdVSCoverage2 ) bitField |= setPlexIdVSCoverage2;
00304      else                                    bitField |= setPlexIdVSCoverage;
00305    }
00306    return (PlaneCoverage::PlaneCoverage_t) bitField;
00307 }
00308 
00309 inline PlaneView::PlaneView_t PlexPlaneId::GetPlaneView() const
00310 {
00311    Int_t bitField = ( fEncoded & maskPlexIdView ) >> shftPlexIdView;
00312    if (GetDetector()==Detector::kFar && IsVetoShield()) 
00313      bitField |= setPlexIdVSView;
00314    return (PlaneView::PlaneView_t) bitField;
00315 }
00316 
00317 inline void PlexPlaneId::SetDetector(Detector::Detector_t detector)
00318 {
00319    fEncoded = ( fEncoded & ~maskPlexIdDetector ) | 
00320       ( ( detector << shftPlexIdDetector ) & maskPlexIdDetector );
00321 }
00322 
00323 inline void PlexPlaneId::SetIsSteel(Bool_t isSteel)
00324 {
00325   if (isSteel) fEncoded |=  maskPlexIdIsSteel;
00326   else         fEncoded &= ~maskPlexIdIsSteel;
00327 }
00328 
00329 inline void PlexPlaneId::SetPlaneCoverage(PlaneCoverage::PlaneCoverage_t coverage)
00330 {
00331    fEncoded = ( fEncoded & ~(maskPlexIdCoverage|maskPlexIdVSCoverage2) ) | 
00332       ( ( coverage << shftPlexIdCoverage ) & maskPlexIdCoverage );
00333    // set extra bit for higher VetoShield enum values
00334    if ( coverage >= PlaneCoverage::kVScS ) fEncoded |= maskPlexIdVSCoverage2;
00335 }
00336 
00337 inline void PlexPlaneId::SetPlaneView(PlaneView::PlaneView_t view)
00338 {
00339    fEncoded = ( fEncoded & ~maskPlexIdView ) | 
00340       ( ( view << shftPlexIdView ) & maskPlexIdView );
00341 }
00342 
00343 inline PlexPlaneId 
00344   PlexPlaneId::GetAdjoin(Int_t dir, EPlaneType ptype,
00345                          PlaneView::PlaneView_t view,
00346                          PlaneCoverage::PlaneCoverage_t cover) const
00347 {
00348   return (dir<0) ? GetPrevious(ptype,view,cover) : GetNext(ptype,view,cover); 
00349 }
00350 
00351 inline PlexPlaneId 
00352   PlexPlaneId::GetAdjoinScint(Int_t dir,
00353                               PlaneView::PlaneView_t view,
00354                               PlaneCoverage::PlaneCoverage_t cover) const
00355 { return GetAdjoin(dir,PlexPlaneId::kScint,view,cover); }
00356 
00357 inline PlexPlaneId 
00358   PlexPlaneId::GetAdjoinSteel(Int_t dir,
00359                               PlaneView::PlaneView_t view,
00360                               PlaneCoverage::PlaneCoverage_t cover) const
00361 { return GetAdjoin(dir,PlexPlaneId::kSteel,view,cover); }
00362 
00363 #endif /* __CINT__ */
00364 #endif // PLEXPLANEID_H

Generated on Sat Nov 21 22:47:20 2009 for loon by  doxygen 1.3.9.1