CMS 3D CMS Logo

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), theDetUnits(nullptr), theDets(nullptr), theDetUnitIds(nullptr), theDetIds(nullptr)
16 {}
17 
19 {
20  delete theDetTypes.load();
21  theDetTypes = nullptr;
22  delete theDetUnits.load();
23  theDetUnits = nullptr;
24  delete theDets.load();
25  theDets = nullptr;
26  delete theDetUnitIds.load();
27  theDetUnitIds = nullptr;
28  delete theDetIds.load();
29  theDetIds = nullptr;
30 }
31 
33 
34  const TrackingGeometry* tg = slaveGeometry(id);
35 
36  if (tg != nullptr) {
37  return tg->idToDetUnit(id);
38  } else {
39  return nullptr;
40  }
41 }
42 
43 
45 
46  const TrackingGeometry* tg = slaveGeometry(id);
47 
48  if (tg != nullptr) {
49  return tg->idToDet(id);
50  } else {
51  return nullptr;
52  }
53 }
54 
56 
57  int idx = id.det()-1;
58  if (id.det() == DetId::Muon) {
59 
60  idx+=id.subdetId(); //-1; // remove the -1 from before since MTD is there
61  }
62  if( id.det() == DetId::Forward &&
63  id.subdetId() == ForwardSubdetector::FastTime ) {
64  idx = 1;
65  }
66 
67  if (theGeometries[idx]==nullptr) throw cms::Exception("NoGeometry") << "No Tracking Geometry is available for DetId " << id.rawId() << std::endl;
68 
69  return theGeometries[idx];
70 }
71 
74 {
75  if (!theDetTypes.load(std::memory_order_acquire)) {
76  std::unique_ptr<DetTypeContainer> ptr{new DetTypeContainer()};
77  for(auto theGeometrie : theGeometries)
78  {
79  if( theGeometrie == nullptr ) continue;
80  DetTypeContainer detTypes(theGeometrie->detTypes());
81  if( detTypes.size() + ptr->size() < ptr->capacity()) ptr->resize( detTypes.size() + ptr->size());
82  for(auto detType : detTypes)
83  ptr->emplace_back( detType );
84  }
85  DetTypeContainer* expect = nullptr;
86  if(theDetTypes.compare_exchange_strong(expect, ptr.get(), std::memory_order_acq_rel)) {
87  ptr.release();
88  }
89  }
90  return *theDetTypes.load(std::memory_order_acquire);
91 }
92 
95 {
96  if (!theDetUnits.load(std::memory_order_acquire)) {
97  std::unique_ptr<DetContainer> ptr{new DetContainer()};
98  for(auto theGeometrie : theGeometries)
99  {
100  if( theGeometrie == nullptr ) continue;
101  DetContainer detUnits(theGeometrie->detUnits());
102  if( detUnits.size() + ptr->size() < ptr->capacity()) ptr->resize( detUnits.size() + ptr->size());
103  for(auto detUnit : detUnits)
104  ptr->emplace_back( detUnit );
105  }
106  DetContainer* expect = nullptr;
107  if(theDetUnits.compare_exchange_strong(expect, ptr.get(), std::memory_order_acq_rel)) {
108  ptr.release();
109  }
110  }
111  return *theDetUnits.load(std::memory_order_acquire);
112 }
113 
116 {
117  if (!theDets.load(std::memory_order_acquire)) {
118  std::unique_ptr<DetContainer> ptr{new DetContainer()};
119  for(auto theGeometrie : theGeometries)
120  {
121  if( theGeometrie == nullptr ) continue;
122  DetContainer dets(theGeometrie->dets());
123  if( dets.size() + ptr->size() < ptr->capacity()) ptr->resize( dets.size() + ptr->size());
124  for(auto det : dets)
125  ptr->emplace_back( det );
126  }
127  DetContainer* expect = nullptr;
128  if(theDets.compare_exchange_strong(expect, ptr.get(), std::memory_order_acq_rel)) {
129  ptr.release();
130  }
131  }
132  return *theDets.load(std::memory_order_acquire);
133 }
134 
137 {
138  if (!theDetUnitIds.load(std::memory_order_acquire)) {
139  std::unique_ptr<DetIdContainer> ptr{new DetIdContainer()};
140  for(auto theGeometrie : theGeometries)
141  {
142  if( theGeometrie == nullptr ) continue;
143  DetIdContainer detUnitIds(theGeometrie->detUnitIds());
144  if( detUnitIds.size() + ptr->size() < ptr->capacity()) ptr->resize( detUnitIds.size() + ptr->size());
145  for(auto detUnitId : detUnitIds)
146  ptr->emplace_back( detUnitId );
147  }
148  DetIdContainer* expect = nullptr;
149  if(theDetUnitIds.compare_exchange_strong(expect, ptr.get(), std::memory_order_acq_rel)) {
150  ptr.release();
151  }
152  }
153  return *theDetUnitIds.load(std::memory_order_acquire);
154 }
155 
158 {
159  if (!theDetIds.load(std::memory_order_acquire)) {
160  std::unique_ptr<DetIdContainer> ptr{new DetIdContainer()};
161  for(auto theGeometrie : theGeometries)
162  {
163  if( theGeometrie == nullptr ) continue;
164  DetIdContainer detIds(theGeometrie->detIds());
165  if( detIds.size() + ptr->size() < ptr->capacity()) ptr->resize( detIds.size() + ptr->size());
166  for(auto detId : detIds)
167  ptr->emplace_back( detId );
168  }
169  DetIdContainer* expect = nullptr;
170  if(theDetIds.compare_exchange_strong(expect, ptr.get(), std::memory_order_acq_rel)) {
171  ptr.release();
172  }
173  }
174  return *theDetIds.load(std::memory_order_acquire);
175 }
std::vector< const TrackingGeometry * > theGeometries
std::atomic< DetIdContainer * > theDetUnitIds
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
#define nullptr
virtual const GeomDet * idToDet(DetId) const =0
std::atomic< DetContainer * > theDets
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.
std::atomic< DetContainer * > theDetUnits
Definition: DetId.h:18
GlobalTrackingGeometry(std::vector< const TrackingGeometry * > &geos)
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
const GeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
std::vector< DetId > DetIdContainer
const DetTypeContainer & detTypes() const override
Return a vector of all det types.
std::vector< const GeomDet * > DetContainer
const GeomDet * idToDet(DetId) const override
virtual const GeomDet * idToDetUnit(DetId) const =0
Return the pointer to the GeomDetUnit corresponding to a given DetId.
std::vector< const GeomDetType * > DetTypeContainer