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  template <class KeyType, class ValueType> class SimpleCache {
19  public:
20  SimpleCache(int initSize) { reserve(initSize); }
21  virtual ~SimpleCache() { clear(); }
22  void reserve(int size) { theContainer.reserve(size); }
23  const ValueType* get(const KeyType & key) {
24  for (ConstItr it = theContainer.begin(); it != theContainer.end(); it++) {
25  if ( it->first == key) return it->second;
26  }
27  return 0;
28  }
30  void add(const KeyType & key, const ValueType * value) {
31  theContainer.push_back( std::make_pair(key,value));
32  }
34  virtual void clear() {
35  for (ConstItr i=theContainer.begin(); i!= theContainer.end(); i++) { delete i->second; }
36  theContainer.clear();
37  }
38  protected:
39  typedef std::pair< KeyType, const ValueType * > KeyValuePair;
40  std::vector< KeyValuePair > theContainer;
41  typedef typename std::vector< KeyValuePair >::const_iterator ConstItr;
42  private:
43  SimpleCache(const SimpleCache &) { }
44  };
45 
46 private:
47  typedef const DetLayer * LayerRegionKey;
49  public:
50  LayerHitMapCache(int initSize=50) { theCache = new Cache(initSize); }
51 
53 
54  void clear() { theCache->clear(); }
55 
57  const ctfseeding::SeedingLayer * layer, const TrackingRegion & region,
58  const edm::Event & iEvent, const edm::EventSetup & iSetup) {
59  LayerRegionKey key(layer->detLayer());
60  const RecHitsSortedInPhi * lhm = theCache->get(key);
61  if (lhm==0) {
62  lhm=new RecHitsSortedInPhi (region.hits(iEvent,iSetup,layer));
63  LogDebug("LayerHitMapCache")<<" I got"<< lhm->all().second-lhm->all().first<<" hits in the cache for: "<<layer->detLayer();
64  theCache->add( key, lhm);
65  }
66  else{
67  LogDebug("LayerHitMapCache")<<" I got"<< lhm->all().second-lhm->all().first<<" hits FROM THE cache for: "<<layer->detLayer();
68  }
69  return *lhm;
70  }
71 
72 public:
74 
75 private:
77 };
78 
79 #endif
80 
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
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
SimpleCache(const SimpleCache &)
const DetLayer * detLayer() const
Definition: SeedingLayer.cc:80
std::vector< KeyValuePair > theContainer
const DetLayer * LayerRegionKey
std::pair< KeyType, const ValueType * > KeyValuePair
int iEvent
Definition: GenABIO.cc:243
const ValueType * get(const KeyType &key)
virtual void clear()
emptify cache, delete values associated to Key
const RecHitsSortedInPhi & operator()(const ctfseeding::SeedingLayer *layer, const TrackingRegion &region, const edm::Event &iEvent, const edm::EventSetup &iSetup)
SimpleCache< LayerRegionKey, RecHitsSortedInPhi > Cache
list key
Definition: combine.py:13
LayerHitMapCache(const LayerHitMapCache &)
std::vector< KeyValuePair >::const_iterator ConstItr
void add(const KeyType &key, const ValueType *value)
add object to cache. It is caller responsibility to check that object is not yet there.
tuple size
Write out results.
LayerHitMapCache(int initSize=50)