ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
G4AtlasRunManager Class Reference

ATLAS custom singleton run manager. More...

#include <G4AtlasRunManager.h>

Inheritance diagram for G4AtlasRunManager:
Collaboration diagram for G4AtlasRunManager:

Public Member Functions

virtual ~G4AtlasRunManager ()
 
bool ProcessEvent (G4Event *event)
 Does the work of simulating an ATLAS event. More...
 
void RunTermination () override final
 G4 function called at end of run. More...
 
void SetDetGeoSvc (const std::string &typeAndName)
 Configure the detector geometry service handle. More...
 
void SetFastSimMasterTool (const std::string &typeAndName)
 Configure the Fast Simulation Master Tool handle. More...
 
void SetPhysListSvc (const std::string &typeAndName)
 Configure the Physics List Tool handle. More...
 
void SetRecordFlux (bool b, std::unique_ptr< IFluxRecorder > f)
 
void SetLogLevel (int)
 
void SetVolumeSmartlessLevel (const std::map< std::string, double > &nameAndValue)
 
bool msgLvl (const MSG::Level lvl) const
 Test the output level. More...
 
MsgStream & msg () const
 The standard message stream. More...
 
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream. More...
 
void setLevel (MSG::Level lvl)
 Change the current logging level. More...
 

Static Public Member Functions

static G4AtlasRunManager *GetG4AtlasRunManager ATLAS_NOT_THREAD_SAFE ()
 Retrieve the singleton instance. More...
 

Protected Member Functions

Overridden G4 init methods for customization
void Initialize () override final
 
void InitializeGeometry () override final
 
void InitializePhysics () override final
 

Private Member Functions

 G4AtlasRunManager ()
 Pure singleton private constructor. More...
 
void EndEvent ()
 
void initMessaging () const
 Initialize our message level and MessageSvc. More...
 

Private Attributes

bool m_recordFlux
 
ToolHandle< IFastSimulationMasterToolm_fastSimTool
 
ServiceHandle< IPhysicsListSvcm_physListSvc
 
ServiceHandle< IDetectorGeometrySvcm_detGeoSvc
 
std::unique_ptr< IFluxRecorderm_fluxRecorder
 Interface to flux recording. More...
 
std::map< std::string, double > m_volumeSmartlessLevel
 
std::string m_nm
 Message source name. More...
 
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels) More...
 
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer. More...
 
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level. More...
 
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging) More...
 

Detailed Description

ATLAS custom singleton run manager.

This is the run manager used for serial (not-MT) jobs.

Todo:
sync and reduce code duplication with MT run managers.

Definition at line 30 of file G4AtlasRunManager.h.

Constructor & Destructor Documentation

◆ ~G4AtlasRunManager()

virtual G4AtlasRunManager::~G4AtlasRunManager ( )
inlinevirtual

Definition at line 34 of file G4AtlasRunManager.h.

34 {}

◆ G4AtlasRunManager()

G4AtlasRunManager::G4AtlasRunManager ( )
private

Pure singleton private constructor.

Definition at line 22 of file G4AtlasRunManager.cxx.

23  : G4RunManager()
24  , AthMessaging("G4AtlasRunManager")
25  , m_recordFlux(false)
26  , m_fastSimTool("FastSimulationMasterTool")
27  , m_physListSvc("PhysicsListSvc", "G4AtlasRunManager")
28  , m_detGeoSvc("DetectorGeometrySvc", "G4AtlasRunManager")
30 { }

Member Function Documentation

◆ ATLAS_NOT_THREAD_SAFE()

static G4AtlasRunManager* GetG4AtlasRunManager G4AtlasRunManager::ATLAS_NOT_THREAD_SAFE ( )
static

Retrieve the singleton instance.

◆ EndEvent()

void G4AtlasRunManager::EndEvent ( )
private

Definition at line 73 of file G4AtlasRunManager.cxx.

74 {
75  ATH_MSG_DEBUG( "G4AtlasRunManager::EndEvent" );
76 }

◆ Initialize()

void G4AtlasRunManager::Initialize ( )
finaloverrideprotected

