Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:01

0001 #ifndef CTPPSDigi_TotemTimingDigi_h
0002 #define CTPPSDigi_TotemTimingDigi_h
0003 
0004 /** \class TotemTimingDigi
0005  *
0006  * Digi Class for CTPPS Timing Detector
0007  *
0008  * \author Mirko Berretti
0009  * \author Nicola Minafra
0010  * \author Laurent Forthomme
0011  * March 2018
0012  */
0013 
0014 #include <cstdint>
0015 #include <vector>
0016 
0017 #include <DataFormats/CTPPSDigi/interface/TotemTimingEventInfo.h>
0018 
0019 class TotemTimingDigi {
0020 public:
0021   TotemTimingDigi(const uint8_t hwId,
0022                   const uint64_t fpgaTimestamp,
0023                   const uint16_t timestampA,
0024                   const uint16_t timestampB,
0025                   const uint16_t cellInfo,
0026                   const std::vector<uint8_t>& samples,
0027                   const TotemTimingEventInfo& totemTimingEventInfo);
0028   TotemTimingDigi();
0029 
0030   /// Digis are equal if they have all the same values, NOT checking the samples!
0031   bool operator==(const TotemTimingDigi& digi) const;
0032 
0033   /// Return digi values number
0034 
0035   /// Hardware Id formatted as: bits 0-3 Channel Id, bit 4 Sampic Id, bits 5-7 Digitizer Board Id
0036   inline unsigned int hardwareId() const { return hwId_; }
0037 
0038   inline unsigned int hardwareBoardId() const { return (hwId_ & 0xE0) >> 5; }
0039 
0040   inline unsigned int hardwareSampicId() const { return (hwId_ & 0x10) >> 4; }
0041 
0042   inline unsigned int hardwareChannelId() const { return (hwId_ & 0x0F); }
0043 
0044   inline unsigned int fpgaTimestamp() const { return fpgaTimestamp_; }
0045 
0046   inline unsigned int timestampA() const { return timestampA_; }
0047 
0048   inline unsigned int timestampB() const { return timestampB_; }
0049 
0050   inline unsigned int cellInfo() const { return cellInfo_; }
0051 
0052   inline std::vector<uint8_t> samples() const { return samples_; }
0053 
0054   inline std::vector<uint8_t>::const_iterator samplesBegin() const { return samples_.cbegin(); }
0055 
0056   inline std::vector<uint8_t>::const_iterator samplesEnd() const { return samples_.cend(); }
0057 
0058   inline unsigned int numberOfSamples() const { return samples_.size(); }
0059 
0060   inline int sampleAt(const unsigned int i) const {
0061     int sampleValue = -1;
0062     if (i < samples_.size())
0063       sampleValue = (int)samples_.at(i);
0064     return sampleValue;
0065   }
0066 
0067   inline TotemTimingEventInfo eventInfo() const { return totemTimingEventInfo_; }
0068 
0069   /// Set digi values
0070   /// Hardware Id formatted as: bits 0-3 Channel Id, bit 4 Sampic Id, bits 5-7 Digitizer Board Id
0071   inline void setHardwareId(const uint8_t hwId) { hwId_ = hwId; }
0072 
0073   inline void setHardwareBoardId(const unsigned int boardId) {
0074     hwId_ &= 0x1F;  // set board bits to 0
0075     hwId_ |= ((boardId & 0x07) << 5) & 0xE0;
0076   }
0077 
0078   inline void setHardwareSampicId(const unsigned int sampicId) {
0079     hwId_ &= 0xEF;  // set Sampic bit to 0
0080     hwId_ |= ((sampicId & 0x01) << 4) & 0x10;
0081   }
0082 
0083   inline void setHardwareChannelId(const unsigned int channelId) {
0084     hwId_ &= 0xF0;  // Set Sampic bit to 0
0085     hwId_ |= (channelId & 0x0F) & 0x0F;
0086   }
0087 
0088   inline void setFPGATimestamp(const uint64_t fpgaTimestamp) { fpgaTimestamp_ = fpgaTimestamp; }
0089 
0090   inline void setTimestampA(const uint16_t timestampA) { timestampA_ = timestampA; }
0091 
0092   inline void setTimestampB(const uint16_t timestampB) { timestampB_ = timestampB; }
0093 
0094   inline void setCellInfo(const uint16_t cellInfo) { cellInfo_ = cellInfo & 0x3F; }
0095 
0096   inline void setSamples(const std::vector<uint8_t>& samples) { samples_ = samples; }
0097 
0098   inline void addSample(const uint8_t sampleValue) { samples_.emplace_back(sampleValue); }
0099 
0100   inline void setSampleAt(const unsigned int i, const uint8_t sampleValue) {
0101     if (i < samples_.size())
0102       samples_.at(i) = sampleValue;
0103   }
0104 
0105   inline void setEventInfo(const TotemTimingEventInfo& totemTimingEventInfo) {
0106     totemTimingEventInfo_ = totemTimingEventInfo;
0107   }
0108 
0109 private:
0110   uint8_t hwId_;
0111   uint64_t fpgaTimestamp_;
0112   uint16_t timestampA_;
0113   uint16_t timestampB_;
0114   uint16_t cellInfo_;
0115 
0116   std::vector<uint8_t> samples_;
0117 
0118   TotemTimingEventInfo totemTimingEventInfo_;
0119 };
0120 
0121 #include <iostream>
0122 
0123 inline bool operator<(const TotemTimingDigi& one, const TotemTimingDigi& other) {
0124   if (one.eventInfo() < other.eventInfo())
0125     return true;
0126   if (one.hardwareId() < other.hardwareId())
0127     return true;
0128   return false;
0129 }
0130 
0131 inline std::ostream& operator<<(std::ostream& os, const TotemTimingDigi& digi) {
0132   return os << "TotemTimingDigi:"
0133             << "\nHardwareId:\t" << std::hex << digi.hardwareId() << "\nDB: " << std::dec << digi.hardwareBoardId()
0134             << "\tSampic: " << digi.hardwareSampicId() << "\tChannel: " << digi.hardwareChannelId()
0135             << "\nFPGATimestamp:\t" << std::dec << digi.fpgaTimestamp() << "\nTimestampA:\t" << std::dec
0136             << digi.timestampA() << "\nTimestampB:\t" << std::dec << digi.timestampB() << "\nCellInfo:\t" << std::hex
0137             << digi.cellInfo() << "\nNumberOfSamples:\t" << std::dec << digi.numberOfSamples() << std::endl
0138             << digi.eventInfo() << std::endl;
0139 }
0140 
0141 #endif