DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4Kernel.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DD4hep/Detector.h>
16 #include <DD4hep/Memory.h>
17 #include <DD4hep/Plugins.h>
18 #include <DD4hep/Printout.h>
19 #include <DD4hep/Primitives.h>
20 #include <DD4hep/InstanceCount.h>
21 
22 #include <DDG4/Geant4Kernel.h>
23 #include <DDG4/Geant4Context.h>
24 #include <DDG4/Geant4Interrupts.h>
25 #include <DDG4/Geant4ActionPhase.h>
26 
27 // Geant4 include files
28 #include <G4RunManager.hh>
29 #include <G4ScoringManager.hh>
30 #include <G4UIdirectory.hh>
31 #include <G4Threading.hh>
32 #include <G4AutoLock.hh>
33 
34 // C/C++ include files
35 #include <algorithm>
36 #include <pthread.h>
37 #include <csignal>
38 #include <memory>
39 
40 using namespace dd4hep::sim;
41 
42 namespace {
43 
44  G4Mutex kernel_mutex = G4MUTEX_INITIALIZER;
45  std::unique_ptr<Geant4Kernel> s_main_instance;
46  void description_unexpected() {
47  try {
48  throw;
49  }
50  catch( std::exception& e ) {
51  std::cout << "\n"
52  << "**************************************************** \n"
53  << "* A runtime error has occured : \n"
54  << "* " << e.what() << std::endl
55  << "* the program will have to be terminated - sorry. \n"
56  << "**************************************************** \n"
57  << std::endl;
58  // this provokes ROOT seg fault and stack trace (comment out to avoid it)
59  ::exit(1) ;
60  }
61  }
62 }
63 
66  : m_kernel(kernel) {
67 }
68 
71  : m_kernel(c.m_kernel) {
72 }
73 
76  if ( this != &c ) {
77  m_kernel = c.m_kernel;
78  }
79  return *this;
80 }
81 
84  if( Geant4ActionPhase* action_phase = m_kernel->getPhase(nam) )
85  return *action_phase;
86  throw except("Geant4Kernel", "Attempt to access the nonexisting phase '%s'", nam.c_str());
87 }
88 
91  : Geant4ActionContainer(), m_detDesc(&description_ref),
92  m_id(Geant4Kernel::thread_self()), m_master(this), phase(this)
93 {
94  m_ident = -1;
96  declareProperty("OutputLevel", m_outputLevel = DEBUG);
97  declareProperty("NumEvents", m_numEvent = 10);
98  declareProperty("OutputLevels", m_clientLevels);
99  declareProperty("NumberOfThreads", m_numThreads = 0);
100  declareProperty("HaveScoringManager", m_haveScoringMgr = false);
101  declareProperty("SensitiveTypes", m_sensitiveDetectorTypes);
102  declareProperty("RunManagerType", m_runManagerType = "G4RunManager");
103  declareProperty("DefaultSensitiveType", m_dfltSensitiveDetectorType = "Geant4SensDet");
104  m_interrupts = new Geant4Interrupts(*this);
105  m_controlName = "/ddg4/";
106  m_control = new G4UIdirectory(m_controlName.c_str());
107  m_control->SetGuidance("Control for named Geant4 actions");
108  setContext(new Geant4Context(this));
110 }
111 
113 Geant4Kernel::Geant4Kernel(Geant4Kernel* krnl, unsigned long ident)
114  : Geant4ActionContainer(), m_id(ident), m_master(krnl), phase(this)
115 {
116  char text[64];
117  m_numThreads = 1; // Slave instance for one single thread
120  m_ident = m_master->m_workers.size();
128  ::snprintf(text, sizeof(text), "/ddg4.%d/", (int)(m_master->m_workers.size()));
129  m_controlName = text;
130  m_control = new G4UIdirectory(m_controlName.c_str());
131  m_control->SetGuidance("Control for thread specific Geant4 actions");
132  setContext(new Geant4Context(this));
134 }
135 
138  if ( this == s_main_instance.get() ) {
139  s_main_instance.release();
140  }
141  detail::destroyObjects(m_workers);
142  if ( isMaster() ) {
143  detail::releaseObjects(m_globalFilters);
144  detail::releaseObjects(m_globalActions);
145  detail::deletePtr(m_interrupts);
146  }
147  destroyPhases();
148  detail::deletePtr(m_runManager);
150  if ( m_detDesc && isMaster() ) {
151  try {
152  //m_detDesc->removeExtension < Geant4Kernel > (false);
154  m_detDesc = 0;
155  }
156  catch(...) {
157  }
158  }
160 }
161 
164  if ( nullptr == s_main_instance.get() ) {
165  G4AutoLock protection_lock(&kernel_mutex); {
166  if ( nullptr == s_main_instance.get() ) { // Need to check again!
168  std::set_terminate(description_unexpected);
169  s_main_instance.reset(new Geant4Kernel(description));
170  }
171  }
172  }
173  return *(s_main_instance.get());
174 }
175 
178  if ( isMaster() )
179  return *this->m_interrupts;
180  return this->m_master->interruptHandler();
181 }
182 
185  printout(INFO, "Geant4Kernel",
186  "+++ Stop signal seen. Will finish after current event(s) have been processed.");
187  printout(INFO, "Geant4Kernel",
188  "+++ Depending on the complexity of the simulation, this may take some time ...");
190 }
191 
194  return this->m_master->m_processEvents == EVENTLOOP_RUNNING;
195 }
196 
199  if ( sig_num == SIGINT ) {
201  }
202  return false;
203 }
204 
208 }
209 
211 unsigned long int Geant4Kernel::thread_self() {
212  unsigned long int thr_id = (unsigned long int)::pthread_self();
213  return thr_id;
214 }
215 
218  if ( isMaster() ) {
219  unsigned long identifier = thread_self();
220  Geant4Kernel* w = new Geant4Kernel(this, identifier);
221  m_workers[identifier] = w;
222  printout(INFO, "Geant4Kernel", "+++ Created worker instance id=%ul",identifier);
223  return *w;
224  }
225  except("Geant4Kernel", "DDG4: Only the master instance may create workers.");
226  throw std::runtime_error("Geant4Kernel::createWorker");
227 }
228 
230 Geant4Kernel& Geant4Kernel::worker(unsigned long identifier, bool create_if) {
231  if ( Workers::iterator i=m_workers.find(identifier); i != m_workers.end() ) {
232  return *((*i).second);
233  }
234  else if ( identifier == m_id ) {
235  return *this;
236  }
237  else if ( !isMultiThreaded() ) {
238  unsigned long self = thread_self();
239  if ( identifier == self ) {
240  return *this;
241  }
242  }
243  else if( create_if ) {
244  return createWorker();
245  }
246  except("Geant4Kernel", "DDG4: The Kernel object 0x%p does not exists!",(void*)identifier);
247  throw std::runtime_error("Geant4Kernel::worker");
248 }
249 
252  return m_workers.size();
253 }
254 
256 G4VPhysicalVolume* Geant4Kernel::world() const {
257  if( this != m_master ) return m_master->world();
258  return m_world;
259 }
260 
262 void Geant4Kernel::setWorld(G4VPhysicalVolume* volume) {
263  if( this == m_master ) m_world = volume;
264  else m_master->setWorld(volume);
265 }
266 
268 void Geant4Kernel::defineSensitiveDetectorType(const std::string& type, const std::string& factory) {
269  auto iter = m_sensitiveDetectorTypes.find(type);
270  if( iter == m_sensitiveDetectorTypes.end() ) {
271  printout(INFO,"Geant4Kernel","+++ Define sensitive type: %s -> %s", type.c_str(), factory.c_str());
272  m_sensitiveDetectorTypes.emplace(type, factory);
273  return;
274  }
275  else if( iter->first == type && iter->second == factory ) {
276  return;
277  }
278  except("Geant4Kernel",
279  "+++ The sensitive type %s is already defined and used %s. Cannot overwrite with %s",
280  type.c_str(), iter->second.c_str(), factory.c_str());
281 }
282 
284  printout(ALWAYS,"Geant4Kernel","OutputLevel: %d", m_outputLevel);
285  printout(ALWAYS,"Geant4Kernel","UI: %s", m_uiName.c_str());
286  printout(ALWAYS,"Geant4Kernel","NumEvents: %ld", m_numEvent);
287  printout(ALWAYS,"Geant4Kernel","NumThreads: %d", m_numThreads);
288  for( const auto& [name, level] : m_clientLevels )
289  printout(ALWAYS,"Geant4Kernel","OutputLevel[%s]: %d", name.c_str(), level);
290 }
291 
293 bool Geant4Kernel::hasProperty(const std::string& name) const {
294  return m_properties.exists(name);
295 }
296 
298 dd4hep::Property& Geant4Kernel::property(const std::string& name) {
299  return properties()[name];
300 }
301 
303 void Geant4Kernel::setOutputLevel(const std::string object, PrintLevel new_level) {
304  m_clientLevels[object] = new_level;
305 }
306 
308 dd4hep::PrintLevel Geant4Kernel::getOutputLevel(const std::string object) const {
309  if( auto i=m_clientLevels.find(object); i != m_clientLevels.end() )
310  return (PrintLevel)(*i).second;
311  return dd4hep::PrintLevel(dd4hep::printLevel()-1);
312 }
313 
315 dd4hep::PrintLevel Geant4Kernel::setOutputLevel(PrintLevel new_level) {
316  int old = m_outputLevel;
317  m_outputLevel = new_level;
318  return (PrintLevel)old;
319 }
320 
322 G4RunManager& Geant4Kernel::runManager() {
323  if ( m_runManager ) {
324  return *m_runManager;
325  }
326  else if ( isMaster() ) {
327  Geant4Action* mgr =
328  PluginService::Create<Geant4Action*>(m_runManagerType,
329  m_context,
330  std::string("Geant4RunManager"));
331  if ( !mgr ) {
332  except("Geant4Kernel",
333  "+++ Invalid Geant4RunManager class: %s. Aborting.",
334  m_runManagerType.c_str());
335  }
336  mgr->property("NumberOfThreads").set(m_numThreads);
337  mgr->enableUI();
338  if ( this->m_haveScoringMgr ) {
339  if ( nullptr == G4ScoringManager::GetScoringManager() ) {
340  except("Geant4Kernel", "+++ FAILED to create the G4ScoringManager instance.");
341  }
342  }
343  m_runManager = dynamic_cast<G4RunManager*>(mgr);
344  if ( m_runManager ) {
345  return *m_runManager;
346  }
347  except("Geant4Kernel",
348  "+++ Invalid Geant4RunManager action: %s. Invalid inheritance.",
349  m_runManagerType.c_str());
350  }
351  except("Geant4Kernel",
352  "+++ Only the master thread may instantiate a G4RunManager object!");
353  throw std::runtime_error("Is never called -- just to satisfy compiler!");
354 }
355 
357 void Geant4Kernel::loadGeometry(const std::string& compact_file) {
358  char* arg = (char*) compact_file.c_str();
359  m_detDesc->apply("DD4hep_XMLLoader", 1, &arg);
360  //return *this;
361 }
362 
363 // Utility function to load XML files
364 void Geant4Kernel::loadXML(const char* fname) {
365  const char* args[] = { fname, 0 };
366  m_detDesc->apply("DD4hep_XMLLoader", 1, (char**) args);
367 }
368 
370 void Geant4Kernel::register_configure(const std::function<void()>& callback) {
371  m_actionConfigure.push_back(callback);
372 }
373 
375 void Geant4Kernel::register_initialize(const std::function<void()>& callback) {
376  m_actionInitialize.push_back(callback);
377 }
378 
380 void Geant4Kernel::register_terminate(const std::function<void()>& callback) {
381  m_actionTerminate.push_back(callback);
382 }
383 
386  int status = Geant4Exec::configure(*this);
387  if ( status ) {
388  for(auto& call : m_actionConfigure) call();
389  return status;
390  }
391  except("Geant4Kernel","++ FAILED to configure DDG4 executive");
392  return status;
393 }
394 
397  int status = Geant4Exec::initialize(*this);
398  if ( status ) {
399  for(auto& call : m_actionInitialize) call();
400  return status;
401  }
402  except("Geant4Kernel","++ FAILED to initialize DDG4 executive");
403  return status;
404 }
405 
408  try {
409  auto result = Geant4Exec::run(*this);
410  // flush the geant4 stream buffer
411  G4cout << G4endl;
412  return result;
413  }
414  catch(const std::exception& e) {
415  printout(FATAL,"Geant4Kernel","+++ Exception while simulating:%s",e.what());
416  }
417  catch(...) {
418  printout(FATAL,"Geant4Kernel","+++ UNKNOWN exception while simulating.");
419  }
420  return 0;
421 }
422 
423 int Geant4Kernel::runEvents(int num_events) {
424  m_numEvent = num_events;
425  return Geant4Exec::run(*this);
426 }
427 
429  const Geant4Kernel* ptr = s_main_instance.get();
430  printout(INFO,"Geant4Kernel","++ Terminate Geant4 and delete associated actions.");
431  if ( ptr == this ) {
432  auto calls = std::move(m_actionTerminate);
433  for(auto& call : calls) call();
434  Geant4Exec::terminate(*this);
435  m_actionTerminate = std::move(calls);
436  }
437  destroyPhases();
438  detail::releaseObjects(m_globalFilters);
439  detail::releaseObjects(m_globalActions);
440  if ( ptr == this ) {
441  detail::deletePtr(m_runManager);
442  }
444  if ( ptr == this && m_detDesc ) {
445  //m_detDesc->removeExtension < Geant4Kernel > (false);
447  m_detDesc = 0;
448  }
449  return 1;
450 }
451 
453 
458  if( action ) {
459  const std::string& nam = action->name();
460  if( auto i=m_globalActions.find(nam); i == m_globalActions.end() ) {
461  action->addRef();
462  m_globalActions[nam] = action;
463  printout(INFO,"Geant4Kernel","++ Registered global action %s of type %s",
464  nam.c_str(),typeName(typeid(*action)).c_str());
465  return *this;
466  }
467  except("Geant4Kernel", "DDG4: The action '%s' is already globally "
468  "registered. [Action-Already-Registered]", nam.c_str());
469  }
470  except("Geant4Kernel",
471  "DDG4: Attempt to globally register an invalid action. [Action-Invalid]");
472  return *this;
473 }
474 
476 Geant4Action* Geant4Kernel::globalAction(const std::string& nam, bool throw_if_not_present) {
477  if( auto i=m_globalActions.find(nam); i != m_globalActions.end() )
478  return (*i).second;
479  if( throw_if_not_present ) {
480  except("Geant4Kernel", "DDG4: The action '%s' is not globally "
481  "registered. [Action-Missing]", nam.c_str());
482  }
483  return nullptr;
484 }
485 
487 
492  if( filter ) {
493  const std::string& nam = filter->name();
494  if( auto i=m_globalFilters.find(nam); i == m_globalFilters.end()) {
495  filter->addRef();
496  m_globalFilters[nam] = filter;
497  return *this;
498  }
499  except("Geant4Kernel", "DDG4: The filter '%s' is already globally "
500  "registered. [Filter-Already-Registered]", nam.c_str());
501  }
502  except("Geant4Kernel",
503  "DDG4: Attempt to globally register an invalid filter. [Filter-Invalid]");
504  return *this;
505 }
506 
508 Geant4Action* Geant4Kernel::globalFilter(const std::string& filter_name, bool throw_if_not_present) {
509  if( auto i=m_globalFilters.find(filter_name); i != m_globalFilters.end())
510  return (*i).second;
511  if (throw_if_not_present) {
512  except("Geant4Kernel", "DDG4: The filter '%s' is not already globally "
513  "registered. [Filter-Missing]", filter_name.c_str());
514  }
515  return nullptr;
516 }
517 
519 bool Geant4Kernel::executePhase(const std::string& nam, const void** arguments) const {
520  if( auto i=m_phases.find(nam); i != m_phases.end() ) {
521  (*i).second->execute(arguments);
522  return true;
523  }
524  return false;
525 }
526 
528 Geant4ActionPhase* Geant4Kernel::getPhase(const std::string& nam) {
529  if( auto i=m_phases.find(nam); i != m_phases.end() )
530  return (*i).second;
531  except("Geant4Kernel", "DDG4: The Geant4 action phase '%s' does not exist. [No-Entry]", nam.c_str());
532  return nullptr;
533 }
534 
536 Geant4ActionPhase* Geant4Kernel::addSimplePhase(const std::string& name, bool throw_on_exist) {
537  return addPhase(name,typeid(void),typeid(void),typeid(void),throw_on_exist);
538 }
539 
542  const std::type_info& arg0,
543  const std::type_info& arg1,
544  const std::type_info& arg2,
545  bool throw_on_exist)
546 {
547  if( auto i=m_phases.find(nam); i == m_phases.end() ) {
548  Geant4ActionPhase* p = new Geant4ActionPhase(workerContext(), nam, arg0, arg1, arg2);
549  m_phases.emplace(nam, p);
550  return p;
551  }
552  else if (throw_on_exist) {
553  except("Geant4Kernel", "DDG4: The Geant4 action phase %s already exists. [Already-Exists]", nam.c_str());
554  }
555  return nullptr;
556 }
557 
559 bool Geant4Kernel::removePhase(const std::string& nam) {
560  if( auto i=m_phases.find(nam); i != m_phases.end() ) {
561  delete (*i).second;
562  m_phases.erase(i);
563  return true;
564  }
565  return false;
566 }
567 
570  detail::destroyObjects(m_phases);
571 }
dd4hep::sim::Geant4Kernel::triggerStop
void triggerStop()
Trigger smooth end-of-event-loop with finishing currently processing event.
Definition: Geant4Kernel.cpp:184
dd4hep::sim::Geant4Kernel::configure
virtual int configure()
Run the simulation: Configure Geant4.
Definition: Geant4Kernel.cpp:385
dd4hep::sim::Geant4Kernel::m_control
G4UIdirectory * m_control
Top level control directory.
Definition: Geant4Kernel.h:82
dd4hep::sim::Geant4Kernel::phase
class dd4hep::sim::Geant4Kernel::PhaseSelector phase
dd4hep::sim::Geant4Kernel::PhaseSelector::m_kernel
Geant4Kernel * m_kernel
Reference to embedding object.
Definition: Geant4Kernel.h:177
dd4hep::sim::Geant4Kernel::loadXML
virtual void loadXML(const char *fname)
Load XML file.
Definition: Geant4Kernel.cpp:364
dd4hep::SignalHandler::applyHandlers
void applyHandlers()
(Re-)apply registered interrupt handlers to override potentially later registrations by other librari...
dd4hep::sim::Geant4Kernel::defineSensitiveDetectorType
void defineSensitiveDetectorType(const std::string &type, const std::string &factory)
Add new sensitive type to factory list.
Definition: Geant4Kernel.cpp:268
dd4hep::sim::Geant4Kernel::setWorld
void setWorld(G4VPhysicalVolume *volume)
Set the geometry world.
Definition: Geant4Kernel.cpp:262
dd4hep::sim::Geant4Kernel::addSimplePhase
virtual Geant4ActionPhase * addSimplePhase(const std::string &name, bool throw_on_exist)
Add a new phase to the phase.
Definition: Geant4Kernel.cpp:536
dd4hep::Property
The property class to assign options to actions.
Definition: ComponentProperties.h:48
dd4hep::sim::Geant4Kernel::EVENTLOOP_HALT
@ EVENTLOOP_HALT
Definition: Geant4Kernel.h:74
dd4hep::sim::Geant4Interrupts
Interruptsback interface class with argument.
Definition: Geant4Interrupts.h:36
dd4hep::sim::Geant4Exec::configure
static int configure(Geant4Kernel &kernel)
Configure the application.
Definition: Geant4Exec.cpp:552
dd4hep::sim::Geant4Kernel::m_outputLevel
int m_outputLevel
Property: Output level.
Definition: Geant4Kernel.h:115
dd4hep::sim::Geant4Kernel::PhaseSelector
Embedded helper class to facilitate map access to the phases.
Definition: Geant4Kernel.h:174
dd4hep::sim::Geant4Kernel::destroyPhases
virtual void destroyPhases()
Destroy all phases. To be called only at shutdown.
Definition: Geant4Kernel.cpp:569
Geant4Interrupts.h
Detector.h
dd4hep::sim::Geant4ActionContainer::m_context
Geant4Context * m_context
Geant4 worker context (thread specific)
Definition: Geant4ActionContainer.h:64
dd4hep::sim::Geant4Exec::run
static int run(Geant4Kernel &kernel)
Run the application and simulate events.
Definition: Geant4Exec.cpp:635
dd4hep::sim::Geant4Kernel::declareProperty
Geant4Kernel & declareProperty(const std::string &nam, T &val)
Declare property.
Definition: Geant4Kernel.h:355
dd4hep::exception
void exception(const std::string &src, const std::string &msg)
Definition: RootDictionary.h:69
dd4hep::sim::Geant4Kernel::m_dfltSensitiveDetectorType
std::string m_dfltSensitiveDetectorType
Property: Name of the default factory to create G4VSensitiveDetector instances.
Definition: Geant4Kernel.h:109
dd4hep::sim::Geant4Kernel::m_workers
Workers m_workers
Worker threads.
Definition: Geant4Kernel.h:95
dd4hep::sim::Geant4Kernel::addPhase
virtual Geant4ActionPhase * addPhase(const std::string &name, const std::type_info &arg1, const std::type_info &arg2, const std::type_info &arg3, bool throw_on_exist)
Add a new phase to the phase.
Definition: Geant4Kernel.cpp:541
dd4hep::sim::Geant4Kernel::Geant4Kernel
Geant4Kernel(Geant4Kernel *m, unsigned long identifier)
Standard constructor for workers.
Definition: Geant4Kernel.cpp:113
dd4hep::sim::Geant4Kernel::m_master
Geant4Kernel * m_master
Parent reference.
Definition: Geant4Kernel.h:139
dd4hep::sim::Geant4Kernel::registerGlobalAction
Geant4Kernel & registerGlobalAction(Geant4Action *action)
Register action by name to be retrieved when setting up and connecting action objects.
Definition: Geant4Kernel.cpp:457
dd4hep::sim::Geant4Kernel::m_processEvents
int m_processEvents
Master property: Flag if event loop is enabled.
Definition: Geant4Kernel.h:122
dd4hep::sim::Geant4Kernel::property
Property & property(const std::string &name)
Access single property.
Definition: Geant4Kernel.cpp:298
dd4hep::sim::Geant4Kernel
Class, which allows all Geant4Action derivatives to access the DDG4 kernel structures.
Definition: Geant4Kernel.h:64
dd4hep::sim::Geant4Kernel::executePhase
virtual bool executePhase(const std::string &name, const void **args) const
Execute phase action if it exists.
Definition: Geant4Kernel.cpp:519
dd4hep::sim::Geant4ActionPhase
Action phase definition. Client callback at various stage of the simulation processing.
Definition: Geant4ActionPhase.h:68
dd4hep::sim::Geant4Action::property
Property & property(const std::string &name)
Access single property.
Definition: Geant4Action.cpp:99
dd4hep::sim::Geant4Kernel::m_interrupts
Geant4Interrupts * m_interrupts
Interrupt/signal handler: only on master instance.
Definition: Geant4Kernel.h:143
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::sim::Geant4Kernel::setOutputLevel
PrintLevel setOutputLevel(PrintLevel new_level)
Set the global output level of the kernel object; returns previous value.
Definition: Geant4Kernel.cpp:315
dd4hep::sim::Geant4Kernel::removePhase
virtual bool removePhase(const std::string &name)
Remove an existing phase from the phase. If not existing returns false.
Definition: Geant4Kernel.cpp:559
dd4hep::sim::Geant4Kernel::processEvents
bool processEvents() const
Check if event processing should be continued.
Definition: Geant4Kernel.cpp:193
dd4hep::sim::Geant4ActionContainer::workerContext
Geant4Context * workerContext()
Thread's Geant4 execution context.
Definition: Geant4ActionContainer.cpp:65
dd4hep::sim::Geant4Kernel::PhaseSelector::PhaseSelector
PhaseSelector(Geant4Kernel *kernel)
Standard constructor.
Definition: Geant4Kernel.cpp:65
dd4hep::sim::Geant4Kernel::register_initialize
void register_initialize(const std::function< void()> &callback)
Register initialize callback. Signature: (function)()
Definition: Geant4Kernel.cpp:375
dd4hep::PropertyManager::exists
bool exists(const std::string &name) const
Check for existence.
Definition: ComponentProperties.cpp:102
dd4hep::sim::Geant4Kernel::worker
Geant4Kernel & worker(unsigned long thread_identifier, bool create_if=false)
Access worker instance by its identifier.
Definition: Geant4Kernel.cpp:230
dd4hep::sim::Geant4Kernel::m_clientLevels
ClientOutputLevels m_clientLevels
Property: Client output levels.
Definition: Geant4Kernel.h:101
dd4hep::sim::Geant4Kernel::registerGlobalFilter
Geant4Kernel & registerGlobalFilter(Geant4Action *filter)
Register filter by name to be retrieved when setting up and connecting filter objects.
Definition: Geant4Kernel.cpp:491
dd4hep::sim::Geant4Kernel::getOutputLevel
PrintLevel getOutputLevel(const std::string object) const
Retrieve the global output level of a named object.
Definition: Geant4Kernel.cpp:308
dd4hep::sim::Geant4Kernel::register_terminate
void register_terminate(const std::function< void()> &callback)
Register terminate callback. Signature: (function)()
Definition: Geant4Kernel.cpp:380
dd4hep::sim::Geant4Kernel::m_globalActions
GlobalActions m_globalActions
Globally registered actions.
Definition: Geant4Kernel.h:97
dd4hep::sim::Geant4Kernel::m_actionInitialize
UserCallbacks m_actionInitialize
Registered action callbacks on initialize.
Definition: Geant4Kernel.h:128
dd4hep::sim::Geant4Kernel::interruptHandler
Geant4Interrupts & interruptHandler() const
Access interrupt handler. Will be created on the first call.
Definition: Geant4Kernel.cpp:177
dd4hep::sim::Geant4Kernel::PhaseSelector::operator[]
Geant4ActionPhase & operator[](const std::string &name) const
Phase access to the map.
Definition: Geant4Kernel.cpp:83
dd4hep::sim::Geant4Kernel::m_runManager
G4RunManager * m_runManager
Reference to the run manager.
Definition: Geant4Kernel.h:80
dd4hep::sim::Geant4Kernel::getPhase
Geant4ActionPhase * getPhase(const std::string &name)
Access phase by name.
Definition: Geant4Kernel.cpp:528
dd4hep::sim::Geant4ActionContainer::setContext
void setContext(Geant4Context *ctxt)
Set the thread's context.
Definition: Geant4ActionContainer.cpp:71
dd4hep::sim::Geant4Kernel::m_runManagerType
std::string m_runManagerType
Property: Name of the G4 run manager factory to be used. Default: Geant4RunManager.
Definition: Geant4Kernel.h:107
dd4hep::sim::Geant4Kernel::hasProperty
bool hasProperty(const std::string &name) const
Check property for existence.
Definition: Geant4Kernel.cpp:293
dd4hep::sim::Geant4Kernel::m_actionConfigure
UserCallbacks m_actionConfigure
Registered action callbacks on configure.
Definition: Geant4Kernel.h:126
dd4hep::Detector::apply
virtual long apply(const char *factory, int argc, char **argv) const =0
Manipulate geometry using factory converter.
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::sim::Geant4Kernel::m_haveScoringMgr
int m_haveScoringMgr
Master property: Instantiate the Geant4 scoring manager object.
Definition: Geant4Kernel.h:120
dd4hep::Detector::destroyInstance
static void destroyInstance(const std::string &name="default")
Destroy the singleton instance.
Definition: DetectorImp.cpp:162
dd4hep::sim::Geant4Kernel::world
G4VPhysicalVolume * world() const
Access to geometry world.
Definition: Geant4Kernel.cpp:256
Plugins.h
dd4hep::sim::Geant4Exec::terminate
static int terminate(Geant4Kernel &kernel)
Terminate the application.
Definition: Geant4Exec.cpp:661
dd4hep::sim::Geant4Action
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:113
dd4hep::sim::Geant4Kernel::registerInterruptHandler
bool registerInterruptHandler(int sig_num)
Install DDG4 default handler for a given signal. If no handler: return false.
Definition: Geant4Kernel.cpp:198
dd4hep::sim::Geant4Kernel::thread_self
static unsigned long int thread_self()
Access thread identifier.
Definition: Geant4Kernel.cpp:211
dd4hep::sim::Geant4Kernel::properties
PropertyManager & properties()
Access to the properties of the object.
Definition: Geant4Kernel.h:240
dd4hep::sim::Geant4Action::name
const std::string & name() const
Access name of the action.
Definition: Geant4Action.h:280
dd4hep::sim::Geant4Kernel::m_phases
Phases m_phases
Action phases.
Definition: Geant4Kernel.h:93
dd4hep::sim::Geant4Kernel::isMaster
bool isMaster() const
Definition: Geant4Kernel.h:145
dd4hep::sim::Geant4Kernel::globalFilter
Geant4Action * globalFilter(const std::string &filter_name, bool throw_if_not_present=true)
Retrieve filter from repository.
Definition: Geant4Kernel.cpp:508
dd4hep::sim::Geant4Kernel::m_ident
unsigned long m_ident
Definition: Geant4Kernel.h:134
dd4hep::sim::Geant4Kernel::m_numThreads
int m_numThreads
Master property: Number of execution threads in multi threaded mode.
Definition: Geant4Kernel.h:118
dd4hep::sim::Geant4Kernel::register_configure
void register_configure(const std::function< void()> &callback)
Register configure callback. Signature: (function)()
Definition: Geant4Kernel.cpp:370
dd4hep::sim::Geant4Exec::initialize
static int initialize(Geant4Kernel &kernel)
Initialize the application.
Definition: Geant4Exec.cpp:622
dd4hep::sim::Geant4Kernel::EVENTLOOP_RUNNING
@ EVENTLOOP_RUNNING
Definition: Geant4Kernel.h:75
dd4hep::sim::Geant4Kernel::m_uiName
std::string m_uiName
Property: Name of the UI action. Must be member of the global actions.
Definition: Geant4Kernel.h:105
dd4hep::sim::Geant4Kernel::m_globalFilters
GlobalActions m_globalFilters
Globally registered filters of sensitive detectors.
Definition: Geant4Kernel.h:99
dd4hep::sim::Geant4Kernel::m_world
G4VPhysicalVolume * m_world
Access to geometry world.
Definition: Geant4Kernel.h:136
dd4hep::sim::Geant4Kernel::isMultiThreaded
bool isMultiThreaded() const
Definition: Geant4Kernel.h:161
dd4hep::sim::Geant4Kernel::m_numEvent
long m_numEvent
Property: Number of events to be executed in batch mode.
Definition: Geant4Kernel.h:113
Memory.h
dd4hep::sim::Geant4Kernel::globalAction
Geant4Action * globalAction(const std::string &action_name, bool throw_if_not_present=true)
Retrieve action from repository.
Definition: Geant4Kernel.cpp:476
dd4hep::sim::Geant4Kernel::initialize
virtual int initialize()
Run the simulation: Initialize Geant4.
Definition: Geant4Kernel.cpp:396
Primitives.h
dd4hep::sim::Geant4Kernel::instance
static Geant4Kernel & instance(Detector &description)
Instance accessor.
Definition: Geant4Kernel.cpp:163
dd4hep::sim::Geant4ActionContainer::terminate
virtual int terminate()
Terminate all associated action instances.
Definition: Geant4ActionContainer.cpp:51
dd4hep::sim::Geant4Kernel::createWorker
virtual Geant4Kernel & createWorker()
Create identified worker instance.
Definition: Geant4Kernel.cpp:217
dd4hep::sim::Geant4Action::addRef
long addRef()
Increase reference count.
Definition: Geant4Action.cpp:71
dd4hep::sim::Geant4Kernel::run
virtual int run()
Run the simulation: Simulate the number of events given by the property "NumEvents".
Definition: Geant4Kernel.cpp:407
dd4hep::sim::Geant4Kernel::loadGeometry
virtual void loadGeometry(const std::string &compact_file)
Construct detector geometry using description plugin.
Definition: Geant4Kernel.cpp:357
dd4hep::Property::set
void set(const TYPE &value)
Set value of this property.
Definition: ComponentProperties.h:102
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep::sim::Geant4Kernel::m_id
unsigned long m_id
Flag: Master instance (id<0) or worker (id >= 0)
Definition: Geant4Kernel.h:134
dd4hep::sim::Geant4Kernel::m_controlName
std::string m_controlName
Property: Name of the G4UI command tree.
Definition: Geant4Kernel.h:103
dd4hep::sim::Geant4ActionContainer
Class, which allows all Geant4Action to be stored.
Definition: Geant4ActionContainer.h:60
dd4hep::sim::Geant4Kernel::runEvents
virtual int runEvents(int num_events)
Run the simulation: Simulate the number of events "num_events" and modify the property "NumEvents".
Definition: Geant4Kernel.cpp:423
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::sim::Geant4Kernel::m_detDesc
Detector * m_detDesc
Detector description object.
Definition: Geant4Kernel.h:86
Geant4Kernel.h
dd4hep::sim::Geant4Kernel::m_properties
PropertyManager m_properties
Property pool.
Definition: Geant4Kernel.h:88
dd4hep::sim::Geant4Action::enableUI
virtual void enableUI()
Enable and install UI messenger.
Definition: Geant4Action.cpp:134
InstanceCount.h
dd4hep::sim::Geant4Kernel::runManager
G4RunManager & runManager()
Access to the Geant4 run manager.
Definition: Geant4Kernel.cpp:322
Geant4ActionPhase.h
dd4hep::sim::Geant4Kernel::~Geant4Kernel
virtual ~Geant4Kernel()
Default destructor.
Definition: Geant4Kernel.cpp:137
dd4hep::sim::Geant4Interrupts::registerHandler_SIGINT
bool registerHandler_SIGINT()
Specialized handler for SIGINT.
Definition: Geant4Interrupts.cpp:31
dd4hep::sim::Geant4Kernel::PhaseSelector::operator=
PhaseSelector & operator=(const PhaseSelector &c)
Assignment operator.
Definition: Geant4Kernel.cpp:75
Printout.h
Geant4Context.h
dd4hep::sim::Geant4Kernel::m_actionTerminate
UserCallbacks m_actionTerminate
Registered action callbacks on terminate.
Definition: Geant4Kernel.h:130
dd4hep::sim::Geant4Kernel::m_sensitiveDetectorTypes
std::map< std::string, std::string > m_sensitiveDetectorTypes
Property: Names with specialized factories to create G4VSensitiveDetector instances.
Definition: Geant4Kernel.h:111
dd4hep::sim::Geant4Kernel::applyInterruptHandlers
void applyInterruptHandlers()
(Re-)apply registered interrupt handlers to override potentially later registrations by other librari...
Definition: Geant4Kernel.cpp:206
dd4hep::sim::Geant4Kernel::printProperties
void printProperties() const
Print the property values.
Definition: Geant4Kernel.cpp:283
dd4hep::sim::Geant4Kernel::numWorkers
int numWorkers() const
Access number of workers.
Definition: Geant4Kernel.cpp:251
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4Kernel::terminate
virtual int terminate() override
Run the simulation: Terminate Geant4.
Definition: Geant4Kernel.cpp:428