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
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
00032 const char* AsString(Hardware_t type);
00033 Hardware_t FromString(const char* str);
00034 }
00035
00036
00037
00038
00039
00040
00041
00042 class HardwareId {
00043 public:
00044 HardwareId() : m_data(0) {}
00045
00046 HardwareId(int data) { m_data = data; }
00047
00048 HardwareId(unsigned int id, Hardware::Hardware_t hardware)
00049 { m_data = (hardware << 24) | (0x00ffffff & id); }
00050
00051 HardwareId& operator=(const HardwareId& id)
00052 { m_data = id.m_data; return *this; }
00053
00054
00055 virtual ~HardwareId();
00056
00057
00058
00059
00060 int fullPackedData() const { return m_data; }
00061
00062
00063 Hardware::Hardware_t type() const
00064 { return (Hardware::Hardware_t)((m_data&0xff000000)>>24); }
00065
00066 int id() const { return (m_data & 0x00ffffff); }
00067
00068
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
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
00087 PmtHardwareId& operator=(const PmtHardwareId& id)
00088 { m_data = id.m_data; return *this; }
00089
00090 int id() const { return (m_data & 0x00ffffff); }
00091 };
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
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
00118 RpcHardwareId& operator=(const RpcHardwareId& id)
00119 { m_data = id.m_data; return *this; }
00120
00121
00122 int panelId() const { return (m_data & 0x00ff0000) >> 16; }
00123
00124
00125 int layer() const { return (m_data & 0x0000ff00) >> 8; }
00126
00127
00128 int strip() const { return (m_data & 0x000000ff); }
00129 };
00130
00131
00132
00133
00134
00135
00136
00137
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
00149 FeeHardwareId& operator=(const FeeHardwareId& id)
00150 { m_data = id.m_data; return *this; }
00151
00152
00153 int boardId() const { return (m_data & 0x0000ff00) >> 8; }
00154
00155
00156 int connector() const { return (m_data & 0x000000ff); }
00157 };
00158
00159
00160
00161
00162
00163
00164
00165
00166
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
00178 FecHardwareId& operator=(const FecHardwareId& id)
00179 { m_data = id.m_data; return *this; }
00180
00181
00182 int boardId() const { return (m_data & 0x0000ff00) >> 8; }
00183
00184
00185 int connector() const { return (m_data & 0x000000ff); }
00186 };
00187
00188
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