Definition at line 41 of file G4AtlasRunManager.cxx.

42 {
43  // ADA 11/28.2018: switch initialization order to meet ISF requirements
44  // Call the base class Initialize method. This will call
45  // InitializeGeometry and InitializePhysics.
47 }

◆ InitializeGeometry()

void G4AtlasRunManager::InitializeGeometry ( )
finaloverrideprotected

Definition at line 50 of file G4AtlasRunManager.cxx.

51 {
52  ATH_MSG_DEBUG( "InitializeGeometry()" );
53  if (m_detGeoSvc.retrieve().isFailure()) {
54  ATH_MSG_ERROR ( "Could not retrieve the DetectorGeometrySvc" );
55  G4ExceptionDescription description;
56  description << "InitializeGeometry: Failed to retrieve IDetectorGeometrySvc.";
57  G4Exception("G4AtlasRunManager", "CouldNotRetrieveDetGeoSvc", FatalException, description);
58  abort(); // to keep Coverity happy
59  }
60 
61  // Create/assign detector construction
62  G4RunManager::SetUserInitialization(m_detGeoSvc->GetDetectorConstruction());
63  if (userDetector) {
64  G4RunManager::InitializeGeometry();
65  }
66  else {
67  ATH_MSG_WARNING( " User Detector not set!!! Geometry NOT initialized!!!" );
68  }
69  return;
70 }

◆ InitializePhysics()

void G4AtlasRunManager::InitializePhysics ( )
finaloverrideprotected

Definition at line 79 of file G4AtlasRunManager.cxx.

80 {
81  ATH_MSG_INFO( "InitializePhysics()" );
82  kernel->InitializePhysics();
83  physicsInitialized = true;
84 
85  // Grab the physics list tool and set the extra options
86  if (m_physListSvc.retrieve().isFailure()) {
87  ATH_MSG_ERROR ( "Could not retrieve the physics list tool" );
88  G4ExceptionDescription description;
89  description << "InitializePhysics: Failed to retrieve IPhysicsListSvc.";
90  G4Exception("G4AtlasRunManager", "CouldNotRetrievePLTool", FatalException, description);
91  abort(); // to keep Coverity happy
92  }
93  m_physListSvc->SetPhysicsOptions();
94 
95  // Fast simulations last
96  if (m_fastSimTool.retrieve().isFailure()) {
97  ATH_MSG_ERROR ( "Could not retrieve the FastSim master tool" );
98  G4ExceptionDescription description;
99  description << "InitializePhysics: Failed to retrieve IFastSimulationMasterTool.";
100  G4Exception("G4AtlasRunManager", "CouldNotRetrieveFastSimMaster", FatalException, description);
101  abort(); // to keep Coverity happy
102  }
103  if(m_fastSimTool->initializeFastSims().isFailure()) {
104  G4ExceptionDescription description;
105  description << "InitializePhysics: Call to IFastSimulationMasterTool::initializeFastSims failed.";
106  G4Exception("G4AtlasRunManager", "FailedToInitializeFastSims", FatalException, description);
107  abort(); // to keep Coverity happy
108  }
109 
110  if (m_recordFlux) {
111  m_fluxRecorder->InitializeFluxRecording();
112  }
113 
114  return;
115 }

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40 {
42  m_lvl = m_imsg ?
43  static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
44  MSG::INFO;
45 }

◆ msg() [1/2]

MsgStream & AthMessaging::msg ( ) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 164 of file AthMessaging.h.

165 {
166  MsgStream* ms = m_msg_tls.get();
167  if (!ms) {
168  if (!m_initialized.test_and_set()) initMessaging();
169  ms = new MsgStream(m_imsg,m_nm);
170  m_msg_tls.reset( ms );
171  }
172 
173  ms->setLevel (m_lvl);
174  return *ms;
175 }

◆ msg() [2/2]

MsgStream & AthMessaging::msg ( const MSG::Level  lvl) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 179 of file AthMessaging.h.

180 { return msg() << lvl; }

◆ msgLvl()

bool AthMessaging::msgLvl ( const MSG::Level  lvl) const
inlineinherited

