diff --git a/DDG4/include/DDG4/Geant4DetectorConstruction.h b/DDG4/include/DDG4/Geant4DetectorConstruction.h index f925d39272a3dc64eaf08e3e3598e64d4a515d62..ae350400ffbccf11bce5e1dda0675b0d307b376c 100644 --- a/DDG4/include/DDG4/Geant4DetectorConstruction.h +++ b/DDG4/include/DDG4/Geant4DetectorConstruction.h @@ -54,7 +54,8 @@ namespace DD4hep { * \version 1.0 * \ingroup DD4HEP_SIMULATION */ - struct Geant4DetectorConstructionContext { + class Geant4DetectorConstructionContext { + public: /// Reference to geometry object Geometry::LCDD& lcdd; /// Reference to the world after construction diff --git a/DDG4/include/DDG4/Geant4Kernel.h b/DDG4/include/DDG4/Geant4Kernel.h index 5dd89f2490ee7754f57ba785c5ee006e3ee018ef..819b4780b5dc0dd17f291327f1b8ccd6ab5da7da 100644 --- a/DDG4/include/DDG4/Geant4Kernel.h +++ b/DDG4/include/DDG4/Geant4Kernel.h @@ -26,7 +26,6 @@ #include <map> #include <string> #include <typeinfo> -#include <pthread.h> // Forward declarations class G4RunManager; @@ -161,6 +160,10 @@ namespace DD4hep { //bool isMultiThreaded() const { return m_multiThreaded; } bool isMultiThreaded() const { return m_numThreads > 0; } + + /// Access thread identifier + static unsigned long int thread_self(); + public: /// Embedded helper class to facilitate map access to the phases. @@ -367,7 +370,7 @@ namespace DD4hep { /// Create identified worker instance Geant4Kernel& createWorker(); /// Access worker instance by it's identifier - Geant4Kernel& worker(unsigned long thread_identifier); + Geant4Kernel& worker(unsigned long thread_identifier, bool create_if=false); /// Access number of workers int numWorkers() const; diff --git a/DDG4/src/Geant4Exec.cpp b/DDG4/src/Geant4Exec.cpp index a49ba203d9ea904a51f406e13b52101a934f0467..17b68a774953c61cd0a43af2e32efd3f67fbbe35 100644 --- a/DDG4/src/Geant4Exec.cpp +++ b/DDG4/src/Geant4Exec.cpp @@ -387,16 +387,8 @@ namespace DD4hep { void Geant4UserDetectorConstruction::ConstructSDandField() { G4AutoLock protection_lock(&action_mutex); Geant4Context* ctx = m_sequence->context(); - Geant4Kernel* krnl = 0; - try { - krnl = &kernel().worker(::pthread_self()); - } - catch(...) { - } - if ( 0 == krnl ) { - krnl = &kernel().createWorker(); - } - updateContext(krnl->workerContext()); + Geant4Kernel& krnl = kernel().worker(Geant4Kernel::thread_self()); + updateContext(krnl.workerContext()); m_sequence->constructField(&m_ctxt); m_sequence->constructSensitives(&m_ctxt); updateContext(ctx); @@ -419,54 +411,46 @@ namespace DD4hep { /// Build the actions for the worker thread void Geant4UserActionInitialization::Build() const { G4AutoLock protection_lock(&action_mutex); - Geant4Kernel* krnl = 0; - try { - krnl = &kernel().worker(::pthread_self()); - } - catch(...) { - } - if ( 0 == krnl ) { - krnl = &kernel().createWorker(); - } - Geant4Context* ctx = krnl->workerContext(); + Geant4Kernel& krnl = kernel().worker(Geant4Kernel::thread_self()); + Geant4Context* ctx = krnl.workerContext(); if ( m_sequence ) { Geant4Context* old = m_sequence->context(); m_sequence->info("+++ Executing Geant4UserActionInitialization::Build. " - "Context:%p Kernel:%p [%ld]", (void*)ctx, (void*)krnl, krnl->id()); + "Context:%p Kernel:%p [%ld]", (void*)ctx, (void*)&krnl, krnl.id()); m_sequence->updateContext(ctx); m_sequence->build(); m_sequence->updateContext(old); } // Set user generator action sequence. Not optional, since event context is defined inside - Geant4UserGeneratorAction* gen_action = new Geant4UserGeneratorAction(ctx,krnl->generatorAction(false)); + Geant4UserGeneratorAction* gen_action = new Geant4UserGeneratorAction(ctx,krnl.generatorAction(false)); SetUserAction(gen_action); // Set the run action sequence. Not optional, since run context is defined/destroyed inside - Geant4UserRunAction* run_action = new Geant4UserRunAction(ctx,krnl->runAction(false)); + Geant4UserRunAction* run_action = new Geant4UserRunAction(ctx,krnl.runAction(false)); SetUserAction(run_action); // Set the event action sequence. Not optional, since event context is destroyed inside - Geant4UserEventAction* evt_action = new Geant4UserEventAction(ctx,krnl->eventAction(false)); + Geant4UserEventAction* evt_action = new Geant4UserEventAction(ctx,krnl.eventAction(false)); run_action->eventAction = evt_action; evt_action->runAction = run_action; SetUserAction(evt_action); // Set the tracking action sequence - Geant4TrackingActionSequence* trk_action = krnl->trackingAction(false); + Geant4TrackingActionSequence* trk_action = krnl.trackingAction(false); if ( trk_action ) { Geant4UserTrackingAction* action = new Geant4UserTrackingAction(ctx, trk_action); SetUserAction(action); } // Set the stepping action sequence - Geant4SteppingActionSequence* stp_action = krnl->steppingAction(false); + Geant4SteppingActionSequence* stp_action = krnl.steppingAction(false); if ( stp_action ) { Geant4UserSteppingAction* action = new Geant4UserSteppingAction(ctx, stp_action); SetUserAction(action); } // Set the stacking action sequence - Geant4StackingActionSequence* stk_action = krnl->stackingAction(false); + Geant4StackingActionSequence* stk_action = krnl.stackingAction(false); if ( stk_action ) { Geant4UserStackingAction* action = new Geant4UserStackingAction(ctx, stk_action); SetUserAction(action); @@ -567,7 +551,7 @@ int Geant4Exec::configure(Geant4Kernel& kernel) { if ( 0 == phys_seq ) { string phys_model = "QGSP_BERT"; phys_seq = kernel.physicsList(true); - phys_seq->property("extends").set<string>(phys_model); + phys_seq->property("extends").set(phys_model); } G4VUserPhysicsList* physics = phys_seq->extensionList(); if (0 == physics) { diff --git a/DDG4/src/Geant4Kernel.cpp b/DDG4/src/Geant4Kernel.cpp index dcadd83396e347ae64e3eccd5513c39775b3bbd5..ffa3a15fa45b7839f1ee1c32ba974721a0dd00f7 100644 --- a/DDG4/src/Geant4Kernel.cpp +++ b/DDG4/src/Geant4Kernel.cpp @@ -44,6 +44,7 @@ // C/C++ include files #include <stdexcept> #include <algorithm> +#include <pthread.h> using namespace std; using namespace DD4hep::Simulation; @@ -80,7 +81,7 @@ Geant4Kernel::Geant4Kernel(LCDD& lcdd_ref) : m_runManager(0), m_generatorAction(0), m_runAction(0), m_eventAction(0), m_trackingAction(0), m_steppingAction(0), m_stackingAction(0), m_constructionAction(0), m_sensDetActions(0), m_physicsList(0), m_userInit(0), m_lcdd(lcdd_ref), - m_numThreads(0), m_id(pthread_self()), m_master(this), phase(this) + m_numThreads(0), m_id(Geant4Kernel::thread_self()), m_master(this), phase(this) { m_sensDetActions = new Geant4SensDetSequences(); m_lcdd.addExtension < Geant4Kernel > (this); @@ -164,6 +165,12 @@ Geant4Kernel& Geant4Kernel::access(LCDD& lcdd) { return *kernel; } +/// Access thread identifier +unsigned long int Geant4Kernel::thread_self() { + unsigned long int thr_id = (unsigned long int)::pthread_self(); + return thr_id; +} + Geant4Context* Geant4Kernel::workerContext() { if ( m_threadContext ) return m_threadContext; throw runtime_error(format("Geant4Kernel", "DDG4: Master kernel object has no thread context! [Invalid Handle]")); @@ -172,7 +179,7 @@ Geant4Context* Geant4Kernel::workerContext() { /// Create identified worker instance Geant4Kernel& Geant4Kernel::createWorker() { if ( isMaster() ) { - unsigned long identifier = ::pthread_self(); + unsigned long identifier = thread_self(); Geant4Kernel* w = new Geant4Kernel(m_lcdd, this, identifier); m_workers[identifier] = w; printout(INFO,"Geant4Kernel","+++ Created worker instance id=%ul",identifier); @@ -182,17 +189,20 @@ Geant4Kernel& Geant4Kernel::createWorker() { } /// Access worker instance by it's identifier -Geant4Kernel& Geant4Kernel::worker(unsigned long identifier) { +Geant4Kernel& Geant4Kernel::worker(unsigned long identifier, bool create_if) { Workers::iterator i = m_workers.find(identifier); if ( i != m_workers.end() ) { return *((*i).second); } else if ( !isMultiThreaded() ) { - unsigned long self = ::pthread_self(); + unsigned long self = thread_self(); if ( identifier == self ) { return *this; } } + else if ( create_if ) { + return createWorker(); + } throw runtime_error(format("Geant4Kernel", "DDG4: The Kernel object 0x%p does not exists!",(void*)identifier)); } diff --git a/cmake/FindPYTHON.cmake b/cmake/FindPYTHON.cmake index b4358b5b41b69f0b3f78cc2eba297a2ea08e0eed..dca408fb696ddd67e674a17b529b99ccd393ef8a 100644 --- a/cmake/FindPYTHON.cmake +++ b/cmake/FindPYTHON.cmake @@ -29,7 +29,10 @@ find_package(PythonInterp 2.7 REQUIRED) find_package(PythonLibs 2.7 REQUIRED) if (PYTHONLIBS_FOUND) - get_filename_component(PYTHON_LIBRARY_DIR ${PYTHON_LIBRARIES} DIRECTORY) + message(STATUS "DEBUG: ******** PYTHON: PYTHON_LIBRARIES: ${PYTHON_LIBRARIES}") + message(STATUS "DEBUG: ******** PYTHON: PYTHON_INCLUDE_DIRS: ${PYTHON_INCLUDE_DIRS}") + get_filename_component(PYTHON_LIBRARY_DIR ${PYTHON_LIBRARIES} PATH) + message(STATUS "DEBUG: ******** PYTHON: PYTHON_LIBRARY_DIR: ${PYTHON_LIBRARY_DIR}") #get_filename_component(PYTHON_LIBRARY_NAME ${PYTHON_LIBRARIES} NAME_WE) set(PYTHON_LIBRARY_DIR ${PYTHON_LIBRARY_DIR}) set(PYTHON_LIBRARIES ${PYTHON_LIBRARIES}) diff --git a/doc/LaTex/DD4hep-setup.tex b/doc/LaTex/DD4hep-setup.tex index 4057c97fd62898004d065a0cca7c3d061b71ee79..d834b7dfaa2d7ffdf9cb586aae1d27231544095a 100644 --- a/doc/LaTex/DD4hep-setup.tex +++ b/doc/LaTex/DD4hep-setup.tex @@ -88,8 +88,8 @@ % % === Title page command =============================== % -\newcommand{\mytitle}[2]{ -\begin{titlepage} +% +\newcommand{\basictitle}[2]{ % \pagestyle{empty} % @@ -106,18 +106,25 @@ \vspace{3cm} {\Huge\bf{#2}} +\vspace{3cm} -\vspace{5cm} -%M.Frank%\textsuperscript{1}, -F.Gaede -%\textsuperscript{2}, -%C.Grefe\textsuperscript{1}, -%P.Mato\textsuperscript{1} +\end{center} +} + + +\newcommand{\mytitle}[3]{ +\begin{titlepage} +\basictitle{#1}{#2} +\begin{center} +{#3} -%{\textsuperscript{1} -{CERN, 1211 Geneva 23, Switzerland\\} -%{\textsuperscript{2} -{Desy, 22607 Hamburg, Germany} +%%M.Frank %%\textsuperscript{1} +%%%F.Gaede\textsuperscript{2}, +%%%C.Grefe\textsuperscript{1} +%%\vspace{1cm} +%%\textsuperscript{1} +%%{CERN, 1211 Geneva 23, Switzerland} +%%%{\textsuperscript{2} {Desy, 22607 Hamburg, Germany} \end{center} \end{titlepage} } diff --git a/doc/LaTex/DD4hepManual.tex b/doc/LaTex/DD4hepManual.tex index 62f388e414867d6e637d34a0a591997f29704d36..0170a1f5e78ae9fae8548d378501bea324c94796 100644 --- a/doc/LaTex/DD4hepManual.tex +++ b/doc/LaTex/DD4hepManual.tex @@ -16,6 +16,8 @@ for High Energy Physics\\ \vspace{0.3cm} Experiments } +{M. Frank \\ +{CERN, 1211 Geneva 23, Switzerland}} % % %== Abstract =============================================================== diff --git a/doc/LaTex/DDAlignManual.tex b/doc/LaTex/DDAlignManual.tex index 2e6421191a5bb60a27d13436a2e564a79476b309..092b9fb4e4683f75b7088becbe0f64c5872a93f7 100644 --- a/doc/LaTex/DDAlignManual.tex +++ b/doc/LaTex/DDAlignManual.tex @@ -17,7 +17,10 @@ DD4hep Geometry Description \\ \vspace{0.5cm} Toolkit \vspace{2cm} -}{DDAlign User Manual} +} +{M. Frank \\ +{CERN, 1211 Geneva 23, Switzerland}} + % % %== Abstract =============================================================== diff --git a/doc/LaTex/DDConditionsManual.tex b/doc/LaTex/DDConditionsManual.tex index 103da1d9a72004fd3e5c9978cccae7ce306d29df..bcf205a663a5103d20afba07b1d142de0f88029a 100644 --- a/doc/LaTex/DDConditionsManual.tex +++ b/doc/LaTex/DDConditionsManual.tex @@ -7,16 +7,19 @@ % \begin{document} % -\mytitle{ -DDCond -}{ +\mytitle{DDCond} +{ Conditions Support for the \\ \vspace{0.5cm} DD4hep Geometry Description \\ \vspace{0.5cm} Toolkit \vspace{2cm} -}{DDAlign User Manual} +} +{ +M. Frank \\ +{CERN, 1211 Geneva 23, Switzerland} +} % % %== Abstract =============================================================== diff --git a/doc/LaTex/DDEveManual.tex b/doc/LaTex/DDEveManual.tex index 034ac70f2486fa508ed10f12fb13cbb001c8b01b..0eb1079e6ad48169308be68f170ca65db89adc68 100644 --- a/doc/LaTex/DDEveManual.tex +++ b/doc/LaTex/DDEveManual.tex @@ -15,7 +15,9 @@ An Event Display for \\ DD4hep Geometries \\ \vspace{2.5cm} -- DRAFT -- \\ -}{DDEve User Manual} +} +{M. Frank \\ +{CERN, 1211 Geneva 23, Switzerland}} % % %== Abstract =============================================================== diff --git a/doc/LaTex/DDG4Manual-Introduction.tex b/doc/LaTex/DDG4Manual-Introduction.tex index f65f55cd33433f038ae58634ad843bf1d7f88abf..e0bf5d2d93a418e7aa2faa7dc7a3a360d8437cf2 100644 --- a/doc/LaTex/DDG4Manual-Introduction.tex +++ b/doc/LaTex/DDG4Manual-Introduction.tex @@ -27,7 +27,7 @@ is strongly influenced by the technical choices and precise simulations depends on the very specific detection techniques. \noindent -Similar to the aim of \DDhep~\cite{bib:DD4hep}, +Similar to the aim of \DDhep\cite{bib:DD4hep}, where with time a standard palette of detector components developed by users should become part of the toolkit, \DDG also hopes to provide a standard palette of components used diff --git a/doc/LaTex/DDG4Manual.tex b/doc/LaTex/DDG4Manual.tex index fa718202bac7ee384ff754aa8267ba8e2dfc4356..b58e8ddf7aaa08fa6064c9093235974c5eb369bf 100644 --- a/doc/LaTex/DDG4Manual.tex +++ b/doc/LaTex/DDG4Manual.tex @@ -7,17 +7,20 @@ % \begin{document} % -\mytitle{ -DDG4 -}{ +\mytitle{DDG4} % Abbreviated title +{ % Detailed title A Simulation Toolkit for \\ \vspace{0.5cm} High Energy Physics Experiments\\ \vspace{0.5cm} using Geant4 and the \\ \vspace{0.5cm} -DD4hep Geometry Description -}{DDG4 User Manual} +DD4hep Geometry Description\\ +} +{ % Author list +M. Frank \\ +{CERN, 1211 Geneva 23, Switzerland} +} % % %== Abstract =============================================================== @@ -45,7 +48,7 @@ code to achieve the desired result. \end{abstract} -\vspace{8cm} +\vspace{10cm} \begin{center} {\large{\bf{