DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4DataConversion.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 #ifndef DDG4_GEANT4DATACONVERSION_H
15 #define DDG4_GEANT4DATACONVERSION_H
16 
17 // Framework include files
18 #include <DD4hep/VolumeManager.h>
19 #include <DD4hep/DetElement.h>
20 #include <typeinfo>
21 
23 namespace dd4hep {
24 
26  namespace sim {
27 
29 
35  public:
39  virtual ~Geant4ConversionHelper();
41  static std::string encoding(VolumeManager vm, VolumeID vid);
43  static std::string encoding(Handle<SensitiveDetectorObject> sd);
45  static std::string encoding(Readout ro);
46  };
47 
49 
54  template <typename OUTPUT, typename ARGS> class Geant4Conversion : public Geant4ConversionHelper {
55  public:
56  typedef ARGS arg_t;
57  typedef OUTPUT output_t;
59  typedef std::map<const std::type_info*, Geant4Conversion*> Converters;
61  static const Geant4Conversion& converter(const std::type_info& typ);
65  virtual ~Geant4Conversion();
66  virtual OUTPUT* operator()(const ARGS& args) const = 0;
67  };
68  } // End namespace sim
69 } // End namespace dd4hep
70 
71 #if defined(DDG4_MAKE_INSTANTIATIONS)
72 #include <stdexcept>
73 
74 /*
75  * dd4hep namespace declaration
76  */
77 namespace dd4hep {
78 
79  /*
80  * Simulation namespace declaration
81  */
82  namespace sim {
83 
84  template <typename OUTPUT,typename ARGS>
86  : Geant4ConversionHelper()
87  {
88  }
89 
90  template <typename OUTPUT,typename ARGS>
92  {
93  }
94 
95  template <typename OUTPUT,typename ARGS>
98  {
99  static Converters s_converter;
100  return s_converter;
101  }
102 
103  template <typename OUTPUT, typename ARGS>
104  const Geant4Conversion<OUTPUT,ARGS>&
105  Geant4Conversion<OUTPUT,ARGS>::converter(const std::type_info& typ)
106  {
107  typename Converters::const_iterator i = conversions().find(&typ);
108  if ( i != conversions().end() ) {
109  return *((*i).second);
110  }
111  throw std::runtime_error(typeName(typeid(self_t))+
112  ": No appropriate LCIO_OUTPUT conversion "
113  "mechanism known for tag:"+
114  typeName(typ));
115  }
116 
118 
123  template <typename OUTPUT, typename ARGS, typename TAG>
124  class Geant4DataConversion : public Geant4Conversion<OUTPUT,ARGS> {
125  public:
126  typedef TAG tag_t;
127  typedef ARGS arg_t;
128  typedef OUTPUT output_t;
129  typedef Geant4Conversion<output_t,arg_t> self_t;
130  Geant4DataConversion(void*) : Geant4Conversion<OUTPUT,ARGS>()
131  {
132  this->self_t::conversions().emplace(&typeid(TAG),this);
133  //std::cout << "Registered " << typeName(typeid(*this)) << std::endl;
134  }
135  virtual OUTPUT* operator()(const ARGS& args) const override;
136  };
137 
138  } // End namespace sim
139 } // End namespace dd4hep
140 
141 #define GEANT4_CNAME(a,b) a ## _instance_ ## b
142 #define DECLARE_GEANT4_DATACONVERTER(output_type,args_type,tag,serial) \
143  dd4hep::sim::Geant4DataConversion<output_type,args_type,tag> GEANT4_CNAME(s_g4_data_cnv,serial) (0);
144 
145 #define DECLARE_GEANT4_HITCONVERTER(output_type,args_type,tag) DECLARE_GEANT4_DATACONVERTER(output_type,args_type,tag,__LINE__)
146 
147 #endif
148 
149 #endif // DDG4_GEANT4DATACONVERSION_H
dd4hep::sim::Geant4Conversion::arg_t
ARGS arg_t
Definition: Geant4DataConversion.h:56
dd4hep::sim::Geant4ConversionHelper::~Geant4ConversionHelper
virtual ~Geant4ConversionHelper()
Default destructor.
Definition: Geant4DataConversion.cpp:24
dd4hep::sim::Geant4Conversion
Data conversion class.
Definition: Geant4DataConversion.h:54
dd4hep::Handle< SensitiveDetectorObject >
dd4hep::sim::Geant4Conversion::output_t
OUTPUT output_t
Definition: Geant4DataConversion.h:57
VolumeManager.h
dd4hep::sim::Geant4Conversion::Converters
std::map< const std::type_info *, Geant4Conversion * > Converters
Definition: Geant4DataConversion.h:59
dd4hep::VolumeManager
Class to support the retrieval of detector elements and volumes given a valid identifier.
Definition: VolumeManager.h:135
dd4hep::sim::Geant4Conversion::Geant4Conversion
Geant4Conversion()
Default constructor.
dd4hep::sim::Geant4Conversion::conversions
static Converters & conversions()
dd4hep::sim::Geant4Conversion::~Geant4Conversion
virtual ~Geant4Conversion()
Default destructor.
dd4hep::sim::Geant4ConversionHelper::Geant4ConversionHelper
Geant4ConversionHelper()
Default constructor.
Definition: Geant4DataConversion.cpp:20
VolumeID
dd4hep::DDSegmentation::VolumeID VolumeID
Definition: SegmentationDictionary.h:50
DetElement.h
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::sim::Geant4ConversionHelper
Helper class for data conversion.
Definition: Geant4DataConversion.h:34
dd4hep::Readout
Handle to the implementation of the readout structure of a subdetector.
Definition: Readout.h:38
dd4hep::sim::Geant4Conversion::converter
static const Geant4Conversion & converter(const std::type_info &typ)
dd4hep::sim::Geant4Conversion::self_t
Geant4Conversion< output_t, arg_t > self_t
Definition: Geant4DataConversion.h:58
dd4hep::sim::Geant4ConversionHelper::encoding
static std::string encoding(VolumeManager vm, VolumeID vid)
Access to the data encoding using the volume manager and a specified volume id.
Definition: Geant4DataConversion.cpp:28
dd4hep::sim::Geant4Conversion::operator()
virtual OUTPUT * operator()(const ARGS &args) const =0