diff --git a/DDCore/include/DD4hep/BasicGrammar_inl.h b/DDCore/include/DD4hep/BasicGrammar_inl.h index c63ec7056f1f3143f6ab5c447699f4ffbbd9e40e..e6d2fd580937982a2c27ef4c2ac83326f1ec6502 100644 --- a/DDCore/include/DD4hep/BasicGrammar_inl.h +++ b/DDCore/include/DD4hep/BasicGrammar_inl.h @@ -40,15 +40,9 @@ #include "DD4hep/Parsers.h" #include "DD4hep/ToStream.h" namespace DD4hep { XmlTools::Evaluator& g4Evaluator(); } -namespace { static XmlTools::Evaluator& s__eval(DD4hep::g4Evaluator()); } -#endif #endif - -#ifndef DD4HEP_PARSERS_NO_ROOT -#include "Math/Point3D.h" -#include "Math/Vector3D.h" -#include "Math/Vector4D.h" #endif +namespace { static XmlTools::Evaluator& s__eval(DD4hep::g4Evaluator()); } // C/C++ include files #include <string> diff --git a/DDCore/include/DD4hep/Plugins.h b/DDCore/include/DD4hep/Plugins.h index c96eb6f407b6f4b483693bc63c482d065336e31e..02173cf274b99062662c99c15058b6398745151b 100644 --- a/DDCore/include/DD4hep/Plugins.h +++ b/DDCore/include/DD4hep/Plugins.h @@ -22,6 +22,9 @@ #ifndef DD4HEP_PARSERS_NO_ROOT #include "RVersion.h" +#if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0) +#define DD4HEP_ROOT_VERSION_5 1 +#endif #endif /// Namespace for the AIDA detector description toolkit @@ -112,7 +115,7 @@ namespace DD4hep { const std::type_info& signature_type, const std::type_info& return_type); -#if !defined(DD4HEP_PARSERS_NO_ROOT) && ROOT_VERSION_CODE < ROOT_VERSION(6,0,0) +#if defined(DD4HEP_ROOT_VERSION_5) template <typename R> static R Create(const std::string& name); template <typename R, typename A0> @@ -145,7 +148,7 @@ namespace DD4hep { public: typedef PluginService svc_t; typedef SIGNATURE signature_t; -#if !defined(DD4HEP_PARSERS_NO_ROOT) && ROOT_VERSION_CODE < ROOT_VERSION(6,0,0) +#if defined(DD4HEP_ROOT_VERSION_5) typedef void (*stub_t)(void *retaddr, void*, const std::vector<void*>& arg, void*); static void add(const char* name, stub_t stub); #else @@ -156,7 +159,12 @@ namespace DD4hep { }; } /* End namespace DD4hep */ -#if !defined(DD4HEP_PARSERS_NO_ROOT) && ROOT_VERSION_CODE < ROOT_VERSION(6,0,0) +namespace { + /// Base factory template + template <typename P, typename S> class Factory {}; +} + +#if defined(DD4HEP_ROOT_VERSION_5) #define DD4HEP_FACTORY_CALL(type,name,signature) DD4hep::PluginRegistry<signature>::add(name,Factory<type,signature>::wrapper); #else namespace DD4hep { diff --git a/DDCore/src/Plugins.cpp b/DDCore/src/Plugins.cpp index c6178fbee791db25142c7c00e49f05e5bde6d613..143d1b0dc7554192f6c89c0e8429c40ee80d326e 100644 --- a/DDCore/src/Plugins.cpp +++ b/DDCore/src/Plugins.cpp @@ -13,11 +13,10 @@ //========================================================================== // Framework include files -//#include "DD4hep/LCDD.h" -//#include "DD4hep/Handle.h" +#include "DD4hep/Plugins.h" +#if defined(DD4HEP_ROOT_VERSION_5) #include "DD4hep/Plugins.inl" -//#include "DD4hep/GeoHandler.h" -//#include "XML/XMLElements.h" +#endif using namespace std; using namespace DD4hep; @@ -40,7 +39,7 @@ bool PluginService::setDebug(bool new_value) { return old_value; } -#if !defined(DD4HEP_PARSERS_NO_ROOT) && ROOT_VERSION_CODE < ROOT_VERSION(6,0,0) +#if !defined(DD4HEP_PARSERS_NO_ROOT) && DD4HEP_ROOT_VERSION_5 /// Default constructor PluginDebug::PluginDebug(int dbg) @@ -66,13 +65,14 @@ string PluginDebug::missingFactory(const string& name) const { void* PluginService::getCreator(const std::string&, const std::type_info&) { return 0; } void PluginService::addFactory(const std::string&, void*, const std::type_info&, const std::type_info&) {} -#else // ROOT 6 +#else // ROOT 6 or no ROOT at all #include "DD4hep/Printout.h" #if !defined(DD4HEP_PARSERS_NO_ROOT) #include "TSystem.h" #else #include <dlfcn.h> #endif +#include <cstring> namespace { struct PluginInterface { @@ -91,38 +91,42 @@ namespace { }; template <typename T> - static inline T get_func(const char* plugin, const char* entry) { + static inline T get_func(void* handle, const char* plugin, const char* entry) { #if !defined(DD4HEP_PARSERS_NO_ROOT) PluginService::FuncPointer<Func_t> fun(gSystem->DynFindSymbol(plugin,entry)); + PluginService::FuncPointer<T> fp(fun.fptr.ptr); #else - PluginService::FuncPointer<Func_t> fun(0); - if ( 0 == fun.fun.ptr ) { - - } + PluginService::FuncPointer<T> fp(::dlsym(handle, entry)); + if ( !fp.fptr.ptr ) fp.fptr.ptr = ::dlsym(0, entry); #endif - PluginService::FuncPointer<T> fp(fun.fptr.ptr); if ( 0 == fp.fptr.ptr ) { string err = "DD4hep:PluginService: Failed to access symbol " - "\""+string(entry)+"\" in plugin library "+string(plugin); + "\""+string(entry)+"\" in plugin library "+string(plugin)+ + " ["+string(::strerror(errno))+"]"; throw runtime_error(err); } return fp.fptr.fcn; } PluginInterface::PluginInterface() : getDebug(0), setDebug(0), create(0), add(0) { + void* handle = 0; const char* plugin_name = ::getenv("DD4HEP_PLUGINMGR"); if ( 0 == plugin_name ) { plugin_name = "libDD4hepGaudiPluginMgr"; } +#if !defined(DD4HEP_PARSERS_NO_ROOT) gSystem->Load(plugin_name); - getDebug = get_func< int (*) ()>(plugin_name,"dd4hep_pluginmgr_getdebug"); - setDebug = get_func< int (*) (int)>(plugin_name,"dd4hep_pluginmgr_getdebug"); +#else + handle = ::dlopen(plugin_name, RTLD_LAZY | RTLD_GLOBAL); +#endif + getDebug = get_func< int (*) ()>(handle, plugin_name,"dd4hep_pluginmgr_getdebug"); + setDebug = get_func< int (*) (int)>(handle, plugin_name,"dd4hep_pluginmgr_getdebug"); create = get_func< void* (*) (const char*, - const char*)>(plugin_name,"dd4hep_pluginmgr_create"); + const char*)>(handle, plugin_name,"dd4hep_pluginmgr_create"); add = get_func< void (*) (const char* identifier, void* creator_stub, const char* signature, - const char* return_type)>(plugin_name,"dd4hep_pluginmgr_add_factory"); + const char* return_type)>(handle, plugin_name,"dd4hep_pluginmgr_add_factory"); } } @@ -159,6 +163,11 @@ void PluginService::addFactory(const std::string& id, stub_t stub, } #endif +#if !defined(DD4HEP_PARSERS_NO_ROOT) +#include "DD4hep/LCDD.h" +#include "DD4hep/Handle.h" +#include "DD4hep/GeoHandler.h" +#include "XML/XMLElements.h" DD4HEP_IMPLEMENT_PLUGIN_REGISTRY(NamedObject*, (Geometry::LCDD*,XML::Handle_t*,Geometry::Ref_t*)) DD4HEP_IMPLEMENT_PLUGIN_REGISTRY(NamedObject*, (Geometry::LCDD*,XML::Handle_t*)) DD4HEP_IMPLEMENT_PLUGIN_REGISTRY(NamedObject*, (Geometry::LCDD*)) @@ -170,3 +179,4 @@ DD4HEP_IMPLEMENT_PLUGIN_REGISTRY(long, (Geometry::LCDD*, const Geometry::GeoHand DD4HEP_IMPLEMENT_PLUGIN_REGISTRY(long, ()) DD4HEP_IMPLEMENT_PLUGIN_REGISTRY(void*, (const char*)) DD4HEP_IMPLEMENT_PLUGIN_REGISTRY(void*, (Geometry::LCDD*,int,char**)) +#endif diff --git a/DDG4/examples/readHEPMC.py b/DDG4/examples/readHEPMC.py index e40ef078907b477662cb7333a3e3bed8031b37a9..9834519b57edd7b24687b860860b99698f7f842d 100644 --- a/DDG4/examples/readHEPMC.py +++ b/DDG4/examples/readHEPMC.py @@ -1,10 +1,3 @@ -# -# -import os, time, getopt, DDG4 -from DDG4 import OutputLevel as Output -from SystemOfUnits import * -# -# """ DD4hep simulation example setup using the python configuration @@ -13,21 +6,43 @@ DD4hep simulation example setup using the python configuration @version 1.0 """ -def run(): +def run(input_file): + import DDG4 + from DDG4 import OutputLevel as Output kernel = DDG4.Kernel() lcdd = kernel.lcdd() - gen = DDG4.GeneratorAction(kernel,"Geant4InputAction/Input") kernel.generatorAction().adopt(gen) - gen.Input = "Geant4EventReaderHepMC|/home/frankm/SW/data/data.hepmc.txt" - gen.Input = "Geant4EventReaderHepMC|/home/frankm/SW/data/Atlas_Pythia8.hepmc" + gen.Input = "Geant4EventReaderHepMC|/home/frankm/SW/data/hepmc_geant4.dat" + gen.Input = "Geant4EventReaderHepMC|/home/frankm/SW/data/" + gen.Input = "Geant4EventReaderHepMC|"+input_file gen.OutputLevel = Output.DEBUG + prim_vtx = DDG4.Geant4Vertex() + prim_vtx.x = 0.0 + prim_vtx.y = 0.0 + prim_vtx.z = 0.0 parts = gen.new_particles() ret = 1 while ret: - ret = gen.readParticles(0,parts) - parts.clear() - print 132*'*',ret - + ret = gen.readParticles(0,prim_vtx,parts) + if ret: + for p in parts: + print 'ID:%5d PDG-id:%8d Charge:%1d Mass:%8.3g Momentum:(%8.2g,%8.2g,%8.2g) '\ + 'Vertex:(%8.2g,%8.2g,%8.2g) NDau:%2d Status:%08X'%\ + (p.id,p.pdgID,int(p.charge3()),p.mass,p.psx,p.psy,p.psz,\ + p.vsx,p.vsy,p.vsz,len(p.daughters),p.status) + parts.clear() + else: + print ' *** End of recordset or read failure.....' + print 132*'*' + return 0 + if __name__ == "__main__": - run() + import sys + input_file = None + if len(sys.argv) > 1: + input_file = sys.argv[1] + sys.exit(run(input_file)) + else: + print 'No input file given. Try again....' + sys.exit(2) # ENOENT diff --git a/DDG4/include/DDG4/Factories.h b/DDG4/include/DDG4/Factories.h index d0496b01571354d431edf1ce3cf99a0a42f0f71d..5a4152452260eb056fef7116d95a671d0bf5e568 100644 --- a/DDG4/include/DDG4/Factories.h +++ b/DDG4/include/DDG4/Factories.h @@ -72,9 +72,6 @@ namespace DD4hep { namespace { - /// Base factory template - template <typename P, typename S> class Factory {}; - namespace DS = DD4hep::Simulation; struct _ns { typedef DD4hep::Geometry::LCDD LCDD; diff --git a/DDG4/include/DDG4/Geant4Particle.h b/DDG4/include/DDG4/Geant4Particle.h index f3a4dbdd87a544a6fe7eca9f5040910abf252001..721c6a0efa034e027ac008c78496d6c35a090138 100644 --- a/DDG4/include/DDG4/Geant4Particle.h +++ b/DDG4/include/DDG4/Geant4Particle.h @@ -145,6 +145,8 @@ namespace DD4hep { Geant4Particle& get_data(Geant4Particle& c); /// Remove daughter from set void removeDaughter(int id_daughter); + /// Charge accessor (for python etc.) + int charge3() const { return charge; } }; #ifndef __DDG4_STANDALONE_DICTIONARIES__ diff --git a/DDG4/plugins/Geant4EventReaderHepMC.cpp b/DDG4/plugins/Geant4EventReaderHepMC.cpp index 69b6c124d02e2ffa7d6799b41e054dc94f30daad..25cbd455dde303d3ccea088b07624c78b4e45b68 100644 --- a/DDG4/plugins/Geant4EventReaderHepMC.cpp +++ b/DDG4/plugins/Geant4EventReaderHepMC.cpp @@ -195,23 +195,35 @@ Geant4EventReaderHepMC::moveToEvent(int event_number) { ++m_currEvent; } } - printout(INFO,"EventReaderHepMC::moveToEvent","Event number after skipping: %d", m_currEvent ); + printout(INFO,"EventReaderHepMC::moveToEvent","Current event number: %d", m_currEvent ); return EVENT_READER_OK; } /// Read an event and fill a vector of MCParticles. Geant4EventReaderHepMC::EventReaderStatus Geant4EventReaderHepMC::readParticles(int /* ev_id */, - Vertex& /* primary_vertex */, + Vertex& primary_vertex, Particles& output) { if ( !m_events->ok() ) { return EVENT_READER_IO_ERROR; } else if ( m_events->read() ) { EventStream::Particles& parts = m_events->particles(); + Position pos(primary_vertex.x,primary_vertex.y,primary_vertex.z); output.reserve(parts.size()); transform(parts.begin(),parts.end(),back_inserter(output),reference2nd(parts)); m_events->clear(); + if (pos.mag2() > numeric_limits<double>::epsilon() ) { + for(Particles::iterator k=output.begin(); k != output.end(); ++k) { + Geant4ParticleHandle p(*k); + p->vsx += pos.x(); + p->vsy += pos.y(); + p->vsz += pos.z(); + p->vex += pos.x(); + p->vey += pos.y(); + p->vez += pos.z(); + } + } for(Particles::const_iterator k=output.begin(); k != output.end(); ++k) { Geant4ParticleHandle p(*k); printout(VERBOSE,m_name, diff --git a/DDG4/python/DDG4.py b/DDG4/python/DDG4.py index eabb0108b9e3950921aab089a927cb4636f861bf..e41d01c1d61a946d0bd784eb7b8e1e44a5cea982 100644 --- a/DDG4/python/DDG4.py +++ b/DDG4/python/DDG4.py @@ -223,6 +223,10 @@ _setup('Geant4DetectorConstructionSequence') _setup('Geant4UserInitializationSequence') _setup('Geant4Sensitive') _setup('Geant4ParticleHandler') +_import_class('Sim','Geant4Vertex') +_import_class('Sim','Geant4Particle') +_import_class('Sim','Geant4VertexVector') +_import_class('Sim','Geant4ParticleVector') _import_class('Sim','Geant4Action') _import_class('Sim','Geant4Filter') _import_class('Sim','Geant4RunAction') diff --git a/DDG4/python/DDG4Dict.C b/DDG4/python/DDG4Dict.C index bcba966b2e3062f06e07a9a88de2477f918eb59a..200b4acd821ee41ed92f2e0f1499de7b74818073 100644 --- a/DDG4/python/DDG4Dict.C +++ b/DDG4/python/DDG4Dict.C @@ -33,8 +33,11 @@ #include "DDG4/Geant4InputAction.h" #include "DDG4/Geant4GeneratorWrapper.h" +/// Namespace for the AIDA detector description toolkit namespace DD4hep { - namespace Simulation { + + /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit + namespace Simulation { using std::string; @@ -199,12 +202,21 @@ namespace DD4hep { return 0; } }; + + /// Container definitions for Geant4Vertex + typedef vector<Geant4Vertex*> Geant4VertexVector; + typedef map<int,Geant4Vertex*> Geant4VertexIntMap; + + /// Container definitions for Geant4Particle + typedef vector<Geant4Particle*> Geant4ParticleVector; + typedef map<int,Geant4Particle*> Geant4ParticleIntMap; } } typedef DD4hep::Simulation::Geant4ActionCreation Geant4ActionCreation; #include "DD4hep/objects/DetectorInterna.h" + using namespace std; using namespace DD4hep; using namespace DD4hep::Simulation; @@ -227,6 +239,12 @@ using namespace DD4hep::Simulation; #pragma link C++ class map<int,Geant4PrimaryInteraction*>+; #pragma link C++ class Geant4PrimaryEvent+; +#pragma link C++ typedef Geant4VertexVector; +#pragma link C++ typedef Geant4VertexIntMap; + +#pragma link C++ typedef Geant4ParticleVector; +#pragma link C++ typedef Geant4ParticleIntMap; + #pragma link C++ class PropertyResult; #pragma link C++ class Geant4InputAction::Particles;