CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QIE11DataFrame.h
Go to the documentation of this file.
1 #ifndef DATAFORMATS_HCALDIGI_QIE11DATAFRAME_H
2 #define DATAFORMATS_HCALDIGI_QIE11DATAFRAME_H
3 
6 #include <ostream>
7 
12 public:
13  static const int WORDS_PER_SAMPLE = 1;
14  static const int HEADER_WORDS = 1;
15  static const int FLAG_WORDS = 1;
16 
17  static const int OFFSET_FLAVOR = 12;
18  static const int MASK_FLAVOR = 0x7;
19  static const int FLAVOR_HB = 3;
20  static const int MASK_LINKERROR = 0x800;
21 
22  constexpr QIE11DataFrame() {}
23  constexpr QIE11DataFrame(edm::DataFrame const& df) : m_data(df) {}
24 
25  class Sample {
26  public:
27  constexpr Sample(const edm::DataFrame& frame, edm::DataFrame::size_type i) : frame_(frame), i_(i) {}
28  static const int MASK_ADC = 0xFF;
29  static const int MASK_TDC_HE = 0x3F;
30  static const int MASK_TDC_HB = 0x3;
31  static const int OFFSET_TDC = 8; // 8 bits
32  static const int MASK_SOI = 0x4000;
33  static const int MASK_LE_HB = 0x2000;
34  static const int MASK_CAPID = 0x3;
35  static const int MASK_CAPID_INV_HB = 0xF3FF;
36  static const int MASK_CAPID_KEEP_HB = 0x0C00;
37  static const int OFFSET_CAPID_HE = 8;
38  static const int OFFSET_CAPID_HB = 10;
39  constexpr int flavor() const { return ((frame_[0] >> OFFSET_FLAVOR) & MASK_FLAVOR); }
40  constexpr int adc() const { return frame_[i_] & MASK_ADC; }
41  constexpr int tdc() const {
42  return (frame_[i_] >> OFFSET_TDC) & ((flavor() == FLAVOR_HB) ? (MASK_TDC_HB) : (MASK_TDC_HE));
43  }
44  constexpr bool soi() const { return frame_[i_] & MASK_SOI; }
45  constexpr int capid() const {
46  return (flavor() == FLAVOR_HB)
49  }
50  constexpr bool linkError() const {
51  return (flavor() == FLAVOR_HB) ? (frame_[i_] & MASK_LE_HB) : (frame_[0] & MASK_LINKERROR);
52  }
53 
54  private:
57  };
58 
59  constexpr void copyContent(const QIE11DataFrame& digi) {
60  for (edm::DataFrame::size_type i = 0; i < size() && i < digi.size(); i++) {
61  Sample sam = digi[i];
62  setSample(i, sam.adc(), sam.tdc(), sam.soi());
63  }
64  }
65 
67  constexpr DetId detid() const { return DetId(m_data.id()); }
68  constexpr edm::DataFrame::id_type id() const { return m_data.id(); }
70  constexpr edm::DataFrame::size_type size() const { return m_data.size(); }
72  constexpr edm::DataFrame::iterator begin() { return m_data.begin(); }
73  constexpr edm::DataFrame::iterator end() { return m_data.end(); }
74  constexpr edm::DataFrame::const_iterator begin() const { return m_data.begin(); }
75  constexpr edm::DataFrame::const_iterator end() const { return m_data.end(); }
77  constexpr int samples() const { return (size() - HEADER_WORDS - FLAG_WORDS) / WORDS_PER_SAMPLE; }
79  constexpr int presamples() const {
80  for (int i = 0; i < samples(); i++) {
81  if ((*this)[i].soi())
82  return i;
83  }
84  return -1;
85  }
87  constexpr int flavor() const { return ((m_data[0] >> OFFSET_FLAVOR) & MASK_FLAVOR); }
89  constexpr bool linkError() const { return m_data[0] & MASK_LINKERROR; }
91  static const int MASK_CAPIDERROR = 0x400;
92  constexpr bool capidError() const { return m_data[0] & MASK_CAPIDERROR; }
94  constexpr bool zsMarkAndPass() const { return (flavor() == 1); }
96  constexpr void setZSInfo(bool markAndPass) {
97  if (markAndPass)
98  m_data[0] |= (markAndPass & MASK_FLAVOR) << OFFSET_FLAVOR;
99  }
101  constexpr inline Sample operator[](edm::DataFrame::size_type i) const { return Sample(m_data, i + HEADER_WORDS); }
102 
103  // set flavor
104  constexpr void setFlavor(int flavor) {
105  m_data[0] &= 0x9FFF; // inversion of flavor mask
106  m_data[0] |= ((flavor & MASK_FLAVOR) << OFFSET_FLAVOR);
107  }
108 
109  constexpr void setCapid0(int cap0) {
110  if (flavor() == FLAVOR_HB) {
111  for (int i = 0; i < samples(); i++) {
113  m_data[i + 1] |= ((cap0 + i) & Sample::MASK_CAPID) << Sample::OFFSET_CAPID_HB;
114  }
115  } else {
116  m_data[0] &= 0xFCFF; // inversion of the capid0 mask
118  }
119  }
121  constexpr void setSample(edm::DataFrame::size_type isample, int adc, int tdc, bool soi = false) {
122  if (isample >= size())
123  return;
124  if (flavor() == FLAVOR_HB)
125  m_data[isample + 1] = (adc & Sample::MASK_ADC) | (soi ? (Sample::MASK_SOI) : (0)) |
127  (m_data[isample + 1] & Sample::MASK_CAPID_KEEP_HB);
128  else
129  m_data[isample + 1] = (adc & Sample::MASK_ADC) | (soi ? (Sample::MASK_SOI) : (0)) |
131  }
133  constexpr uint16_t flags() const { return m_data[size() - 1]; }
135  constexpr void setFlags(uint16_t v) { m_data[size() - 1] = v; }
136 
137 private:
139 };
140 
141 std::ostream& operator<<(std::ostream&, const QIE11DataFrame&);
142 
143 #endif // DATAFORMATS_HCALDIGI_QIE11DATAFRAME_H
constexpr QIE11DataFrame()
unsigned int id_type
Definition: DataFrame.h:18
static const int FLAG_WORDS
constexpr int capid() const
edm::DataFrame::size_type i_
constexpr iterator end()
Definition: DataFrame.h:35
static const int MASK_CAPID
constexpr int tdc() const
static const int HEADER_WORDS
constexpr void setZSInfo(bool markAndPass)
set ZS params
constexpr int flavor() const
constexpr edm::DataFrame::size_type size() const
more accessors
static const int MASK_ADC
static const int MASK_FLAVOR
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:167
constexpr int adc() const
static const int WORDS_PER_SAMPLE
static const int MASK_LINKERROR
static const int MASK_CAPIDERROR
was there a capid rotation error?
unsigned int size_type
Definition: DataFrame.h:17
constexpr Sample(const edm::DataFrame &frame, edm::DataFrame::size_type i)
static const int OFFSET_CAPID_HB
constexpr id_type id() const
Definition: DataFrame.h:41
constexpr void setFlags(uint16_t v)
set the flag word
constexpr void setFlavor(int flavor)
constexpr int presamples() const
for backward compatibility
constexpr bool soi() const
constexpr size_type size() const
Definition: DataFrame.h:43
constexpr edm::DataFrame::iterator end()
const edm::DataFrame & frame_
constexpr bool zsMarkAndPass() const
was this a mark-and-pass ZS event?
static const int OFFSET_FLAVOR
constexpr void setSample(edm::DataFrame::size_type isample, int adc, int tdc, bool soi=false)
set the sample contents
edm::DataFrame m_data
Definition: DetId.h:17
static const int OFFSET_TDC
constexpr int samples() const
total number of samples in the digi
constexpr QIE11DataFrame(edm::DataFrame const &df)
constexpr edm::DataFrame::iterator begin()
iterators
constexpr int flavor() const
get the flavor of the frame
constexpr iterator begin()
Definition: DataFrame.h:33
static const int MASK_CAPID_KEEP_HB
static const int MASK_TDC_HB
static const int MASK_SOI
static const int MASK_CAPID_INV_HB
constexpr edm::DataFrame::const_iterator begin() const
constexpr edm::DataFrame::id_type id() const
data_type * iterator
Definition: DataFrame.h:20
constexpr edm::DataFrame::const_iterator end() const
data_type const * const_iterator
Definition: DataFrame.h:21
constexpr bool linkError() const
was there a link error?
constexpr bool linkError() const
static const int OFFSET_CAPID_HE
constexpr void copyContent(const QIE11DataFrame &digi)
constexpr uint16_t flags() const
get the flag word
constexpr void setCapid0(int cap0)
constexpr Sample operator[](edm::DataFrame::size_type i) const
get the sample
static const int MASK_LE_HB
constexpr bool capidError() const
static const int FLAVOR_HB
static const int MASK_TDC_HE
uint16_t *__restrict__ uint16_t const *__restrict__ adc
constexpr DetId detid() const
Get the detector id.