GeoModel - GeoModelCore
GeoVFullPhysVol.cxx
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "GeoModelKernel/GeoVFullPhysVol.h"
6 #include "GeoModelKernel/GeoVAlignmentStore.h"
7 #include <string>
8 
9 GeoVFullPhysVol::GeoVFullPhysVol(const GeoLogVol* logVol)
10  : GeoVPhysVol(logVol)
11  , m_id(nullptr)
12  , m_absPosInfo(nullptr)
13 {
14 }
15 
16 GeoVFullPhysVol::~GeoVFullPhysVol()
17 {
18  delete m_absPosInfo;
19  delete m_id;
20 }
21 
22 const GeoTrf::Transform3D & GeoVFullPhysVol::getAbsoluteTransform(GeoVAlignmentStore* store) const
23 {
24  //------------------------------------------------------------------------------------------------//
25  // //
26  // Get ready for something to go wrong: //
27  // //
28  static std::string errorMessage("Full Physical Volume errroneously placed in a shared portion of a detector description graph.\nName of shared volume: ");
29  // //
30  //------------------------------------------------------------------------------------------------//
31  if(isShared()) throw std::runtime_error(errorMessage);
32 
33  if(store==nullptr && !m_absPosInfo) m_absPosInfo = new GeoAbsPositionInfo();
34 
35  //
36  // Check the cache first. If not empty, then return the cached value
37  //
38  if(store==nullptr){
39  if(m_absPosInfo->getAbsTransform()) return *m_absPosInfo->getAbsTransform();
40  }
41  else {
42  const GeoTrf::Transform3D* storedPos = store->getAbsPosition(this);
43  if(storedPos!=nullptr) return *storedPos;
44  }
45 
46  // The cache is empty. Compute the absolute position from the top of the tree down to here, and cache it
47  PVConstLink child(this), parent(getParent());
48  GeoTrf::Transform3D tProd(GeoTrf::Transform3D::Identity());
49 
50  while (parent) {
51 #ifdef HOSED
52  int index = parent->indexOf (child);
53  GeoTrf::Transform3D transform = parent->getXToChildVol(index,store);
54 #else
55  GeoTrf::Transform3D transform = child->getX(store);
56 #endif
57  tProd = transform * tProd;
58  child = parent;
59  if(child->isShared()) {
60  throw std::runtime_error(errorMessage);
61  }
62  else {
63  parent = child->getParent();
64  }
65  }
66 
67  if(store==nullptr) {
68  m_absPosInfo->setAbsTransform(tProd);
69  return *m_absPosInfo->getAbsTransform();
70  }
71  else {
72  store->setAbsPosition(this,tProd);
73  const GeoTrf::Transform3D* storedPosition = store->getAbsPosition(this);
74  return *storedPosition;
75  }
76 }
77 
79 {
80  delete m_absPosInfo;
81  m_absPosInfo = nullptr;
82 }
83 
84 const GeoTrf::Transform3D& GeoVFullPhysVol::getDefAbsoluteTransform(GeoVAlignmentStore* store) const
85 {
86  //------------------------------------------------------------------------------------------------//
87  // //
88  // Get ready for something to go wrong: //
89  // //
90  static std::string errorMessage("Full Physical Volume errroneously placed in a shared portion of a detector description graph.\nName of shared volume: ");
91  // //
92  //------------------------------------------------------------------------------------------------//
93  if(isShared()) throw std::runtime_error(errorMessage);
94 
95  if(store==nullptr && !m_absPosInfo) m_absPosInfo = new GeoAbsPositionInfo();
96 
97  //
98  // Check the cache first. If not empty, then return the cached value
99  //
100  if(store==nullptr){
101  if(m_absPosInfo->getDefAbsTransform()) return *m_absPosInfo->getDefAbsTransform();
102  }
103  else {
104  const GeoTrf::Transform3D* storedPos = store->getDefAbsPosition(this);
105  if(storedPos!=nullptr) return *storedPos;
106  }
107 
108  // The cache is empty. Compute the absolute position from the top of the tree down to here, and cache it
109  PVConstLink child(this), parent(getParent());
110  GeoTrf::Transform3D tProd(GeoTrf::Transform3D::Identity());
111 
112  while (parent) {
113 #ifdef HOSED
114  int index = parent->indexOf (child);
115  GeoTrf::Transform3D transform = parent->getDefXToChildVol(index,store);
116 #else
117  GeoTrf::Transform3D transform = child->getDefX(store);
118 #endif
119  tProd = transform * tProd;
120  child = parent;
121  if(child->isShared()) {
122  throw std::runtime_error(errorMessage);
123  }
124  else {
125  parent = child->getParent();
126  }
127  }
128 
129  if(store==nullptr) {
130  m_absPosInfo->setDefAbsTransform(tProd);
131  return *m_absPosInfo->getDefAbsTransform();
132  }
133  else {
134  store->setDefAbsPosition(this,tProd);
135  const GeoTrf::Transform3D* storedPosition = store->getDefAbsPosition(this);
136  return *storedPosition;
137  }
138 }
139 
140 const std::string & GeoVFullPhysVol::getAbsoluteName ()
141 {
142  //------------------------------------------------------------------------------------------------//
143  // //
144  // Get ready for something to go wrong: //
145  // //
146  static std::string errorMessage("Full Physical Volume errroneously placed in a shared portion of a detector description graph.\nName of shared volume: ");
147  // //
148  //------------------------------------------------------------------------------------------------//
149 
150  if(m_absName == "") {
151  if(isShared()) throw std::runtime_error(errorMessage);
152 
153  //
154  // Check the cache. If it is empty, compute the absolute position from the
155  // top of the tree down to here, and update the cache
156  //
157  PVConstLink child(this), parent(getParent());
158  std::string tProd;
159 
160  while (parent) {
161  int index = parent->indexOf (child);
162  std::string name = parent->getNameOfChildVol (index);
163 
164  tProd = tProd + "/" + name;
165  child = parent;
166  if (child->isShared ()) {
167  throw std::runtime_error(errorMessage);
168  }
169  else {
170  parent = child->getParent ();
171  }
172  }
173  m_absName = tProd;
174  }
175 
176  return m_absName;
177 }
178 
179 unsigned int GeoVFullPhysVol::getId () const
180 {
181  //------------------------------------------------------------------------------------------------//
182  // //
183  // Get ready for something to go wrong: //
184  // //
185  static std::string errorMessage("Full Physical Volume errroneously placed in a shared portion of a detector description graph.\nName of shared volume: ");
186  // //
187  //------------------------------------------------------------------------------------------------//
188 
189  if(m_id==nullptr) {
190  if(isShared()) throw std::runtime_error(errorMessage);
191 
192  //
193  // Check the cache. If it is empty, compute the absolute position from the
194  // top of the tree down to here, and update the cache
195  //
196  PVConstLink child = this, parent = nullptr;
197  if(child->isShared()) {
198  throw std::runtime_error(errorMessage);
199  }
200  else {
201  parent = child->getParent();
202  }
203 
204  int index = parent->indexOf(child);
205  m_id = new Query<int>(parent->getIdOfChildVol(index));
206  }
207  return *m_id;
208 }
209 
const std::string & getAbsoluteName()
Returns the absolute name of this node.
void clearPositionInfo() const
virtual GeoTrf::Transform3D getXToChildVol(unsigned int index, const GeoVAlignmentStore *store=nullptr) const =0
Returns the transform to the ith volume.
unsigned int getId() const
Returns the identification bits.
A Logical Volume, or agglomeration of shape and material. The logical volume increases the reference ...
Definition: GeoLogVol.h:20
virtual std::string getNameOfChildVol(unsigned int i) const =0
Returns the name of the child.
Abstract base class for GeoModel alignment stores The interface allows to store/retrieve transformati...
const GeoTrf::Transform3D & getAbsoluteTransform(GeoVAlignmentStore *store=nullptr) const
Returns the absolute transform of the volume.
PVConstLink getParent() const
Gets the parent, if the parent is unique, and otherwise returns a nullptr pointer.
Definition: GeoVPhysVol.cxx:33
virtual GeoTrf::Transform3D getDefXToChildVol(unsigned int index, const GeoVAlignmentStore *store=nullptr) const =0
Returns the default transform to the ith volume.
Query< unsigned int > indexOf(PVConstLink daughter) const
Definition: GeoVPhysVol.cxx:24
bool isShared() const
Definition: GeoVPhysVol.h:101
const GeoTrf::Transform3D & getDefAbsoluteTransform(GeoVAlignmentStore *store=nullptr) const
Returns the default absolute transform of the volume.
This class represents anything whose default and aligned postions are known and cached.