Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-08 06:27:45

0001 #ifndef DataFormats_EcalDigi_EcalMGPASample_h
0002 #define DataFormats_EcalDigi_EcalMGPASample_h
0003 
0004 #include <iosfwd>
0005 #include <cstdint>
0006 #include "DataFormats/EcalDigi/interface/EcalConstants.h"
0007 
0008 namespace ecalMGPA {
0009   typedef uint16_t sample_type;
0010 
0011   /// get the ADC sample (12 bits)
0012   constexpr int adc(sample_type sample) { return sample & ecalPh1::kAdcMask; }
0013   /// get the gainId (2 bits)
0014   constexpr int gainId(sample_type sample) { return (sample >> ecalPh1::NBITS) & ecalPh1::kGainIdMask; }
0015   constexpr sample_type pack(int adc, int gainId) {
0016     return (adc & ecalPh1::kAdcMask) | ((gainId & ecalPh1::kGainIdMask) << ecalPh1::NBITS);
0017   }
0018 }  // namespace ecalMGPA
0019 
0020 /** \class EcalMGPASample
0021  *  Simple container packer/unpacker for a single sample from the MGPA electronics
0022  *
0023  *
0024  */
0025 class EcalMGPASample {
0026 public:
0027   EcalMGPASample() { theSample = 0; }
0028   EcalMGPASample(uint16_t data) { theSample = data; }
0029   EcalMGPASample(int adc, int gainId);
0030 
0031   /// get the raw word
0032   uint16_t raw() const { return theSample; }
0033   /// get the ADC sample (12 bits)
0034   int adc() const { return theSample & ecalPh1::kAdcMask; }
0035   /// get the gainId (2 bits)
0036   int gainId() const { return (theSample >> ecalPh1::NBITS) & ecalPh1::kGainIdMask; }
0037   /// for streaming
0038   uint16_t operator()() const { return theSample; }
0039   operator uint16_t() const { return theSample; }
0040 
0041 private:
0042   uint16_t theSample;
0043 };
0044 
0045 std::ostream& operator<<(std::ostream&, const EcalMGPASample&);
0046 
0047 #endif