DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SurfaceInstaller.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation for LCD
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_DDREC_SURFACEINSTALLER_H
14 #define DD4HEP_DDREC_SURFACEINSTALLER_H 1
15 
16 // Framework include files
17 #include "DD4hep/LCDD.h"
18 #include "DD4hep/DetectorTools.h"
20 
21 // C/C++ include files
22 #include <map>
23 #include <algorithm>
24 
26 namespace DDSurfaces {
28  class SurfaceType;
29 }
30 
32 namespace DD4hep {
33 
35  namespace DDRec {
37  // class SurfaceData;
38  class VolSurfaceBase;
39  }
40 
52  protected:
61 
62  typedef std::map<TGeoVolume*, SurfaceData* > Surfaces;
72  void scan(DetElement de);
73 
74  public:
76  SurfaceInstaller(LCDD& lcdd, int argc, char** argv);
78  virtual ~SurfaceInstaller() {}
80  void stopScanning() { m_stopScanning = true; }
82  void invalidInstaller(const std::string& msg) const;
86  const double* placementTranslation(DetElement component) const;
88  void scan();
90  virtual void install(DetElement e, PlacedVolume pv);
92  template <typename T> static long run(LCDD& lcdd,int argc,char** argv);
93  };
94 
96  template <typename T> inline long SurfaceInstaller::run(Geometry::LCDD& lcdd,int argc,char** argv) {
97  T installer(lcdd, argc, argv);
98  installer.scan();
99  return 1;
100  }
101 
102 #define DECLARE_SURFACE_INSTALLER(name,class) \
103  namespace DD4hep { \
104  template long SurfaceInstaller::run< class >(Geometry::LCDD& lcdd,int argc,char** argv); \
105  } \
106  DECLARE_APPLY(name,SurfaceInstaller::run< class >)
107 
108 } // End namespace DD4hep
109 
110 
111 #if defined(DD4HEP_USE_SURFACEINSTALL_HELPER)
112 
113 #include "DDRec/Surface.h"
114 #include "DDRec/DetectorData.h"
115 
116 #ifndef SURFACEINSTALLER_DATA
117 typedef void* SURFACEINSTALLER_DATA;
118 #endif
119 
130 namespace {
131 
140  template <typename UserData> class Installer : public DD4hep::SurfaceInstaller {
141  public:
142  typedef DD4hep::DDRec::Vector3D Vector3D;
143  typedef DD4hep::DDRec::VolSurface VolSurface;
145  typedef DDSurfaces::SurfaceType Type;
146  UserData data;
147 
149  void handle_arguments(int argc, char** argv);
150  public:
152  Installer(LCDD& lcdd, int argc, char** argv);
154  virtual ~Installer() {}
156  virtual void install(DetElement component, PlacedVolume pv);
158  bool handleUsingCache(DetElement comp, Volume vol) const;
160  void addSurface(DetElement component, const DD4hep::DDRec::VolSurface& surf);
161  template <typename T> bool checkShape(const T& shape) const {
162  if ( shape.isValid() ) return true;
163  invalidInstaller("Shape is not of the required type:"+DD4hep::typeName(typeid(T)));
164  return false;
165  }
166  };
167 
169  template <typename UserData>
170  Installer<UserData>::Installer(LCDD& lcdd, int argc, char** argv)
171  : DD4hep::SurfaceInstaller(lcdd, argc, argv)
172  {
173  handle_arguments(argc, argv);
174  }
175 
177  template <typename UserData>
178  bool Installer<UserData>::handleUsingCache(DetElement comp, Volume vol) const {
179  Surfaces::const_iterator is = m_surfaces.find(vol.ptr());
180  if ( is != m_surfaces.end() ) {
181  VolSurface surf((*is).second);
182  DD4hep::DDRec::volSurfaceList(comp)->push_back(surf);
183  return true;
184  }
185  return false;
186  }
187 
189  template <typename UserData>
190  void Installer<UserData>::addSurface(DetElement component, const DD4hep::DDRec::VolSurface& surf) {
191  m_surfaces.insert(std::make_pair(surf.volume().ptr(),surf.ptr()));
192  DD4hep::DDRec::volSurfaceList(component)->push_back(surf);
193  }
194 
196  template <typename UserData> void Installer<UserData>::handle_arguments(int, char**) {}
197 #ifndef SURFACEINSTALLER_DATA
198  template <> void Installer<SURFACEINSTALLER_DATA>::handle_arguments(int, char**) {}
199 #endif
200 }
201 
202 typedef Installer<SURFACEINSTALLER_DATA> InstallerClass;
204 
205 #endif /* defined(DD4HEP_USE_SURFACEINSTALL_HELPER) */
206 
207 #endif /* DD4HEP_DDREC_SURFACEINSTALLER_H */
const double * placementTranslation(DetElement component) const
Shortcut to access the translation vector of a given component.
DDSurfaces::SurfaceType SurfaceType
DetElement m_det
Reference to the detector element of the subdetector.
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:135
void stopScanning()
Set flag to stop scanning volumes and detector elements.
Volume parentVolume(DetElement component) const
Shortcut to access the parent detectorelement's volume.
void invalidInstaller(const std::string &msg) const
Indicate error message and throw exception.
Geometry::DetectorTools::PlacementPath PlacementPath
std::string typeName(const std::type_info &type)
ABI information about type names.
Definition: Primitives.cpp:186
std::vector< DetElement > ElementPath
Definition: DetectorTools.h:40
LCDD & m_lcdd
Reference to the LCDD instance.
SurfaceInstaller(LCDD &lcdd, int argc, char **argv)
Initializing constructor.
return e
Definition: Volumes.cpp:297
#define SURFACEINSTALLER_DATA
T * ptr() const
Access to the held object.
Definition: Handle.h:149
bool m_stopScanning
Flag to inhibit useless further scans.
DD4hep::Geometry::DetElement DetElement
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:237
void scan()
Scan through tree of detector elements.
#define DECLARE_SURFACE_INSTALLER(name, class)
std::vector< PlacedVolume > PlacementPath
Definition: DetectorTools.h:41
virtual ~SurfaceInstaller()
Default destructor.
#define DD4HEP_USE_SURFACEINSTALL_HELPER
Geometry::DetElement DetElement
DDRec::VolSurfaceBase SurfaceData
static ComponentCast * component(void *p)
Geometry::PlacedVolume PlacedVolume
VolSurfaceHandle< VolPlaneImpl > VolPlane
Definition: Surface.h:487
virtual void install(DetElement e, PlacedVolume pv)
Install volume information. Default implementation only prints!
VolSurfaceBase * ptr() const
pointer to underlying object
Definition: Surface.h:230
static long run(LCDD &lcdd, int argc, char **argv)
Executor.
Geometry::Volume volume() const
the volume to which this surface is attached.
Definition: Surface.h:227
Handle class describing a detector element.
Definition: Detector.h:172
VolSurfaceList * volSurfaceList(DetElement &det)
Definition: Surface.cpp:511
Geometry::DetectorTools::ElementPath ElementPath
std::map< TGeoVolume *, SurfaceData * > Surfaces
The main interface to the DD4hep detector description package.
Definition: LCDD.h:82
Surfaces m_surfaces
Map of surface instances keyed by the logical volume.