CMS 3D CMS Logo

LayerHitMapCache.h
Go to the documentation of this file.
1 #ifndef LayerHitMapCache_H
2 #define LayerHitMapCache_H
3 
13 
15 private:
16  class SimpleCache {
17  public:
19  using KeyType = int;
20  SimpleCache(unsigned int initSize) : theContainer(initSize) {}
21  SimpleCache(const SimpleCache&) = delete;
22  SimpleCache& operator=(const SimpleCache&) = delete;
23  SimpleCache(SimpleCache&&) = default;
24  SimpleCache& operator=(SimpleCache&&) = default;
26  void resize(int size) { theContainer.resize(size); }
27  const ValueType* get(KeyType key) const { return theContainer[key].get(); }
30  if (key >= int(theContainer.size()))
31  resize(key + 1);
32  theContainer[key].reset(value);
33  }
34  void extend(const SimpleCache& other) {
35  // N.B. Here we assume that the lifetime of 'other' is longer than of 'this'.
36  if (other.theContainer.size() > theContainer.size())
37  resize(other.theContainer.size());
38 
39  for (size_t i = 0, size = other.theContainer.size(); i != size; ++i) {
40  assert(get(i) == nullptr); // We don't want to override any existing value
41  auto v = other.get(i);
42  if (v) {
43  // pass by reference to denote that we don't own it
44  theContainer[i].reset(*(other.get(i)));
45  } else {
46  theContainer[i].reset();
47  }
48  }
49  }
51  void clear() {
52  for (auto& v : theContainer) {
53  v.reset();
54  }
55  }
56 
57  private:
58  std::vector<mayown_ptr<ValueType> > theContainer;
59  };
60 
61 private:
62  typedef SimpleCache Cache;
63 
64 public:
65  LayerHitMapCache(unsigned int initSize = 50) : theCache(initSize) {}
68 
69  void clear() { theCache.clear(); }
70 
71  void extend(const LayerHitMapCache& other) { theCache.extend(other.theCache); }
72 
73  // Mainly for FastSim, overrides old hits if exists
74  RecHitsSortedInPhi* add(const SeedingLayerSetsHits::SeedingLayer& layer, std::unique_ptr<RecHitsSortedInPhi> hits) {
75  RecHitsSortedInPhi* ptr = hits.get();
76  theCache.add(layer.index(), hits.release());
77  return ptr;
78  }
79 
81  int key = layer.index();
82  assert(key >= 0);
83  const RecHitsSortedInPhi* lhm = theCache.get(key);
84  if (lhm == nullptr) {
85  auto tmp =
86  add(layer, std::make_unique<RecHitsSortedInPhi>(region.hits(layer), region.origin(), layer.detLayer()));
87  tmp->theOrigin = region.origin();
88  lhm = tmp;
89  LogDebug("LayerHitMapCache") << " I got" << lhm->all().second - lhm->all().first
90  << " hits in the cache for: " << layer.detLayer();
91  } else {
92  // std::cout << region.origin() << " " << lhm->theOrigin << std::endl;
93  LogDebug("LayerHitMapCache") << " I got" << lhm->all().second - lhm->all().first
94  << " hits FROM THE cache for: " << layer.detLayer();
95  }
96  return *lhm;
97  }
98 
99 private:
101 };
102 
103 #endif
size
Write out results.
void extend(const SimpleCache &other)
SimpleCache & operator=(const SimpleCache &)=delete
LayerHitMapCache(unsigned int initSize=50)
std::vector< mayown_ptr< ValueType > > theContainer
assert(be >=bs)
LayerHitMapCache & operator=(LayerHitMapCache &&)=default
constexpr std::array< uint8_t, layerIndexSize > layer
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
const RecHitsSortedInPhi & operator()(const SeedingLayerSetsHits::SeedingLayer &layer, const TrackingRegion &region)
void clear()
emptify cache, delete values associated to Key
RecHitsSortedInPhi * add(const SeedingLayerSetsHits::SeedingLayer &layer, std::unique_ptr< RecHitsSortedInPhi > hits)
void extend(const LayerHitMapCache &other)
SimpleCache(unsigned int initSize)
tmp
align.sh
Definition: createJobs.py:716
const ValueType * get(KeyType key) const
#define LogDebug(id)