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_GEANT4DATACONVERSION_H
0015 #define DDG4_GEANT4DATACONVERSION_H
0016
0017
0018 #include <DD4hep/VolumeManager.h>
0019 #include <DD4hep/DetElement.h>
0020 #include <typeinfo>
0021
0022
0023 namespace dd4hep {
0024
0025
0026 namespace sim {
0027
0028
0029
0030
0031
0032
0033
0034 class Geant4ConversionHelper {
0035 public:
0036
0037 Geant4ConversionHelper();
0038
0039 virtual ~Geant4ConversionHelper();
0040
0041 static std::string encoding(VolumeManager vm, VolumeID vid);
0042
0043 static std::string encoding(Handle<SensitiveDetectorObject> sd);
0044
0045 static std::string encoding(Readout ro);
0046 };
0047
0048
0049
0050
0051
0052
0053
0054 template <typename OUTPUT, typename ARGS> class Geant4Conversion : public Geant4ConversionHelper {
0055 public:
0056 typedef ARGS arg_t;
0057 typedef OUTPUT output_t;
0058 typedef Geant4Conversion<output_t, arg_t> self_t;
0059 typedef std::map<const std::type_info*, Geant4Conversion*> Converters;
0060 static Converters& conversions();
0061 static const Geant4Conversion& converter(const std::type_info& typ);
0062
0063 Geant4Conversion();
0064
0065 virtual ~Geant4Conversion();
0066 virtual OUTPUT* operator()(const ARGS& args) const = 0;
0067 };
0068 }
0069 }
0070
0071 #if defined(DDG4_MAKE_INSTANTIATIONS)
0072 #include <stdexcept>
0073
0074
0075
0076
0077 namespace dd4hep {
0078
0079
0080
0081
0082 namespace sim {
0083
0084 template <typename OUTPUT,typename ARGS>
0085 Geant4Conversion<OUTPUT,ARGS>::Geant4Conversion()
0086 : Geant4ConversionHelper()
0087 {
0088 }
0089
0090 template <typename OUTPUT,typename ARGS>
0091 Geant4Conversion<OUTPUT,ARGS>::~Geant4Conversion()
0092 {
0093 }
0094
0095 template <typename OUTPUT,typename ARGS>
0096 typename Geant4Conversion<OUTPUT,ARGS>::Converters&
0097 Geant4Conversion<OUTPUT,ARGS>::conversions()
0098 {
0099 static Converters s_converter;
0100 return s_converter;
0101 }
0102
0103 template <typename OUTPUT, typename ARGS>
0104 const Geant4Conversion<OUTPUT,ARGS>&
0105 Geant4Conversion<OUTPUT,ARGS>::converter(const std::type_info& typ)
0106 {
0107 typename Converters::const_iterator i = conversions().find(&typ);
0108 if ( i != conversions().end() ) {
0109 return *((*i).second);
0110 }
0111 throw std::runtime_error(typeName(typeid(self_t))+
0112 ": No appropriate LCIO_OUTPUT conversion "
0113 "mechanism known for tag:"+
0114 typeName(typ));
0115 }
0116
0117
0118
0119
0120
0121
0122
0123 template <typename OUTPUT, typename ARGS, typename TAG>
0124 class Geant4DataConversion : public Geant4Conversion<OUTPUT,ARGS> {
0125 public:
0126 typedef TAG tag_t;
0127 typedef ARGS arg_t;
0128 typedef OUTPUT output_t;
0129 typedef Geant4Conversion<output_t,arg_t> self_t;
0130 Geant4DataConversion(void*) : Geant4Conversion<OUTPUT,ARGS>()
0131 {
0132 this->self_t::conversions().emplace(&typeid(TAG),this);
0133
0134 }
0135 virtual OUTPUT* operator()(const ARGS& args) const;
0136 };
0137
0138 }
0139 }
0140
0141 #define GEANT4_CNAME(a,b) a ## _instance_ ## b
0142 #define DECLARE_GEANT4_DATACONVERTER(output_type,args_type,tag,serial) \
0143 dd4hep::sim::Geant4DataConversion<output_type,args_type,tag> GEANT4_CNAME(s_g4_data_cnv,serial) (0);
0144
0145 #define DECLARE_GEANT4_HITCONVERTER(output_type,args_type,tag) DECLARE_GEANT4_DATACONVERTER(output_type,args_type,tag,__LINE__)
0146
0147 #endif
0148
0149 #endif