File indexing completed on 2025-01-18 09:55:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef DDG4_GEANT4HANDLE_H
0015 #define DDG4_GEANT4HANDLE_H
0016
0017
0018 #include <DD4hep/ComponentProperties.h>
0019 #include <DD4hep/Detector.h>
0020
0021
0022 #include <string>
0023 #include <memory>
0024
0025
0026 namespace dd4hep {
0027
0028
0029 namespace sim {
0030
0031
0032 class Geant4Kernel;
0033 class Geant4Action;
0034
0035
0036
0037
0038
0039
0040
0041 template <typename TYPE> class Geant4Handle {
0042 protected:
0043 void checked_assign(TYPE* p);
0044 TYPE* null() { return nullptr; }
0045 public:
0046
0047 mutable TYPE* value {nullptr};
0048
0049 explicit Geant4Handle() = default;
0050
0051 Geant4Handle(TYPE* typ);
0052
0053 template <typename T> Geant4Handle(T* typ) : value(0) {
0054 checked_assign(dynamic_cast<TYPE*>(typ));
0055 }
0056
0057 Geant4Handle(const Geant4Handle& handle);
0058
0059 Geant4Handle(Geant4Handle&& handle);
0060
0061 Geant4Handle(Geant4Kernel&, const char* type_name, bool shared=false);
0062
0063 Geant4Handle(Geant4Kernel&, const std::string& type_name, bool shared=false);
0064
0065 Geant4Handle(Geant4Kernel& ctxt, const std::string& type_name, const std::string& detector, bool shared=false);
0066
0067 ~Geant4Handle();
0068
0069 Property& operator[](const std::string& property_name) const;
0070
0071 Geant4Handle& operator=(const Geant4Handle& handle);
0072
0073 Geant4Handle& operator=(Geant4Handle&& handle);
0074
0075 Geant4Handle& operator=(TYPE* ptr);
0076
0077 bool operator!() const;
0078
0079 Geant4Action* action() const;
0080
0081 TYPE* operator->() const;
0082
0083 operator TYPE*() const;
0084
0085 TYPE* get() const;
0086
0087 TYPE* release();
0088 };
0089
0090
0091
0092
0093
0094
0095
0096 class KernelHandle {
0097 public:
0098
0099 mutable Geant4Kernel* value {nullptr};
0100
0101 explicit KernelHandle();
0102
0103 explicit KernelHandle(Geant4Kernel* k);
0104
0105 KernelHandle(const KernelHandle& k) : value(k.value) {}
0106
0107 ~KernelHandle() { }
0108
0109 operator Geant4Kernel*() const { return value; }
0110
0111 Geant4Kernel* get() const { return value; }
0112
0113 Geant4Kernel* operator->() const { return value; }
0114
0115 KernelHandle worker();
0116
0117 void destroy();
0118 };
0119
0120 }
0121 }
0122
0123 #endif