CMS 3D CMS Logo

LayerHitMapCache.h
Go to the documentation of this file.
1 #ifndef LayerHitMapCache_H
2 #define LayerHitMapCache_H
3 
13 
15 
16 private:
17 
18  class SimpleCache {
19  public:
21  using KeyType = int;
22  SimpleCache(unsigned int initSize) : theContainer(initSize){}
25  void resize(int size) { theContainer.resize(size); }
26  const ValueType* get(KeyType key) const { return theContainer[key].get();}
29  if (key>=int(theContainer.size())) resize(key+1);
30  theContainer[key].reset(value);
31  }
32  void extend(const SimpleCache& other) {
33  // N.B. Here we assume that the lifetime of 'other' is longer than of 'this'.
34  if(other.theContainer.size() > theContainer.size())
35  resize(other.theContainer.size());
36 
37  for(size_t i=0, size=other.theContainer.size(); i != size; ++i) {
38  assert(get(i) == nullptr); // We don't want to override any existing value
39  theContainer[i].reset(*(other.get(i))); // pass by reference to denote that we don't own it
40  }
41  }
43  void clear() {
44  for ( auto & v : theContainer) { v.reset(); }
45  }
46  private:
47  std::vector<mayown_ptr<ValueType> > theContainer;
48  private:
49  SimpleCache(const SimpleCache &) { }
50  };
51 
52 private:
53  typedef SimpleCache Cache;
54 public:
55  LayerHitMapCache(unsigned int initSize=50) : theCache(initSize) { }
57 
58  void clear() { theCache.clear(); }
59 
60  void extend(const LayerHitMapCache& other) {
61  theCache.extend(other.theCache);
62  }
63 
64  const RecHitsSortedInPhi &
66  const edm::EventSetup & iSetup) {
67  int key = layer.index();
68  assert (key>=0);
69  const RecHitsSortedInPhi * lhm = theCache.get(key);
70  if (lhm==nullptr) {
71  auto tmp=new RecHitsSortedInPhi (region.hits(iSetup,layer), region.origin(), layer.detLayer());
72  tmp->theOrigin = region.origin();
73  theCache.add( key, tmp);
74  lhm = tmp;
75  LogDebug("LayerHitMapCache")<<" I got"<< lhm->all().second-lhm->all().first<<" hits in the cache for: "<<layer.detLayer();
76  }
77  else{
78  // std::cout << region.origin() << " " << lhm->theOrigin << std::endl;
79  LogDebug("LayerHitMapCache")<<" I got"<< lhm->all().second-lhm->all().first<<" hits FROM THE cache for: "<<layer.detLayer();
80  }
81  return *lhm;
82  }
83 
84 private:
85  Cache theCache;
86 };
87 
88 #endif
89 
#define LogDebug(id)
size
Write out results.
void extend(const SimpleCache &other)
GlobalPoint const & origin() const
LayerHitMapCache(LayerHitMapCache &&rh)
LayerHitMapCache(unsigned int initSize=50)
SimpleCache(const SimpleCache &)
std::vector< mayown_ptr< ValueType > > theContainer
const RecHitsSortedInPhi & operator()(const SeedingLayerSetsHits::SeedingLayer &layer, const TrackingRegion &region, const edm::EventSetup &iSetup)
void add(KeyType key, ValueType *value)
add object to cache. It is caller responsibility to check that object is not yet there.
Definition: value.py:1
void clear()
emptify cache, delete values associated to Key
virtual Hits hits(const edm::EventSetup &es, const SeedingLayerSetsHits::SeedingLayer &layer) const =0
get hits from layer compatible with region constraints
const DetLayer * detLayer() const
void extend(const LayerHitMapCache &other)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
const ValueType * get(KeyType key) const
SimpleCache(unsigned int initSize)
def move(src, dest)
Definition: eostools.py:510