Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:41

0001 #ifndef SimDataFormats_EncodedEventId_H
0002 #define SimDataFormats_EncodedEventId_H 1
0003 
0004 #include <cmath>
0005 #include <ostream>
0006 #include <cstdint>
0007 
0008 /** \class EncodedEventId
0009 
0010 */
0011 class EncodedEventId {
0012 public:
0013   /// Create an empty or null id (also for persistence)
0014   EncodedEventId();
0015   /// Create an id from a raw number
0016   explicit EncodedEventId(uint32_t id);
0017   /// Create an id, filling the bunch crossing and event infomrations
0018   EncodedEventId(int bunchX, int event) {
0019     id_ = std::abs(bunchX) << bunchXStartBit_ | event;
0020     if (bunchX < 0)
0021       id_ = id_ | bunchNegMask_;
0022   }
0023 
0024   /// get the detector field from this detid
0025   int bunchCrossing() const {
0026     int bcr = int((id_ >> bunchXStartBit_) & 0x7FFF);
0027     return id_ & bunchNegMask_ ? -bcr : bcr;
0028   }
0029   /// get the contents of the subdetector field (should be protected?)
0030   int event() const { return int(id_ & 0xFFFF); }
0031   uint32_t operator()() const { return id_; }
0032   /// get the raw id
0033   uint32_t rawId() const { return id_; }
0034   /// equality
0035   int operator==(const EncodedEventId& id) const { return id_ == id.id_; }
0036   /// inequality
0037   int operator!=(const EncodedEventId& id) const { return id_ != id.id_; }
0038   /// comparison
0039   int operator<(const EncodedEventId& id) const { return id_ < id.id_; }
0040 
0041 private:
0042   static const unsigned int bunchXStartBit_ = 16;
0043   static const unsigned int eventStartBit_ = 0;
0044   static const unsigned int bunchXMask_ = 0x10;
0045   static const unsigned int bunchNegMask_ = 0x80000000;
0046   static const unsigned int eventMask_ = 0x10;
0047 
0048 protected:
0049   uint32_t id_;
0050 };
0051 #endif