CMS 3D CMS Logo

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 
14  static const int WORDS_PER_SAMPLE = 2;
15  static const int HEADER_WORDS = 1;
16  static const int FLAG_WORDS = 1;
17 
20 
21  class Sample {
22  public:
23  typedef uint32_t wide_type;
24 
25  constexpr Sample(const edm::DataFrame& frame, edm::DataFrame::size_type i) : word1_(frame[i]), word2_(frame[i+1]) { }
26  constexpr Sample(const edm::DataFrame::data_type& word1, const edm::DataFrame::data_type& word2) : word1_(word1), word2_(word2) {}
27  explicit Sample(const wide_type wide)
28  : word1_{0}, word2_{0} {
29  static_assert(sizeof(wide) == 2*sizeof(word1_),
30  "The wide input type must be able to contain two words");
31  const edm::DataFrame::data_type* ptr =
32  reinterpret_cast<const edm::DataFrame::data_type*>(&wide);
33  word1_ = ptr[0];
34  word2_ = ptr[1];
35  }
36 
37  static const int MASK_ADC = 0xFF;
38  static const int MASK_LE_TDC = 0x3F;
39  static const int MASK_TE_TDC = 0x1F;
40  static const int OFFSET_TE_TDC = 6;
41  static const int MASK_SOI = 0x2000;
42  static const int MASK_OK = 0x1000;
43  static const int MASK_CAPID = 0x3;
44  static const int OFFSET_CAPID = 12;
45 
46  constexpr inline int adc() const { return word1_&MASK_ADC; }
47  constexpr inline int le_tdc() const { return word2_&MASK_LE_TDC; }
48  constexpr inline int te_tdc() const { return (word2_>>OFFSET_TE_TDC)&MASK_TE_TDC; }
49  constexpr inline bool ok() const { return word1_&MASK_OK; }
50  constexpr inline bool soi() const { return word1_&MASK_SOI; }
51  constexpr inline int capid() const { return (word2_>>OFFSET_CAPID)&MASK_CAPID; }
53  { return (i > WORDS_PER_SAMPLE) ? 0 : ( (i==1) ? word2_ : word1_ ); }
55  static_assert(sizeof(QIE10DataFrame::Sample::wide_type) == 2*sizeof(word1_),
56  "The wide result type must be able to contain two words");
57  wide_type result = 0;
59  reinterpret_cast<edm::DataFrame::data_type*>(&result);
60  ptr[0] = word1_;
61  ptr[1] = word2_;
62  return result;
63  }
64 
65  private:
68  };
69 
70  constexpr void copyContent(const QIE10DataFrame& digi) {
71  for (edm::DataFrame::size_type i=0; i<size() && i<digi.size();i++){
72  Sample sam = digi[i];
73  setSample(i, sam.adc(), sam.le_tdc(), sam.te_tdc(), sam.capid(), sam.soi(), sam.ok());
74  }
75  }
76 
78  constexpr DetId detid() const { return DetId(m_data.id()); }
88  constexpr int samples() const { return (size()-HEADER_WORDS-FLAG_WORDS)/WORDS_PER_SAMPLE; }
90  constexpr int presamples() const {
91  for (int i=0; i<samples(); i++) {
92  if ((*this)[i].soi()) return i;
93  }
94  return -1;
95  }
97  static const int OFFSET_FLAVOR = 12;
98  static const int MASK_FLAVOR = 0x7;
99  constexpr int flavor() const { return ((m_data[0]>>OFFSET_FLAVOR)&MASK_FLAVOR); }
101  static const int MASK_LINKERROR = 0x800;
102  constexpr bool linkError() const { return m_data[0]&MASK_LINKERROR; }
104  static const int MASK_MARKPASS = 0x100;
105  constexpr bool zsMarkAndPass() const {return m_data[0]&MASK_MARKPASS; }
108  if(markAndPass) m_data[0] |= MASK_MARKPASS;
109  }
111  constexpr inline Sample operator[](edm::DataFrame::size_type i) const { return Sample(m_data,i*WORDS_PER_SAMPLE+HEADER_WORDS); }
114  int le_tdc, int te_tdc, int capid, bool soi=false,
115  bool ok=true) {
116  if (isample>=size()) return;
117  m_data[isample*WORDS_PER_SAMPLE+HEADER_WORDS]=(adc&Sample::MASK_ADC)|(soi?(Sample::MASK_SOI):(0))|(ok?(Sample::MASK_OK):(0));
118  m_data[isample*WORDS_PER_SAMPLE+HEADER_WORDS+1]=(le_tdc&Sample::MASK_LE_TDC)|((te_tdc&Sample::MASK_TE_TDC)<<Sample::OFFSET_TE_TDC)|((capid&Sample::MASK_CAPID)<<Sample::OFFSET_CAPID)|0x4000; // 0x4000 marks this as second word of a pair
119  }
121  constexpr uint16_t flags() const { return m_data[size()-1]; }
123  constexpr void setFlags(uint16_t v) {
124  m_data[size()-1]=v;
125  }
126 
127  private:
129 
130 };
131 
132 std::ostream& operator<<(std::ostream&, const QIE10DataFrame&);
133 
134 
135 #endif // DATAFORMATS_HCALDIGI_QIE10DATAFRAME_H
int samples() const
total number of samples in the digi
unsigned int id_type
Definition: DataFrame.h:19
static const int MASK_OK
edm::DataFrame::iterator begin()
iterators
static const int MASK_SOI
edm::DataFrame::const_iterator end() const
constexpr iterator end()
Definition: DataFrame.h:51
int flavor() const
void setFlags(uint16_t v)
set the flag word
static const int MASK_CAPID
static const int MASK_LE_TDC
int presamples() const
for backward compatibility
unsigned short data_type
Definition: DataFrame.h:20
uint16_t flags() const
get the flag word
Sample operator[](edm::DataFrame::size_type i) const
get the sample
bool linkError() const
Sample(const wide_type wide)
edm::DataFrame m_data
edm::DataFrame::id_type id() const
static const int WORDS_PER_SAMPLE
edm::DataFrame::size_type size() const
more accessors
edm::DataFrame::const_iterator begin() const
void setZSInfo(bool markAndPass)
set ZS params
static const int MASK_LINKERROR
was there a link error?
static const int MASK_ADC
unsigned int size_type
Definition: DataFrame.h:18
constexpr id_type id() const
Definition: DataFrame.h:61
Sample(const edm::DataFrame &frame, edm::DataFrame::size_type i)
static const int MASK_MARKPASS
was this a mark-and-pass ZS event?
bool zsMarkAndPass() const
constexpr size_type size() const
Definition: DataFrame.h:64
DetId detid() const
Get the detector id.
static const int OFFSET_TE_TDC
QIE10DataFrame::Sample::wide_type wideRaw() const
edm::DataFrame::data_type word1_
edm::DataFrame::iterator end()
static const int OFFSET_FLAVOR
get the flavor of the frame
edm::DataFrame::data_type word2_
void copyContent(const QIE10DataFrame &digi)
Definition: DetId.h:18
static const int FLAG_WORDS
edm::DataFrame::data_type raw(edm::DataFrame::size_type i) const
static const int HEADER_WORDS
constexpr iterator begin()
Definition: DataFrame.h:48
Sample(const edm::DataFrame::data_type &word1, const edm::DataFrame::data_type &word2)
data_type * iterator
Definition: DataFrame.h:21
data_type const * const_iterator
Definition: DataFrame.h:22
static const int MASK_TE_TDC
std::ostream & operator<<(std::ostream &, const QIE10DataFrame &)
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 MASK_FLAVOR
QIE10DataFrame(edm::DataFrame const &df)
static const int OFFSET_CAPID
#define constexpr