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

PlexPinDiodeId.h

Go to the documentation of this file.
00001 
00002 // $Id: PlexPinDiodeId.h,v 1.15 2005/08/26 18:47:03 rhatcher Exp $
00003 //
00004 // PlexPinDiodeId
00005 //
00006 // PlexPinDiodeId encapsulates mux/inbox/gain number encoding
00007 //
00008 // Author:  R. Hatcher 2001.06.26
00009 //
00011 
00012 #ifndef PLEXPINDIODEID_H
00013 #define PLEXPINDIODEID_H
00014 
00015 #include "PlexMuxBoxId.h"
00016 
00017 // for now include obsolete methods
00018 //#define ENABLE_PINDIODEID_ISNULL
00019 //#define ENABLE_PINDIODEID_ENCODEMUXBOX
00020 
00021 class PlexPinDiodeId;
00022 std::ostream& operator<<(std::ostream& os, const PlexPinDiodeId& p);
00023 
00024 class PlexPinDiodeId : public PlexMuxBoxId {
00025 
00026  public:
00027 
00028    PlexPinDiodeId();                        // necessary for streamer io
00029    PlexPinDiodeId(Detector::Detector_t detector,
00030                   ElecType::Elec_t electronics,
00031                   Char_t eastwest, Char_t racklevel, 
00032                   UInt_t rackbay, UInt_t inrack,
00033                   UInt_t inbox, UInt_t gain);
00034    PlexPinDiodeId(PlexMuxBoxId muxbox,
00035                   UInt_t inbox, UInt_t gain);
00036 
00037    // non-virtual dtor would be okay, but ClassDef brings in virtualness
00038    virtual ~PlexPinDiodeId();
00039 
00040    // use these two with caution as they work on the rawest level
00041    explicit PlexPinDiodeId(const UInt_t encoded);
00042    inline UInt_t            GetEncoded() const;
00043 
00044    const char              *AsString(Option_t *option="") const;
00045 
00046    UShort_t                 GetInBox() const;
00047    UShort_t                 GetGain() const;
00048    // the assignment of High/Low is plain weird, but that's how it is
00049    Bool_t                   IsHighGain() const { return GetGain()==0; }
00050    Bool_t                   IsLowGain() const { return GetGain()==1; }
00051 
00052    Bool_t                   IsValid() const;
00053 #ifdef ENABLE_PINDIODEID_ISNULL
00054    Bool_t                   IsNull() const;
00055 #endif
00056 
00057    void Print(Option_t *option="") const;
00058 
00059    void SetInBox(UInt_t inbox);
00060    void SetGain(UInt_t gain);
00061 
00062    friend Bool_t operator< (const PlexPinDiodeId &lhs, const PlexPinDiodeId &rhs);
00063    friend Bool_t operator<=(const PlexPinDiodeId &lhs, const PlexPinDiodeId &rhs);
00064    friend Bool_t operator==(const PlexPinDiodeId &lhs, const PlexPinDiodeId &rhs);
00065    friend Bool_t operator!=(const PlexPinDiodeId &lhs, const PlexPinDiodeId &rhs);
00066    friend Bool_t operator> (const PlexPinDiodeId &lhs, const PlexPinDiodeId &rhs);
00067    friend Bool_t operator>=(const PlexPinDiodeId &lhs, const PlexPinDiodeId &rhs);
00068 
00069 #ifdef ENABLE_PINDIODEID_ENCODEMUXBOX
00070    static Int_t EncodeMuxBox(Char_t eastwest, Char_t racklevel,
00071                              Int_t rackbay, Int_t inrack);
00072 
00073    static void  DecodeMuxBox(Int_t muxbox, Char_t& eastwest, Char_t& racklevel,
00074                              Int_t& rackbay, Int_t& inrack);
00075 #endif
00076 
00077  private:
00078 
00079    ClassDef(PlexPinDiodeId,3)
00080 };
00081 
00082 #ifndef __CINT__
00083 //==========================================================================
00084 // Implementation details 
00085 //==========================================================================
00086 //
00087 // The details of the encoding of PlexPinDiodeId are here in 
00088 // PlexPinDiodeId.h; this is so that the compiler can inline the code
00089 // Users should NOT rely on intimate knowledge of these details.
00090 //
00091 //    MSB                          LSB
00092 //     3         2         1         0
00093 //    10987654321098765432109876543210
00094 //    ddddeemmmmmmmmmmmm-----iiiiiiiig  old pin diode id
00095 //    vdddeeWELLBBBBBIIII----iiiiiiiig  new pin diode id
00096 //    77776666555544443333222211110000
00097 
00098 const UInt_t maskPlexPinGain         = 0x00000001; // 0=low, 1=high
00099 const UInt_t shftPlexPinGain         = 0;
00100 const UInt_t maskPlexPinInBox        = 0x000001FE; // 0:255
00101 const UInt_t shftPlexPinInBox        = 1;
00102 
00103 const UInt_t zeroPlexPinGain = ~maskPlexPinGain;
00104 const UInt_t zeroPlexPinInBoxGain = ~(maskPlexPinInBox|maskPlexPinGain);
00105            
00106 //==========================================================================
00107 
00108 inline Bool_t operator< (const PlexPinDiodeId &lhs, const PlexPinDiodeId &rhs)
00109 { lhs.ConvertToVersion2(); rhs.ConvertToVersion2();
00110   return lhs.fEncoded <  rhs.fEncoded; }
00111 
00112 inline Bool_t operator<=(const PlexPinDiodeId &lhs, const PlexPinDiodeId &rhs)
00113 { lhs.ConvertToVersion2(); rhs.ConvertToVersion2();
00114   return lhs.fEncoded <= rhs.fEncoded; }
00115 
00116 inline Bool_t operator==(const PlexPinDiodeId &lhs, const PlexPinDiodeId &rhs)
00117 { lhs.ConvertToVersion2(); rhs.ConvertToVersion2();
00118   return lhs.fEncoded == rhs.fEncoded; }
00119 
00120 inline Bool_t operator!=(const PlexPinDiodeId &lhs, const PlexPinDiodeId &rhs)
00121 { lhs.ConvertToVersion2(); rhs.ConvertToVersion2();
00122   return lhs.fEncoded != rhs.fEncoded; }
00123 
00124 inline Bool_t operator> (const PlexPinDiodeId &lhs, const PlexPinDiodeId &rhs)
00125 { lhs.ConvertToVersion2(); rhs.ConvertToVersion2();
00126   return lhs.fEncoded >  rhs.fEncoded; }
00127 
00128 inline Bool_t operator>=(const PlexPinDiodeId &lhs, const PlexPinDiodeId &rhs)
00129 { lhs.ConvertToVersion2(); rhs.ConvertToVersion2();
00130   return lhs.fEncoded >= rhs.fEncoded; }
00131 
00132 inline UInt_t PlexPinDiodeId::GetEncoded() const
00133 { ConvertToVersion2(); return fEncoded; }
00134 
00135 inline UShort_t PlexPinDiodeId::GetInBox() const
00136 {
00137   ConvertToVersion2();
00138   return (fEncoded & maskPlexPinInBox ) >> shftPlexPinInBox;
00139 }
00140 
00141 inline UShort_t PlexPinDiodeId::GetGain() const
00142 {
00143   ConvertToVersion2();
00144   return (fEncoded & maskPlexPinGain ) >> shftPlexPinGain;
00145 }
00146 
00147 inline void PlexPinDiodeId::SetInBox(UInt_t inbox)
00148 {
00149   ConvertToVersion2();
00150   fEncoded = (fEncoded & ~maskPlexPinInBox) |
00151       ( ( inbox << shftPlexPinInBox ) & maskPlexPinInBox );
00152 }
00153 
00154 inline void PlexPinDiodeId::SetGain(UInt_t gain)
00155 {
00156   ConvertToVersion2();
00157   fEncoded = (fEncoded & ~maskPlexPinGain) |
00158       ( ( gain << shftPlexPinGain ) & maskPlexPinGain );
00159 }
00160 
00161 inline Bool_t PlexPinDiodeId::IsValid() const
00162 { 
00163    // test whether this is the nonsensical default value
00164    return  ( fEncoded & zeroPlexMuxVersion ) != defaultMuxBoxId;
00165    // (fEncoded&~(maskPlexMuxVersion|maskPlexPinInBox|maskPlexPinGain)) != defaultMuxBoxId;
00166 }
00167 
00168 #endif /* __CINT__ */
00169 #endif // PLEXPINDIODEID_H

Generated on Fri Mar 28 15:37:38 2008 for loon by  doxygen 1.3.9.1