ATLAS Offline Software
GeoVisitVolumes.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
3  */
14 #include "GeoModelKernel/GeoNameTag.h"
15 #include "GeoModelKernel/GeoSerialDenominator.h"
16 #include "GeoModelKernel/GeoSerialIdentifier.h"
17 
18 #include "CxxUtils/inline_hints.h"
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 
48 void GeoVisitVolumes::handleTransform (const GeoTransform *xform)
49 {
50  if (m_action.index() == 0)
51  m_pendingTransformList.push_back (xform);
52 }
53 
54 
55 void 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) {
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);
87  m_pendingTransformList.clear();
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 
98 void GeoVisitVolumes::handlePhysVol (const GeoPhysVol *vol)
99 {
100  handleVol (vol);
101 }
102 
103 void GeoVisitVolumes::handleFullPhysVol (const GeoFullPhysVol *vol)
104 {
105  handleVol (vol);
106 }
107 
108 
109 void GeoVisitVolumes::handleNameTag (const GeoNameTag *nameTag)
110 {
111  m_nameTag = nameTag;
112  m_serialDenominator = nullptr;
113 }
114 
115 
116 void GeoVisitVolumes::handleSerialDenominator (const GeoSerialDenominator *sD)
117 {
118  m_serialDenominator = sD;
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
130 void 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 
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;
164  if (m_serialDenominator) {
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;
183  m_pendingTransformList.clear();
184 }
185 
186 
187 void GeoVisitVolumes::handleIdentifierTag (const GeoIdentifierTag *idTag)
188 {
189  m_idTag = idTag;
190  m_serialIdentifier = nullptr;
191 }
192 
193 
194 void GeoVisitVolumes::handleSerialIdentifier(const GeoSerialIdentifier *sI)
195 {
196  m_serialIdentifier = sI;
197 }
198 
199 
211 GeoVolumeVec_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,
221  const GeoTrf::Transform3D& /*defTransform*/)
222  { ret.emplace_back (volume, transform); },
223  node,
224  depthLimit);
225  return ret;
226 }
227 
228 
239 std::vector<const GeoVPhysVol*>
240 geoGetVolumesNoXform (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 }
GeoVisitVolumes::handleFullPhysVol
virtual void handleFullPhysVol(const GeoFullPhysVol *vol) override
Handles a physical volume.
Definition: GeoVisitVolumes.cxx:103
geoVisitVolumesNoXform
void geoVisitVolumesNoXform(FUNCTION f, const GeoGraphNode *node, int depthLimit=1)
Template helper for running the visitor.
Definition: GeoVisitVolumes.h:199
inline_hints.h
GeoVolumeVec_t
std::vector< std::pair< const GeoVPhysVol *, GeoTrf::Transform3D > > GeoVolumeVec_t
Return the child volumes and associated transforms.
Definition: GeoVisitVolumes.h:219
GeoVisitVolumes::handleIdentifierTag
virtual void handleIdentifierTag(const GeoIdentifierTag *idTag) override
Handles an Identifier Tag.
Definition: GeoVisitVolumes.cxx:187
GeoVisitVolumes::m_idTag
const GeoIdentifierTag * m_idTag
A pointer to an identifier tag. If the volume is identified.
Definition: GeoVisitVolumes.h:127
GeoVisitVolumes::handleNameTag
virtual void handleNameTag(const GeoNameTag *nameTag) override
Handles a Name Tag.
Definition: GeoVisitVolumes.cxx:109
GeoVisitVolumes::handleSerialTransformer
virtual void handleSerialTransformer(const GeoSerialTransformer *sT) override
Handles a Serial Transformer.
Definition: GeoVisitVolumes.cxx:130
GeoVisitVolumes::handleVol
void handleVol(const GeoVPhysVol *vol)
Definition: GeoVisitVolumes.cxx:55
GeoVisitVolumes::handleSerialDenominator
virtual void handleSerialDenominator(const GeoSerialDenominator *sD) override
Handles a Serial Denominator.
Definition: GeoVisitVolumes.cxx:116
geoGetVolumesNoXform
std::vector< const GeoVPhysVol * > geoGetVolumesNoXform(const GeoGraphNode *node, int depthLimit, int sizeHint)
Return the child volumes.
Definition: GeoVisitVolumes.cxx:240
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
GeoVisitVolumes::m_pendingTransformList
std::vector< const GeoTransform * > m_pendingTransformList
List of Pending Transformations.
Definition: GeoVisitVolumes.h:130
GeoVisitVolumes::m_serialDenominator
const GeoSerialDenominator * m_serialDenominator
A pointer to a serial denominator. If one exists.
Definition: GeoVisitVolumes.h:124
GeoVisitVolumes.h
Visitor to process all volumes under a GeoModel node.
IGeoVisitVolumesNoXformAction
Define a simple callback for each volume found, without keeping track of geometrical transforms.
Definition: GeoVisitVolumes.h:57
lumiFormat.i
int i
Definition: lumiFormat.py:85
ATH_FLATTEN
#define ATH_FLATTEN
Definition: inline_hints.h:52
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
PyPoolBrowser.node
node
Definition: PyPoolBrowser.py:131
geoGetVolumes
GeoVolumeVec_t geoGetVolumes(const GeoGraphNode *node, int depthLimit, int sizeHint)
Return the child volumes and associated transforms.
Definition: GeoVisitVolumes.cxx:211
GeoVisitVolumes::GeoVisitVolumes
GeoVisitVolumes(IGeoVisitVolumesAction &action, int depthLimit=1)
Initialize to visit volumes keeping track of transformations.
Definition: GeoVisitVolumes.cxx:23
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
GeoVisitVolumes::handlePhysVol
virtual void handlePhysVol(const GeoPhysVol *vol) override
Handles a physical volume.
Definition: GeoVisitVolumes.cxx:98
GeoVisitVolumes::m_action
std::variant< IGeoVisitVolumesAction *, IGeoVisitVolumesNoXformAction * > m_action
Callback.
Definition: GeoVisitVolumes.h:118
IGeoVisitVolumesAction
Define a simple callback for each volume found.
Definition: GeoVisitVolumes.h:38
GeoVisitVolumes::m_nameTag
const GeoNameTag * m_nameTag
A pointer to a name tag. If the volume is named.
Definition: GeoVisitVolumes.h:121
python.CaloScaleNoiseConfig.action
action
Definition: CaloScaleNoiseConfig.py:77
GeoVisitVolumes::handleSerialIdentifier
virtual void handleSerialIdentifier(const GeoSerialIdentifier *sI) override
Handles an Serial Identifier.
Definition: GeoVisitVolumes.cxx:194
GeoVisitVolumes::m_serialIdentifier
const GeoSerialIdentifier * m_serialIdentifier
Definition: GeoVisitVolumes.h:132
GeoVisitVolumes::handleTransform
virtual void handleTransform(const GeoTransform *xform) override
Handles a Transform.
Definition: GeoVisitVolumes.cxx:48
node
Definition: memory_hooks-stdcmalloc.h:74
geoVisitVolumes
void geoVisitVolumes(FUNCTION f, const GeoGraphNode *node, int depthLimit=1)
Template helper for running the visitor.
Definition: GeoVisitVolumes.h:185