Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef SimDataFormats_TrackerDigiSimLink_interface_StripCompactDigiSimLinks_h
0002 #define SimDataFormats_TrackerDigiSimLink_interface_StripCompactDigiSimLinks_h
0003 
0004 #include <map>
0005 #include <algorithm>
0006 #include <vector>
0007 #include <boost/range.hpp>
0008 #include "SimDataFormats/EncodedEventId/interface/EncodedEventId.h"
0009 #include <cstdint>
0010 
0011 class StripCompactDigiSimLinks {
0012 public:
0013   /// Empty constructor, for ROOT persistence
0014   StripCompactDigiSimLinks() {}
0015   ~StripCompactDigiSimLinks() {}
0016 
0017   typedef std::pair<EncodedEventId, unsigned int> key_type;
0018   struct HitRecord {
0019     HitRecord() {}
0020     HitRecord(uint32_t detid, uint16_t first, uint16_t size) : detId(detid), firstStrip(first), nStrips(size) {}
0021     uint32_t detId;
0022     uint16_t firstStrip;
0023     uint16_t nStrips;
0024   };
0025   typedef boost::sub_range<const std::vector<HitRecord> > Links;
0026   typedef Links value_type;
0027 
0028   void swap(StripCompactDigiSimLinks &other) {
0029     using std::swap;
0030     swap(trackRecords_, other.trackRecords_);
0031     swap(hitRecords_, other.hitRecords_);
0032   }
0033 
0034   Links getLinks(const key_type &key) const;
0035   Links operator[](const key_type &key) const { return getLinks(key); }
0036 
0037   class Filler {
0038   public:
0039     Filler() : storage_(), num_keys_(0), num_values_(0) {}
0040 
0041     // out of line destructor to avoid code bloat
0042     ~Filler();
0043 
0044     void insert(const key_type &key, const HitRecord &record);
0045 
0046     typedef std::map<key_type, std::vector<HitRecord> > Map;
0047     const Map &storage() const { return storage_; }
0048 
0049     unsigned int keySize() const { return num_keys_; }
0050     unsigned int dataSize() const { return num_values_; }
0051 
0052   private:
0053     Map storage_;
0054     unsigned int num_keys_;
0055     unsigned int num_values_;
0056   };
0057   /// This is the real constructor you will use
0058   StripCompactDigiSimLinks(const Filler &filler);
0059 
0060   struct TrackRecord {
0061     TrackRecord() {}
0062     TrackRecord(key_type k, unsigned int offset) : key(k), start(offset) {}
0063     key_type key;
0064     unsigned int start;  // first index in HitRecord
0065     //unsigned int   length;
0066     inline bool operator<(const TrackRecord &other) const { return key < other.key; }
0067     inline bool operator<(const key_type &otherKey) const { return key < otherKey; }
0068     inline bool operator==(const key_type &otherKey) const { return key == otherKey; }
0069   };
0070 
0071   struct RevLink {
0072     RevLink(const TrackRecord &track, const HitRecord &hit)
0073         : eventId(track.key.first),
0074           simTrackId(track.key.second),
0075           firstStrip(hit.firstStrip),
0076           lastStrip(hit.firstStrip + hit.nStrips - 1) {}
0077     EncodedEventId eventId;
0078     unsigned int simTrackId;
0079     uint16_t firstStrip;
0080     uint16_t lastStrip;
0081   };
0082 
0083   /// Make the map in the reverse direction. SLOW! call it only once.
0084   std::map<uint32_t, std::vector<RevLink> > makeReverseMap() const;
0085 
0086 private:
0087   /// These MUST be sorted at the same time by key and by start
0088   /// The rule is enforced by allowing to create this only through a Filler
0089   std::vector<TrackRecord> trackRecords_;
0090 
0091   std::vector<HitRecord> hitRecords_;
0092 };
0093 
0094 inline void swap(StripCompactDigiSimLinks &a, StripCompactDigiSimLinks &b) { a.swap(b); }
0095 #endif