Skip to content

Commit

Permalink
First cut of cppyy interface for eAST (command-based)
Browse files Browse the repository at this point in the history
  • Loading branch information
buddhasystem committed Jun 23, 2023
1 parent b127f99 commit e4e05a4
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 24 deletions.
36 changes: 24 additions & 12 deletions Makefile-shared
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,33 @@ CXX = g++

CXXFLAGS_DYNAMIC = -fPIC -std=c++17

SRCS = Core/src/eASTInitialization.cc Core/src/eASTDetectorConstruction.cc Core/src/eASTDetectorConstructionMessenger.cc Core/src/eASTMagneticField.cc Core/src/eASTActionInitialization.cc Core/src/eASTUserActionDispatcher.cc
SRCS := $(wildcard Core/src/*.cc)
OBJS := $(patsubst Core/src/%.cc, %.o, $(SRCS) )

SRCS1 = PhysicsList/Base/src/eASTPhysicsList.cc PhysicsList/Base/src/eASTPhysicsListMessenger.cc
SRCS1 := $(wildcard PhysicsList/Base/src/*.cc)

OBJS1 := $(patsubst PhysicsList/Base/src/%.cc, %.o, $(SRCS1) )

SRCS2 = Components/Beampipe/src/eASTBeamPipe.cc Components/Beampipe/src/eASTSupportStructure.cc
SRCS2 := $(wildcard Components/Beampipe/src/*.cc)
OBJS2 := $(patsubst Components/Beampipe/src/%.cc, %.o, $(SRCS2) )


SRCS3 = Components/Base/src/eASTVDetectorComponent.cc Components/Base/src/eASTDetectorComponentMessenger.cc Components/Base/src/eASTDetectorComponentGDML.cc
SRCS3 := $(wildcard Components/Base/src/*.cc)
OBJS3 := $(patsubst Components/Base/src/%.cc, %.o, $(SRCS3) )


SRCS4 := $(wildcard PrimGenInterface/src/*.cc)
OBJS4 := $(patsubst PrimGenInterface/src/%.cc, %.o, $(SRCS4) )

# ------------------------------------------------------------------------
LIBRARY = east.so

all: $(OBJS) $(OBJS1) $(OBJS2) $(OBJS3)

LIBRARY: $(OBJS) $(OBJS1) $(OBJS2) $(OBJS3) $(OBJS4)
@echo Building the shared library
g++ $(OBJS) $(OBJS1) $(OBJS2) $(OBJS3) $(OBJS4) -shared -lxerces-c -o $(LIBRARY)

all: $(OBJS) $(OBJS1) $(OBJS2) $(OBJS3) $(OBJS4)
# $(CXX) -c $(CXXFLAGS_DYNAMIC) -o eASTInitialization.o Core/src/eASTInitialization.cc
# $(CXX) -c $(CXXFLAGS_DYNAMIC) -o eASTDetectorConstruction.o Core/src/eASTDetectorConstruction.cc

Expand All @@ -33,16 +44,17 @@ $(OBJS2): %.o: Components/Beampipe/src/%.cc
$(OBJS3): %.o: Components/Base/src/%.cc
$(CXX) -c $(CXXFLAGS_DYNAMIC) $< -o $@

$(OBJS4): %.o: PrimGenInterface/src/%.cc
$(CXX) -c $(CXXFLAGS_DYNAMIC) $< -o $@

#$(BUILD):
# $(shell mkdir -p $(BUILD))

LIBRARY:
@echo Building the shared library
g++ $(OBJS) $(OBJS1) $(OBJS2) $(OBJS3) -shared -lxerces-c -o $(LIBRARY)




clean:
rm -f $(LIBRARY)
rm -f $(OBJS)
rm -f $(OBJS)

# SRCS1 = PhysicsList/Base/src/eASTPhysicsList.cc PhysicsList/Base/src/eASTPhysicsListMessenger.cc PhysicsList/Base/src/eASTProtonPhysics.cc PhysicsList/Base/src/eASTNeutronPhysics.cc
# SRCS2 = Components/Beampipe/src/eASTBeamPipe.cc Components/Beampipe/src/eASTSupportStructure.cc
# SRCS3 = Components/Base/src/eASTVDetectorComponent.cc Components/Base/src/eASTDetectorComponentMessenger.cc Components/Base/src/eASTDetectorComponentGDML.cc
Empty file modified PhysicsList/Base/src/eASTProtonPhysics.cc
100644 → 100755
Empty file.
79 changes: 68 additions & 11 deletions Python/loadtest.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,54 @@
#!/usr/bin/env python3
import cppyy
from cppyy import ll
import argparse
import cppyy
from cppyy import ll

# ---
preload = [
'G4Types.hh',
'G4String.hh',
'G4RunManagerFactory.hh',
'G4UImanager.hh',
'G4UIExecutive.hh',
'G4VisExecutive.hh',
'eASTInitialization.hh',
]

libload = [
'libG4run',
'libG4graphics_reps',
'libG4intercoms',
'libG4physicslists',
'libG4persistency',
'east',
]

# ---
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", action='store_true', help="Verbose mode")
parser.add_argument("-m", "--macrofile",type=str, help="The optional macro file", default='')
# ---

args = parser.parse_args()

verb = args.verbose
macro = args.macrofile


for pre in preload:
print(f'''Preloading {pre}''')
if verb: print(f'''Loading header file {pre}''')
cppyy.include(pre)

if verb: print('--- Finished loading headers ---')

cppyy.load_library('libG4run')
cppyy.load_library('libG4graphics_reps')
cppyy.load_library('libG4intercoms')
cppyy.load_library('east')
for lib in libload:
if verb: print(f'''Loading library {lib}''')
cppyy.load_library(lib)

if verb: print('--- Finished loading libraries ---')


# --- Initialize the critical elelement to get hold of the UI:

from cppyy.gbl import G4RunManagerFactory, G4UImanager, eASTInitialization

Expand All @@ -29,18 +58,46 @@

UImanager = G4UImanager.GetUIpointer()

searchpath = UImanager.GetMacroSearchPath()

print(searchpath)
# searchpath = UImanager.GetMacroSearchPath()
# print(searchpath)

eastI = eASTInitialization()

# UImanager = G4UImanager.GetUIpointer()
if macro!='':
try:
f=open(macro)
except:
print(f'''Error opening macro file "{macro}", exiting...''')
exit(-1)

lines = [line.rstrip() for line in f]

if verb: print(f'''Read {len(lines)} lines from the file "{macro}"''')


for line in lines:
if len(line)==0: continue
if line[0]=='#': continue
if verb: print(f'''Executing command: {line}''')
UImanager.ApplyCommand(line)


exit(0)



# UImanager = G4UImanager.GetUIpointer()
UImanager.ApplyCommand("#")
UImanager.ApplyCommand("/control/verbose 2")

# UImanager.ApplyCommand("/run/initialize")

# visManager = G4VisExecutive("Quiet")


# -------------- ATTIC ---------------------

# cppyy.load_library('libG4run')
# cppyy.load_library('libG4graphics_reps')
# cppyy.load_library('libG4intercoms')
# cppyy.load_library('east')
2 changes: 1 addition & 1 deletion Python/setup_example.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export LD_LIBRARY_PATH=/opt/geant4/lib/:/opt/hepmc3/lib/
export CPATH=/opt/geant4/include/Geant4/:/opt/east/include/
export CPATH=/opt/geant4/include/Geant4/:/opt/east/include/:/opt/hepmc3/include/

0 comments on commit e4e05a4

Please sign in to comment.