DD4hep  1.28.0
Detector Description Toolkit for High Energy Physics
SurfaceInstaller.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 #ifndef DD4HEP_SURFACEINSTALLER_H
14 #define DD4HEP_SURFACEINSTALLER_H 1
15 
16 // Framework include files
17 #include "DD4hep/Detector.h"
18 #include "DD4hep/DetectorTools.h"
20 
21 // C/C++ include files
22 #include <map>
23 #include <algorithm>
24 
25 
26 
27 namespace dd4hep{
28  namespace rec{
29  class VolSurfaceBase;
30  class SurfaceType;
31  }
32 }
33 
34 
36 namespace dd4hep {
37 
39  namespace rec {
41  // class SurfaceData;
42  class VolSurfaceBase;
43  }
44 
46  /*
47  * The class scans the geometry of a subdetector and gives callbacks
48  * to user classes, which then should install in the proper callback
49  * routines the surface instances to the detector elements.
50  *
51  * \author M.Frank
52  * \version 1.0
53  * \ingroup DD4HEP
54  */
56  protected:
61  typedef std::map<TGeoVolume*, SurfaceData* > Surfaces;
62 
72  void scan(DetElement de);
73 
74  public:
76  SurfaceInstaller() = delete;
80  SurfaceInstaller(Detector& description, int argc, char** argv);
82  virtual ~SurfaceInstaller() = default;
86  void stopScanning() { m_stopScanning = true; }
88  void invalidInstaller(const std::string& msg) const;
90  Volume parentVolume(DetElement component) const;
92  const double* placementTranslation(DetElement component) const;
94  void scan();
96  virtual void install(DetElement e, PlacedVolume pv);
98  template <typename T> static long run(Detector& description,int argc,char** argv);
99  };
100 
102  template <typename T> inline long SurfaceInstaller::run(Detector& description,int argc,char** argv) {
103  T installer(description, argc, argv);
104  installer.scan();
105  return 1;
106  }
107 
108 #define DECLARE_SURFACE_INSTALLER(name,class) \
109  namespace dd4hep { \
110  template long SurfaceInstaller::run< class >(Detector& description,int argc,char** argv); \
111  } \
112  DECLARE_APPLY(name,SurfaceInstaller::run< class >)
113 
114 } // End namespace dd4hep
115 
116 
117 #if defined(DD4HEP_USE_SURFACEINSTALL_HELPER)
118 
119 #include "DDRec/Surface.h"
120 #include "DDRec/DetectorData.h"
121 
122 #ifndef SURFACEINSTALLER_DATA
123 typedef void* SURFACEINSTALLER_DATA;
124 #endif
125 
136 namespace {
137 
139  /*
140  * See the base class SurfaceInstaller for further details.
141  *
142  * \author M.Frank
143  * \version 1.0
144  * \ingroup DD4HEP
145  */
146  template <typename UserData> class Installer : public dd4hep::SurfaceInstaller {
147  public:
148  typedef dd4hep::rec::Vector3D Vector3D;
149  typedef dd4hep::rec::VolSurface VolSurface;
151  typedef dd4hep::rec::SurfaceType Type;
152  UserData data;
153 
155  void handle_arguments(int argc, char** argv);
156  public:
158  Installer() = delete;
160  Installer(const Installer& copy) = delete;
162  Installer(dd4hep::Detector& description, int argc, char** argv);
164  virtual ~Installer() = default;
166  Installer& operator=(const Installer& copy) = delete;
168  virtual void install(dd4hep::DetElement component, dd4hep::PlacedVolume pv);
170  bool handleUsingCache(dd4hep::DetElement comp, dd4hep::Volume vol) const;
172  void addSurface(dd4hep::DetElement component, const dd4hep::rec::VolSurface& surf);
173  template <typename T> bool checkShape(const T& shape) const {
174  if ( shape.isValid() ) return true;
175  invalidInstaller("Shape is not of the required type:"+dd4hep::typeName(typeid(T)));
176  return false;
177  }
178  };
179 
181  template <typename UserData>
182  Installer<UserData>::Installer(dd4hep::Detector& description, int argc, char** argv)
183  : dd4hep::SurfaceInstaller(description, argc, argv), data()
184  {
185  handle_arguments(argc, argv);
186  }
187 
189  template <typename UserData>
190  bool Installer<UserData>::handleUsingCache(dd4hep::DetElement comp, dd4hep::Volume vol) const {
191  Surfaces::const_iterator is = m_surfaces.find(vol.ptr());
192  if ( is != m_surfaces.end() ) {
193  VolSurface surf((*is).second);
194  dd4hep::rec::volSurfaceList(comp)->emplace_back(surf);
195  return true;
196  }
197  return false;
198  }
199 
201  template <typename UserData>
202  void Installer<UserData>::addSurface(dd4hep::DetElement component, const dd4hep::rec::VolSurface& surf) {
203  m_surfaces.insert(std::make_pair(surf.volume().ptr(),surf.ptr()));
204  dd4hep::rec::volSurfaceList(component)->emplace_back(surf);
205  }
206 
208  template <typename UserData> void Installer<UserData>::handle_arguments(int, char**) {}
209 #ifndef SURFACEINSTALLER_DATA
210  template <> void Installer<SURFACEINSTALLER_DATA>::handle_arguments(int, char**) {}
211 #endif
212 }
213 
214 typedef Installer<SURFACEINSTALLER_DATA> InstallerClass;
216 
217 #endif /* defined(DD4HEP_USE_SURFACEINSTALL_HELPER) */
218 #endif // DD4HEP_SURFACEINSTALLER_H
DetectorData.h
dd4hep::SurfaceInstaller::Surfaces
std::map< TGeoVolume *, SurfaceData * > Surfaces
Definition: SurfaceInstaller.h:61
dd4hep::SurfaceInstaller::operator=
SurfaceInstaller & operator=(const SurfaceInstaller &copy)=delete
No assignment.
SURFACEINSTALLER_DATA
#define SURFACEINSTALLER_DATA
Definition: CaloFaceBarrel_surfaces.cpp:29
dd4hep::detail::tools::ElementPath
std::vector< DetElement > ElementPath
Definition: DetectorTools.h:38
dd4hep::rec::Vector3D
Definition: Vector3D.h:32
Detector.h
dd4hep::PlacedVolume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:173
dd4hep::rec::VolSurface::volume
Volume volume() const
the volume to which this surface is attached.
Definition: Surface.h:214
dd4hep::SurfaceInstaller::m_det
DetElement m_det
Reference to the detector element of the subdetector.
Definition: SurfaceInstaller.h:66
DD4HEP_USE_SURFACEINSTALL_HELPER
#define DD4HEP_USE_SURFACEINSTALL_HELPER
Definition: CaloFaceBarrel_surfaces.cpp:30
Surface.h
dd4hep::SurfaceInstaller::SurfaceType
rec::SurfaceType SurfaceType
Definition: SurfaceInstaller.h:60
dd4hep::SurfaceInstaller::install
virtual void install(DetElement e, PlacedVolume pv)
Install volume information. Default implementation only prints!
Definition: SurfaceInstaller.cpp:74
dd4hep::rec::VolPlane
VolSurfaceHandle< VolPlaneImpl > VolPlane
Definition: Surface.h:474
dd4hep::rec::volSurfaceList
VolSurfaceList * volSurfaceList(DetElement &det)
Definition: Surface.cpp:528
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::rec::VolSurfaceHandle
Definition: Surface.h:461
dd4hep::Volume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:378
dd4hep::SurfaceInstaller::scan
void scan()
Scan through tree of detector elements.
Definition: SurfaceInstaller.cpp:126
dd4hep::rec::VolSurface
Definition: Surface.h:181
dd4hep::SurfaceInstaller::SurfaceInstaller
SurfaceInstaller()=delete
No default constructor.
DetectorTools.h
dd4hep::SurfaceInstaller::parentVolume
Volume parentVolume(DetElement component) const
Shortcut to access the parent detectorelement's volume.
Definition: SurfaceInstaller.cpp:58
dd4hep::SurfaceInstaller::invalidInstaller
void invalidInstaller(const std::string &msg) const
Indicate error message and throw exception.
Definition: SurfaceInstaller.cpp:47
dd4hep::SurfaceInstaller::run
static long run(Detector &description, int argc, char **argv)
Executor.
Definition: SurfaceInstaller.h:102
dd4hep::SurfaceInstaller::m_surfaces
Surfaces m_surfaces
Map of surface instances keyed by the logical volume.
Definition: SurfaceInstaller.h:68
dd4hep::SurfaceInstaller::m_detDesc
Detector & m_detDesc
Reference to the Detector instance.
Definition: SurfaceInstaller.h:64
dd4hep::SurfaceInstaller::PlacementPath
detail::tools::PlacementPath PlacementPath
Definition: SurfaceInstaller.h:58
dd4hep::rec::SurfaceType
Definition: ISurface.h:140
DECLARE_SURFACE_INSTALLER
#define DECLARE_SURFACE_INSTALLER(name, class)
Definition: SurfaceInstaller.h:108
dd4hep::rec::VolSurfaceBase
Definition: Surface.h:43
DetFactoryHelper.h
dd4hep::SurfaceInstaller::placementTranslation
const double * placementTranslation(DetElement component) const
Shortcut to access the translation vector of a given component.
Definition: SurfaceInstaller.cpp:67
dd4hep::SurfaceInstaller::ElementPath
detail::tools::ElementPath ElementPath
Definition: SurfaceInstaller.h:57
dd4hep::Handle::ptr
T * ptr() const
Access to the held object.
Definition: Handle.h:153
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::detail::tools::PlacementPath
std::vector< PlacedVolume > PlacementPath
Definition: DetectorTools.h:39
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::SurfaceInstaller
Base class to implement surface installers for known detector patterns.
Definition: SurfaceInstaller.h:55
dd4hep::detail::tools::copy
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
Definition: AlignmentTools.cpp:43
dd4hep::SurfaceInstaller::stopScanning
void stopScanning()
Set flag to stop scanning volumes and detector elements.
Definition: SurfaceInstaller.h:86
dd4hep::SurfaceInstaller::~SurfaceInstaller
virtual ~SurfaceInstaller()=default
Default destructor.
dd4hep::SurfaceInstaller::SurfaceData
rec::VolSurfaceBase SurfaceData
Definition: SurfaceInstaller.h:59
dd4hep::SurfaceInstaller::SurfaceInstaller
SurfaceInstaller(const SurfaceInstaller &copy)=delete
No copy constructor.
dd4hep::SurfaceInstaller::m_stopScanning
bool m_stopScanning
Flag to inhibit useless further scans.
Definition: SurfaceInstaller.h:70
dd4hep::rec::VolSurface::ptr
VolSurfaceBase * ptr() const
pointer to underlying object
Definition: Surface.h:217