File indexing completed on 2021-02-14 12:53:12
0001 #ifndef CTPPSDigi_TotemTimingDigi_h
0002 #define CTPPSDigi_TotemTimingDigi_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
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(const TotemTimingDigi& digi);
0029 TotemTimingDigi();
0030 ~TotemTimingDigi(){};
0031
0032
0033 bool operator==(const TotemTimingDigi& digi) const;
0034
0035
0036
0037
0038 inline unsigned int hardwareId() const { return hwId_; }
0039
0040 inline unsigned int hardwareBoardId() const { return (hwId_ & 0xE0) >> 5; }
0041
0042 inline unsigned int hardwareSampicId() const { return (hwId_ & 0x10) >> 4; }
0043
0044 inline unsigned int hardwareChannelId() const { return (hwId_ & 0x0F); }
0045
0046 inline unsigned int fpgaTimestamp() const { return fpgaTimestamp_; }
0047
0048 inline unsigned int timestampA() const { return timestampA_; }
0049
0050 inline unsigned int timestampB() const { return timestampB_; }
0051
0052 inline unsigned int cellInfo() const { return cellInfo_; }
0053
0054 inline std::vector<uint8_t> samples() const { return samples_; }
0055
0056 inline std::vector<uint8_t>::const_iterator samplesBegin() const { return samples_.cbegin(); }
0057
0058 inline std::vector<uint8_t>::const_iterator samplesEnd() const { return samples_.cend(); }
0059
0060 inline unsigned int numberOfSamples() const { return samples_.size(); }
0061
0062 inline int sampleAt(const unsigned int i) const {
0063 int sampleValue = -1;
0064 if (i < samples_.size())
0065 sampleValue = (int)samples_.at(i);
0066 return sampleValue;
0067 }
0068
0069 inline TotemTimingEventInfo eventInfo() const { return totemTimingEventInfo_; }
0070
0071
0072
0073 inline void setHardwareId(const uint8_t hwId) { hwId_ = hwId; }
0074
0075 inline void setHardwareBoardId(const unsigned int boardId) {
0076 hwId_ &= 0x1F;
0077 hwId_ |= ((boardId & 0x07) << 5) & 0xE0;
0078 }
0079
0080 inline void setHardwareSampicId(const unsigned int sampicId) {
0081 hwId_ &= 0xEF;
0082 hwId_ |= ((sampicId & 0x01) << 4) & 0x10;
0083 }
0084
0085 inline void setHardwareChannelId(const unsigned int channelId) {
0086 hwId_ &= 0xF0;
0087 hwId_ |= (channelId & 0x0F) & 0x0F;
0088 }
0089
0090 inline void setFPGATimestamp(const uint64_t fpgaTimestamp) { fpgaTimestamp_ = fpgaTimestamp; }
0091
0092 inline void setTimestampA(const uint16_t timestampA) { timestampA_ = timestampA; }
0093
0094 inline void setTimestampB(const uint16_t timestampB) { timestampB_ = timestampB; }
0095
0096 inline void setCellInfo(const uint16_t cellInfo) { cellInfo_ = cellInfo & 0x3F; }
0097
0098 inline void setSamples(const std::vector<uint8_t>& samples) { samples_ = samples; }
0099
0100 inline void addSample(const uint8_t sampleValue) { samples_.emplace_back(sampleValue); }
0101
0102 inline void setSampleAt(const unsigned int i, const uint8_t sampleValue) {
0103 if (i < samples_.size())
0104 samples_.at(i) = sampleValue;
0105 }
0106
0107 inline void setEventInfo(const TotemTimingEventInfo& totemTimingEventInfo) {
0108 totemTimingEventInfo_ = totemTimingEventInfo;
0109 }
0110
0111 private:
0112 uint8_t hwId_;
0113 uint64_t fpgaTimestamp_;
0114 uint16_t timestampA_;
0115 uint16_t timestampB_;
0116 uint16_t cellInfo_;
0117
0118 std::vector<uint8_t> samples_;
0119
0120 TotemTimingEventInfo totemTimingEventInfo_;
0121 };
0122
0123 #include <iostream>
0124
0125 inline bool operator<(const TotemTimingDigi& one, const TotemTimingDigi& other) {
0126 if (one.eventInfo() < other.eventInfo())
0127 return true;
0128 if (one.hardwareId() < other.hardwareId())
0129 return true;
0130 return false;
0131 }
0132
0133 inline std::ostream& operator<<(std::ostream& os, const TotemTimingDigi& digi) {
0134 return os << "TotemTimingDigi:"
0135 << "\nHardwareId:\t" << std::hex << digi.hardwareId() << "\nDB: " << std::dec << digi.hardwareBoardId()
0136 << "\tSampic: " << digi.hardwareSampicId() << "\tChannel: " << digi.hardwareChannelId()
0137 << "\nFPGATimestamp:\t" << std::dec << digi.fpgaTimestamp() << "\nTimestampA:\t" << std::dec
0138 << digi.timestampA() << "\nTimestampB:\t" << std::dec << digi.timestampB() << "\nCellInfo:\t" << std::hex
0139 << digi.cellInfo() << "\nNumberOfSamples:\t" << std::dec << digi.numberOfSamples() << std::endl
0140 << digi.eventInfo() << std::endl;
0141 }
0142
0143 #endif