CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/SimDataFormats/TrackerDigiSimLink/interface/StripCompactDigiSimLinks.h

Go to the documentation of this file.
00001 #ifndef SimDataFormats_TrackerDigiSimLink_interface_StripCompactDigiSimLinks_h
00002 #define SimDataFormats_TrackerDigiSimLink_interface_StripCompactDigiSimLinks_h
00003 
00004 #include <map>
00005 #include <algorithm>
00006 #include <boost/cstdint.hpp>
00007 #include <boost/range.hpp>
00008 #include "SimDataFormats/EncodedEventId/interface/EncodedEventId.h"
00009 
00010 class StripCompactDigiSimLinks {
00011     public:
00013         StripCompactDigiSimLinks() {}
00014         ~StripCompactDigiSimLinks() {}
00015 
00016         typedef std::pair<EncodedEventId,unsigned int> key_type;
00017         struct HitRecord {
00018             HitRecord() {}
00019             HitRecord(uint32_t detid, uint16_t first, uint16_t size) : 
00020                  detId(detid), firstStrip(first), nStrips(size) {}
00021             uint32_t detId;
00022             uint16_t firstStrip;
00023             uint16_t nStrips;
00024         };
00025         typedef boost::sub_range<const std::vector<HitRecord> > Links;
00026         typedef Links value_type;
00027         
00028         void swap(StripCompactDigiSimLinks &other) {
00029             using std::swap;
00030             swap(trackRecords_, other.trackRecords_);
00031             swap(hitRecords_,   other.hitRecords_);
00032         }
00033        
00034         Links getLinks(const key_type &key) const ;
00035         Links operator[](const key_type &key) const { return getLinks(key); }
00036         
00037         class Filler {
00038             public:
00039                 Filler() : storage_(), num_keys_(0), num_values_(0) {}
00040 
00041                 // out of line destructor to avoid code bloat
00042                 ~Filler() ;
00043 
00044                 void insert(const key_type  &key, const HitRecord &record);
00045 
00046                 typedef std::map<key_type, std::vector<HitRecord> >  Map;
00047                 const Map & storage() const { return storage_; }
00048 
00049                 unsigned int keySize()  const { return num_keys_;   }
00050                 unsigned int dataSize() const { return num_values_; }
00051             private:
00052                 Map storage_;
00053                 unsigned int num_keys_;
00054                 unsigned int num_values_;
00055         };
00057         StripCompactDigiSimLinks(const Filler &filler) ;
00058 
00059         struct TrackRecord {
00060             TrackRecord(){}
00061             TrackRecord(key_type k, unsigned int offset) : key(k), start(offset) {}
00062             key_type       key;
00063             unsigned int   start;    // first index in HitRecord
00064             //unsigned int   length;
00065             inline bool operator< (const TrackRecord &other) const { return key <  other.key; }
00066             inline bool operator< (const key_type &otherKey) const { return key <  otherKey;  }
00067             inline bool operator==(const key_type &otherKey) const { return key == otherKey;  }
00068         };
00069 
00070         struct RevLink {
00071             RevLink(const TrackRecord &track, const HitRecord &hit) : 
00072                 eventId(track.key.first), simTrackId(track.key.second), 
00073                 firstStrip(hit.firstStrip), lastStrip(hit.firstStrip+hit.nStrips-1) {}
00074             EncodedEventId eventId;
00075             unsigned int simTrackId;
00076             uint16_t firstStrip;
00077             uint16_t lastStrip;
00078         };
00079 
00081         std::map<uint32_t, std::vector<RevLink> > makeReverseMap() const ;
00082     private:
00085         std::vector<TrackRecord> trackRecords_; 
00086 
00087         std::vector<HitRecord>   hitRecords_;
00088 };
00089 
00090 inline void swap(StripCompactDigiSimLinks &a, StripCompactDigiSimLinks &b) { a.swap(b); }
00091 #endif