CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/RecoTracker/TkHitPairs/interface/LayerHitMapCache.h

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   class SimpleCache {
00019   public:
00020     using ValueType = RecHitsSortedInPhi;
00021     using KeyType = int;
00022     SimpleCache(unsigned int initSize) : theContainer(initSize, nullptr){}
00023     ~SimpleCache() { clear(); }
00024     void resize(int size) { theContainer.resize(size,nullptr); }
00025     const ValueType*  get(KeyType key) { return theContainer[key];}
00027     void add(KeyType key, const ValueType * value) {
00028       if (key>=int(theContainer.size())) resize(key+1);
00029       theContainer[key]=value;
00030     }
00032     void clear() {
00033       for ( auto & v : theContainer)  { delete v; v=nullptr;}
00034     }
00035   private:
00036     std::vector< const ValueType *> theContainer;
00037   private:
00038     SimpleCache(const SimpleCache &) { }
00039   };
00040 
00041 private:
00042   typedef SimpleCache Cache;
00043 public:
00044   LayerHitMapCache(unsigned int initSize=50) : theCache(initSize) { }
00045 
00046   void clear() { theCache.clear(); }
00047   
00048   const RecHitsSortedInPhi & 
00049   operator()(const ctfseeding::SeedingLayer * layer, const TrackingRegion & region, 
00050              const edm::Event & iEvent, const edm::EventSetup & iSetup) {
00051     int key = layer->detLayer()->seqNum();
00052     assert (key>=0);
00053     const RecHitsSortedInPhi * lhm = theCache.get(key);
00054     if (lhm==nullptr) {
00055       lhm=new RecHitsSortedInPhi (region.hits(iEvent,iSetup,layer), region.origin(), layer->detLayer());
00056       lhm->theOrigin = region.origin();
00057       LogDebug("LayerHitMapCache")<<" I got"<< lhm->all().second-lhm->all().first<<" hits in the cache for: "<<layer->detLayer();
00058       theCache.add( key, lhm); 
00059     }
00060     else{
00061       // std::cout << region.origin() << " " <<  lhm->theOrigin << std::endl;
00062       LogDebug("LayerHitMapCache")<<" I got"<< lhm->all().second-lhm->all().first<<" hits FROM THE cache for: "<<layer->detLayer();
00063     }
00064     return *lhm;
00065   }
00066 
00067 
00068 private:
00069   Cache theCache; 
00070 };
00071 
00072 #endif
00073