00001 #ifndef DTRawToDigi_DTROChainCoding_h 00002 #define DTRawToDigi_DTROChainCoding_h 00003 00012 #include <EventFilter/DTRawToDigi/interface/DTDDUWords.h> 00013 00014 #include <vector> 00015 00016 #include <boost/cstdint.hpp> 00017 00018 00020 /* 00021 A major problem is the numbering of the 00022 RO componenets: do they all start from 0? 00023 I think yes but mapping and coding (THIS class) 00024 must be arranged accordingly. 00025 00026 So far TDC channels and ID are bound to start from 0 00027 whereas ROB, ROS and DDU are free to start from 0 00028 or from 1. This has to be coded into the map 00029 00030 */ 00031 00032 00033 class DTROChainCoding { 00034 00035 public: 00036 00038 00039 DTROChainCoding(): code(0) {} 00040 00041 DTROChainCoding(const int & ddu, const int & ros, 00042 const int & rob, const int & tdc, const int & channel) { 00043 code = 00044 ddu << DDU_SHIFT | 00045 ros << ROS_SHIFT | 00046 rob << ROB_SHIFT | 00047 tdc << TDC_SHIFT | 00048 channel << CHANNEL_SHIFT; 00049 } 00050 00051 DTROChainCoding(uint32_t code_): code(code_) {} 00052 00054 virtual ~DTROChainCoding() {} 00055 00057 inline void setCode(const uint32_t & code_) {code = code_;} 00058 inline void setChain(const int & ddu, const int & ros, 00059 const int & rob, const int & tdc, const int & channel) { 00060 00061 code = 00062 ddu << DDU_SHIFT | 00063 ros << ROS_SHIFT | 00064 rob << ROB_SHIFT | 00065 tdc << TDC_SHIFT | 00066 channel << CHANNEL_SHIFT; 00067 } 00068 00070 inline void setDDU(const int & ID) { 00071 code = ( code & (~(DDU_MASK << DDU_SHIFT)) ) | (ID << DDU_SHIFT); 00072 } 00073 inline void setROS(const int & ID) { 00074 code = ( code & (~(ROS_MASK << ROS_SHIFT)) ) | (ID << ROS_SHIFT); 00075 } 00076 inline void setROB(const int & ID) { 00077 code = ( code & (~(ROB_MASK << ROB_SHIFT)) ) | (ID << ROB_SHIFT); 00078 } 00079 inline void setTDC(const int & ID) { 00080 code = ( code & (~(TDC_MASK << TDC_SHIFT)) ) | (ID << TDC_SHIFT); 00081 } 00082 inline void setChannel(const int & ID) { 00083 code = ( code & (~(CHANNEL_MASK << CHANNEL_SHIFT)) ) | (ID << CHANNEL_SHIFT); 00084 } 00085 00087 inline uint32_t getCode() const { return code; } 00088 inline int getDDU() const { return (code >> DDU_SHIFT) & DDU_MASK; } 00089 inline int getDDUID() const { return (code >> DDU_SHIFT) ; } 00090 inline int getROS() const { return (code >> ROS_SHIFT) & ROS_MASK; } 00091 inline int getROSID() const { return (code >> ROS_SHIFT) ; } 00092 inline int getROB() const { return (code >> ROB_SHIFT) & ROB_MASK; } 00093 inline int getROBID() const { return (code >> ROB_SHIFT) ; } 00094 inline int getTDC() const { return (code >> TDC_SHIFT) & TDC_MASK; } 00095 inline int getTDCID() const { return (code >> TDC_SHIFT) ; } 00096 inline int getChannel() const { return (code >> CHANNEL_SHIFT) & CHANNEL_MASK; } 00097 inline int getChannelID() const { return (code >> CHANNEL_SHIFT) ; } 00098 00100 inline int getSC() const { return (code >> ROS_SHIFT) & ROS_MASK; } 00101 inline int getSCID() const { return (code >> ROS_SHIFT) ; } 00102 00103 00104 private: 00105 00106 uint32_t code; 00107 00108 // First shift the bits then apply the mask 00109 00110 // ddu bit are the last ones. I DONT CARE if the ID is > than 730 (I always get the lsb) 00111 static const int DDU_SHIFT = 16; 00112 static const int DDU_MASK = 0x3FF; 00113 00114 static const int ROS_SHIFT = 12; 00115 static const int ROS_MASK = 0xF; 00116 00117 static const int ROB_SHIFT = 7; 00118 static const int ROB_MASK = 0x1F; 00119 00120 static const int TDC_SHIFT = 5; 00121 static const int TDC_MASK = 0x3; 00122 00123 static const int CHANNEL_SHIFT = 0; 00124 static const int CHANNEL_MASK = 0x1F; 00125 00126 00127 }; 00128 00129 #endif