| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Hardware.h

Go to the documentation of this file.
00001 
00006 #ifndef CONVENTIONS_HARDWARE_H
00007 #define CONVENTIONS_HARDWARE_H 1
00008 
00009 #include <string>
00010 #include <ostream>
00011 
00015 namespace DayaBay {
00016   
00017   // Define the types of hardware
00018   namespace Hardware {
00019     enum Hardware_t {
00020       kUnknown = 0,
00021       kPmt8inch,
00022       kPmt2inch,
00023       kRpc,
00024       kFee,
00025       kFec,
00026       kRot,
00027       kRom,
00028       kHighVoltage
00029     };
00030 
00031     // Convert type enum back and forth to string.
00032     const char* AsString(Hardware_t type);
00033     Hardware_t  FromString(const char* str);  
00034   }
00035 
00036   /* Uniquely define a piece of physical hardware by an ID number.
00037    *
00038    * Data is packed into a single integer as follows:
00039    * Bits: |   8   |   8   |   8   |   8   |
00040    * Data: | type  |        id number      |
00041    */
00042   class HardwareId {
00043   public:
00044     HardwareId() : m_data(0) {}
00045     // Define an ID based on packed data
00046     HardwareId(int data) { m_data = data; }
00047     // Define an ID based on the id / hardware type combination
00048     HardwareId(unsigned int id, Hardware::Hardware_t hardware)
00049       { m_data = (hardware << 24) | (0x00ffffff & id); }
00050     // Assignment Operator
00051     HardwareId& operator=(const HardwareId& id) 
00052       { m_data = id.m_data; return *this; }
00053 
00054     // Destructor
00055     virtual ~HardwareId();
00056     
00057     // Return the full ID as a raw packed integer.  If created by
00058     // subclass, this may include values in the lower three
00059     // bytes.
00060     int fullPackedData() const { return m_data; }
00061 
00062     // Hardware type
00063     Hardware::Hardware_t type() const
00064       { return (Hardware::Hardware_t)((m_data&0xff000000)>>24); }
00065     // Return the ID only
00066     int id() const { return (m_data & 0x00ffffff); }
00067 
00068     // Comparisons
00069     bool operator==(const HardwareId& rhs) const { return this->m_data == rhs.m_data; }
00070     bool operator!=(const HardwareId& rhs) const { return !(*this == rhs); }
00071 
00072   protected:
00073     unsigned int m_data;
00074   };
00075 
00076   bool operator<(const DayaBay::HardwareId& a, const DayaBay::HardwareId& b);
00077 
00078   // Identify a physical PMT + base assembly
00079   class PmtHardwareId : public HardwareId {
00080   public:
00081     PmtHardwareId() : HardwareId(0) {}
00082     PmtHardwareId(unsigned int id, Hardware::Hardware_t hardware) 
00083       : HardwareId(id, hardware) {}
00084     PmtHardwareId(int data) : HardwareId(data) {}    
00085     virtual ~PmtHardwareId() {}
00086     // Assignment Operator
00087     PmtHardwareId& operator=(const PmtHardwareId& id) 
00088       { m_data = id.m_data; return *this; }
00089     // Return the pmt ID only
00090     int id() const { return (m_data & 0x00ffffff); }
00091   };
00092 
00093   /* Identify a physical Rpc assembly
00094    *
00095    * Can be used to identify a full 2x2m RPC panel, as well as a
00096    * specific layer and strip.  The data is stored as follows:
00097    * Bits: |   8   |   8   |   8   |   8   |
00098    * Data: | type  |panelId| layer | strip |
00099    * Layers are indexed from 1 to 4 starting from the lowest layer of the panel
00100    * Strips are indexed from 1 to 8.
00101    * For layers with strips oriented parallel to the readout edge, the
00102    * numbering starts closest to the readout edge.  For layers with
00103    * strips oriented perpendicular to the readout edge, the numbering
00104    * starts at the right when looking from the direction of the
00105    * readout edge.
00106    */
00107   class RpcHardwareId : public HardwareId {
00108   public:
00109     RpcHardwareId() : HardwareId(0) {}
00110     RpcHardwareId(int panelId, int layer, int strip) : 
00111       HardwareId((0x000000ff & panelId)<<16 |
00112                  (0x000000ff & layer)<<8 |
00113                  (0x000000ff & strip), 
00114                  Hardware::kRpc) {}
00115     RpcHardwareId(int data) : HardwareId(data) {}
00116     virtual ~RpcHardwareId() {}
00117     // Assignment Operator
00118     RpcHardwareId& operator=(const RpcHardwareId& id) 
00119       { m_data = id.m_data; return *this; }
00120 
00121     // Return the panel ID only
00122     int panelId() const { return (m_data & 0x00ff0000) >> 16; }
00123 
00124     // Return the layer index only
00125     int layer() const { return (m_data & 0x0000ff00) >> 8; }
00126 
00127     // Return the strip index only
00128     int strip() const { return (m_data & 0x000000ff); }
00129   };
00130 
00131   /* Identify a physical Front-end electronics board
00132    *
00133    * Can be used to identify an entire FEE board, as well as a
00134    * specific connector on the board.  The data is stored as follows:
00135    * Bits: |   8   |   8   |   8   |   8       |
00136    * Data: | type  |       |boardId| connector |
00137    * Connectors are indexed from 1 to 16 starting from the top edge of the board
00138    */
00139   class FeeHardwareId : public HardwareId {
00140   public:
00141     FeeHardwareId() : HardwareId(0) {}
00142     FeeHardwareId(int boardId, int connector) : 
00143       HardwareId((0x000000ff & boardId)<<8 |
00144                  (0x000000ff & connector),
00145                  Hardware::kFee) {}
00146     FeeHardwareId(int data) : HardwareId(data) {}
00147     virtual ~FeeHardwareId() {}
00148     // Assignment Operator
00149     FeeHardwareId& operator=(const FeeHardwareId& id) 
00150       { m_data = id.m_data; return *this; }
00151 
00152     // Return the board ID only
00153     int boardId() const { return (m_data & 0x0000ff00) >> 8; }
00154 
00155     // Return the connector only
00156     int connector() const { return (m_data & 0x000000ff); }
00157   };
00158 
00159   /* Identify a physical RPC Front-end card
00160    *
00161    * Can be used to identify an entire FEC board, as well as a
00162    * specific connector on the board.  The data is stored as follows:
00163    * Bits: |   8   |   8   |   8   |   8       |
00164    * Data: | type  |       |boardId| connector |
00165    * Connectors are indexed from 1 to 32 starting from the left-most
00166    * on the board when looking at the connectors edge-on.
00167    */
00168   class FecHardwareId : public HardwareId {
00169   public:
00170     FecHardwareId() : HardwareId(0) {}
00171     FecHardwareId(int boardId, int connector) : 
00172       HardwareId((0x000000ff & boardId)<<8 |
00173                  (0x000000ff & connector),
00174                  Hardware::kFee) {}
00175     FecHardwareId(int data) : HardwareId(data) {}
00176     virtual ~FecHardwareId() {}
00177     // Assignment Operator
00178     FecHardwareId& operator=(const FecHardwareId& id) 
00179       { m_data = id.m_data; return *this; }
00180 
00181     // Return the board ID only
00182     int boardId() const { return (m_data & 0x0000ff00) >> 8; }
00183 
00184     // Return the connector only
00185     int connector() const { return (m_data & 0x000000ff); }
00186   };
00187 
00188   // Helper functions for printing hardware IDs
00189   std::ostream& operator<<(std::ostream& str, 
00190                            const DayaBay::HardwareId& hardwareId);
00191   std::ostream& operator<<(std::ostream& str, 
00192                            const DayaBay::PmtHardwareId& pmtHrdwId);
00193   std::ostream& operator<<(std::ostream& str, 
00194                            const DayaBay::RpcHardwareId& rpcHrdwId);
00195   std::ostream& operator<<(std::ostream& str, 
00196                            const DayaBay::FeeHardwareId& feeHrdwId);
00197   std::ostream& operator<<(std::ostream& str, 
00198                            const DayaBay::FecHardwareId& fecHrdwId);
00199   
00200 }
00201 
00202 #endif  // CONVENTIONS_HARDWARE_H
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:14:47 2011 for Conventions by doxygen 1.4.7