Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 09:58:04

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 #ifndef DD4HEP_SURFACEINSTALLER_H
0014 #define DD4HEP_SURFACEINSTALLER_H 1
0015 
0016 // Framework include files
0017 #include <DD4hep/Detector.h>
0018 #include <DD4hep/DetectorTools.h>
0019 #include <DD4hep/DetFactoryHelper.h>
0020 
0021 // C/C++ include files
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 /// Namespace for the AIDA detector description toolkit
0036 namespace dd4hep  {
0037   
0038   /// Namespace for the reconstruction part of the AIDA detector description toolkit
0039   namespace rec  {
0040     /// Class describing surface data
0041     //    class SurfaceData;
0042     class VolSurfaceBase;
0043   }
0044   
0045   /// Base class to implement surface installers for known detector patterns
0046   /*
0047    *  The class scans the geometry of a subdetector and gives callbacks
0048    *  to user classes, which then should install in the proper callback
0049    *  routines the surface instances to the detector elements.
0050    *
0051    *  \author  M.Frank
0052    *  \version 1.0
0053    *  \ingroup DD4HEP
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     /// Reference to the Detector instance
0064     Detector&         m_detDesc;
0065     /// Reference to the detector element of the subdetector
0066     DetElement    m_det;
0067     /// Map of surface instances keyed by the logical volume
0068     Surfaces      m_surfaces;
0069     /// Flag to inhibit useless further scans
0070     bool          m_stopScanning;
0071     /// Scan through tree of detector elements
0072     void scan(DetElement de);
0073 
0074   public:
0075     /// No default constructor
0076     SurfaceInstaller() = delete;
0077     /// No copy constructor
0078     SurfaceInstaller(const SurfaceInstaller& copy) = delete;
0079     /// Initializing constructor
0080     SurfaceInstaller(Detector& description, int argc, char** argv);
0081     /// Default destructor
0082     virtual ~SurfaceInstaller() = default;
0083     /// No assignment
0084     SurfaceInstaller& operator=(const SurfaceInstaller& copy) = delete;
0085     /// Set flag to stop scanning volumes and detector elements
0086     void stopScanning()   {  m_stopScanning = true;   }
0087     /// Indicate error message and throw exception
0088     void invalidInstaller(const std::string& msg) const;
0089     /// Shortcut to access the parent detectorelement's volume
0090     Volume parentVolume(DetElement component)  const;
0091     /// Shortcut to access the translation vector of a given component
0092     const double* placementTranslation(DetElement component)  const;
0093     /// Scan through tree of detector elements
0094     void scan();
0095     /// Install volume information. Default implementation only prints!
0096     virtual void install(DetElement e, PlacedVolume pv);
0097     /// Executor
0098     template <typename T> static long run(Detector& description,int argc,char** argv);
0099   };
0100 
0101   /// Action routine to execute the test
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 }   // End namespace dd4hep
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 /** If you want to save yourself some typing when creating surface installers,
0127  *  set the compile macro DD4HEP_USE_SURFACEINSTALL_HELPER LOCALLY !
0128  *  This will then enable the code below and the only thing you will have to
0129  *  type is the installer member function to create a measurement surface for
0130  *  a given volume.
0131  *
0132  *  \author  M.Frank
0133  *  \version 1.0
0134  *  \ingroup DD4HEP
0135  */
0136 namespace {
0137 
0138   /// Installer class template to create surface installer plugins
0139   /*
0140    *  See the base class SurfaceInstaller for further details.
0141    *
0142    *  \author  M.Frank
0143    *  \version 1.0
0144    *  \ingroup DD4HEP
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     /// Default (empty argument handler
0155     void handle_arguments(int argc, char** argv);
0156   public:
0157     /// No default constructor
0158     Installer() = delete;
0159     /// No copy constructor
0160     Installer(const Installer& copy) = delete;
0161     /// Initializing constructor
0162     Installer(dd4hep::Detector& description, int argc, char** argv);
0163     /// Default destructor
0164     virtual ~Installer() = default;
0165     /// No assignment
0166     Installer& operator=(const Installer& copy) = delete;
0167     /// Install volume information. Default implementation only prints!
0168     virtual void install(dd4hep::DetElement component, dd4hep::PlacedVolume pv);
0169     /// Try to handle surface using the surface cache
0170     bool handleUsingCache(dd4hep::DetElement comp, dd4hep::Volume vol)  const;
0171     /// Add a new surface to the surface manager and the local cache
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   /// Initializing constructor
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   /// Handle surface installation using cached surfaces.
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   /// Add a new surface to the surface manager and the local cache
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   /// Default (empty argument handler
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 /* defined(DD4HEP_USE_SURFACEINSTALL_HELPER) */
0218 #endif // DD4HEP_SURFACEINSTALLER_H