Go to the documentation of this file.00001 #ifndef LayerHitMapCache_H
00002 #define LayerHitMapCache_H
00003
00008 #include "RecoTracker/TkTrackingRegions/interface/TrackingRegion.h"
00009 #include "RecoTracker/TkHitPairs/interface/RecHitsSortedInPhi.h"
00010 #include "RecoTracker/TkSeedingLayers/interface/SeedingLayer.h"
00011 #include "FWCore/Framework/interface/EventSetup.h"
00012
00013
00014 class LayerHitMapCache {
00015
00016 private:
00017
00018 template <class KeyType, class ValueType> class SimpleCache {
00019 public:
00020 SimpleCache(int initSize) { reserve(initSize); }
00021 virtual ~SimpleCache() { clear(); }
00022 void reserve(int size) { theContainer.reserve(size); }
00023 const ValueType* get(const KeyType & key) {
00024 for (ConstItr it = theContainer.begin(); it != theContainer.end(); it++) {
00025 if ( it->first == key) return it->second;
00026 }
00027 return 0;
00028 }
00030 void add(const KeyType & key, const ValueType * value) {
00031 theContainer.push_back( std::make_pair(key,value));
00032 }
00034 virtual void clear() {
00035 for (ConstItr i=theContainer.begin(); i!= theContainer.end(); i++) { delete i->second; }
00036 theContainer.clear();
00037 }
00038 protected:
00039 typedef std::pair< KeyType, const ValueType * > KeyValuePair;
00040 std::vector< KeyValuePair > theContainer;
00041 typedef typename std::vector< KeyValuePair >::const_iterator ConstItr;
00042 private:
00043 SimpleCache(const SimpleCache &) { }
00044 };
00045
00046 private:
00047 typedef const DetLayer * LayerRegionKey;
00048 typedef SimpleCache<LayerRegionKey, RecHitsSortedInPhi> Cache;
00049 public:
00050 LayerHitMapCache(int initSize=50) { theCache = new Cache(initSize); }
00051
00052 ~LayerHitMapCache() { delete theCache; }
00053
00054 void clear() { theCache->clear(); }
00055
00056 const RecHitsSortedInPhi & operator()(
00057 const ctfseeding::SeedingLayer * layer, const TrackingRegion & region,
00058 const edm::Event & iEvent, const edm::EventSetup & iSetup) {
00059 LayerRegionKey key(layer->detLayer());
00060 const RecHitsSortedInPhi * lhm = theCache->get(key);
00061 if (lhm==0) {
00062 lhm=new RecHitsSortedInPhi (region.hits(iEvent,iSetup,layer));
00063 theCache->add( key, lhm);
00064 }
00065 return *lhm;
00066 }
00067
00068 public:
00069 LayerHitMapCache(const LayerHitMapCache &) { }
00070
00071 private:
00072 Cache * theCache;
00073 };
00074
00075 #endif
00076