CMS 3D CMS Logo

GlobalTrackingGeometry.cc
Go to the documentation of this file.
1 
8 
9 #include <memory>
10 
11 GlobalTrackingGeometry::GlobalTrackingGeometry(std::vector<const TrackingGeometry*>& geos)
12  : theGeometries(geos),
13  theDetTypes(nullptr), theDetUnits(nullptr), theDets(nullptr), theDetUnitIds(nullptr), theDetIds(nullptr)
14 {}
15 
17 {
18  delete theDetTypes.load();
19  theDetTypes = nullptr;
20  delete theDetUnits.load();
21  theDetUnits = nullptr;
22  delete theDets.load();
23  theDets = nullptr;
24  delete theDetUnitIds.load();
25  theDetUnitIds = nullptr;
26  delete theDetIds.load();
27  theDetIds = nullptr;
28 }
29 
31 
32  const TrackingGeometry* tg = slaveGeometry(id);
33 
34  if (tg != nullptr) {
35  return tg->idToDetUnit(id);
36  } else {
37  return nullptr;
38  }
39 }
40 
41 
43 
44  const TrackingGeometry* tg = slaveGeometry(id);
45 
46  if (tg != nullptr) {
47  return tg->idToDet(id);
48  } else {
49  return nullptr;
50  }
51 }
52 
54 
55  int idx = id.det()-1;
56  if (id.det() == DetId::Muon) {
57 
58  idx+=id.subdetId()-1;
59  }
60 
61  if (theGeometries[idx]==nullptr) throw cms::Exception("NoGeometry") << "No Tracking Geometry is available for DetId " << id.rawId() << std::endl;
62 
63  return theGeometries[idx];
64 }
65 
68 {
69  if (!theDetTypes.load(std::memory_order_acquire)) {
70  std::unique_ptr<DetTypeContainer> ptr{new DetTypeContainer()};
71  for(auto theGeometrie : theGeometries)
72  {
73  if( theGeometrie == nullptr ) continue;
74  DetTypeContainer detTypes(theGeometrie->detTypes());
75  if( detTypes.size() + ptr->size() < ptr->capacity()) ptr->resize( detTypes.size() + ptr->size());
76  for(auto detType : detTypes)
77  ptr->emplace_back( detType );
78  }
79  DetTypeContainer* expect = nullptr;
80  if(theDetTypes.compare_exchange_strong(expect, ptr.get(), std::memory_order_acq_rel)) {
81  ptr.release();
82  }
83  }
84  return *theDetTypes.load(std::memory_order_acquire);
85 }
86 
89 {
90  if (!theDetUnits.load(std::memory_order_acquire)) {
91  std::unique_ptr<DetUnitContainer> ptr{new DetUnitContainer()};
92  for(auto theGeometrie : theGeometries)
93  {
94  if( theGeometrie == nullptr ) continue;
95  DetUnitContainer detUnits(theGeometrie->detUnits());
96  if( detUnits.size() + ptr->size() < ptr->capacity()) ptr->resize( detUnits.size() + ptr->size());
97  for(auto detUnit : detUnits)
98  ptr->emplace_back( detUnit );
99  }
100  DetUnitContainer* expect = nullptr;
101  if(theDetUnits.compare_exchange_strong(expect, ptr.get(), std::memory_order_acq_rel)) {
102  ptr.release();
103  }
104  }
105  return *theDetUnits.load(std::memory_order_acquire);
106 }
107 
110 {
111  if (!theDets.load(std::memory_order_acquire)) {
112  std::unique_ptr<DetContainer> ptr{new DetContainer()};
113  for(auto theGeometrie : theGeometries)
114  {
115  if( theGeometrie == nullptr ) continue;
116  DetContainer dets(theGeometrie->dets());
117  if( dets.size() + ptr->size() < ptr->capacity()) ptr->resize( dets.size() + ptr->size());
118  for(auto det : dets)
119  ptr->emplace_back( det );
120  }
121  DetContainer* expect = nullptr;
122  if(theDets.compare_exchange_strong(expect, ptr.get(), std::memory_order_acq_rel)) {
123  ptr.release();
124  }
125  }
126  return *theDets.load(std::memory_order_acquire);
127 }
128 
131 {
132  if (!theDetUnitIds.load(std::memory_order_acquire)) {
133  std::unique_ptr<DetIdContainer> ptr{new DetIdContainer()};
134  for(auto theGeometrie : theGeometries)
135  {
136  if( theGeometrie == nullptr ) continue;
137  DetIdContainer detUnitIds(theGeometrie->detUnitIds());
138  if( detUnitIds.size() + ptr->size() < ptr->capacity()) ptr->resize( detUnitIds.size() + ptr->size());
139  for(auto detUnitId : detUnitIds)
140  ptr->emplace_back( detUnitId );
141  }
142  DetIdContainer* expect = nullptr;
143  if(theDetUnitIds.compare_exchange_strong(expect, ptr.get(), std::memory_order_acq_rel)) {
144  ptr.release();
145  }
146  }
147  return *theDetUnitIds.load(std::memory_order_acquire);
148 }
149 
152 {
153  if (!theDetIds.load(std::memory_order_acquire)) {
154  std::unique_ptr<DetIdContainer> ptr{new DetIdContainer()};
155  for(auto theGeometrie : theGeometries)
156  {
157  if( theGeometrie == nullptr ) continue;
158  DetIdContainer detIds(theGeometrie->detIds());
159  if( detIds.size() + ptr->size() < ptr->capacity()) ptr->resize( detIds.size() + ptr->size());
160  for(auto detId : detIds)
161  ptr->emplace_back( detId );
162  }
163  DetIdContainer* expect = nullptr;
164  if(theDetIds.compare_exchange_strong(expect, ptr.get(), std::memory_order_acq_rel)) {
165  ptr.release();
166  }
167  }
168  return *theDetIds.load(std::memory_order_acquire);
169 }
std::vector< GeomDetType const * > DetTypeContainer
std::vector< const TrackingGeometry * > theGeometries
std::atomic< DetIdContainer * > theDetUnitIds
~GlobalTrackingGeometry() override
Destructor.
virtual const GeomDet * idToDet(DetId) const =0
const GeomDetUnit * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
#define nullptr
std::atomic< DetContainer * > theDets
virtual const GeomDetUnit * idToDetUnit(DetId) const =0
Return the pointer to the GeomDetUnit corresponding to a given DetId.
std::atomic< DetUnitContainer * > theDetUnits
std::atomic< DetIdContainer * > theDetIds
const DetIdContainer & detIds() const override
Returm a vector of all GeomDet DetIds (including those of GeomDetUnits)
const DetIdContainer & detUnitIds() const override
Returm a vector of all GeomDetUnit DetIds.
std::atomic< DetTypeContainer * > theDetTypes
const TrackingGeometry * slaveGeometry(DetId id) const
Return the pointer to the actual geometry for a given DetId.
Definition: DetId.h:18
const DetUnitContainer & detUnits() const override
Returm a vector of all GeomDetUnit.
GlobalTrackingGeometry(std::vector< const TrackingGeometry * > &geos)
Constructor.
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
const DetTypeContainer & detTypes() const override
Return a vector of all det types.
const GeomDet * idToDet(DetId) const override
std::vector< GeomDet const * > DetContainer
std::vector< GeomDetUnit const * > DetUnitContainer
std::vector< DetId > DetIdContainer