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)
 
void SetQuietMode (bool quietMode)
 Configure the QuietMode option. More...
 
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
 
bool m_quietMode {true}
 Quiet Mode for production. More...
 
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 74 of file G4AtlasRunManager.cxx.

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

◆ 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.
46  if (m_quietMode) { SetVerboseLevel(0); } // HACK
48 }

◆ InitializeGeometry()

void G4AtlasRunManager::InitializeGeometry ( )
finaloverrideprotected

Definition at line 51 of file G4AtlasRunManager.cxx.

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

◆ InitializePhysics()

void G4AtlasRunManager::InitializePhysics ( )
finaloverrideprotected

Definition at line 80 of file G4AtlasRunManager.cxx.

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

◆ 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 118 of file G4AtlasRunManager.cxx.

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

◆ RunTermination()

void G4AtlasRunManager::RunTermination ( )
finaloverride

G4 function called at end of run.

Definition at line 142 of file G4AtlasRunManager.cxx.

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

◆ 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  }

◆ SetQuietMode()

void G4AtlasRunManager::SetQuietMode ( bool  quietMode)
inline

Configure the QuietMode option.

Definition at line 68 of file G4AtlasRunManager.h.

68  {
69  m_quietMode = quietMode;
70  }

◆ 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 63 of file G4AtlasRunManager.h.

63  {
64  m_volumeSmartlessLevel = nameAndValue;
65  }

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 93 of file G4AtlasRunManager.h.

◆ m_fastSimTool

ToolHandle<IFastSimulationMasterTool> G4AtlasRunManager::m_fastSimTool
private

Definition at line 90 of file G4AtlasRunManager.h.

◆ m_fluxRecorder

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

Interface to flux recording.

Definition at line 97 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 91 of file G4AtlasRunManager.h.

◆ m_quietMode

bool G4AtlasRunManager::m_quietMode {true}
private

Quiet Mode for production.

Definition at line 104 of file G4AtlasRunManager.h.

◆ m_recordFlux

bool G4AtlasRunManager::m_recordFlux
private

Definition at line 88 of file G4AtlasRunManager.h.

◆ m_volumeSmartlessLevel

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

Definition at line 101 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
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
G4AtlasRunManager::m_quietMode
bool m_quietMode
Quiet Mode for production.
Definition: G4AtlasRunManager.h:104
G4AtlasRunManager::m_physListSvc
ServiceHandle< IPhysicsListSvc > m_physListSvc
Definition: G4AtlasRunManager.h:91
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:97
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:101
G4AtlasRunManager::m_recordFlux
bool m_recordFlux
Definition: G4AtlasRunManager.h:88
G4AtlasRunManager::m_detGeoSvc
ServiceHandle< IDetectorGeometrySvc > m_detGeoSvc
Definition: G4AtlasRunManager.h:93
hist_file_dump.f
f
Definition: hist_file_dump.py:135
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:90
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