L1GctInternHtMiss

L1GctInternHtMissType

ShiftsAndMasks

numberOfBits

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
#ifndef L1GCTINTERNHTMISS_H
#define L1GCTINTERNHTMISS_H

/*! 
 * \class L1GctInternHtMiss
 * \brief L1 GCT internal Ht Miss component(s) Ht_x and/or Ht_y 
 * 
 * \author Robert Frazier
 * \date March 2009
 */

// C++ headers
#include <ostream>
#include <cstdint>

class L1GctInternHtMiss {
public:
  /// Enum for the variants of Internal HtMiss.
  enum L1GctInternHtMissType { nulltype, miss_htx, miss_hty, miss_htx_and_hty, jf_miss_htx_and_hty };

  enum numberOfBits {
    // TODO - tidy up all these enums.
    // These numbers of bits are needed to specify data sizes in the emulator
    // Other masks are below in the private section.
    kJetMissHtNBits = 12,
    kMissHxAndHyNBits = 14,
    kMissHxOrHyNBits = 16
  };

  /// default constructor (for vector initialisation etc.)
  L1GctInternHtMiss();

  /// destructor
  ~L1GctInternHtMiss();

  /* Named Constructors */

  /// Named ctor for making missing Ht x-component object from unpacker raw data.
  static L1GctInternHtMiss unpackerMissHtx(const uint16_t capBlock,
                                           const uint16_t capIndex,
                                           const int16_t bx,
                                           const uint32_t data);

  /// Named ctor for making missing Ht y-component object from unpacker raw data.
  static L1GctInternHtMiss unpackerMissHty(const uint16_t capBlock,
                                           const uint16_t capIndex,
                                           const int16_t bx,
                                           const uint32_t data);

  /// Named ctor for making missing Ht x & y components object from unpacker raw data (wheel input).
  static L1GctInternHtMiss unpackerMissHtxHty(const uint16_t capBlock,
                                              const uint16_t capIndex,
                                              const int16_t bx,
                                              const uint32_t data);

  /// Named ctor for making missing Ht x & y components object from emulator (jetFinder output).
  static L1GctInternHtMiss emulatorJetMissHt(const int htx, const int hty, const bool overFlow, const int16_t bx);

  /// Named ctor for making missing Ht x & y components object from emulator (wheel input).
  static L1GctInternHtMiss emulatorMissHtxHty(const int htx, const int hty, const bool overFlow, const int16_t bx);

  /// Named ctor for making missing Ht x component object from emulator
  static L1GctInternHtMiss emulatorMissHtx(const int htx, const bool overFlow, const int16_t bx);

  /// Named ctor for making missing Ht y component object from emulator
  static L1GctInternHtMiss emulatorMissHty(const int hty, const bool overFlow, const int16_t bx);

  /* Metadata */

  /// 'type' of object?
  L1GctInternHtMiss::L1GctInternHtMissType type() const { return type_; }

  /// Get capture block
  uint16_t capBlock() const { return capBlock_; }

  /// Get index within capture block
  uint16_t capIndex() const { return capIndex_; }

  /// Get BX number
  int16_t bx() const { return bx_; }

  /// Is there a valid Ht x-component stored?
  bool isThereHtx() const {
    return (type() == miss_htx || type() == miss_htx_and_hty || type() == jf_miss_htx_and_hty);
  }

  /// Is there a valid Ht y-component stored?
  bool isThereHty() const {
    return (type() == miss_hty || type() == miss_htx_and_hty || type() == jf_miss_htx_and_hty);
  }

  /* Access to the actual data */

  /// Get the raw data
  uint32_t raw() const { return data_; }

  /// Get Ht x-component value
  int16_t htx() const;

  /// Get Ht y-component
  int16_t hty() const;

  /// Get overflow
  bool overflow() const;

  /* Operators */

  /// Equality operator
  bool operator==(const L1GctInternHtMiss& rhs) const { return (type() == rhs.type() && raw() == rhs.raw()); }

  /// Inequality operator
  bool operator!=(const L1GctInternHtMiss& rhs) const { return !(*this == rhs); }

private:
  /// Useful bit masks and bit shifts
  enum ShiftsAndMasks {
    kDoubleComponentHtyShift = 16,          // Bit shift for Hty in miss_htx_and_hty
    kSingleComponentOflowMask = (1 << 30),  // Overflow bit mask in miss_htx or miss_hty
    kDoubleComponentOflowMask = (1 << 15),  // Overflow bit mask in miss_htx_and_hty
    kSingleComponentHtMask = 0xffff,        // Ht component mask in miss_htx or miss_hty
    kDoubleComponentHtMask = 0x3fff,        // Ht component mask in miss_htx_and_hty
    kJetFinderComponentHtMask = 0x0fff,     // Ht component mask in jf_miss_htx_and_hty
    kSingleComponentRawMask = kSingleComponentOflowMask |
                              kSingleComponentHtMask,  // To mask off all the non-data bits in raw data (e.g. BC0, etc)
    kDoubleComponentRawMask =
        (kDoubleComponentHtMask << kDoubleComponentHtyShift) | kDoubleComponentOflowMask | kDoubleComponentHtMask
  };

  /* Private ctors and methods */

  /// Private constructor that the named ctors use.
  L1GctInternHtMiss(const L1GctInternHtMissType type,
                    const uint16_t capBlock,
                    const uint16_t capIndex,
                    const int16_t bx,
                    const uint32_t data);

  /// Converts 14-bit two's complement numbers to 16-bit two's complement (i.e. an int16_t)
  /*! The input is the raw bits of the 14-bit two's complement in a 16-bit unsigned number. */
  int16_t convert14BitTwosCompTo16Bit(const uint16_t data) const;

  /* Private data */

  /// 'Type' of the data
  L1GctInternHtMissType type_;

  // source of the data
  uint16_t capBlock_;
  uint16_t capIndex_;
  int16_t bx_;

  /// The captured raw data
  uint32_t data_;
};

// Pretty-print operator for L1GctInternHtMiss
std::ostream& operator<<(std::ostream& os, const L1GctInternHtMiss& rhs);

#endif