CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 != 0) {
35  return tg->idToDetUnit(id);
36  } else {
37  return 0;
38  }
39 }
40 
41 
43 
44  const TrackingGeometry* tg = slaveGeometry(id);
45 
46  if (tg != 0) {
47  return tg->idToDet(id);
48  } else {
49  return 0;
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]==0) 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 geom = theGeometries.cbegin(), geomEnd = theGeometries.cend(); geom != geomEnd; ++geom )
72  {
73  if( *geom == 0 ) continue;
74  DetTypeContainer detTypes(( *geom )->detTypes());
75  if( detTypes.size() + ptr->size() < ptr->capacity()) ptr->resize( detTypes.size() + ptr->size());
76  for( auto detType = detTypes.cbegin(), detTypeEnd = detTypes.cend(); detType != detTypeEnd; ++detType )
77  ptr->push_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 geom = theGeometries.cbegin(), geomEnd = theGeometries.cend(); geom != geomEnd; ++geom )
93  {
94  if( *geom == 0 ) continue;
95  DetUnitContainer detUnits(( *geom )->detUnits());
96  if( detUnits.size() + ptr->size() < ptr->capacity()) ptr->resize( detUnits.size() + ptr->size());
97  for( auto detUnit = detUnits.cbegin(), detUnitEnd = detUnits.cend(); detUnit != detUnitEnd; ++detUnit )
98  ptr->push_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 geom = theGeometries.cbegin(), geomEnd = theGeometries.cend(); geom != geomEnd; ++geom )
114  {
115  if( *geom == 0 ) continue;
116  DetContainer dets(( *geom )->dets());
117  if( dets.size() + ptr->size() < ptr->capacity()) ptr->resize( dets.size() + ptr->size());
118  for( auto det = dets.cbegin(), detEnd = dets.cend(); det != detEnd; ++det )
119  ptr->push_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 geom = theGeometries.cbegin(), geomEnd = theGeometries.cend(); geom != geomEnd; ++geom )
135  {
136  if( *geom == 0 ) continue;
137  DetIdContainer detUnitIds(( *geom )->detUnitIds());
138  if( detUnitIds.size() + ptr->size() < ptr->capacity()) ptr->resize( detUnitIds.size() + ptr->size());
139  for( auto detUnitId = detUnitIds.cbegin(), detUnitIdEnd = detUnitIds.cend(); detUnitId != detUnitIdEnd; ++detUnitId )
140  ptr->push_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 geom = theGeometries.cbegin(), geomEnd = theGeometries.cend(); geom != geomEnd; ++geom )
156  {
157  if( *geom == 0 ) continue;
158  DetIdContainer detIds(( *geom )->detIds());
159  if( detIds.size() + ptr->size() < ptr->capacity()) ptr->resize( detIds.size() + ptr->size());
160  for( auto detId = detIds.cbegin(), detIdEnd = detIds.cend(); detId != detIdEnd; ++detId )
161  ptr->push_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
#define nullptr
std::atomic< DetContainer * > theDets
virtual const GeomDet * idToDet(DetId) const
virtual const GeomDetUnit * idToDetUnit(DetId) const =0
Return the pointer to the GeomDetUnit corresponding to a given DetId.
virtual const GeomDetUnit * idToDetUnit(DetId) const
Return the pointer to the GeomDetUnit corresponding to a given DetId.
std::atomic< DetUnitContainer * > theDetUnits
std::atomic< DetIdContainer * > theDetIds
std::atomic< DetTypeContainer * > theDetTypes
const TrackingGeometry * slaveGeometry(DetId id) const
Return the pointer to the actual geometry for a given DetId.
virtual ~GlobalTrackingGeometry()
Destructor.
virtual const DetUnitContainer & detUnits() const
Returm a vector of all GeomDetUnit.
virtual const DetIdContainer & detIds() const
Returm a vector of all GeomDet DetIds (including those of GeomDetUnits)
virtual const DetContainer & dets() const
Returm a vector of all GeomDet (including all GeomDetUnits)
Definition: DetId.h:18
GlobalTrackingGeometry(std::vector< const TrackingGeometry * > &geos)
Constructor.
virtual const GeomDet * idToDet(DetId) const =0
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
virtual const DetTypeContainer & detTypes() const
Return a vector of all det types.
std::vector< GeomDet const * > DetContainer
std::vector< GeomDetUnit const * > DetUnitContainer
virtual const DetIdContainer & detUnitIds() const
Returm a vector of all GeomDetUnit DetIds.
std::vector< DetId > DetIdContainer