CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GlobalTrackingGeometry.cc
Go to the documentation of this file.
1 
8 
10 
11 #include <memory>
12 
13 GlobalTrackingGeometry::GlobalTrackingGeometry(std::vector<const TrackingGeometry*>& geos)
14  : theGeometries(geos),
15  theDetTypes(nullptr),
16  theDetUnits(nullptr),
17  theDets(nullptr),
18  theDetUnitIds(nullptr),
19  theDetIds(nullptr) {}
20 
22  delete theDetTypes.load();
23  theDetTypes = nullptr;
24  delete theDetUnits.load();
25  theDetUnits = nullptr;
26  delete theDets.load();
27  theDets = nullptr;
28  delete theDetUnitIds.load();
29  theDetUnitIds = nullptr;
30  delete theDetIds.load();
31  theDetIds = nullptr;
32 }
33 
35  const TrackingGeometry* tg = slaveGeometry(id);
36 
37  if (tg != nullptr) {
38  return tg->idToDetUnit(id);
39  } else {
40  return nullptr;
41  }
42 }
43 
45  const TrackingGeometry* tg = slaveGeometry(id);
46 
47  if (tg != nullptr) {
48  return tg->idToDet(id);
49  } else {
50  return nullptr;
51  }
52 }
53 
55  int idx = id.det() - 1;
56  if (id.det() == DetId::Muon) {
57  idx += id.subdetId(); //-1; // remove the -1 from before since MTD is there
58  }
59  if (id.det() == DetId::Forward && id.subdetId() == ForwardSubdetector::FastTime) {
60  idx = 1;
61  }
62 
63  if (theGeometries[idx] == nullptr)
64  throw cms::Exception("NoGeometry") << "No Tracking Geometry is available for DetId " << id.rawId() << std::endl;
65 
66  return theGeometries[idx];
67 }
68 
70  if (!theDetTypes.load(std::memory_order_acquire)) {
71  std::unique_ptr<DetTypeContainer> ptr{new DetTypeContainer()};
72  for (auto theGeometrie : theGeometries) {
73  if (theGeometrie == nullptr)
74  continue;
75  DetTypeContainer detTypes(theGeometrie->detTypes());
76  if (detTypes.size() + ptr->size() < ptr->capacity())
77  ptr->resize(detTypes.size() + ptr->size());
78  for (auto detType : detTypes)
79  ptr->emplace_back(detType);
80  }
81  DetTypeContainer* expect = nullptr;
82  if (theDetTypes.compare_exchange_strong(expect, ptr.get(), std::memory_order_acq_rel)) {
83  ptr.release();
84  }
85  }
86  return *theDetTypes.load(std::memory_order_acquire);
87 }
88 
90  if (!theDetUnits.load(std::memory_order_acquire)) {
91  std::unique_ptr<DetContainer> ptr{new DetContainer()};
92  for (auto theGeometrie : theGeometries) {
93  if (theGeometrie == nullptr)
94  continue;
95  DetContainer detUnits(theGeometrie->detUnits());
96  if (detUnits.size() + ptr->size() < ptr->capacity())
97  ptr->resize(detUnits.size() + ptr->size());
98  for (auto detUnit : detUnits)
99  ptr->emplace_back(detUnit);
100  }
101  DetContainer* expect = nullptr;
102  if (theDetUnits.compare_exchange_strong(expect, ptr.get(), std::memory_order_acq_rel)) {
103  ptr.release();
104  }
105  }
106  return *theDetUnits.load(std::memory_order_acquire);
107 }
108 
110  if (!theDets.load(std::memory_order_acquire)) {
111  std::unique_ptr<DetContainer> ptr{new DetContainer()};
112  for (auto theGeometrie : theGeometries) {
113  if (theGeometrie == nullptr)
114  continue;
115  DetContainer dets(theGeometrie->dets());
116  if (dets.size() + ptr->size() < ptr->capacity())
117  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 
130  if (!theDetUnitIds.load(std::memory_order_acquire)) {
131  std::unique_ptr<DetIdContainer> ptr{new DetIdContainer()};
132  for (auto theGeometrie : theGeometries) {
133  if (theGeometrie == nullptr)
134  continue;
135  DetIdContainer detUnitIds(theGeometrie->detUnitIds());
136  if (detUnitIds.size() + ptr->size() < ptr->capacity())
137  ptr->resize(detUnitIds.size() + ptr->size());
138  for (auto detUnitId : detUnitIds)
139  ptr->emplace_back(detUnitId);
140  }
141  DetIdContainer* expect = nullptr;
142  if (theDetUnitIds.compare_exchange_strong(expect, ptr.get(), std::memory_order_acq_rel)) {
143  ptr.release();
144  }
145  }
146  return *theDetUnitIds.load(std::memory_order_acquire);
147 }
148 
150  if (!theDetIds.load(std::memory_order_acquire)) {
151  std::unique_ptr<DetIdContainer> ptr{new DetIdContainer()};
152  for (auto theGeometrie : theGeometries) {
153  if (theGeometrie == nullptr)
154  continue;
155  DetIdContainer detIds(theGeometrie->detIds());
156  if (detIds.size() + ptr->size() < ptr->capacity())
157  ptr->resize(detIds.size() + ptr->size());
158  for (auto detId : detIds)
159  ptr->emplace_back(detId);
160  }
161  DetIdContainer* expect = nullptr;
162  if (theDetIds.compare_exchange_strong(expect, ptr.get(), std::memory_order_acq_rel)) {
163  ptr.release();
164  }
165  }
166  return *theDetIds.load(std::memory_order_acquire);
167 }
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
std::vector< const TrackingGeometry * > theGeometries
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
std::atomic< DetIdContainer * > theDetUnitIds
const GeomDet * idToDet(DetId) const override
std::atomic< DetContainer * > theDets
const DetIdContainer & detIds() const override
Returm a vector of all GeomDet DetIds (including those of GeomDetUnits)
std::vector< const GeomDet * > DetContainer
std::atomic< DetIdContainer * > theDetIds
virtual const GeomDet * idToDetUnit(DetId) const =0
Return the pointer to the GeomDetUnit corresponding to a given DetId.
std::atomic< DetTypeContainer * > theDetTypes
const TrackingGeometry * slaveGeometry(DetId id) const
Return the pointer to the actual geometry for a given DetId.
std::atomic< DetContainer * > theDetUnits
Definition: DetId.h:17
GlobalTrackingGeometry(std::vector< const TrackingGeometry * > &geos)
virtual const GeomDet * idToDet(DetId) const =0
std::vector< DetId > DetIdContainer
std::vector< const GeomDetType * > DetTypeContainer
const DetTypeContainer & detTypes() const override
Return a vector of all det types.
const DetIdContainer & detUnitIds() const override
Returm a vector of all GeomDetUnit DetIds.
const GeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.