CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QIE10DataFrame.h
Go to the documentation of this file.
1 #ifndef DATAFORMATS_HCALDIGI_QIE10DATAFRAME_H
2 #define DATAFORMATS_HCALDIGI_QIE10DATAFRAME_H
3 
6 #include <ostream>
7 
12 public:
13  static const int WORDS_PER_SAMPLE = 2;
14  static const int HEADER_WORDS = 1;
15  static const int FLAG_WORDS = 1;
16 
17  constexpr QIE10DataFrame() {}
18  constexpr QIE10DataFrame(edm::DataFrame const& df) : m_data(df) {}
19 
20  class Sample {
21  public:
22  typedef uint32_t wide_type;
23 
25  : word1_(frame[i]), word2_(frame[i + 1]) {}
26  constexpr Sample(const edm::DataFrame::data_type& word1, const edm::DataFrame::data_type& word2)
27  : word1_(word1), word2_(word2) {}
28  explicit Sample(const wide_type wide) : word1_{0}, word2_{0} {
29  static_assert(sizeof(wide) == 2 * sizeof(word1_), "The wide input type must be able to contain two words");
30  const edm::DataFrame::data_type* ptr = reinterpret_cast<const edm::DataFrame::data_type*>(&wide);
31  word1_ = ptr[0];
32  word2_ = ptr[1];
33  }
34 
35  static const int MASK_ADC = 0xFF;
36  static const int MASK_LE_TDC = 0x3F;
37  static const int MASK_TE_TDC = 0x1F;
38  static const int OFFSET_TE_TDC = 6;
39  static const int MASK_SOI = 0x2000;
40  static const int MASK_OK = 0x1000;
41  static const int MASK_CAPID = 0x3;
42  static const int OFFSET_CAPID = 12;
43 
44  constexpr inline int adc() const { return word1_ & MASK_ADC; }
45  constexpr inline int le_tdc() const { return word2_ & MASK_LE_TDC; }
46  constexpr inline int te_tdc() const { return (word2_ >> OFFSET_TE_TDC) & MASK_TE_TDC; }
47  constexpr inline bool ok() const { return word1_ & MASK_OK; }
48  constexpr inline bool soi() const { return word1_ & MASK_SOI; }
49  constexpr inline int capid() const { return (word2_ >> OFFSET_CAPID) & MASK_CAPID; }
51  return (i > WORDS_PER_SAMPLE) ? 0 : ((i == 1) ? word2_ : word1_);
52  }
54  static_assert(sizeof(QIE10DataFrame::Sample::wide_type) == 2 * sizeof(word1_),
55  "The wide result type must be able to contain two words");
56  wide_type result = 0;
58  ptr[0] = word1_;
59  ptr[1] = word2_;
60  return result;
61  }
62 
63  private:
66  };
67 
68  constexpr void copyContent(const QIE10DataFrame& digi) {
69  for (edm::DataFrame::size_type i = 0; i < size() && i < digi.size(); i++) {
70  Sample sam = digi[i];
71  setSample(i, sam.adc(), sam.le_tdc(), sam.te_tdc(), sam.capid(), sam.soi(), sam.ok());
72  }
73  }
74 
76  constexpr DetId detid() const { return DetId(m_data.id()); }
77  constexpr edm::DataFrame::id_type id() const { return m_data.id(); }
79  constexpr edm::DataFrame::size_type size() const { return m_data.size(); }
81  constexpr edm::DataFrame::iterator begin() { return m_data.begin(); }
82  constexpr edm::DataFrame::iterator end() { return m_data.end(); }
83  constexpr edm::DataFrame::const_iterator begin() const { return m_data.begin(); }
84  constexpr edm::DataFrame::const_iterator end() const { return m_data.end(); }
86  constexpr int samples() const { return (size() - HEADER_WORDS - FLAG_WORDS) / WORDS_PER_SAMPLE; }
88  constexpr int presamples() const {
89  for (int i = 0; i < samples(); i++) {
90  if ((*this)[i].soi())
91  return i;
92  }
93  return -1;
94  }
96  static const int OFFSET_FLAVOR = 12;
97  static const int MASK_FLAVOR = 0x7;
98  constexpr int flavor() const { return ((m_data[0] >> OFFSET_FLAVOR) & MASK_FLAVOR); }
100  static const int MASK_LINKERROR = 0x800;
101  constexpr bool linkError() const { return m_data[0] & MASK_LINKERROR; }
103  static const int MASK_MARKPASS = 0x100;
104  constexpr bool zsMarkAndPass() const { return m_data[0] & MASK_MARKPASS; }
106  constexpr void setZSInfo(bool markAndPass) {
107  if (markAndPass)
108  m_data[0] |= MASK_MARKPASS;
109  }
111  constexpr inline Sample operator[](edm::DataFrame::size_type i) const {
113  }
115  constexpr void setSample(
116  edm::DataFrame::size_type isample, int adc, int le_tdc, int te_tdc, int capid, bool soi = false, bool ok = true) {
117  if (isample >= size())
118  return;
119  m_data[isample * WORDS_PER_SAMPLE + HEADER_WORDS] =
120  (adc & Sample::MASK_ADC) | (soi ? (Sample::MASK_SOI) : (0)) | (ok ? (Sample::MASK_OK) : (0));
121  m_data[isample * WORDS_PER_SAMPLE + HEADER_WORDS + 1] =
122  (le_tdc & Sample::MASK_LE_TDC) | ((te_tdc & Sample::MASK_TE_TDC) << Sample::OFFSET_TE_TDC) |
123  ((capid & Sample::MASK_CAPID) << Sample::OFFSET_CAPID) | 0x4000; // 0x4000 marks this as second word of a pair
124  }
126  constexpr uint16_t flags() const { return m_data[size() - 1]; }
128  constexpr void setFlags(uint16_t v) { m_data[size() - 1] = v; }
129 
130 private:
132 };
133 
134 std::ostream& operator<<(std::ostream&, const QIE10DataFrame&);
135 
136 #endif // DATAFORMATS_HCALDIGI_QIE10DATAFRAME_H
unsigned int id_type
Definition: DataFrame.h:18
constexpr int capid() const
static const int MASK_OK
constexpr void setFlags(uint16_t v)
set the flag word
static const int MASK_SOI
constexpr Sample operator[](edm::DataFrame::size_type i) const
get the sample
constexpr QIE10DataFrame(edm::DataFrame const &df)
constexpr iterator end()
Definition: DataFrame.h:35
constexpr edm::DataFrame::const_iterator end() const
static const int MASK_CAPID
static const int MASK_LE_TDC
constexpr edm::DataFrame::id_type id() const
constexpr edm::DataFrame::size_type size() const
more accessors
constexpr QIE10DataFrame()
constexpr edm::DataFrame::iterator end()
unsigned short data_type
Definition: DataFrame.h:19
Sample(const wide_type wide)
edm::DataFrame m_data
constexpr void setSample(edm::DataFrame::size_type isample, int adc, int le_tdc, int te_tdc, int capid, bool soi=false, bool ok=true)
set the sample contents
static const int WORDS_PER_SAMPLE
constexpr edm::DataFrame::iterator begin()
iterators
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:167
static const int MASK_LINKERROR
was there a link error?
constexpr void setZSInfo(bool markAndPass)
set ZS params
constexpr Sample(const edm::DataFrame::data_type &word1, const edm::DataFrame::data_type &word2)
static const int MASK_ADC
unsigned int size_type
Definition: DataFrame.h:17
tuple result
Definition: mps_fire.py:311
constexpr id_type id() const
Definition: DataFrame.h:41
constexpr DetId detid() const
Get the detector id.
constexpr uint16_t flags() const
get the flag word
static const int MASK_MARKPASS
was this a mark-and-pass ZS event?
constexpr bool zsMarkAndPass() const
constexpr size_type size() const
Definition: DataFrame.h:43
constexpr bool linkError() const
constexpr bool soi() const
static const int OFFSET_TE_TDC
QIE10DataFrame::Sample::wide_type wideRaw() const
edm::DataFrame::data_type word1_
static const int OFFSET_FLAVOR
get the flavor of the frame
edm::DataFrame::data_type word2_
constexpr int le_tdc() const
constexpr int adc() const
constexpr int flavor() const
Definition: DetId.h:17
static const int FLAG_WORDS
static const int HEADER_WORDS
constexpr Sample(const edm::DataFrame &frame, edm::DataFrame::size_type i)
constexpr iterator begin()
Definition: DataFrame.h:33
constexpr int presamples() const
for backward compatibility
constexpr void copyContent(const QIE10DataFrame &digi)
constexpr int samples() const
total number of samples in the digi
constexpr int te_tdc() const
data_type * iterator
Definition: DataFrame.h:20
data_type const * const_iterator
Definition: DataFrame.h:21
static const int MASK_TE_TDC
constexpr bool ok() const
constexpr edm::DataFrame::const_iterator begin() const
constexpr edm::DataFrame::data_type raw(edm::DataFrame::size_type i) const
static const int MASK_FLAVOR
static const int OFFSET_CAPID
uint16_t *__restrict__ uint16_t const *__restrict__ adc