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_GEANT4DATACONVERSION_H
0015 #define DDG4_GEANT4DATACONVERSION_H
0016 
0017 // Framework include files
0018 #include <DD4hep/VolumeManager.h>
0019 #include <DD4hep/DetElement.h>
0020 #include <typeinfo>
0021 
0022 /// Namespace for the AIDA detector description toolkit
0023 namespace dd4hep {
0024 
0025   /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
0026   namespace sim {
0027 
0028     /// Helper class for data conversion
0029     /**
0030      *  \author  M.Frank
0031      *  \version 1.0
0032      *  \ingroup DD4HEP_SIMULATION
0033      */
0034     class Geant4ConversionHelper {
0035     public:
0036       /// Default constructor
0037       Geant4ConversionHelper();
0038       /// Default destructor
0039       virtual ~Geant4ConversionHelper();
0040       /// Access to the data encoding using the volume manager and a specified volume id
0041       static std::string encoding(VolumeManager vm, VolumeID vid);
0042       /// Access to the hit encoding in this sensitive detector
0043       static std::string encoding(Handle<SensitiveDetectorObject> sd);
0044       /// Access to the hit encoding in this readout object
0045       static std::string encoding(Readout ro);
0046     };
0047 
0048     /// Data conversion class
0049     /**
0050      *  \author  M.Frank
0051      *  \version 1.0
0052      *  \ingroup DD4HEP_SIMULATION
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       /// Default constructor
0063       Geant4Conversion();
0064       /// Default destructor
0065       virtual ~Geant4Conversion();
0066       virtual OUTPUT* operator()(const ARGS& args) const = 0;
0067     };
0068   }    // End namespace sim
0069 }      // End namespace dd4hep
0070 
0071 #if defined(DDG4_MAKE_INSTANTIATIONS)
0072 #include <stdexcept>
0073 
0074 /*
0075  *   dd4hep namespace declaration
0076  */
0077 namespace dd4hep {
0078 
0079   /*
0080    *   Simulation namespace declaration
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     /// Template class for data conversion. To be specialized by the client.
0118     /**
0119      *  \author  M.Frank
0120      *  \version 1.0
0121      *  \ingroup DD4HEP_SIMULATION
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         //std::cout << "Registered " << typeName(typeid(*this)) << std::endl;
0134       }
0135       virtual OUTPUT* operator()(const ARGS& args) const;
0136     };
0137 
0138   }    // End namespace sim
0139 }      // End namespace dd4hep
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 // DDG4_GEANT4DATACONVERSION_H