GeoModel - GeoModelCore
GeoVPhysVol.cxx
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "GeoModelKernel/GeoVPhysVol.h"
6 #include "GeoModelKernel/GeoVolumeAction.h"
7 #include "GeoModelKernel/GeoAccessVolumeAction.h"
8 
9 #include <stdexcept>
10 #include <string>
11 
12 GeoVPhysVol::GeoVPhysVol(const GeoLogVol* LogVol)
13  : m_parentPtr(nullptr)
14  , m_logVol(LogVol)
15 {
16  if(m_logVol) m_logVol->ref();
17 }
18 
19 GeoVPhysVol::~GeoVPhysVol()
20 {
21  if(m_logVol) m_logVol->unref();
22 }
23 
25 {
26  unsigned int nChildVols{getNChildVols()};
27  for(unsigned int i=0; i<nChildVols; i++) { // To Do: replace this with Volume Iterator!
28  if(getChildVol(i) == daughter) return i;
29  }
30  return Query<unsigned int >();
31 }
32 
34 {
35  if(m_parentPtr != this) return m_parentPtr;
36  return nullptr;
37 }
38 
40 {
41  return m_logVol;
42 }
43 
45 {
46  int nVols(0);
47  switch(action->getType()) {
48  case GeoVolumeAction::TOP_DOWN:
49  action->handleVPhysVol(this);
50  if(action->shouldTerminate()) return;
51 
52  action->getState()->nextLevel(this);
53  nVols = getNChildVols();
54  for(int d = 0; d < nVols; d++) {
55  GeoAccessVolumeAction av(d,nullptr);
56  exec (&av);
57 
58  action->getState()->setTransform(av.getTransform());
59  action->getState()->setDefTransform(av.getDefTransform());
60  action->getState()->setId(av.getId());
61  action->getState()->setName(av.getName());
62 
63  av.getVolume()->apply(action);
64  if(action->shouldTerminate()) break;
65  }
66  action->getState()->previousLevel();
67  break;
68  case GeoVolumeAction::BOTTOM_UP:
69  action->getState()->nextLevel(this);
70  nVols = getNChildVols();
71  for(int d = 0; d < nVols; d++) {
72  GeoAccessVolumeAction av(d,nullptr);
73  exec(&av);
74 
75  action->getState()->setTransform(av.getTransform());
76  action->getState()->setDefTransform(av.getDefTransform());
77  action->getState()->setId(av.getId());
78  action->getState()->setName(av.getName());
79 
80  av.getVolume()->apply(action);
81  if(action->shouldTerminate()) break;
82  }
83  action->getState()->previousLevel();
84 
85  action->handleVPhysVol(this);
86  if(action->shouldTerminate()) return; // To Do: do I need this?
87  break;
88  default:
89  throw std::runtime_error("GeoVPhysVol::apply(). Unsupported GeoVolumeAction type " + std::to_string((unsigned)action->getType()));
90  }
91 }
92 
94 {
95  if(m_parentPtr) {
96  m_parentPtr = this;
97  }
98  else {
99  m_parentPtr = parent;
100  }
101 }
A Logical Volume, or agglomeration of shape and material. The logical volume increases the reference ...
Definition: GeoLogVol.h:20
This type of action sees and traverses a simpler tree of positioned volumes. It does not descend into...
PVConstLink getVolume() const
Returns the selected physical volume or nullptr if not found.
const std::string & getName() const
Returns the name of the volume. From nametag or serial denominator.
Query< int > getId() const
Returns the id of the volume. From the identifier.
void apply(GeoVolumeAction *action) const
Definition: GeoVPhysVol.cxx:44
virtual void dockTo(GeoVPhysVol *parent)
Definition: GeoVPhysVol.cxx:93
PVConstLink getParent() const
Gets the parent, if the parent is unique, and otherwise returns a nullptr pointer.
Definition: GeoVPhysVol.cxx:33
const GeoLogVol * getLogVol() const
Returns the logical volume.
Definition: GeoVPhysVol.cxx:39
const GeoTrf::Transform3D & getDefTransform() const
Returns the default ransformation to the volume.
Query< unsigned int > indexOf(PVConstLink daughter) const
Definition: GeoVPhysVol.cxx:24
const GeoTrf::Transform3D & getTransform() const
Returns the transformation to the volume.
Accesses volumes, returning the ith volume and also its transformation relative to the parent...