Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:49:36

0001 #ifndef CTPPSDigi_TotemTimingEventInfo_h
0002 #define CTPPSDigi_TotemTimingEventInfo_h
0003 
0004 /** \class TotemTimingEventInfo
0005  *
0006  * Event Info Class for CTPPS Timing Detector
0007  *
0008  * \author Mirko Berretti
0009  * \author Nicola Minafra
0010  * \author Laurent Forthomme
0011  * \date March 2018
0012  */
0013 
0014 #include <cstdint>
0015 #include <bitset>
0016 
0017 class TotemTimingEventInfo {
0018 public:
0019   TotemTimingEventInfo(const uint8_t hwId,
0020                        const uint64_t l1ATimestamp,
0021                        const uint16_t bunchNumber,
0022                        const uint32_t orbitNumber,
0023                        const uint32_t eventNumber,
0024                        const uint16_t channelMap,
0025                        const uint16_t l1ALatency,
0026                        const uint8_t numberOfSamples,
0027                        const uint8_t offsetOfSamples,
0028                        const uint8_t pllInfo);
0029   TotemTimingEventInfo(const TotemTimingEventInfo& eventInfo);
0030   TotemTimingEventInfo();
0031   ~TotemTimingEventInfo(){};
0032 
0033   /// Digis are equal if they have all the same values, NOT checking the samples!
0034   bool operator==(const TotemTimingEventInfo& eventInfo) const;
0035 
0036   /// Return digi values number
0037 
0038   /// Hardware Id formatted as: bits 0-3 Channel Id, bit 4 Sampic Id, bits 5-7 Digitizer Board Id
0039   inline unsigned int hardwareId() const { return hwId_; }
0040 
0041   inline unsigned int hardwareBoardId() const { return (hwId_ & 0xE0) >> 5; }
0042 
0043   inline unsigned int hardwareSampicId() const { return (hwId_ & 0x10) >> 4; }
0044 
0045   inline unsigned int hardwareChannelId() const { return (hwId_ & 0x0F); }
0046 
0047   inline unsigned int l1ATimestamp() const { return l1ATimestamp_; }
0048 
0049   inline unsigned int bunchNumber() const { return bunchNumber_; }
0050 
0051   inline unsigned int orbitNumber() const { return orbitNumber_; }
0052 
0053   inline unsigned int eventNumber() const { return eventNumber_; }
0054 
0055   inline uint16_t channelMap() const { return channelMap_; }
0056 
0057   inline unsigned int l1ALatency() const { return l1ALatency_; }
0058 
0059   inline unsigned int numberOfSamples() const { return numberOfSamples_; }
0060 
0061   inline unsigned int offsetOfSamples() const { return offsetOfSamples_; }
0062 
0063   inline uint8_t pllInfo() const { return pllInfo_; }
0064 
0065   /// Set digi values
0066   /// Hardware Id formatted as: bits 0-3 Channel Id, bit 4 Sampic Id, bits 5-7 Digitizer Board Id
0067   inline void setHardwareId(const uint8_t hwId) { hwId_ = hwId; }
0068 
0069   inline void setHardwareBoardId(const unsigned int boardId) {
0070     hwId_ &= 0x1F;  // Set board bits to 0
0071     hwId_ |= ((boardId & 0x07) << 5) & 0xE0;
0072   }
0073 
0074   inline void setHardwareSampicId(const unsigned int sampicId) {
0075     hwId_ &= 0xEF;  // set Sampic bit to 0
0076     hwId_ |= ((sampicId & 0x01) << 4) & 0x10;
0077   }
0078 
0079   inline void setHardwareChannelId(const unsigned int channelId) {
0080     hwId_ &= 0xF0;  // set Sampic bit to 0
0081     hwId_ |= (channelId & 0x0F) & 0x0F;
0082   }
0083 
0084   inline void setL1ATimestamp(const uint64_t l1ATimestamp) { l1ATimestamp_ = l1ATimestamp; }
0085 
0086   inline void setBunchNumber(const uint16_t bunchNumber) { bunchNumber_ = bunchNumber; }
0087 
0088   inline void setOrbitNumber(const uint32_t orbitNumber) { orbitNumber_ = orbitNumber; }
0089 
0090   inline void setEventNumber(const uint32_t eventNumber) { eventNumber_ = eventNumber; }
0091 
0092   inline void setChannelMap(const uint16_t channelMap) { channelMap_ = channelMap; }
0093 
0094   inline void setL1ALatency(const uint16_t l1ALatency) { l1ALatency_ = l1ALatency; }
0095 
0096   inline void setNumberOfSamples(const uint8_t numberOfSamples) { numberOfSamples_ = numberOfSamples; }
0097 
0098   inline void setOffsetOfSamples(const uint8_t offsetOfSamples) { offsetOfSamples_ = offsetOfSamples; }
0099 
0100   inline void setPLLInfo(const uint8_t pllInfo) { pllInfo_ = pllInfo; }
0101 
0102 private:
0103   uint8_t hwId_;
0104   uint64_t l1ATimestamp_;
0105   uint16_t bunchNumber_;
0106   uint32_t orbitNumber_;
0107   uint32_t eventNumber_;
0108   uint16_t channelMap_;
0109   uint16_t l1ALatency_;
0110   uint8_t numberOfSamples_;
0111   uint8_t offsetOfSamples_;
0112   uint8_t pllInfo_;
0113 };
0114 
0115 #include <iostream>
0116 
0117 inline bool operator<(const TotemTimingEventInfo& one, const TotemTimingEventInfo& other) {
0118   if (one.eventNumber() < other.eventNumber())
0119     return true;
0120   if (one.l1ATimestamp() < other.l1ATimestamp())
0121     return true;
0122   if (one.hardwareId() < other.hardwareId())
0123     return true;
0124   return false;
0125 }
0126 
0127 inline std::ostream& operator<<(std::ostream& o, const TotemTimingEventInfo& digi) {
0128   std::bitset<16> bitsPLLInfo(digi.pllInfo());
0129   return o << "TotemTimingEventInfo:"
0130            << "\nHardwareId:\t" << std::hex << digi.hardwareId() << "\nDB: " << std::dec << digi.hardwareBoardId()
0131            << "\tSampic: " << digi.hardwareSampicId() << "\tChannel: " << digi.hardwareChannelId()
0132            << "\nL1A Timestamp:\t" << std::dec << digi.l1ATimestamp() << "\nL1A Latency:\t" << std::dec
0133            << digi.l1ALatency() << "\nBunch Number:\t" << std::dec << digi.bunchNumber() << "\nOrbit Number:\t"
0134            << std::dec << digi.orbitNumber() << "\nEvent Number:\t" << std::dec << digi.eventNumber()
0135            << "\nChannels fired:\t" << std::hex << digi.channelMap() << "\nNumber of Samples:\t" << std::dec
0136            << digi.numberOfSamples() << "\nOffset of Samples:\t" << std::dec << digi.offsetOfSamples()
0137            << "\nPLL Info:\t" << bitsPLLInfo.to_string() << std::endl;
0138 }
0139 
0140 #endif