CMS 3D CMS Logo

DigiCollection.h
Go to the documentation of this file.
1 #ifndef CUDADataFormats_HcalDigi_interface_DigiCollection_h
2 #define CUDADataFormats_HcalDigi_interface_DigiCollection_h
3 
5 
6 namespace hcal {
7 
8  // FLAVOR_HE_QIE11 = 1; Phase1 upgrade
9  struct Flavor1 {
10  static constexpr int WORDS_PER_SAMPLE = 1;
11  static constexpr int SAMPLES_PER_WORD = 1;
12  static constexpr int HEADER_WORDS = 1;
13 
14  static constexpr uint8_t adc(uint16_t const* const sample_start) { return (*sample_start & 0xff); }
15  static constexpr uint8_t tdc(uint16_t const* const sample_start) { return (*sample_start >> 8) & 0x3f; }
16  static constexpr uint8_t soibit(uint16_t const* const sample_start) { return (*sample_start >> 14) & 0x1; }
17  };
18 
19  // FLAVOR_HB_QIE11 = 3; Phase1 upgrade
20  struct Flavor3 {
21  static constexpr int WORDS_PER_SAMPLE = 1;
22  static constexpr int SAMPLES_PER_WORD = 1;
23  static constexpr int HEADER_WORDS = 1;
24 
25  static constexpr uint8_t adc(uint16_t const* const sample_start) { return (*sample_start & 0xff); }
26  static constexpr uint8_t tdc(uint16_t const* const sample_start) { return ((*sample_start >> 8) & 0x3); }
27  static constexpr uint8_t soibit(uint16_t const* const sample_start) { return ((*sample_start >> 14) & 0x1); }
28  static constexpr uint8_t capid(uint16_t const* const sample_start) { return ((*sample_start >> 10) & 0x3); }
29  };
30 
31  // FLAVOR_HB_QIE10 = 5; Phase0
32  struct Flavor5 {
33  static constexpr float WORDS_PER_SAMPLE = 0.5;
34  static constexpr int SAMPLES_PER_WORD = 2;
35  static constexpr int HEADER_WORDS = 1;
36 
37  static constexpr uint8_t adc(uint16_t const* const sample_start, uint8_t const shifter) {
38  return ((*sample_start >> shifter * 8) & 0x7f);
39  }
40  };
41 
42  template <typename Flavor>
43  constexpr uint8_t capid_for_sample(uint16_t const* const dfstart, uint32_t const sample) {
44  auto const capid_first = (*dfstart >> 8) & 0x3;
45  return (capid_first + sample) & 0x3; // same as % 4
46  }
47 
48  template <>
49  constexpr uint8_t capid_for_sample<Flavor3>(uint16_t const* const dfstart, uint32_t const sample) {
51  }
52 
53  template <typename Flavor>
54  constexpr uint8_t soibit_for_sample(uint16_t const* const dfstart, uint32_t const sample) {
55  return Flavor::soibit(dfstart + Flavor::HEADER_WORDS + sample * Flavor::WORDS_PER_SAMPLE);
56  }
57 
58  template <typename Flavor>
59  constexpr uint8_t adc_for_sample(uint16_t const* const dfstart, uint32_t const sample) {
60  return Flavor::adc(dfstart + Flavor::HEADER_WORDS + sample * Flavor::WORDS_PER_SAMPLE);
61  }
62 
63  template <typename Flavor>
64  constexpr uint8_t tdc_for_sample(uint16_t const* const dfstart, uint32_t const sample) {
65  return Flavor::tdc(dfstart + Flavor::HEADER_WORDS + sample * Flavor::WORDS_PER_SAMPLE);
66  }
67 
68  template <>
69  constexpr uint8_t adc_for_sample<Flavor5>(uint16_t const* const dfstart, uint32_t const sample) {
70  // avoid using WORDS_PER_SAMPLE and simply shift
71  return Flavor5::adc(dfstart + Flavor5::HEADER_WORDS + (sample >> 1), sample % 2);
72  }
73 
74  template <typename Flavor>
75  constexpr uint32_t compute_stride(uint32_t const nsamples) {
76  return static_cast<uint32_t>(nsamples * Flavor::WORDS_PER_SAMPLE) + Flavor::HEADER_WORDS;
77  }
78 
79  template <typename Flavor>
80  constexpr uint32_t compute_nsamples(uint32_t const nwords) {
81  if constexpr (Flavor::SAMPLES_PER_WORD >= 1)
82  return (nwords - Flavor::HEADER_WORDS) * Flavor::SAMPLES_PER_WORD;
83  else
84  return (nwords - Flavor::HEADER_WORDS) / Flavor::WORDS_PER_SAMPLE;
85  }
86 
87  //
88  template <typename StoragePolicy>
89  struct DigiCollectionBase : public ::calo::common::AddSize<typename StoragePolicy::TagType> {
90  DigiCollectionBase() = default;
91  DigiCollectionBase(DigiCollectionBase const&) = default;
93 
96 
97  template <typename T = typename StoragePolicy::TagType>
99  ids.resize(size);
100  data.resize(size * stride);
101  }
102 
103  template <typename T = typename StoragePolicy::TagType>
105  ids.reserve(size);
106  data.reserve(size * stride);
107  }
108 
109  template <typename T = typename StoragePolicy::TagType>
111  ids.clear();
112  data.clear();
113  }
114 
117  uint32_t stride{0};
118  };
119 
120  template <typename Flavor, typename StoragePolicy>
121  struct DigiCollection : public DigiCollectionBase<StoragePolicy> {
123  };
124 
125  // NOTE: base ctors will not be available
126  template <typename StoragePolicy>
127  struct DigiCollection<Flavor5, StoragePolicy> : public DigiCollectionBase<StoragePolicy> {
128  DigiCollection() = default;
129 
130  DigiCollection(DigiCollection const&) = default;
131  DigiCollection& operator=(DigiCollection const&) = default;
132 
133  DigiCollection(DigiCollection&&) = default;
135 
136  template <typename T = typename StoragePolicy::TagType>
139  npresamples.resize(size);
140  }
141 
142  template <typename T = typename StoragePolicy::TagType>
145  npresamples.reserve(size);
146  }
147 
148  template <typename T = typename StoragePolicy::TagType>
151  npresamples.clear();
152  }
153 
154  // add npresamples member
156  };
157 
158 } // namespace hcal
159 
160 #endif // CUDADataFormats_HcalDigi_interface_DigiCollection_h
constexpr uint32_t compute_nsamples(uint32_t const nwords)
static constexpr int HEADER_WORDS
std::enable_if< std::is_same< T, ::calo::common::tags::Vec >::value, void >::type resize(std::size_t size)
static constexpr int WORDS_PER_SAMPLE
static constexpr int SAMPLES_PER_WORD
StoragePolicy::template StorageSelector< uint16_t >::type data
constexpr uint8_t tdc_for_sample(uint16_t const *const dfstart, uint32_t const sample)
DigiCollectionBase & operator=(DigiCollectionBase const &)=default
constexpr uint8_t soibit_for_sample(uint16_t const *const dfstart, uint32_t const sample)
static constexpr uint8_t soibit(uint16_t const *const sample_start)
static constexpr uint8_t adc(uint16_t const *const sample_start)
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
constexpr uint8_t capid_for_sample(uint16_t const *const dfstart, uint32_t const sample)
StoragePolicy::template StorageSelector< uint32_t >::type ids
constexpr uint8_t adc_for_sample< Flavor5 >(uint16_t const *const dfstart, uint32_t const sample)
constexpr uint32_t compute_stride(uint32_t const nsamples)
static constexpr int SAMPLES_PER_WORD
static constexpr uint8_t soibit(uint16_t const *const sample_start)
static constexpr uint8_t adc(uint16_t const *const sample_start, uint8_t const shifter)
std::enable_if< std::is_same< T, ::calo::common::tags::Vec >::value, void >::type resize(std::size_t size)
std::enable_if< std::is_same< T, ::calo::common::tags::Vec >::value, void >::type reserve(std::size_t size)
StoragePolicy::template StorageSelector< uint8_t >::type npresamples
static constexpr uint8_t tdc(uint16_t const *const sample_start)
static constexpr int SAMPLES_PER_WORD
static constexpr int HEADER_WORDS
constexpr uint8_t adc_for_sample(uint16_t const *const dfstart, uint32_t const sample)
constexpr uint8_t capid_for_sample< Flavor3 >(uint16_t const *const dfstart, uint32_t const sample)
static constexpr uint8_t adc(uint16_t const *const sample_start)
static constexpr float WORDS_PER_SAMPLE
std::enable_if< std::is_same< T, ::calo::common::tags::Vec >::value, void >::type clear()
static constexpr int HEADER_WORDS
std::enable_if< std::is_same< T, ::calo::common::tags::Vec >::value, void >::type clear()
static constexpr int WORDS_PER_SAMPLE
static constexpr uint8_t tdc(uint16_t const *const sample_start)
uint16_t *__restrict__ uint16_t const *__restrict__ adc
std::enable_if< std::is_same< T, ::calo::common::tags::Vec >::value, void >::type reserve(std::size_t size)
static constexpr uint8_t capid(uint16_t const *const sample_start)