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){}
23  SimpleCache(const SimpleCache&) = delete;
24  SimpleCache& operator=(const SimpleCache&) = delete;
25  SimpleCache(SimpleCache&&) = default;
26  SimpleCache& operator=(SimpleCache&&) = default;
28  void resize(int size) { theContainer.resize(size); }
29  const ValueType* get(KeyType key) const { return theContainer[key].get();}
32  if (key>=int(theContainer.size())) resize(key+1);
33  theContainer[key].reset(value);
34  }
35  void extend(const SimpleCache& other) {
36  // N.B. Here we assume that the lifetime of 'other' is longer than of 'this'.
37  if(other.theContainer.size() > theContainer.size())
38  resize(other.theContainer.size());
39 
40  for(size_t i=0, size=other.theContainer.size(); i != size; ++i) {
41  assert(get(i) == nullptr); // We don't want to override any existing value
42  theContainer[i].reset(*(other.get(i))); // pass by reference to denote that we don't own it
43  }
44  }
46  void clear() {
47  for ( auto & v : theContainer) { v.reset(); }
48  }
49  private:
50  std::vector<mayown_ptr<ValueType> > theContainer;
51  };
52 
53 private:
54  typedef SimpleCache Cache;
55 public:
56  LayerHitMapCache(unsigned int initSize=50) : theCache(initSize) { }
59 
60 
61  void clear() { theCache.clear(); }
62 
63  void extend(const LayerHitMapCache& other) {
64  theCache.extend(other.theCache);
65  }
66 
67  const RecHitsSortedInPhi &
69  const edm::EventSetup & iSetup) {
70  int key = layer.index();
71  assert (key>=0);
72  const RecHitsSortedInPhi * lhm = theCache.get(key);
73  if (lhm==nullptr) {
74  auto tmp=new RecHitsSortedInPhi (region.hits(iSetup,layer), region.origin(), layer.detLayer());
75  tmp->theOrigin = region.origin();
76  theCache.add( key, tmp);
77  lhm = tmp;
78  LogDebug("LayerHitMapCache")<<" I got"<< lhm->all().second-lhm->all().first<<" hits in the cache for: "<<layer.detLayer();
79  }
80  else{
81  // std::cout << region.origin() << " " << lhm->theOrigin << std::endl;
82  LogDebug("LayerHitMapCache")<<" I got"<< lhm->all().second-lhm->all().first<<" hits FROM THE cache for: "<<layer.detLayer();
83  }
84  return *lhm;
85  }
86 
87 private:
88  Cache theCache;
89 };
90 
91 #endif
92 
#define LogDebug(id)
size
Write out results.
void extend(const SimpleCache &other)
SimpleCache & operator=(const SimpleCache &)=delete
GlobalPoint const & origin() const
LayerHitMapCache(unsigned int initSize=50)
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)