Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:23

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 
0014 #ifndef DDG4_GEANT4HANDLE_H
0015 #define DDG4_GEANT4HANDLE_H
0016 
0017 /// Framework include files
0018 #include <DD4hep/ComponentProperties.h>
0019 #include <DD4hep/Detector.h>
0020 
0021 /// C/C++ include files
0022 #include <string>
0023 #include <memory>
0024 
0025 /// Namespace for the AIDA detector description toolkit
0026 namespace dd4hep {
0027 
0028   /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
0029   namespace sim {
0030 
0031     /// Forward declarations
0032     class Geant4Kernel;
0033     class Geant4Action;
0034 
0035     /// Handle to Geant4 actions with built-in creation mechanism
0036     /**
0037      *  \author  M.Frank
0038      *  \version 1.0
0039      *  \ingroup DD4HEP_SIMULATION
0040      */
0041     template <typename TYPE> class Geant4Handle {
0042     protected:
0043       void checked_assign(TYPE* p);
0044       TYPE* null()  { return nullptr; }
0045     public:
0046       /// Pointer to referenced object
0047       mutable TYPE* value  {nullptr};
0048       /// Default constructor
0049       explicit Geant4Handle() = default;
0050       /// Construction initialized with object pointer
0051       Geant4Handle(TYPE* typ);
0052       /// Cross type initialization
0053       template <typename T> Geant4Handle(T* typ) : value(0) {
0054         checked_assign(dynamic_cast<TYPE*>(typ));
0055       }
0056       /// Copy constructor
0057       Geant4Handle(const Geant4Handle& handle);
0058       /// Move constructor
0059       Geant4Handle(Geant4Handle&& handle);
0060       /// Initializing constructor
0061       Geant4Handle(Geant4Kernel&, const char* type_name, bool shared=false);
0062       /// Initializing constructor
0063       Geant4Handle(Geant4Kernel&, const std::string& type_name, bool shared=false);
0064       /// Constructor only implemented for sensitive objects
0065       Geant4Handle(Geant4Kernel& ctxt, const std::string& type_name, const std::string& detector, bool shared=false);
0066       /// Default destructor
0067       ~Geant4Handle();
0068       /// Property accessor
0069       Property& operator[](const std::string& property_name) const;
0070       /// Assignment operator
0071       Geant4Handle& operator=(const Geant4Handle& handle);
0072       /// Move assignment operator
0073       Geant4Handle& operator=(Geant4Handle&& handle);
0074       /// Assignment operator
0075       Geant4Handle& operator=(TYPE* ptr);
0076       /// Validity check
0077       bool operator!() const;
0078       /// Access to the underlying object
0079       Geant4Action* action() const;
0080       /// Access to the underlying object
0081       TYPE* operator->() const;
0082       /// Conversion operator
0083       operator TYPE*() const;
0084       /// Access to the underlying object
0085       TYPE* get() const;
0086       /// Release the underlying object
0087       TYPE* release();
0088     };
0089 
0090     /// Handle to Geant4 actions with built-in creation mechanism
0091     /**
0092      *  \author  M.Frank
0093      *  \version 1.0
0094      *  \ingroup DD4HEP_SIMULATION
0095      */
0096     class KernelHandle {
0097     public:
0098       /// Pointer to referenced object
0099       mutable Geant4Kernel* value {nullptr};
0100       /// Default constructor
0101       explicit KernelHandle();
0102       /// Construction initialized with object pointer
0103       explicit KernelHandle(Geant4Kernel* k);
0104       /// Copy constructor
0105       KernelHandle(const KernelHandle& k) : value(k.value) {}
0106       /// Default destructor
0107       ~KernelHandle()                  {               }
0108       /// Conversion operator
0109       operator Geant4Kernel*() const   { return value; }
0110       /// Access to the underlying object
0111       Geant4Kernel* get() const        { return value; }
0112       /// Access to the underlying object
0113       Geant4Kernel* operator->() const { return value; }
0114       /// Access to worker thread
0115       KernelHandle worker();
0116       /// Destroy referenced object (program termination)
0117       void destroy();
0118     };
0119 
0120   }    // End namespace sim
0121 }      // End namespace dd4hep
0122 
0123 #endif // DDG4_GEANT4HANDLE_H