CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LayerHitMapCache.h
Go to the documentation of this file.
1 #ifndef LayerHitMapCache_H
2 #define LayerHitMapCache_H
3 
12 
13 
15 
16 private:
17 
18  class SimpleCache {
19  public:
21  using KeyType = int;
22  SimpleCache(unsigned int initSize) : theContainer(initSize, nullptr){}
24  void resize(int size) { theContainer.resize(size,nullptr); }
25  const ValueType* get(KeyType key) { return theContainer[key];}
27  void add(KeyType key, const ValueType * value) {
28  if (key>=int(theContainer.size())) resize(key+1);
30  }
32  void clear() {
33  for ( auto & v : theContainer) { delete v; v=nullptr;}
34  }
35  private:
36  std::vector< const ValueType *> theContainer;
37  private:
38  SimpleCache(const SimpleCache &) { }
39  };
40 
41 private:
42  typedef SimpleCache Cache;
43 public:
44  LayerHitMapCache(unsigned int initSize=50) : theCache(initSize) { }
45 
46  void clear() { theCache.clear(); }
47 
48  const RecHitsSortedInPhi &
50  const edm::Event & iEvent, const edm::EventSetup & iSetup) {
51  int key = layer.index();
52  assert (key>=0);
53  const RecHitsSortedInPhi * lhm = theCache.get(key);
54  if (lhm==nullptr) {
55  lhm=new RecHitsSortedInPhi (region.hits(iEvent,iSetup,layer), region.origin(), layer.detLayer());
56  lhm->theOrigin = region.origin();
57  LogDebug("LayerHitMapCache")<<" I got"<< lhm->all().second-lhm->all().first<<" hits in the cache for: "<<layer.detLayer();
58  theCache.add( key, lhm);
59  }
60  else{
61  // std::cout << region.origin() << " " << lhm->theOrigin << std::endl;
62  LogDebug("LayerHitMapCache")<<" I got"<< lhm->all().second-lhm->all().first<<" hits FROM THE cache for: "<<layer.detLayer();
63  }
64  return *lhm;
65  }
66 
67 private:
69 };
70 
71 #endif
72 
#define LogDebug(id)
virtual Hits hits(const edm::Event &ev, const edm::EventSetup &es, const ctfseeding::SeedingLayer *layer) const =0
get hits from layer compatible with region constraints
GlobalPoint const & origin() const
LayerHitMapCache(unsigned int initSize=50)
#define nullptr
SimpleCache(const SimpleCache &)
std::vector< const ValueType * > theContainer
int iEvent
Definition: GenABIO.cc:243
const RecHitsSortedInPhi & operator()(const SeedingLayerSetsHits::SeedingLayer &layer, const TrackingRegion &region, const edm::Event &iEvent, const edm::EventSetup &iSetup)
void clear()
emptify cache, delete values associated to Key
const ValueType * get(KeyType key)
const DetLayer * detLayer() const
list key
Definition: combine.py:13
void add(KeyType key, const ValueType *value)
add object to cache. It is caller responsibility to check that object is not yet there.
SimpleCache(unsigned int initSize)
tuple size
Write out results.