Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:45

0001 #ifndef CUDADataFormats_HcalDigi_interface_DigiCollection_h
0002 #define CUDADataFormats_HcalDigi_interface_DigiCollection_h
0003 
0004 #include "CUDADataFormats/CaloCommon/interface/Common.h"
0005 
0006 namespace hcal {
0007 
0008   // FLAVOR_HE_QIE11 = 1; Phase1 upgrade
0009   struct Flavor1 {
0010     static constexpr int WORDS_PER_SAMPLE = 1;
0011     static constexpr int SAMPLES_PER_WORD = 1;
0012     static constexpr int HEADER_WORDS = 1;
0013 
0014     static constexpr uint8_t adc(uint16_t const* const sample_start) { return (*sample_start & 0xff); }
0015     static constexpr uint8_t tdc(uint16_t const* const sample_start) { return (*sample_start >> 8) & 0x3f; }
0016     static constexpr uint8_t soibit(uint16_t const* const sample_start) { return (*sample_start >> 14) & 0x1; }
0017   };
0018 
0019   // FLAVOR_HB_QIE11 = 3; Phase1 upgrade
0020   struct Flavor3 {
0021     static constexpr int WORDS_PER_SAMPLE = 1;
0022     static constexpr int SAMPLES_PER_WORD = 1;
0023     static constexpr int HEADER_WORDS = 1;
0024 
0025     static constexpr uint8_t adc(uint16_t const* const sample_start) { return (*sample_start & 0xff); }
0026     static constexpr uint8_t tdc(uint16_t const* const sample_start) { return ((*sample_start >> 8) & 0x3); }
0027     static constexpr uint8_t soibit(uint16_t const* const sample_start) { return ((*sample_start >> 14) & 0x1); }
0028     static constexpr uint8_t capid(uint16_t const* const sample_start) { return ((*sample_start >> 10) & 0x3); }
0029   };
0030 
0031   // FLAVOR_HB_QIE10 = 5; Phase0
0032   struct Flavor5 {
0033     static constexpr float WORDS_PER_SAMPLE = 0.5;
0034     static constexpr int SAMPLES_PER_WORD = 2;
0035     static constexpr int HEADER_WORDS = 1;
0036 
0037     static constexpr uint8_t adc(uint16_t const* const sample_start, uint8_t const shifter) {
0038       return ((*sample_start >> shifter * 8) & 0x7f);
0039     }
0040   };
0041 
0042   template <typename Flavor>
0043   constexpr uint8_t capid_for_sample(uint16_t const* const dfstart, uint32_t const sample) {
0044     auto const capid_first = (*dfstart >> 8) & 0x3;
0045     return (capid_first + sample) & 0x3;  // same as % 4
0046   }
0047 
0048   template <>
0049   constexpr uint8_t capid_for_sample<Flavor3>(uint16_t const* const dfstart, uint32_t const sample) {
0050     return Flavor3::capid(dfstart + Flavor3::HEADER_WORDS + sample * Flavor3::WORDS_PER_SAMPLE);
0051   }
0052 
0053   template <typename Flavor>
0054   constexpr uint8_t soibit_for_sample(uint16_t const* const dfstart, uint32_t const sample) {
0055     return Flavor::soibit(dfstart + Flavor::HEADER_WORDS + sample * Flavor::WORDS_PER_SAMPLE);
0056   }
0057 
0058   template <typename Flavor>
0059   constexpr uint8_t adc_for_sample(uint16_t const* const dfstart, uint32_t const sample) {
0060     return Flavor::adc(dfstart + Flavor::HEADER_WORDS + sample * Flavor::WORDS_PER_SAMPLE);
0061   }
0062 
0063   template <typename Flavor>
0064   constexpr uint8_t tdc_for_sample(uint16_t const* const dfstart, uint32_t const sample) {
0065     return Flavor::tdc(dfstart + Flavor::HEADER_WORDS + sample * Flavor::WORDS_PER_SAMPLE);
0066   }
0067 
0068   template <>
0069   constexpr uint8_t adc_for_sample<Flavor5>(uint16_t const* const dfstart, uint32_t const sample) {
0070     // avoid using WORDS_PER_SAMPLE and simply shift
0071     return Flavor5::adc(dfstart + Flavor5::HEADER_WORDS + (sample >> 1), sample % 2);
0072   }
0073 
0074   template <typename Flavor>
0075   constexpr uint32_t compute_stride(uint32_t const nsamples) {
0076     return static_cast<uint32_t>(nsamples * Flavor::WORDS_PER_SAMPLE) + Flavor::HEADER_WORDS;
0077   }
0078 
0079   template <typename Flavor>
0080   constexpr uint32_t compute_nsamples(uint32_t const nwords) {
0081     if constexpr (Flavor::SAMPLES_PER_WORD >= 1)
0082       return (nwords - Flavor::HEADER_WORDS) * Flavor::SAMPLES_PER_WORD;
0083     else
0084       return (nwords - Flavor::HEADER_WORDS) / Flavor::WORDS_PER_SAMPLE;
0085   }
0086 
0087   //
0088   template <typename StoragePolicy>
0089   struct DigiCollectionBase : public ::calo::common::AddSize<typename StoragePolicy::TagType> {
0090     DigiCollectionBase() = default;
0091     DigiCollectionBase(DigiCollectionBase const&) = default;
0092     DigiCollectionBase& operator=(DigiCollectionBase const&) = default;
0093 
0094     DigiCollectionBase(DigiCollectionBase&&) = default;
0095     DigiCollectionBase& operator=(DigiCollectionBase&&) = default;
0096 
0097     template <typename T = typename StoragePolicy::TagType>
0098     typename std::enable_if<std::is_same<T, ::calo::common::tags::Vec>::value, void>::type resize(std::size_t size) {
0099       ids.resize(size);
0100       data.resize(size * stride);
0101     }
0102 
0103     template <typename T = typename StoragePolicy::TagType>
0104     typename std::enable_if<std::is_same<T, ::calo::common::tags::Vec>::value, void>::type reserve(std::size_t size) {
0105       ids.reserve(size);
0106       data.reserve(size * stride);
0107     }
0108 
0109     template <typename T = typename StoragePolicy::TagType>
0110     typename std::enable_if<std::is_same<T, ::calo::common::tags::Vec>::value, void>::type clear() {
0111       ids.clear();
0112       data.clear();
0113     }
0114 
0115     typename StoragePolicy::template StorageSelector<uint32_t>::type ids;
0116     typename StoragePolicy::template StorageSelector<uint16_t>::type data;
0117     uint32_t stride{0};
0118   };
0119 
0120   template <typename Flavor, typename StoragePolicy>
0121   struct DigiCollection : public DigiCollectionBase<StoragePolicy> {
0122     using DigiCollectionBase<StoragePolicy>::DigiCollectionBase;
0123   };
0124 
0125   // NOTE: base ctors will not be available
0126   template <typename StoragePolicy>
0127   struct DigiCollection<Flavor5, StoragePolicy> : public DigiCollectionBase<StoragePolicy> {
0128     DigiCollection() = default;
0129 
0130     DigiCollection(DigiCollection const&) = default;
0131     DigiCollection& operator=(DigiCollection const&) = default;
0132 
0133     DigiCollection(DigiCollection&&) = default;
0134     DigiCollection& operator=(DigiCollection&&) = default;
0135 
0136     template <typename T = typename StoragePolicy::TagType>
0137     typename std::enable_if<std::is_same<T, ::calo::common::tags::Vec>::value, void>::type resize(std::size_t size) {
0138       DigiCollectionBase<StoragePolicy>::resize(size);
0139       npresamples.resize(size);
0140     }
0141 
0142     template <typename T = typename StoragePolicy::TagType>
0143     typename std::enable_if<std::is_same<T, ::calo::common::tags::Vec>::value, void>::type reserve(std::size_t size) {
0144       DigiCollectionBase<StoragePolicy>::reserve(size);
0145       npresamples.reserve(size);
0146     }
0147 
0148     template <typename T = typename StoragePolicy::TagType>
0149     typename std::enable_if<std::is_same<T, ::calo::common::tags::Vec>::value, void>::type clear() {
0150       DigiCollectionBase<StoragePolicy>::clear();
0151       npresamples.clear();
0152     }
0153 
0154     // add npresamples member
0155     typename StoragePolicy::template StorageSelector<uint8_t>::type npresamples;
0156   };
0157 
0158 }  // namespace hcal
0159 
0160 #endif  // CUDADataFormats_HcalDigi_interface_DigiCollection_h