Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:14:47

0001 #ifndef DTRawToDigi_DTROChainCoding_h
0002 #define DTRawToDigi_DTROChainCoding_h
0003 
0004 /** \class DTROChainCoding
0005  *  A class for handling the DT Read-out chain.
0006  *
0007  *  \author M. Zanetti - INFN Padova
0008  */
0009 
0010 #include <DataFormats/DTDigi/interface/DTDDUWords.h>
0011 
0012 #include <vector>
0013 #include <cstdint>
0014 
0015 /// FIXEME:
0016 /*
0017   A major problem is the numbering of the
0018   RO componenets: do they all start from 0?
0019   I think yes but mapping and coding (THIS class)
0020   must be arranged accordingly.
0021 
0022   So far TDC channels and ID are bound to start from 0
0023   whereas ROB, ROS and DDU are free to start from 0 
0024   or from 1. This has to be coded into the map
0025 
0026 */
0027 
0028 class DTROChainCoding {
0029 public:
0030   /// Constructors
0031 
0032   DTROChainCoding() : code(0) {}
0033 
0034   DTROChainCoding(const int& ddu, const int& ros, const int& rob, const int& tdc, const int& channel) {
0035     code = ddu << DDU_SHIFT | ros << ROS_SHIFT | rob << ROB_SHIFT | tdc << TDC_SHIFT | channel << CHANNEL_SHIFT;
0036   }
0037 
0038   DTROChainCoding(uint32_t code_) : code(code_) {}
0039 
0040   /// Destructor
0041   virtual ~DTROChainCoding() {}
0042 
0043   /// Setters  ///////////////////////
0044   inline void setCode(const uint32_t& code_) { code = code_; }
0045   inline void setChain(const int& ddu, const int& ros, const int& rob, const int& tdc, const int& channel) {
0046     code = ddu << DDU_SHIFT | ros << ROS_SHIFT | rob << ROB_SHIFT | tdc << TDC_SHIFT | channel << CHANNEL_SHIFT;
0047   }
0048 
0049   /// need to reset the bits before setting
0050   inline void setDDU(const int& ID) { code = (code & (~(DDU_MASK << DDU_SHIFT))) | (ID << DDU_SHIFT); }
0051   inline void setROS(const int& ID) { code = (code & (~(ROS_MASK << ROS_SHIFT))) | (ID << ROS_SHIFT); }
0052   inline void setROB(const int& ID) { code = (code & (~(ROB_MASK << ROB_SHIFT))) | (ID << ROB_SHIFT); }
0053   inline void setTDC(const int& ID) { code = (code & (~(TDC_MASK << TDC_SHIFT))) | (ID << TDC_SHIFT); }
0054   inline void setChannel(const int& ID) { code = (code & (~(CHANNEL_MASK << CHANNEL_SHIFT))) | (ID << CHANNEL_SHIFT); }
0055 
0056   /// Getters ///////////////////////
0057   inline uint32_t getCode() const { return code; }
0058   inline int getDDU() const { return (code >> DDU_SHIFT) & DDU_MASK; }
0059   inline int getDDUID() const { return (code >> DDU_SHIFT); }
0060   inline int getROS() const { return (code >> ROS_SHIFT) & ROS_MASK; }
0061   inline int getROSID() const { return (code >> ROS_SHIFT); }
0062   inline int getROB() const { return (code >> ROB_SHIFT) & ROB_MASK; }
0063   inline int getROBID() const { return (code >> ROB_SHIFT); }
0064   inline int getTDC() const { return (code >> TDC_SHIFT) & TDC_MASK; }
0065   inline int getTDCID() const { return (code >> TDC_SHIFT); }
0066   inline int getChannel() const { return (code >> CHANNEL_SHIFT) & CHANNEL_MASK; }
0067   inline int getChannelID() const { return (code >> CHANNEL_SHIFT); }
0068 
0069   /// SC getters: same as ROS getters (SC data goes in the corresponding ROS)
0070   inline int getSC() const { return (code >> ROS_SHIFT) & ROS_MASK; }
0071   inline int getSCID() const { return (code >> ROS_SHIFT); }
0072 
0073 private:
0074   uint32_t code;
0075 
0076   // First shift the bits then apply the mask
0077 
0078   // ddu bit are the last ones. I DONT CARE if the ID is > than 730 (I always get the lsb)
0079   static const int DDU_SHIFT = 16;
0080   static const int DDU_MASK = 0x3FF;
0081 
0082   static const int ROS_SHIFT = 12;
0083   static const int ROS_MASK = 0xF;
0084 
0085   static const int ROB_SHIFT = 7;
0086   static const int ROB_MASK = 0x1F;
0087 
0088   static const int TDC_SHIFT = 5;
0089   static const int TDC_MASK = 0x3;
0090 
0091   static const int CHANNEL_SHIFT = 0;
0092   static const int CHANNEL_MASK = 0x1F;
0093 };
0094 
0095 #endif