ATLAS Offline Software
FastSimulationBase.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include <G4Region.hh>
7 
8 // Geant4 includes used in functions
9 #include "G4RegionStore.hh"
10 #include "G4FastSimulationManager.hh"
11 
12 FastSimulationBase::FastSimulationBase(const std::string& type, const std::string& name, const IInterface* parent)
13  : base_class(type,name,parent)
14 {
15 }
16 
18 {
20 }
21 
23 {
24  if (m_regionName.value().empty()) {
25  return nullptr;
26  }
27  return G4RegionStore::GetInstance()->GetRegion(m_regionName.value());
28 }
29 
30 
31 // Athena method, used to get out the G4 geometry and set up the Fast Simulation Models
33  ATH_MSG_VERBOSE( name() << "::initializeFastSim()" );
34 
35  // Make sure Fast Simulation Model isn't already registered
36  if(getFastSimModel()){
37  ATH_MSG_ERROR("Trying to create a Fast Simulation Model which already exists!");
38  return StatusCode::FAILURE;
39  }
40 
41  // Make the FastSimModel stored by this tool
42  auto* fastsimmodel = makeFastSimModel();
43  setFastSimModel(fastsimmodel);
44 
45  // Set the verbosity information on this thing - this will have to go into the makeFastSimModel methods...
46  //if(msgLvl(MSG::VERBOSE)) m_FastSimModel->SetVerboseLevel(10);
47  //else if(msgLvl(MSG::DEBUG)) m_FastSimModel->SetVerboseLevel(5);
48 
49  return StatusCode::SUCCESS;
50 }
51 
52 G4VFastSimulationModel* FastSimulationBase::getFastSimModel()
53 {
54 #ifdef G4MULTITHREADED
55  // Get current thread-ID
56  const auto tid = std::this_thread::get_id();
57  // Retrieve it from the FastSimModel map
58  auto fastsimmodelPair = m_fastsimmodelThreadMap.find(tid);
59  if(fastsimmodelPair == m_fastsimmodelThreadMap.end()) return nullptr;
60  return fastsimmodelPair->second;
61 #else
62  return m_FastSimModel;
63 #endif
64 }
65 
66 void FastSimulationBase::setFastSimModel(G4VFastSimulationModel* fastsimmodel)
67 {
68 #ifdef G4MULTITHREADED
69  // Make sure one isn't already assigned
70  const auto tid = std::this_thread::get_id();
71  ATH_MSG_DEBUG("Creating and registering FastSimModel " << fastsimmodel << " in thread " << tid);
72  m_fastsimmodelThreadMap.insert( std::make_pair(tid, fastsimmodel) );
73 #else
74  m_FastSimModel = fastsimmodel;
75 #endif
76 }
77 
79 {
80 #ifdef G4MULTITHREADED
81  for(auto& threadMapPair : m_fastsimmodelThreadMap)
82  {
83  auto fastSimModel = threadMapPair.second;
84  if (fastSimModel)
85  delete fastSimModel;
86  }
87  m_fastsimmodelThreadMap.clear();
88 #else
89  if(m_FastSimModel)
90  {
91  delete m_FastSimModel;
92  m_FastSimModel = 0;
93  }
94 #endif
95 }
FastSimulationBase.h
FastSimulationBase::m_regionName
Gaudi::Property< std::string > m_regionName
The region to which this fast sim is assigned.
Definition: FastSimulationBase.h:57
FastSimulationBase::deleteFastSimModel
void deleteFastSimModel()
Delete the current model.
Definition: FastSimulationBase.cxx:78
FastSimulationBase::m_FastSimModel
G4VFastSimulationModel * m_FastSimModel
The Fast Simulation Model to which this thing corresponds.
Definition: FastSimulationBase.h:78
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
FastSimulationBase::~FastSimulationBase
virtual ~FastSimulationBase()
Definition: FastSimulationBase.cxx:17
FastSimulationBase::setFastSimModel
void setFastSimModel(G4VFastSimulationModel *)
Set the current model. In hive, this gets assigned as the thread-local model.
Definition: FastSimulationBase.cxx:66
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
FastSimulationBase::FastSimulationBase
FastSimulationBase(const std::string &type, const std::string &name, const IInterface *parent)
Definition: FastSimulationBase.cxx:12
test_pyathena.parent
parent
Definition: test_pyathena.py:15
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
FastSimulationBase::getFastSimModel
G4VFastSimulationModel * getFastSimModel()
Retrieve the current Fast Simulation Model.
Definition: FastSimulationBase.cxx:52
FastSimulationBase::initializeFastSim
StatusCode initializeFastSim() override
Construct and setup the fast simulation model.
Definition: FastSimulationBase.cxx:32
FastSimulationBase::getRegion
G4Region * getRegion() const
Definition: FastSimulationBase.cxx:22