Test the output level.

Parameters
lvlThe message level to test against
Returns
boolean Indicating if messages at given level will be printed
Return values
trueMessages at level "lvl" will be printed

Definition at line 151 of file AthMessaging.h.

152 {
153  if (!m_initialized.test_and_set()) initMessaging();
154  if (m_lvl <= lvl) {
155  msg() << lvl;
156  return true;
157  } else {
158  return false;
159  }
160 }

◆ ProcessEvent()

bool G4AtlasRunManager::ProcessEvent ( G4Event *  event)

Does the work of simulating an ATLAS event.

Definition at line 117 of file G4AtlasRunManager.cxx.

118 {
119 
120  G4StateManager* stateManager = G4StateManager::GetStateManager();
121  stateManager->SetNewState(G4State_GeomClosed);
122 
123  currentEvent = event;
124 
125  eventManager->ProcessOneEvent(currentEvent);
126  if (currentEvent->IsAborted()) {
127  ATH_MSG_WARNING( "G4AtlasRunManager::ProcessEvent: Event Aborted at Detector Simulation level" );
128  currentEvent = nullptr;
129  return true;
130  }
131 
132  if (m_recordFlux) { m_fluxRecorder->RecordFlux(currentEvent); }
133 
134  this->StackPreviousEvent(currentEvent);
135  bool abort = currentEvent->IsAborted();
136  currentEvent = nullptr;
137 
138  return abort;
139 }

◆ RunTermination()

void G4AtlasRunManager::RunTermination ( )
finaloverride

G4 function called at end of run.

Definition at line 141 of file G4AtlasRunManager.cxx.

142 {
143  ATH_MSG_DEBUG( " G4AtlasRunManager::RunTermination() " );
144  if (m_recordFlux) {
145  m_fluxRecorder->WriteFluxInformation();
146  }
147 
148  this->CleanUpPreviousEvents();
149  previousEvents->clear();
150 
151  if (userRunAction) {
152  userRunAction->EndOfRunAction(currentRun);
153  }
154 
155  delete currentRun;
156  currentRun = nullptr;
157  runIDCounter++;
158 
159  ATH_MSG_VERBOSE( "Changing the state..." );
160  G4StateManager* stateManager = G4StateManager::GetStateManager();
161  stateManager->SetNewState(G4State_Idle);
162 
163  ATH_MSG_VERBOSE( "Opening the geometry back up" );
164  G4GeometryManager::GetInstance()->OpenGeometry();
165 
166  ATH_MSG_VERBOSE( "Terminating the run... State is " << stateManager->GetStateString( stateManager->GetCurrentState() ) );
167  kernel->RunTermination();
168  ATH_MSG_VERBOSE( "All done..." );
169 
170  userRunAction = nullptr;
171  userEventAction = nullptr;
172  userSteppingAction = nullptr;
173  userStackingAction = nullptr;
174  userTrackingAction = nullptr;
175  userDetector = nullptr;
176  userPrimaryGeneratorAction = nullptr;
177 
178  return;
179 }

◆ SetDetGeoSvc()

void G4AtlasRunManager::SetDetGeoSvc ( const std::string &  typeAndName)
inline

Configure the detector geometry service handle.

Definition at line 46 of file G4AtlasRunManager.h.

46  {
47  m_detGeoSvc.setTypeAndName(typeAndName);
48  }

◆ SetFastSimMasterTool()

void G4AtlasRunManager::SetFastSimMasterTool ( const std::string &  typeAndName)
inline

Configure the Fast Simulation Master Tool handle.

Definition at line 51 of file G4AtlasRunManager.h.

51  {
52  m_fastSimTool.setTypeAndName(typeAndName);
53  }

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level  lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29 {
30  m_lvl = lvl;
31 }

◆ SetLogLevel()

void G4AtlasRunManager::SetLogLevel ( int  )
inline

Definition at line 61 of file G4AtlasRunManager.h.

61 { /* Not implemented */ }

◆ SetPhysListSvc()

void G4AtlasRunManager::SetPhysListSvc ( const std::string &  typeAndName)
inline

