ATLAS Offline Software
Loading...
Searching...
No Matches
GeoVisitVolumes.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
3 */
12
14#include "GeoModelKernel/GeoNameTag.h"
15#include "GeoModelKernel/GeoSerialDenominator.h"
16#include "GeoModelKernel/GeoSerialIdentifier.h"
17
19
20#include <string>
21
22
24 int depthLimit /*= 1*/)
25 : m_action(&action)
26 , m_nameTag(nullptr)
27 , m_serialDenominator(nullptr)
28 , m_idTag(nullptr)
29 , m_serialIdentifier(nullptr)
30{
31 setDepthLimit (depthLimit);
32 m_pendingTransformList.reserve(1);
33}
34
35
37 int depthLimit /*= 1*/)
38 : m_action(&action)
39 , m_nameTag(nullptr)
40 , m_serialDenominator(nullptr)
41 , m_idTag(nullptr)
42 , m_serialIdentifier(nullptr)
43{
44 setDepthLimit (depthLimit);
45}
46
47
48void GeoVisitVolumes::handleTransform (const GeoTransform *xform)
49{
50 if (m_action.index() == 0)
51 m_pendingTransformList.push_back (xform);
52}
53
54
55void GeoVisitVolumes::handleVol (const GeoVPhysVol *vol)
56{
57 //
58 // Return if we have not got to any children:
59 //
60 if(getPath()->getLength()-1 == 0)
61 return;
62
63 const static std::string anon = "ANON";
64 const std::string& name = m_nameTag ? m_nameTag->getName() : anon;
65
66 int id = m_idTag ? m_idTag->getIdentifier() : -1;
67
68 if (m_action.index() == 0) {
69 GeoTrf::Transform3D transform;
70 GeoTrf::Transform3D defTransform;
71
72 if (m_pendingTransformList.size() == 0) {
73 transform = GeoTrf::Transform3D::Identity();
74 defTransform = GeoTrf::Transform3D::Identity();
75 }
76 else {
77 transform = m_pendingTransformList[0]->getTransform(nullptr);
78 defTransform = m_pendingTransformList[0]->getDefTransform(nullptr);
79 for (size_t i = 1; i < m_pendingTransformList.size(); ++i) {
80 const GeoTransform* t = m_pendingTransformList[i];
81 transform = transform * t->getTransform(nullptr);
82 defTransform = defTransform * t->getDefTransform(nullptr);
83 }
84 }
85
86 (*std::get<0>(m_action)) (*this, id, name, vol, transform, defTransform);
88 }
89 else {
90 (*std::get<1>(m_action)) (*this, id, name, vol);
91 }
92
93 m_idTag = nullptr;
94 m_nameTag = nullptr;
95}
96
97
98void GeoVisitVolumes::handlePhysVol (const GeoPhysVol *vol)
99{
100 handleVol (vol);
101}
102
103void GeoVisitVolumes::handleFullPhysVol (const GeoFullPhysVol *vol)
104{
105 handleVol (vol);
106}
107
108
109void GeoVisitVolumes::handleNameTag (const GeoNameTag *nameTag)
110{
111 m_nameTag = nameTag;
112 m_serialDenominator = nullptr;
113}
114
115
116void GeoVisitVolumes::handleSerialDenominator (const GeoSerialDenominator *sD)
117{
119}
120
121
122#if defined(FLATTEN)
123// We compile this package with optimization, even in debug builds; otherwise,
124// the heavy use of Eigen makes it too slow. However, from here we may call
125// to out-of-line Eigen code that is linked from other DSOs; in that case,
126// it would not be optimized. Avoid this by forcing all Eigen code
127// to be inlined here if possible
129#endif
130void GeoVisitVolumes::handleSerialTransformer (const GeoSerialTransformer *sT)
131{
132 const GeoVPhysVol* vol = &*sT->getVolume();
133 unsigned int ncopies = sT->getNCopies();
134 int idbase = -1;
135 if (m_serialIdentifier) {
136 idbase = m_serialIdentifier->getBaseId();
137 }
138
139 GeoTrf::Transform3D transform;
140 GeoTrf::Transform3D defTransform;
141 if (m_action.index() == 0) {
142 if (m_pendingTransformList.size() == 0) {
143 transform = GeoTrf::Transform3D::Identity();
144 defTransform = GeoTrf::Transform3D::Identity();
145 }
146 else {
147 transform = m_pendingTransformList[0]->getTransform(nullptr);
148 defTransform = m_pendingTransformList[0]->getDefTransform(nullptr);
149 for (size_t i = 1; i < m_pendingTransformList.size(); ++i) {
150 const GeoTransform* t = m_pendingTransformList[i];
151 transform = transform * t->getTransform(nullptr);
152 defTransform = defTransform * t->getDefTransform(nullptr);
153 }
154 }
155 }
156
157 for (unsigned int i = 0; i < ncopies; i++) {
158 int id = idbase;
159 if (id >= 0) {
160 id += i;
161 }
162
163 std::string name;
165 name = m_serialDenominator->getBaseName() + std::to_string(i);
166 }
167 else {
168 name = "ANON";
169 }
170
171 if (m_action.index() == 0) {
172 (*std::get<0>(m_action)) (*this, id, name, vol,
173 transform * sT->getTransform (i),
174 defTransform * sT->getTransform (i));
175 }
176 else {
177 (*std::get<1>(m_action)) (*this, id, name, vol);
178 }
179 }
180
181 m_idTag = nullptr;
182 m_nameTag = nullptr;
184}
185
186
187void GeoVisitVolumes::handleIdentifierTag (const GeoIdentifierTag *idTag)
188{
189 m_idTag = idTag;
190 m_serialIdentifier = nullptr;
191}
192
193
194void GeoVisitVolumes::handleSerialIdentifier(const GeoSerialIdentifier *sI)
195{
197}
198
199
211GeoVolumeVec_t geoGetVolumes (const GeoGraphNode* node,
212 int depthLimit /*= 1*/,
213 int sizeHint /* 20*/)
214{
215 GeoVolumeVec_t ret;
216 ret.reserve (sizeHint);
217 geoVisitVolumes ([&] (int /*id*/,
218 const std::string& /*name*/,
219 const GeoVPhysVol* volume,
220 const GeoTrf::Transform3D& transform,
221 const GeoTrf::Transform3D& /*defTransform*/)
222 { ret.emplace_back (volume, transform); },
223 node,
224 depthLimit);
225 return ret;
226}
227
228
239std::vector<const GeoVPhysVol*>
240geoGetVolumesNoXform (const GeoGraphNode* node,
241 int depthLimit /*= 1*/,
242 int sizeHint /* 20*/)
243{
244 std::vector<const GeoVPhysVol*> ret;
245 ret.reserve (sizeHint);
246 geoVisitVolumesNoXform ([&] (int /*id*/,
247 const std::string& /*name*/,
248 const GeoVPhysVol* volume)
249 { ret.push_back (volume); },
250 node,
251 depthLimit);
252 return ret;
253}
GeoVolumeVec_t geoGetVolumes(const GeoGraphNode *node, int depthLimit, int sizeHint)
Return the child volumes and associated transforms.
std::vector< const GeoVPhysVol * > geoGetVolumesNoXform(const GeoGraphNode *node, int depthLimit, int sizeHint)
Return the child volumes.
Visitor to process all volumes under a GeoModel node.
void geoVisitVolumesNoXform(FUNCTION f, const GeoGraphNode *node, int depthLimit=1)
Template helper for running the visitor.
std::vector< std::pair< const GeoVPhysVol *, GeoTrf::Transform3D > > GeoVolumeVec_t
Return the child volumes and associated transforms.
void geoVisitVolumes(FUNCTION f, const GeoGraphNode *node, int depthLimit=1)
Template helper for running the visitor.
virtual void handleNameTag(const GeoNameTag *nameTag) override
Handles a Name Tag.
virtual void handleSerialTransformer(const GeoSerialTransformer *sT) override
Handles a Serial Transformer.
std::vector< const GeoTransform * > m_pendingTransformList
List of Pending Transformations.
virtual void handlePhysVol(const GeoPhysVol *vol) override
Handles a physical volume.
GeoVisitVolumes(IGeoVisitVolumesAction &action, int depthLimit=1)
Initialize to visit volumes keeping track of transformations.
const GeoIdentifierTag * m_idTag
A pointer to an identifier tag. If the volume is identified.
virtual void handleTransform(const GeoTransform *xform) override
Handles a Transform.
const GeoNameTag * m_nameTag
A pointer to a name tag. If the volume is named.
const GeoSerialDenominator * m_serialDenominator
A pointer to a serial denominator. If one exists.
const GeoSerialIdentifier * m_serialIdentifier
std::variant< IGeoVisitVolumesAction *, IGeoVisitVolumesNoXformAction * > m_action
Callback.
virtual void handleIdentifierTag(const GeoIdentifierTag *idTag) override
Handles an Identifier Tag.
virtual void handleSerialDenominator(const GeoSerialDenominator *sD) override
Handles a Serial Denominator.
virtual void handleFullPhysVol(const GeoFullPhysVol *vol) override
Handles a physical volume.
virtual void handleSerialIdentifier(const GeoSerialIdentifier *sI) override
Handles an Serial Identifier.
void handleVol(const GeoVPhysVol *vol)
Define a simple callback for each volume found.
Define a simple callback for each volume found, without keeping track of geometrical transforms.
Definition node.h:24
#define ATH_FLATTEN