Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:28:52

0001 #include "SimDataFormats/TrackerDigiSimLink/interface/StripCompactDigiSimLinks.h"
0002 
0003 #include <algorithm>
0004 
0005 StripCompactDigiSimLinks::Links StripCompactDigiSimLinks::getLinks(const StripCompactDigiSimLinks::key_type &key) const {
0006   std::vector<TrackRecord>::const_iterator last = trackRecords_.end();
0007   std::vector<TrackRecord>::const_iterator match = std::lower_bound(trackRecords_.begin(), last, key);
0008   if ((match != last) && (*match == key)) {
0009     // std::vector<TrackRecord>::const_iterator next = match+1;
0010     unsigned int end = (match + 1 == last ? hitRecords_.size() : (match + 1)->start);
0011     return Links(hitRecords_.begin() + match->start, hitRecords_.begin() + end);
0012   } else {
0013     return Links(hitRecords_.end(), hitRecords_.end());
0014   }
0015 }
0016 
0017 StripCompactDigiSimLinks::StripCompactDigiSimLinks(const StripCompactDigiSimLinks::Filler &filler) {
0018   trackRecords_.reserve(filler.keySize());
0019   hitRecords_.reserve(filler.dataSize());
0020   for (auto const &pair : filler.storage()) {
0021     trackRecords_.push_back(TrackRecord(pair.first, hitRecords_.size()));
0022     hitRecords_.insert(hitRecords_.end(), pair.second.begin(), pair.second.end());
0023   }
0024 }
0025 
0026 StripCompactDigiSimLinks::Filler::~Filler() {}
0027 
0028 void StripCompactDigiSimLinks::Filler::insert(const StripCompactDigiSimLinks::key_type &key,
0029                                               const StripCompactDigiSimLinks::HitRecord &record) {
0030   Filler::Map::iterator it = storage_.find(key);
0031   if (it == storage_.end()) {
0032     storage_.insert(std::make_pair(key, std::vector<HitRecord>(1, record)));
0033     num_keys_++;
0034     num_values_++;
0035   } else {
0036     it->second.push_back(record);
0037     num_values_++;
0038   }
0039 }
0040 
0041 std::map<uint32_t, std::vector<StripCompactDigiSimLinks::RevLink> > StripCompactDigiSimLinks::makeReverseMap() const {
0042   std::map<uint32_t, std::vector<StripCompactDigiSimLinks::RevLink> > ret;
0043   typedef std::vector<TrackRecord>::const_iterator trk_it;
0044   typedef std::vector<HitRecord>::const_iterator hit_it;
0045   hit_it hstart = hitRecords_.begin(), ith = hstart;
0046   for (trk_it itt = trackRecords_.begin(), endt = trackRecords_.end(); itt != endt; ++itt) {
0047     hit_it edh = (itt + 1 != endt ? hstart + (itt + 1)->start : hitRecords_.end());
0048     for (; ith < edh; ++ith) {
0049       ret[ith->detId].push_back(RevLink(*itt, *ith));
0050     }
0051   }
0052   return ret;
0053 }