File indexing completed on 2023-03-17 13:02:38
0001
0002
0003
0004
0005
0006 #include "Geometry/CommonTopologies/interface/GlobalTrackingGeometry.h"
0007 #include "FWCore/Utilities/interface/Exception.h"
0008
0009 #include "DataFormats/ForwardDetId/interface/ForwardSubdetector.h"
0010
0011 #include <memory>
0012
0013 GlobalTrackingGeometry::GlobalTrackingGeometry(std::vector<const TrackingGeometry*>& geos)
0014 : theGeometries(geos),
0015 theDetTypes(nullptr),
0016 theDetUnits(nullptr),
0017 theDets(nullptr),
0018 theDetUnitIds(nullptr),
0019 theDetIds(nullptr) {}
0020
0021 GlobalTrackingGeometry::~GlobalTrackingGeometry() {
0022 delete theDetTypes.load();
0023 theDetTypes = nullptr;
0024 delete theDetUnits.load();
0025 theDetUnits = nullptr;
0026 delete theDets.load();
0027 theDets = nullptr;
0028 delete theDetUnitIds.load();
0029 theDetUnitIds = nullptr;
0030 delete theDetIds.load();
0031 theDetIds = nullptr;
0032 }
0033
0034 const GeomDet* GlobalTrackingGeometry::idToDetUnit(DetId id) const {
0035 const TrackingGeometry* tg = slaveGeometry(id);
0036
0037 if (tg != nullptr) {
0038 return tg->idToDetUnit(id);
0039 } else {
0040 return nullptr;
0041 }
0042 }
0043
0044 const GeomDet* GlobalTrackingGeometry::idToDet(DetId id) const {
0045 const TrackingGeometry* tg = slaveGeometry(id);
0046
0047 if (tg != nullptr) {
0048 return tg->idToDet(id);
0049 } else {
0050 return nullptr;
0051 }
0052 }
0053
0054 const TrackingGeometry* GlobalTrackingGeometry::slaveGeometry(DetId id) const {
0055 int idx = id.det() - 1;
0056 if (id.det() == DetId::Muon) {
0057 idx += id.subdetId();
0058 }
0059 if (id.det() == DetId::Forward && id.subdetId() == ForwardSubdetector::FastTime) {
0060 idx = 1;
0061 }
0062
0063 if (theGeometries[idx] == nullptr)
0064 throw cms::Exception("NoGeometry") << "No Tracking Geometry is available for DetId " << id.rawId() << std::endl;
0065
0066 return theGeometries[idx];
0067 }
0068
0069 const TrackingGeometry::DetTypeContainer& GlobalTrackingGeometry::detTypes(void) const {
0070 if (!theDetTypes.load(std::memory_order_acquire)) {
0071 std::unique_ptr<DetTypeContainer> ptr{new DetTypeContainer()};
0072 for (auto theGeometrie : theGeometries) {
0073 if (theGeometrie == nullptr)
0074 continue;
0075 DetTypeContainer detTypes(theGeometrie->detTypes());
0076 if (detTypes.size() + ptr->size() < ptr->capacity())
0077 ptr->resize(detTypes.size() + ptr->size());
0078 for (auto detType : detTypes)
0079 ptr->emplace_back(detType);
0080 }
0081 DetTypeContainer* expect = nullptr;
0082 if (theDetTypes.compare_exchange_strong(expect, ptr.get(), std::memory_order_acq_rel)) {
0083 ptr.release();
0084 }
0085 }
0086 return *theDetTypes.load(std::memory_order_acquire);
0087 }
0088
0089 const TrackingGeometry::DetContainer& GlobalTrackingGeometry::detUnits(void) const {
0090 if (!theDetUnits.load(std::memory_order_acquire)) {
0091 std::unique_ptr<DetContainer> ptr{new DetContainer()};
0092 for (auto theGeometrie : theGeometries) {
0093 if (theGeometrie == nullptr)
0094 continue;
0095 DetContainer detUnits(theGeometrie->detUnits());
0096 if (detUnits.size() + ptr->size() < ptr->capacity())
0097 ptr->resize(detUnits.size() + ptr->size());
0098 for (auto detUnit : detUnits)
0099 ptr->emplace_back(detUnit);
0100 }
0101 DetContainer* expect = nullptr;
0102 if (theDetUnits.compare_exchange_strong(expect, ptr.get(), std::memory_order_acq_rel)) {
0103 ptr.release();
0104 }
0105 }
0106 return *theDetUnits.load(std::memory_order_acquire);
0107 }
0108
0109 const TrackingGeometry::DetContainer& GlobalTrackingGeometry::dets(void) const {
0110 if (!theDets.load(std::memory_order_acquire)) {
0111 std::unique_ptr<DetContainer> ptr{new DetContainer()};
0112 for (auto theGeometrie : theGeometries) {
0113 if (theGeometrie == nullptr)
0114 continue;
0115 DetContainer dets(theGeometrie->dets());
0116 if (dets.size() + ptr->size() < ptr->capacity())
0117 ptr->resize(dets.size() + ptr->size());
0118 for (auto det : dets)
0119 ptr->emplace_back(det);
0120 }
0121 DetContainer* expect = nullptr;
0122 if (theDets.compare_exchange_strong(expect, ptr.get(), std::memory_order_acq_rel)) {
0123 ptr.release();
0124 }
0125 }
0126 return *theDets.load(std::memory_order_acquire);
0127 }
0128
0129 const TrackingGeometry::DetIdContainer& GlobalTrackingGeometry::detUnitIds(void) const {
0130 if (!theDetUnitIds.load(std::memory_order_acquire)) {
0131 std::unique_ptr<DetIdContainer> ptr{new DetIdContainer()};
0132 for (auto theGeometrie : theGeometries) {
0133 if (theGeometrie == nullptr)
0134 continue;
0135 DetIdContainer detUnitIds(theGeometrie->detUnitIds());
0136 if (detUnitIds.size() + ptr->size() < ptr->capacity())
0137 ptr->resize(detUnitIds.size() + ptr->size());
0138 for (auto detUnitId : detUnitIds)
0139 ptr->emplace_back(detUnitId);
0140 }
0141 DetIdContainer* expect = nullptr;
0142 if (theDetUnitIds.compare_exchange_strong(expect, ptr.get(), std::memory_order_acq_rel)) {
0143 ptr.release();
0144 }
0145 }
0146 return *theDetUnitIds.load(std::memory_order_acquire);
0147 }
0148
0149 const TrackingGeometry::DetIdContainer& GlobalTrackingGeometry::detIds(void) const {
0150 if (!theDetIds.load(std::memory_order_acquire)) {
0151 std::unique_ptr<DetIdContainer> ptr{new DetIdContainer()};
0152 for (auto theGeometrie : theGeometries) {
0153 if (theGeometrie == nullptr)
0154 continue;
0155 DetIdContainer detIds(theGeometrie->detIds());
0156 if (detIds.size() + ptr->size() < ptr->capacity())
0157 ptr->resize(detIds.size() + ptr->size());
0158 for (auto detId : detIds)
0159 ptr->emplace_back(detId);
0160 }
0161 DetIdContainer* expect = nullptr;
0162 if (theDetIds.compare_exchange_strong(expect, ptr.get(), std::memory_order_acq_rel)) {
0163 ptr.release();
0164 }
0165 }
0166 return *theDetIds.load(std::memory_order_acquire);
0167 }