Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /* -*- C++ -*- */
0002 #ifndef HcalUHTRData_H
0003 #define HcalUHTRData_H
0004 
0005 #include <cstdint>
0006 
0007 /**  \class HcalUHTRData
0008  *
0009  *  Interpretive class for HcalUHTRData
0010  *  Since this class requires external specification of the length of the data, it is implemented
0011  *  as an interpreter, rather than a cast-able header class.
0012  *
0013  *  \author J. Mans - UMN
0014  */
0015 
0016 class HcalUHTRData {
0017 public:
0018   static const int FIBERS_PER_UHTR = 24;
0019   static const int CHANNELS_PER_FIBER_HF = 4;
0020   static const int CHANNELS_PER_FIBER_HBHE = 6;
0021   static const int CHANNELS_PER_FIBER_MAX = 8;
0022 
0023   HcalUHTRData();
0024   ~HcalUHTRData() {
0025     if (m_ownData != nullptr)
0026       delete[] m_ownData;
0027   }
0028   HcalUHTRData(int version_to_create);
0029   HcalUHTRData(const uint64_t* data, int length_words);
0030   HcalUHTRData(const HcalUHTRData&);
0031 
0032   HcalUHTRData& operator=(const HcalUHTRData&);
0033 
0034   /** \brief Get the version number of this event */
0035   inline int getFormatVersion() const { return m_formatVersion; }
0036 
0037   /** \brief Get a pointer to the raw data */
0038   inline const unsigned short* getRawData16() const { return m_raw16; }
0039 
0040   /** \brief Get the length of the raw data */
0041   inline const int getRawLengthBytes() const { return m_rawLength64 * sizeof(uint64_t); }
0042 
0043   class const_iterator {
0044   public:
0045     const_iterator(const uint16_t* ptr, const uint16_t* limit = nullptr);
0046 
0047     bool isHeader() const { return ((*m_ptr) & 0x8000) != 0; }
0048     int flavor() const { return ((*m_ptr) >> 12) & 0x7; }
0049     int errFlags() const;
0050     bool dataValid() const;
0051     int capid0() const { return ((*m_ptr) >> 8) & 0x3; }
0052     int channelid() const { return ((*m_ptr)) & 0xFF; }
0053     int technicalDataType() const;
0054 
0055     uint16_t value() const { return *m_ptr; }
0056 
0057     uint8_t adc() const;
0058     uint8_t le_tdc() const;
0059     uint8_t te_tdc() const;
0060     bool soi() const;
0061     uint8_t capid() const;
0062     bool ok() const;
0063 
0064     uint16_t operator*() const { return *m_ptr; }
0065 
0066     /** Increment operator is "magic" and adjusts steps to match channel requirements. */
0067     const_iterator& operator++();
0068 
0069     bool operator==(const const_iterator& i) { return m_ptr == i.m_ptr; }
0070     bool operator!=(const const_iterator& i) { return m_ptr != i.m_ptr; }
0071     const uint16_t* raw() const { return m_ptr; }
0072 
0073   private:
0074     void determineMode();
0075     const uint16_t *m_ptr, *m_limit;
0076     const uint16_t *m_header_ptr, *m_0th_data_ptr;
0077     int m_microstep;
0078     int m_stepclass;
0079     int m_flavor;
0080     int m_technicalDataType;
0081   };
0082 
0083   const_iterator begin() const;
0084   const_iterator end() const;
0085 
0086   /** \brief Get the HTR event number */
0087   inline uint32_t l1ANumber() const { return uint32_t(m_raw64[0] >> 32) & 0xFFFFFF; }
0088   /** \brief Get the HTR bunch number */
0089   inline uint32_t bunchNumber() const { return uint32_t(m_raw64[0] >> 20) & 0xFFF; }
0090   /** \brief Get the HTR orbit number */
0091   inline uint32_t orbitNumber() const { return uint32_t(m_raw64[1] >> 16) & 0xFFFF; }
0092   /** \brief Get the event type */
0093   int getEventType() const { return uint32_t(m_raw64[1] >> 40) & 0xF; }
0094   /** \brief Get the raw board id */
0095   inline uint32_t boardId() const { return uint32_t(m_raw64[1]) & 0xFFFF; }
0096   /** \brief Get the board crate */
0097   inline uint32_t crateId() const { return uint32_t(m_raw64[1]) & 0xFF; }
0098   /** \brief Get the board slot */
0099   inline uint32_t slot() const { return uint32_t(m_raw64[1] >> 8) & 0xF; }
0100   /** \brief Get the presamples */
0101   inline uint32_t presamples() const { return uint32_t(m_raw64[1] >> 12) & 0xF; }
0102 
0103   /** \brief Was this channel passed as part of Mark&Pass ZS?*/
0104   bool wasMarkAndPassZS(int fiber, int fiberchan) const;
0105   /** \brief Was this channel passed as part of Mark&Pass ZS?*/
0106   bool wasMarkAndPassZSTP(int slb, int slbchan) const;
0107 
0108   /** \brief Get the HTR firmware version */
0109   unsigned int getFirmwareRevision() const { return uint32_t(m_raw64[1] >> 48) & 0xFFFF; }
0110   /** \brief Get the HTR firmware flavor */
0111   int getFirmwareFlavor() const { return uint32_t(m_raw64[1] >> 32) & 0xFF; }
0112 
0113 protected:
0114   int m_formatVersion;
0115   int m_rawLength64;
0116   const uint64_t* m_raw64;
0117   const uint16_t* m_raw16;
0118   uint64_t* m_ownData;
0119 };
0120 
0121 #endif