Configure the Physics List Tool handle.

Definition at line 56 of file G4AtlasRunManager.h.

56  {
57  m_physListSvc.setTypeAndName(typeAndName);
58  }

◆ SetRecordFlux()

void G4AtlasRunManager::SetRecordFlux ( bool  b,
std::unique_ptr< IFluxRecorder f 
)
inline

Definition at line 60 of file G4AtlasRunManager.h.

60 { m_recordFlux = b; m_fluxRecorder=std::move(f);}

◆ SetVolumeSmartlessLevel()

void G4AtlasRunManager::SetVolumeSmartlessLevel ( const std::map< std::string, double > &  nameAndValue)
inline

Definition at line 64 of file G4AtlasRunManager.h.

64  {
65  m_volumeSmartlessLevel = nameAndValue;
66  }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging)

Definition at line 141 of file AthMessaging.h.

◆ m_detGeoSvc

ServiceHandle<IDetectorGeometrySvc> G4AtlasRunManager::m_detGeoSvc
private

Definition at line 89 of file G4AtlasRunManager.h.

◆ m_fastSimTool

ToolHandle<IFastSimulationMasterTool> G4AtlasRunManager::m_fastSimTool
private

Definition at line 86 of file G4AtlasRunManager.h.

◆ m_fluxRecorder

std::unique_ptr<IFluxRecorder> G4AtlasRunManager::m_fluxRecorder
private

Interface to flux recording.

Definition at line 93 of file G4AtlasRunManager.h.

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels)

Definition at line 132 of file AthMessaging.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.

◆ m_physListSvc

ServiceHandle<IPhysicsListSvc> G4AtlasRunManager::m_physListSvc
private

Definition at line 87 of file G4AtlasRunManager.h.

◆ m_recordFlux

bool G4AtlasRunManager::m_recordFlux
private

Definition at line 84 of file G4AtlasRunManager.h.

◆ m_volumeSmartlessLevel

std::map<std::string, double> G4AtlasRunManager::m_volumeSmartlessLevel
private

Definition at line 97 of file G4AtlasRunManager.h.


The documentation for this class was generated from the following files:
AthMessaging::m_lvl
std::atomic< MSG::Level > m_lvl
Current logging level.
Definition: AthMessaging.h:138
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
G4AtlasRunManager::m_physListSvc
ServiceHandle< IPhysicsListSvc > m_physListSvc
Definition: G4AtlasRunManager.h:87
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
AthMessaging::m_imsg
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
Definition: AthMessaging.h:135
python.SystemOfUnits.ms
int ms
Definition: SystemOfUnits.py:132
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
AthMessaging::AthMessaging
AthMessaging()
Default constructor:
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
G4AtlasRunManager::m_fluxRecorder
std::unique_ptr< IFluxRecorder > m_fluxRecorder
Interface to flux recording.
Definition: G4AtlasRunManager.h:93
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
G4AtlasRunManager::m_volumeSmartlessLevel
std::map< std::string, double > m_volumeSmartlessLevel
Definition: G4AtlasRunManager.h:97
G4AtlasRunManager::m_recordFlux
bool m_recordFlux
Definition: G4AtlasRunManager.h:84
G4AtlasRunManager::m_detGeoSvc
ServiceHandle< IDetectorGeometrySvc > m_detGeoSvc
Definition: G4AtlasRunManager.h:89
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
jobOptions.Initialize
Initialize
Definition: jobOptions.pA.py:28
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
AthMessaging::m_nm
std::string m_nm
Message source name.
Definition: AthMessaging.h:129
G4AtlasRunManager::m_fastSimTool
ToolHandle< IFastSimulationMasterTool > m_fastSimTool
Definition: G4AtlasRunManager.h:86
AthMessaging::initMessaging
void initMessaging() const
Initialize our message level and MessageSvc.
Definition: AthMessaging.cxx:39
AthMessaging::m_msg_tls
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels)
Definition: AthMessaging.h:132
description
std::string description
glabal timer - how long have I taken so far?
Definition: hcg.cxx:88