File indexing completed on 2025-02-21 09:58:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DD4HEP_SURFACEINSTALLER_H
0014 #define DD4HEP_SURFACEINSTALLER_H 1
0015
0016
0017 #include <DD4hep/Detector.h>
0018 #include <DD4hep/DetectorTools.h>
0019 #include <DD4hep/DetFactoryHelper.h>
0020
0021
0022 #include <map>
0023 #include <algorithm>
0024
0025
0026
0027 namespace dd4hep{
0028 namespace rec{
0029 class VolSurfaceBase;
0030 class SurfaceType;
0031 }
0032 }
0033
0034
0035
0036 namespace dd4hep {
0037
0038
0039 namespace rec {
0040
0041
0042 class VolSurfaceBase;
0043 }
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055 class SurfaceInstaller {
0056 protected:
0057 typedef detail::tools::ElementPath ElementPath;
0058 typedef detail::tools::PlacementPath PlacementPath;
0059 typedef rec::VolSurfaceBase SurfaceData;
0060 typedef rec::SurfaceType SurfaceType;
0061 typedef std::map<TGeoVolume*, SurfaceData* > Surfaces;
0062
0063
0064 Detector& m_detDesc;
0065
0066 DetElement m_det;
0067
0068 Surfaces m_surfaces;
0069
0070 bool m_stopScanning;
0071
0072 void scan(DetElement de);
0073
0074 public:
0075
0076 SurfaceInstaller() = delete;
0077
0078 SurfaceInstaller(const SurfaceInstaller& copy) = delete;
0079
0080 SurfaceInstaller(Detector& description, int argc, char** argv);
0081
0082 virtual ~SurfaceInstaller() = default;
0083
0084 SurfaceInstaller& operator=(const SurfaceInstaller& copy) = delete;
0085
0086 void stopScanning() { m_stopScanning = true; }
0087
0088 void invalidInstaller(const std::string& msg) const;
0089
0090 Volume parentVolume(DetElement component) const;
0091
0092 const double* placementTranslation(DetElement component) const;
0093
0094 void scan();
0095
0096 virtual void install(DetElement e, PlacedVolume pv);
0097
0098 template <typename T> static long run(Detector& description,int argc,char** argv);
0099 };
0100
0101
0102 template <typename T> inline long SurfaceInstaller::run(Detector& description,int argc,char** argv) {
0103 T installer(description, argc, argv);
0104 installer.scan();
0105 return 1;
0106 }
0107
0108 #define DECLARE_SURFACE_INSTALLER(name,class) \
0109 namespace dd4hep { \
0110 template long SurfaceInstaller::run< class >(Detector& description,int argc,char** argv); \
0111 } \
0112 DECLARE_APPLY(name,SurfaceInstaller::run< class >)
0113
0114 }
0115
0116
0117 #if defined(DD4HEP_USE_SURFACEINSTALL_HELPER)
0118
0119 #include <DDRec/Surface.h>
0120 #include <DDRec/DetectorData.h>
0121
0122 #ifndef SURFACEINSTALLER_DATA
0123 typedef void* SURFACEINSTALLER_DATA;
0124 #endif
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136 namespace {
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146 template <typename UserData> class Installer : public dd4hep::SurfaceInstaller {
0147 public:
0148 typedef dd4hep::rec::Vector3D Vector3D;
0149 typedef dd4hep::rec::VolSurface VolSurface;
0150 typedef dd4hep::rec::VolPlane VolPlane;
0151 typedef dd4hep::rec::SurfaceType Type;
0152 UserData data;
0153
0154
0155 void handle_arguments(int argc, char** argv);
0156 public:
0157
0158 Installer() = delete;
0159
0160 Installer(const Installer& copy) = delete;
0161
0162 Installer(dd4hep::Detector& description, int argc, char** argv);
0163
0164 virtual ~Installer() = default;
0165
0166 Installer& operator=(const Installer& copy) = delete;
0167
0168 virtual void install(dd4hep::DetElement component, dd4hep::PlacedVolume pv);
0169
0170 bool handleUsingCache(dd4hep::DetElement comp, dd4hep::Volume vol) const;
0171
0172 void addSurface(dd4hep::DetElement component, const dd4hep::rec::VolSurface& surf);
0173 template <typename T> bool checkShape(const T& shape) const {
0174 if ( shape.isValid() ) return true;
0175 invalidInstaller("Shape is not of the required type:"+dd4hep::typeName(typeid(T)));
0176 return false;
0177 }
0178 };
0179
0180
0181 template <typename UserData>
0182 Installer<UserData>::Installer(dd4hep::Detector& description, int argc, char** argv)
0183 : dd4hep::SurfaceInstaller(description, argc, argv), data()
0184 {
0185 handle_arguments(argc, argv);
0186 }
0187
0188
0189 template <typename UserData>
0190 bool Installer<UserData>::handleUsingCache(dd4hep::DetElement comp, dd4hep::Volume vol) const {
0191 Surfaces::const_iterator is = m_surfaces.find(vol.ptr());
0192 if ( is != m_surfaces.end() ) {
0193 VolSurface surf((*is).second);
0194 dd4hep::rec::volSurfaceList(comp)->emplace_back(surf);
0195 return true;
0196 }
0197 return false;
0198 }
0199
0200
0201 template <typename UserData>
0202 void Installer<UserData>::addSurface(dd4hep::DetElement component, const dd4hep::rec::VolSurface& surf) {
0203 m_surfaces.insert(std::make_pair(surf.volume().ptr(),surf.ptr()));
0204 dd4hep::rec::volSurfaceList(component)->emplace_back(surf);
0205 }
0206
0207
0208 template <typename UserData> void Installer<UserData>::handle_arguments(int, char**) {}
0209 #ifndef SURFACEINSTALLER_DATA
0210 template <> void Installer<SURFACEINSTALLER_DATA>::handle_arguments(int, char**) {}
0211 #endif
0212 }
0213
0214 typedef Installer<SURFACEINSTALLER_DATA> InstallerClass;
0215 DECLARE_SURFACE_INSTALLER(DD4HEP_USE_SURFACEINSTALL_HELPER,InstallerClass)
0216
0217 #endif
0218 #endif