DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geant4DataConversion.h
Go to the documentation of this file.
1 // $Id: $
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 
15 #ifndef DD4HEP_DDG4_GEANT4CONVERSION_H
16 #define DD4HEP_DDG4_GEANT4CONVERSION_H
17 
18 // Framework include files
19 #include "DD4hep/VolumeManager.h"
20 #include "DD4hep/Detector.h"
21 #include <typeinfo>
22 
24 namespace DD4hep {
25 
27  namespace Simulation {
28 
30 
36  public:
40  virtual ~Geant4ConversionHelper();
46  static std::string encoding(Geometry::Readout ro);
47  };
48 
50 
55  template <typename OUTPUT, typename ARGS> class Geant4Conversion : public Geant4ConversionHelper {
56  public:
57  typedef ARGS arg_t;
58  typedef OUTPUT output_t;
60  typedef std::map<const std::type_info*, Geant4Conversion*> Converters;
61  static Converters& conversions();
62  static const Geant4Conversion& converter(const std::type_info& typ);
66  virtual ~Geant4Conversion();
67  virtual OUTPUT* operator()(const ARGS& args) const = 0;
68  };
69  } // End namespace Simulation
70 } // End namespace DD4hep
71 
72 #if defined(DDG4_MAKE_INSTANTIATIONS)
73 #include <stdexcept>
74 
75 /*
76  * DD4hep namespace declaration
77  */
78 namespace DD4hep {
79 
80  /*
81  * Simulation namespace declaration
82  */
83  namespace Simulation {
84 
85  template <typename OUTPUT,typename ARGS>
87  : Geant4ConversionHelper()
88  {
89  }
90 
91  template <typename OUTPUT,typename ARGS>
93  {
94  }
95 
96  template <typename OUTPUT,typename ARGS>
97  typename Geant4Conversion<OUTPUT,ARGS>::Converters&
99  {
100  static Converters s_converter;
101  return s_converter;
102  }
103 
104  template <typename OUTPUT, typename ARGS>
105  const Geant4Conversion<OUTPUT,ARGS>&
106  Geant4Conversion<OUTPUT,ARGS>::converter(const std::type_info& typ)
107  {
108  typename Converters::const_iterator i = conversions().find(&typ);
109  if ( i != conversions().end() ) {
110  return *((*i).second);
111  }
112  throw std::runtime_error(typeName(typeid(self_t))+
113  ": No appropriate LCIO_OUTPUT conversion "
114  "mechanism known for tag:"+
115  typeName(typ));
116  }
117 
119 
124  template <typename OUTPUT, typename ARGS, typename TAG>
125  class Geant4DataConversion : public Geant4Conversion<OUTPUT,ARGS> {
126  public:
127  typedef TAG tag_t;
128  typedef ARGS arg_t;
129  typedef OUTPUT output_t;
130  typedef Geant4Conversion<output_t,arg_t> self_t;
131  Geant4DataConversion(void*) : Geant4Conversion<OUTPUT,ARGS>()
132  {
133  this->self_t::conversions().insert(make_pair(&typeid(TAG),this));
134  //std::cout << "Registered " << typeName(typeid(*this)) << std::endl;
135  }
136  virtual OUTPUT* operator()(const ARGS& args) const;
137  };
138 
139  } // End namespace Simulation
140 } // End namespace DD4hep
141 
142 #define GEANT4_CNAME(a,b) a ## _instance_ ## b
143 #define DECLARE_GEANT4_DATACONVERTER(output_type,args_type,tag,serial) \
144  DD4hep::Simulation::Geant4DataConversion<output_type,args_type,tag> GEANT4_CNAME(s_g4_data_cnv,serial) (0);
145 
146 #define DECLARE_GEANT4_HITCONVERTER(output_type,args_type,tag) DECLARE_GEANT4_DATACONVERTER(output_type,args_type,tag,__LINE__)
147 
148 #endif
149 
150 #endif // DD4HEP_DDG4_GEANT4CONVERSION_H
Geant4Conversion()
Default constructor.
static std::string encoding(Geometry::VolumeManager vm, Geometry::VolumeManager::VolumeID vid)
Access to the data encoding using the volume manager and a specified volume id.
virtual OUTPUT * operator()(const ARGS &args) const =0
std::map< const std::type_info *, Geant4Conversion * > Converters
std::string typeName(const std::type_info &type)
ABI information about type names.
Definition: Primitives.cpp:186
static const Geant4Conversion & converter(const std::type_info &typ)
Handle to the implementation of the readout structure of a subdetector.
Definition: Readout.h:46
Helper class for data conversion.
virtual ~Geant4ConversionHelper()
Default destructor.
virtual ~Geant4Conversion()
Default destructor.
Class to support the retrieval of detector elements and volumes given a valid identifier.
Definition: VolumeManager.h:70
Handle: a templated class like a shared pointer, which allows specialized access to tgeometry objects...
Definition: Handle.h:87
static Converters & conversions()
Geant4Conversion< output_t, arg_t > self_t