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  const TrackingRegion& region,
82  const edm::EventSetup& iSetup) {
83  int key = layer.index();
84  assert(key >= 0);
85  const RecHitsSortedInPhi* lhm = theCache.get(key);
86  if (lhm == nullptr) {
87  auto tmp = add(
88  layer, std::make_unique<RecHitsSortedInPhi>(region.hits(iSetup, layer), region.origin(), layer.detLayer()));
89  tmp->theOrigin = region.origin();
90  lhm = tmp;
91  LogDebug("LayerHitMapCache") << " I got" << lhm->all().second - lhm->all().first
92  << " hits in the cache for: " << layer.detLayer();
93  } else {
94  // std::cout << region.origin() << " " << lhm->theOrigin << std::endl;
95  LogDebug("LayerHitMapCache") << " I got" << lhm->all().second - lhm->all().first
96  << " hits FROM THE cache for: " << layer.detLayer();
97  }
98  return *lhm;
99  }
100 
101 private:
103 };
104 
105 #endif
mps_fire.i
i
Definition: mps_fire.py:355
SeedingLayerSetsHits::SeedingLayer::index
LayerIndex index() const
Definition: SeedingLayerSetsHits.h:48
RecHitsSortedInPhi::all
Range all() const
Definition: RecHitsSortedInPhi.h:84
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
LayerHitMapCache::SimpleCache
Definition: LayerHitMapCache.h:16
SeedingLayerSetsHits::SeedingLayer::detLayer
const DetLayer * detLayer() const
Definition: SeedingLayerSetsHits.h:50
LayerHitMapCache::SimpleCache::theContainer
std::vector< mayown_ptr< ValueType > > theContainer
Definition: LayerHitMapCache.h:58
cms::cuda::assert
assert(be >=bs)
LayerHitMapCache::extend
void extend(const LayerHitMapCache &other)
Definition: LayerHitMapCache.h:71
findQualityFiles.v
v
Definition: findQualityFiles.py:179
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
LayerHitMapCache::SimpleCache::~SimpleCache
~SimpleCache()
Definition: LayerHitMapCache.h:25
LayerHitMapCache::add
RecHitsSortedInPhi * add(const SeedingLayerSetsHits::SeedingLayer &layer, std::unique_ptr< RecHitsSortedInPhi > hits)
Definition: LayerHitMapCache.h:74
LayerHitMapCache
Definition: LayerHitMapCache.h:14
SeedingLayerSetsHits.h
RecHitsSortedInPhi.h
LayerHitMapCache::SimpleCache::clear
void clear()
emptify cache, delete values associated to Key
Definition: LayerHitMapCache.h:51
trackingPlots.other
other
Definition: trackingPlots.py:1465
RecHitsSortedInPhi
Definition: RecHitsSortedInPhi.h:17
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
LayerHitMapCache::SimpleCache::SimpleCache
SimpleCache(unsigned int initSize)
Definition: LayerHitMapCache.h:20
createfilelist.int
int
Definition: createfilelist.py:10
value
Definition: value.py:1
LayerHitMapCache::theCache
Cache theCache
Definition: LayerHitMapCache.h:102
LayerHitMapCache::SimpleCache::operator=
SimpleCache & operator=(const SimpleCache &)=delete
LayerHitMapCache::SimpleCache::add
void add(KeyType key, ValueType *value)
add object to cache. It is caller responsibility to check that object is not yet there.
Definition: LayerHitMapCache.h:29
LayerHitMapCache::SimpleCache::KeyType
int KeyType
Definition: LayerHitMapCache.h:19
edm::EventSetup
Definition: EventSetup.h:57
SeedingLayerSetsHits::SeedingLayer
Definition: SeedingLayerSetsHits.h:37
LayerHitMapCache::SimpleCache::resize
void resize(int size)
Definition: LayerHitMapCache.h:26
LayerHitMapCache::LayerHitMapCache
LayerHitMapCache(unsigned int initSize=50)
Definition: LayerHitMapCache.h:65
mayown_ptr.h
LayerHitMapCache::SimpleCache::extend
void extend(const SimpleCache &other)
Definition: LayerHitMapCache.h:34
HLT_2018_cff.region
region
Definition: HLT_2018_cff.py:81479
LayerHitMapCache::clear
void clear()
Definition: LayerHitMapCache.h:69
EventSetup.h
LayerHitMapCache::SimpleCache::get
const ValueType * get(KeyType key) const
Definition: LayerHitMapCache.h:27
TrackingRegion
Definition: TrackingRegion.h:40
LayerHitMapCache::Cache
SimpleCache Cache
Definition: LayerHitMapCache.h:62
TrackingRegion.h
LayerHitMapCache::operator=
LayerHitMapCache & operator=(LayerHitMapCache &&)=default
LayerHitMapCache::operator()
const RecHitsSortedInPhi & operator()(const SeedingLayerSetsHits::SeedingLayer &layer, const TrackingRegion &region, const edm::EventSetup &iSetup)
Definition: LayerHitMapCache.h:80
crabWrapper.key
key
Definition: crabWrapper.py:19
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443