CMS 3D CMS Logo

TotemTimingDigi.h
Go to the documentation of this file.
1 #ifndef CTPPSDigi_TotemTimingDigi_h
2 #define CTPPSDigi_TotemTimingDigi_h
3 
14 #include <cstdint>
15 #include <vector>
16 
18 
20 public:
21  TotemTimingDigi(const uint8_t hwId,
22  const uint64_t fpgaTimestamp,
23  const uint16_t timestampA,
24  const uint16_t timestampB,
25  const uint16_t cellInfo,
26  const std::vector<uint8_t>& samples,
27  const TotemTimingEventInfo& totemTimingEventInfo);
29 
31  bool operator==(const TotemTimingDigi& digi) const;
32 
34 
36  inline unsigned int hardwareId() const { return hwId_; }
37 
38  inline unsigned int hardwareBoardId() const { return (hwId_ & 0xE0) >> 5; }
39 
40  inline unsigned int hardwareSampicId() const { return (hwId_ & 0x10) >> 4; }
41 
42  inline unsigned int hardwareChannelId() const { return (hwId_ & 0x0F); }
43 
44  inline unsigned int fpgaTimestamp() const { return fpgaTimestamp_; }
45 
46  inline unsigned int timestampA() const { return timestampA_; }
47 
48  inline unsigned int timestampB() const { return timestampB_; }
49 
50  inline unsigned int cellInfo() const { return cellInfo_; }
51 
52  inline std::vector<uint8_t> samples() const { return samples_; }
53 
54  inline std::vector<uint8_t>::const_iterator samplesBegin() const { return samples_.cbegin(); }
55 
56  inline std::vector<uint8_t>::const_iterator samplesEnd() const { return samples_.cend(); }
57 
58  inline unsigned int numberOfSamples() const { return samples_.size(); }
59 
60  inline int sampleAt(const unsigned int i) const {
61  int sampleValue = -1;
62  if (i < samples_.size())
63  sampleValue = (int)samples_.at(i);
64  return sampleValue;
65  }
66 
68 
71  inline void setHardwareId(const uint8_t hwId) { hwId_ = hwId; }
72 
73  inline void setHardwareBoardId(const unsigned int boardId) {
74  hwId_ &= 0x1F; // set board bits to 0
75  hwId_ |= ((boardId & 0x07) << 5) & 0xE0;
76  }
77 
78  inline void setHardwareSampicId(const unsigned int sampicId) {
79  hwId_ &= 0xEF; // set Sampic bit to 0
80  hwId_ |= ((sampicId & 0x01) << 4) & 0x10;
81  }
82 
83  inline void setHardwareChannelId(const unsigned int channelId) {
84  hwId_ &= 0xF0; // Set Sampic bit to 0
85  hwId_ |= (channelId & 0x0F) & 0x0F;
86  }
87 
89 
90  inline void setTimestampA(const uint16_t timestampA) { timestampA_ = timestampA; }
91 
92  inline void setTimestampB(const uint16_t timestampB) { timestampB_ = timestampB; }
93 
94  inline void setCellInfo(const uint16_t cellInfo) { cellInfo_ = cellInfo & 0x3F; }
95 
96  inline void setSamples(const std::vector<uint8_t>& samples) { samples_ = samples; }
97 
98  inline void addSample(const uint8_t sampleValue) { samples_.emplace_back(sampleValue); }
99 
100  inline void setSampleAt(const unsigned int i, const uint8_t sampleValue) {
101  if (i < samples_.size())
102  samples_.at(i) = sampleValue;
103  }
104 
105  inline void setEventInfo(const TotemTimingEventInfo& totemTimingEventInfo) {
106  totemTimingEventInfo_ = totemTimingEventInfo;
107  }
108 
109 private:
110  uint8_t hwId_;
112  uint16_t timestampA_;
113  uint16_t timestampB_;
114  uint16_t cellInfo_;
115 
116  std::vector<uint8_t> samples_;
117 
119 };
120 
121 #include <iostream>
122 
123 inline bool operator<(const TotemTimingDigi& one, const TotemTimingDigi& other) {
124  if (one.eventInfo() < other.eventInfo())
125  return true;
126  if (one.hardwareId() < other.hardwareId())
127  return true;
128  return false;
129 }
130 
131 inline std::ostream& operator<<(std::ostream& os, const TotemTimingDigi& digi) {
132  return os << "TotemTimingDigi:"
133  << "\nHardwareId:\t" << std::hex << digi.hardwareId() << "\nDB: " << std::dec << digi.hardwareBoardId()
134  << "\tSampic: " << digi.hardwareSampicId() << "\tChannel: " << digi.hardwareChannelId()
135  << "\nFPGATimestamp:\t" << std::dec << digi.fpgaTimestamp() << "\nTimestampA:\t" << std::dec
136  << digi.timestampA() << "\nTimestampB:\t" << std::dec << digi.timestampB() << "\nCellInfo:\t" << std::hex
137  << digi.cellInfo() << "\nNumberOfSamples:\t" << std::dec << digi.numberOfSamples() << std::endl
138  << digi.eventInfo() << std::endl;
139 }
140 
141 #endif
void setFPGATimestamp(const uint64_t fpgaTimestamp)
std::ostream & operator<<(std::ostream &os, const TotemTimingDigi &digi)
void setSamples(const std::vector< uint8_t > &samples)
void setEventInfo(const TotemTimingEventInfo &totemTimingEventInfo)
TotemTimingEventInfo totemTimingEventInfo_
unsigned int timestampA() const
unsigned int timestampB() const
void setHardwareChannelId(const unsigned int channelId)
unsigned int numberOfSamples() const
bool operator==(const TotemTimingDigi &digi) const
Digis are equal if they have all the same values, NOT checking the samples!
int sampleAt(const unsigned int i) const
unsigned int fpgaTimestamp() const
void setHardwareId(const uint8_t hwId)
void setHardwareBoardId(const unsigned int boardId)
unsigned int hardwareSampicId() const
std::vector< uint8_t > samples() const
void setCellInfo(const uint16_t cellInfo)
std::vector< uint8_t >::const_iterator samplesBegin() const
void setSampleAt(const unsigned int i, const uint8_t sampleValue)
void setHardwareSampicId(const unsigned int sampicId)
unsigned long long uint64_t
Definition: Time.h:13
unsigned int hardwareChannelId() const
uint64_t fpgaTimestamp_
void setTimestampB(const uint16_t timestampB)
std::vector< uint8_t > samples_
unsigned int hardwareId() const
Return digi values number.
TotemTimingEventInfo eventInfo() const
unsigned int hardwareBoardId() const
unsigned int cellInfo() const
bool operator<(const TotemTimingDigi &one, const TotemTimingDigi &other)
void addSample(const uint8_t sampleValue)
std::vector< uint8_t >::const_iterator samplesEnd() const
void setTimestampA(const uint16_t timestampA)