From 73c20a69436a11203ce691e557e95276d717167c Mon Sep 17 00:00:00 2001 From: Markus Frank <Markus.Frank@cern.ch> Date: Mon, 13 Feb 2017 11:59:34 +0100 Subject: [PATCH] Fix example DDG4/examples/readHEPMC.py and allow access to STL containers from DD4hep python interface --- DDG4/examples/readHEPMC.py | 14 +++++++------- DDG4/include/DDG4/Geant4Particle.h | 1 - DDG4/include/DDG4/Geant4ParticleHandler.h | 1 - DDG4/include/DDG4/Geant4ParticlePrint.h | 1 - DDG4/include/DDG4/Geant4PhysicsConstructor.h | 2 +- DDG4/include/DDG4/Geant4Primary.h | 1 - DDG4/include/DDG4/Geant4PrimaryHandler.h | 1 - DDG4/include/DDG4/Geant4Primitives.h | 1 - DDG4/include/DDG4/Geant4Random.h | 1 - DDG4/include/DDG4/Geant4Vertex.h | 1 - DDG4/python/DD4hep.py | 12 ++++++++++++ DDG4/python/DDG4.py | 2 ++ 12 files changed, 22 insertions(+), 16 deletions(-) diff --git a/DDG4/examples/readHEPMC.py b/DDG4/examples/readHEPMC.py index df174fcbe..525d5f0c8 100644 --- a/DDG4/examples/readHEPMC.py +++ b/DDG4/examples/readHEPMC.py @@ -18,10 +18,7 @@ def run(input_file): gen.Input = "Geant4EventReaderHepMC|"+input_file gen.OutputLevel = Output.DEBUG gen.HaveAbort = False - prim_vtx = DDG4.Geant4Vertex() - prim_vtx.x = 0.0 - prim_vtx.y = 0.0 - prim_vtx.z = 0.0 + prim_vtx = DDG4.std_vector('DD4hep::Simulation::Geant4Vertex*')() parts = gen.new_particles() ret = 1 while ret: @@ -31,11 +28,14 @@ def run(input_file): print '\nException: readParticles:',str(X) ret = None if ret: + for v in prim_vtx: + print 'Mask:%04X (X:%8.2g,Y:%8.2g,Z:%8.2g) time:%8.2g Outgoing:%4d particles'%\ + (v.mask,v.x,v.y,v.z,v.time,len(v.out),) for p in parts: - print 'ID:%5d PDG-id:%8d Charge:%1d Mass:%8.3g Momentum:(%8.2g,%8.2g,%8.2g) '\ + print 'Mask:%04X 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) + (p.mask,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.....' diff --git a/DDG4/include/DDG4/Geant4Particle.h b/DDG4/include/DDG4/Geant4Particle.h index f88e083ae..97393a3f7 100644 --- a/DDG4/include/DDG4/Geant4Particle.h +++ b/DDG4/include/DDG4/Geant4Particle.h @@ -1,4 +1,3 @@ -// $Id: $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDG4/include/DDG4/Geant4ParticleHandler.h b/DDG4/include/DDG4/Geant4ParticleHandler.h index 35fbf5a70..5bc85a2b0 100644 --- a/DDG4/include/DDG4/Geant4ParticleHandler.h +++ b/DDG4/include/DDG4/Geant4ParticleHandler.h @@ -1,4 +1,3 @@ -// $Id: $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDG4/include/DDG4/Geant4ParticlePrint.h b/DDG4/include/DDG4/Geant4ParticlePrint.h index c74ef5bee..90e09d007 100644 --- a/DDG4/include/DDG4/Geant4ParticlePrint.h +++ b/DDG4/include/DDG4/Geant4ParticlePrint.h @@ -1,4 +1,3 @@ -// $Id: $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDG4/include/DDG4/Geant4PhysicsConstructor.h b/DDG4/include/DDG4/Geant4PhysicsConstructor.h index 796d85437..4262a5b36 100644 --- a/DDG4/include/DDG4/Geant4PhysicsConstructor.h +++ b/DDG4/include/DDG4/Geant4PhysicsConstructor.h @@ -1,3 +1,4 @@ +//========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) @@ -11,7 +12,6 @@ // \version 1.0 // //========================================================================== -// $Id$ #ifndef DDG4_GEANT4PHYSICSCONSTRUCTOR_H #define DDG4_GEANT4PHYSICSCONSTRUCTOR_H 1 diff --git a/DDG4/include/DDG4/Geant4Primary.h b/DDG4/include/DDG4/Geant4Primary.h index 162e42ea6..86c1d4520 100644 --- a/DDG4/include/DDG4/Geant4Primary.h +++ b/DDG4/include/DDG4/Geant4Primary.h @@ -1,4 +1,3 @@ -// $Id: $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDG4/include/DDG4/Geant4PrimaryHandler.h b/DDG4/include/DDG4/Geant4PrimaryHandler.h index 4cb4b7f45..726a62c5c 100644 --- a/DDG4/include/DDG4/Geant4PrimaryHandler.h +++ b/DDG4/include/DDG4/Geant4PrimaryHandler.h @@ -1,4 +1,3 @@ -// $Id: $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDG4/include/DDG4/Geant4Primitives.h b/DDG4/include/DDG4/Geant4Primitives.h index 917309a5c..aa4fb192a 100644 --- a/DDG4/include/DDG4/Geant4Primitives.h +++ b/DDG4/include/DDG4/Geant4Primitives.h @@ -1,4 +1,3 @@ -// $Id: $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDG4/include/DDG4/Geant4Random.h b/DDG4/include/DDG4/Geant4Random.h index 1085153a4..a1cb78cce 100644 --- a/DDG4/include/DDG4/Geant4Random.h +++ b/DDG4/include/DDG4/Geant4Random.h @@ -1,4 +1,3 @@ -// $Id: $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDG4/include/DDG4/Geant4Vertex.h b/DDG4/include/DDG4/Geant4Vertex.h index e3077f49f..99887430e 100644 --- a/DDG4/include/DDG4/Geant4Vertex.h +++ b/DDG4/include/DDG4/Geant4Vertex.h @@ -1,4 +1,3 @@ -// $Id: $ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- diff --git a/DDG4/python/DD4hep.py b/DDG4/python/DD4hep.py index e869fe74c..03cfeb764 100644 --- a/DDG4/python/DD4hep.py +++ b/DDG4/python/DD4hep.py @@ -87,6 +87,18 @@ class _Levels: self.ALWAYS=7 OutputLevel = _Levels() +#------------------------Generic STL stuff can be accessed using std: ----- +# +#-- e.g. Create an instance of std::vector<DD4hep::Simulation::Geant4Vertex*>: +# >>> v=DD4hep.vector('DD4hep::Simulation::Geant4Vertex*')() +# +#--------------------------------------------------------------------------- +import cppyy +std = cppyy.gbl.std +std_vector = std.vector +std_list = std.list +std_map = std.map +std_pair = std.pair #--------------------------------------------------------------------------- Core = DD4hep Geo = DD4hep.Geometry diff --git a/DDG4/python/DDG4.py b/DDG4/python/DDG4.py index 4f4cf4f8d..558750f6d 100644 --- a/DDG4/python/DDG4.py +++ b/DDG4/python/DDG4.py @@ -49,6 +49,7 @@ except Exception as X: print '| %-100s |'%(str(X),) print '+--%-100s--+'%(100*'-',) exit(1) + from ROOT import CLHEP as CLHEP Core = DD4hep Sim = DD4hep.Simulation @@ -56,6 +57,7 @@ Simulation = DD4hep.Simulation Kernel = Sim.KernelHandle Interface = Sim.Geant4ActionCreation LCDD = Geo.LCDD +from DD4hep import std, std_vector, std_list, std_map, std_pair #--------------------------------------------------------------------------- def _constant(self,name): -- GitLab