Skip to content
Snippets Groups Projects
Commit 01d9149b authored by John Chapman's avatar John Chapman
Browse files

Adapt code to use G4AtlasActionInitialization

Here we adapt the various clients of the `UserActionSvc` to create
(in the case of `G4AtlasAlg`, `G4LegacyTransportTool` and
`G4TransportTool`) `G4AtlasActionInitialization` or use it
(`G4AtlasRunManager`, `G4AtlasUserWorkerThreadInitialization`,
`G4AtlasWorkerRunManager`).
parent 6e492f9a
No related branches found
No related tags found
6 merge requests!58791DataQualityConfigurations: Modify L1Calo config for web display,!46784MuonCondInterface: Enable thread-safety checking.,!46776Updated LArMonitoring config file for WD to match new files produced using MT,!45405updated ART test cron job,!42417Draft: DIRE and VINCIA Base Fragments for Pythia 8.3,!38233Switch to using G4AtlasActionInitialization to initialize UserActions in Simulation jobs
Showing with 28 additions and 70 deletions
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
#ifndef G4ATLASALG_G4AtlasRunManager_h
......@@ -17,7 +17,6 @@
#include "G4AtlasInterfaces/ISensitiveDetectorMasterTool.h"
#include "G4AtlasInterfaces/IFastSimulationMasterTool.h"
#include "G4AtlasInterfaces/IPhysicsListSvc.h"
#include "G4AtlasInterfaces/IUserActionSvc.h"
#include "G4AtlasInterfaces/IDetectorGeometrySvc.h"
#include "G4AtlasInterfaces/IFluxRecorder.h"
......@@ -41,13 +40,6 @@ public:
/// G4 function called at end of run
void RunTermination() override final;
/// @name Methods to pass configuration in from G4AtlasAlg
/// @{
/// Configure the user action service handle
void SetUserActionSvc(const std::string& typeAndName) {
m_userActionSvc.setTypeAndName(typeAndName);
}
/// Configure the detector geometry service handle
void SetDetGeoSvc(const std::string& typeAndName) {
......@@ -103,12 +95,10 @@ private:
ToolHandle<IFastSimulationMasterTool> m_fastSimTool;
ServiceHandle<IPhysicsListSvc> m_physListSvc;
/// Handle to the user action service
ServiceHandle<G4UA::IUserActionSvc> m_userActionSvc;
ServiceHandle<IDetectorGeometrySvc> m_detGeoSvc;
/// Interface to flux recording
std::unique_ptr<IFluxRecorder> m_fluxRecorder;
};
......
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
#ifndef G4ATLASALG_G4ATLASUSERWORKERTHREADINITIALIZATION_H
......@@ -32,11 +32,6 @@ public:
/// @name Methods to pass configuration in from G4AtlasAlg
/// @{
/// Configure the user action service handle
void SetUserActionSvc(const std::string& typeAndName) {
m_userActionSvcName = typeAndName;
}
/// Configure the detector geometry service handle
void SetDetGeoSvc(const std::string& typeAndName) {
m_detGeoSvcName = typeAndName;
......@@ -56,7 +51,6 @@ private:
std::string m_detGeoSvcName{"DetectorGeometrySvc"};
std::string m_senDetToolName{"SensitiveDetectorMasterTool"};
std::string m_fastSimToolName{"FastSimulationMasterTool"};
std::string m_userActionSvcName{"G4UA::UserActionSvc"};
}; // class G4AtlasUserWorkerThreadInitialization
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
#ifndef G4ATLASALG_G4ATLASWORKERRUNMANAGER_H
......@@ -18,7 +18,6 @@
#include "G4AtlasInterfaces/IDetectorGeometrySvc.h"
#include "G4AtlasInterfaces/ISensitiveDetectorMasterTool.h"
#include "G4AtlasInterfaces/IFastSimulationMasterTool.h"
#include "G4AtlasInterfaces/IUserActionSvc.h"
/// @brief ATLAS worker run manager for master-slave multi-threading model
......@@ -41,11 +40,6 @@ public:
/// @name Methods to pass configuration in from G4AtlasUserWorkerThreadInitialization
/// @{
/// Configure the user action service handle
void SetUserActionSvc(const std::string& typeAndName) {
m_userActionSvc.setTypeAndName(typeAndName);
}
/// Configure the detector geometry service handle
void SetDetGeoSvc(const std::string& typeAndName) {
m_detGeoSvc.setTypeAndName(typeAndName);
......@@ -97,9 +91,6 @@ private:
/// Handle to the FastSim tool
ToolHandle<IFastSimulationMasterTool> m_fastSimTool;
/// Handle to the user action service
ServiceHandle<G4UA::IUserActionSvc> m_userActionSvc;
};
#endif // G4MULTITHREADED
......
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
// Local includes
#include "G4AtlasAlg.h"
#include "G4AtlasFluxRecorder.h"
#include "G4AtlasAlg/G4AtlasActionInitialization.h"
#include "AthenaKernel/RNGWrapper.h"
......@@ -121,11 +122,13 @@ void G4AtlasAlg::initializeOnce()
// Worker Thread initialization used to create worker run manager on demand.
std::unique_ptr<G4AtlasUserWorkerThreadInitialization> workerInit =
std::make_unique<G4AtlasUserWorkerThreadInitialization>();
workerInit->SetUserActionSvc( m_userActionSvc.typeAndName() );
workerInit->SetDetGeoSvc( m_detGeoSvc.typeAndName() );
workerInit->SetSDMasterTool( m_senDetTool.typeAndName() );
workerInit->SetFastSimMasterTool( m_fastSimTool.typeAndName() );
runMgr->SetUserInitialization( workerInit.release() );
std::unique_ptr<G4AtlasActionInitialization> actionInitialization =
std::make_unique<G4AtlasActionInitialization>(&*m_userActionSvc);
runMgr->SetUserInitialization(actionInitialization.release());
#else
throw std::runtime_error("Trying to use multi-threading in non-MT build!");
#endif
......@@ -136,11 +139,13 @@ void G4AtlasAlg::initializeOnce()
m_physListSvc->SetPhysicsList();
runMgr->SetRecordFlux( m_recordFlux, std::make_unique<G4AtlasFluxRecorder>() );
runMgr->SetLogLevel( int(msg().level()) ); // Synch log levels
runMgr->SetUserActionSvc( m_userActionSvc.typeAndName() );
runMgr->SetDetGeoSvc( m_detGeoSvc.typeAndName() );
runMgr->SetSDMasterTool(m_senDetTool.typeAndName() );
runMgr->SetFastSimMasterTool(m_fastSimTool.typeAndName() );
runMgr->SetPhysListSvc(m_physListSvc.typeAndName() );
std::unique_ptr<G4AtlasActionInitialization> actionInitialization =
std::make_unique<G4AtlasActionInitialization>(&*m_userActionSvc);
runMgr->SetUserInitialization(actionInitialization.release());
}
// G4 user interface commands
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
#include "G4AtlasAlg/G4AtlasRunManager.h"
......@@ -27,7 +27,6 @@ G4AtlasRunManager::G4AtlasRunManager()
, m_senDetTool("SensitiveDetectorMasterTool")
, m_fastSimTool("FastSimulationMasterTool")
, m_physListSvc("PhysicsListSvc", "G4AtlasRunManager")
, m_userActionSvc("G4UA::UserActionSvc", "G4AtlasRunManager")
, m_detGeoSvc("DetectorGeometrySvc", "G4AtlasRunManager")
{ }
......@@ -42,26 +41,10 @@ G4AtlasRunManager* G4AtlasRunManager::GetG4AtlasRunManager()
void G4AtlasRunManager::Initialize()
{
const std::string methodName = "G4AtlasRunManager::Initialize";
// ADA 11/28.2018: switch initialization order to meet ISF requirements
// Call the base class Initialize method. This will call
// InitializeGeometry and InitializePhysics.
G4RunManager::Initialize();
// Setup the user actions now.
if( !m_userActionSvc.name().empty() ) {
ATH_MSG_INFO("Creating user actions now");
if(m_userActionSvc.retrieve().isFailure()) {
throw GaudiException("Could not retrieve UserActionSvc",
methodName, StatusCode::FAILURE);
}
if(m_userActionSvc->initializeActions().isFailure()) {
throw GaudiException("Failed to initialize actions",
methodName, StatusCode::FAILURE);
}
}
}
......
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
// Hide multi-threading classes from builds without G4MT
......@@ -14,7 +14,6 @@ CreateWorkerRunManager() const
{
// TODO: maybe better to just use the pseudo-singleton mechanism
auto* workerRunManager = G4AtlasWorkerRunManager::GetG4AtlasWorkerRunManager();
workerRunManager->SetUserActionSvc(m_userActionSvcName);
workerRunManager->SetDetGeoSvc(m_detGeoSvcName);
workerRunManager->SetSDMasterTool(m_senDetToolName);
workerRunManager->SetFastSimMasterTool(m_fastSimToolName);
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
// Hide multi-threading classes from builds without G4MT
......@@ -36,7 +36,6 @@ G4AtlasWorkerRunManager::G4AtlasWorkerRunManager()
, m_detGeoSvc("DetectorGeometrySvc", "G4AtlasWorkerRunManager")
, m_senDetTool("SensitiveDetectorMasterTool")
, m_fastSimTool("FastSimulationMasterTool")
, m_userActionSvc("G4UA::UserActionSvc", "G4AtlasWorkerRunManager")
{}
......@@ -54,18 +53,6 @@ void G4AtlasWorkerRunManager::Initialize()
// Locking this initialization to protect currently thread-unsafe services
std::lock_guard<std::mutex> lock(workerInitMutex);
const std::string methodName = "G4AtlasWorkerRunManager::Initialize";
// Setup the user actions for current worker thread.
if(m_userActionSvc.retrieve().isFailure()) {
throw GaudiException("Could not retrieve UserActionSvc for worker thread",
methodName, StatusCode::FAILURE);
}
if(m_userActionSvc->initializeActions().isFailure()) {
throw GaudiException("Failed to initialize actions for worker thread",
methodName, StatusCode::FAILURE);
}
// Setup geometry and physics via the base class
G4RunManager::Initialize();
......@@ -84,6 +71,7 @@ void G4AtlasWorkerRunManager::Initialize()
** will have to be thoroughly reviewed.
*/
ATH_MSG_DEBUG("G4 Command: Trying at the end of Initialize()");
const std::string methodName = "G4AtlasWorkerRunManager::Initialize";
G4MTRunManager* masterRM = G4MTRunManager::GetMasterRunManager();
std::vector<G4String> cmds = masterRM->GetCommandStack();
G4UImanager* uimgr = G4UImanager::GetUIpointer();
......
......@@ -7,6 +7,7 @@
//package includes
#include "G4AtlasAlg/G4AtlasRunManager.h"
#include "G4AtlasAlg/G4AtlasActionInitialization.h"
#include "ISFFluxRecorder.h"
#include "AthenaKernel/RNGWrapper.h"
......@@ -118,11 +119,13 @@ void iGeant4::G4LegacyTransportTool::initializeOnce()
m_pRunMgr->SetRecordFlux( m_recordFlux, std::make_unique<ISFFluxRecorder>() );
m_pRunMgr->SetLogLevel( int(msg().level()) ); // Synch log levels
m_pRunMgr->SetUserActionSvc( m_userActionSvc.typeAndName() );
m_pRunMgr->SetDetGeoSvc( m_detGeoSvc.typeAndName() );
m_pRunMgr->SetSDMasterTool(m_senDetTool.typeAndName() );
m_pRunMgr->SetFastSimMasterTool(m_fastSimTool.typeAndName() );
m_pRunMgr->SetPhysListSvc(m_physListSvc.typeAndName() );
std::unique_ptr<G4AtlasActionInitialization> actionInitialization =
std::make_unique<G4AtlasActionInitialization>(&*m_userActionSvc);
m_pRunMgr->SetUserInitialization(actionInitialization.release());
G4UImanager *ui = G4UImanager::GetUIpointer();
......
......@@ -10,6 +10,7 @@
#include "G4AtlasAlg/G4AtlasWorkerRunManager.h"
#include "G4AtlasAlg/G4AtlasUserWorkerThreadInitialization.h"
#include "G4AtlasAlg/G4AtlasRunManager.h"
#include "G4AtlasAlg/G4AtlasActionInitialization.h"
#include "ISFFluxRecorder.h"
#include "AthenaKernel/RNGWrapper.h"
......@@ -121,11 +122,13 @@ void iGeant4::G4TransportTool::initializeOnce()
// Worker Thread initialization used to create worker run manager on demand.
std::unique_ptr<G4AtlasUserWorkerThreadInitialization> workerInit =
std::make_unique<G4AtlasUserWorkerThreadInitialization>();
workerInit->SetUserActionSvc( m_userActionSvc.typeAndName() );
workerInit->SetDetGeoSvc( m_detGeoSvc.typeAndName() );
workerInit->SetSDMasterTool( m_senDetTool.typeAndName() );
workerInit->SetFastSimMasterTool( m_fastSimTool.typeAndName() );
runMgr->SetUserInitialization( workerInit.release() );
std::unique_ptr<G4AtlasActionInitialization> actionInitialization =
std::make_unique<G4AtlasActionInitialization>(&*m_userActionSvc);
runMgr->SetUserInitialization(actionInitialization.release());
#else
throw std::runtime_error("Trying to use multi-threading in non-MT build!");
#endif
......@@ -136,11 +139,13 @@ void iGeant4::G4TransportTool::initializeOnce()
m_physListSvc->SetPhysicsList();
runMgr->SetRecordFlux( m_recordFlux, std::make_unique<ISFFluxRecorder>() );
runMgr->SetLogLevel( int(msg().level()) ); // Synch log levels
runMgr->SetUserActionSvc( m_userActionSvc.typeAndName() );
runMgr->SetDetGeoSvc( m_detGeoSvc.typeAndName() );
runMgr->SetSDMasterTool(m_senDetTool.typeAndName() );
runMgr->SetFastSimMasterTool(m_fastSimTool.typeAndName() );
runMgr->SetPhysListSvc(m_physListSvc.typeAndName() );
std::unique_ptr<G4AtlasActionInitialization> actionInitialization =
std::make_unique<G4AtlasActionInitialization>(&*m_userActionSvc);
runMgr->SetUserInitialization(actionInitialization.release());
}
G4UImanager *ui = G4UImanager::GetUIpointer();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment