CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/SimDataFormats/TrackerDigiSimLink/src/StripCompactDigiSimLinks.cc

Go to the documentation of this file.
00001 #include "SimDataFormats/TrackerDigiSimLink/interface/StripCompactDigiSimLinks.h"
00002 
00003 #include <algorithm>
00004 #include <boost/foreach.hpp>
00005 
00006 
00007 StripCompactDigiSimLinks::Links 
00008 StripCompactDigiSimLinks::getLinks(const StripCompactDigiSimLinks::key_type &key) const 
00009 {
00010     std::vector<TrackRecord>::const_iterator last  = trackRecords_.end();
00011     std::vector<TrackRecord>::const_iterator match = std::lower_bound(trackRecords_.begin(), last, key);
00012     if ((match != last) && (*match == key)) {
00013         // std::vector<TrackRecord>::const_iterator next = match+1;
00014         unsigned int end = (match+1 == last ? hitRecords_.size() : (match+1)->start);
00015         return Links(hitRecords_.begin()+match->start, hitRecords_.begin()+end);
00016     } else {
00017         return Links(hitRecords_.end(), hitRecords_.end());
00018     }
00019 }
00020 
00021 StripCompactDigiSimLinks::StripCompactDigiSimLinks(const StripCompactDigiSimLinks::Filler &filler) 
00022 {
00023     trackRecords_.reserve(filler.keySize());
00024     hitRecords_.reserve(filler.dataSize());
00025     BOOST_FOREACH( const Filler::Map::value_type &pair, filler.storage() ) {
00026         trackRecords_.push_back(TrackRecord(pair.first, hitRecords_.size()));
00027         hitRecords_.insert(hitRecords_.end(), pair.second.begin(), pair.second.end());
00028     }
00029 }
00030 
00031 StripCompactDigiSimLinks::Filler::~Filler() {
00032 }
00033 
00034 void
00035 StripCompactDigiSimLinks::Filler::insert(const StripCompactDigiSimLinks::key_type &key, const StripCompactDigiSimLinks::HitRecord &record) 
00036 {
00037     Filler::Map::iterator it = storage_.find(key);
00038     if (it == storage_.end()) {
00039         storage_.insert(std::make_pair(key, std::vector<HitRecord>(1,record)));
00040         num_keys_++; 
00041         num_values_++;
00042     } else {
00043         it->second.push_back(record);
00044         num_values_++;
00045     }
00046 }
00047 
00048 std::map<uint32_t, std::vector<StripCompactDigiSimLinks::RevLink> > 
00049 StripCompactDigiSimLinks::makeReverseMap() const
00050 {
00051     std::map<uint32_t, std::vector<StripCompactDigiSimLinks::RevLink> > ret;
00052     typedef std::vector<TrackRecord>::const_iterator trk_it;
00053     typedef std::vector<HitRecord>::const_iterator   hit_it;
00054     hit_it hstart = hitRecords_.begin(), ith = hstart;
00055     for (trk_it itt = trackRecords_.begin(), endt = trackRecords_.end(); itt != endt; ++itt) {
00056         hit_it edh = (itt+1 != endt ? hstart + (itt+1)->start : hitRecords_.end());
00057         for (; ith < edh; ++ith) {
00058             ret[ith->detId].push_back(RevLink(*itt, *ith));
00059         }
00060     }
00061     return ret;
00062 }
00063