10#include "G4LogicalVolumeStore.hh"
11#include "G4MultiSensitiveDetector.hh"
12#include "G4SDManager.hh"
18 const std::string& name,
19 const IInterface* parent)
20 : base_class(
type,name,parent)
32 ATH_MSG_ERROR(
"Initializing SD from " << name() <<
", NoVolumes = "
33 << (
m_noVolumes?
"true" :
"false") <<
", but LogicalVolumeNames = "
35 return StatusCode::FAILURE;
42 return StatusCode::FAILURE;
46 auto sd = std::unique_ptr<G4VSensitiveDetector>(makeSD());
50 return StatusCode::FAILURE;
58 return StatusCode::SUCCESS;
65assignSD(std::unique_ptr<G4VSensitiveDetector> sd,
const std::vector<std::string>& volumes)
const
68 if(msgLvl(MSG::VERBOSE)) sd->SetVerboseLevel(10);
69 else if(msgLvl(MSG::DEBUG)) sd->SetVerboseLevel(5);
73 auto sdMgr = G4SDManager::GetSDMpointer();
74 auto sdPtr = sd.get();
76 sdMgr->AddNewDetector(sd.release());
78 if(!volumes.empty()) {
80 auto logicalVolumeStore = G4LogicalVolumeStore::GetInstance();
81 for(
const auto& volumeName : volumes) {
87 for(
auto* logVol : *logicalVolumeStore) {
89 ATH_MSG_VERBOSE(
"Check whether "<<logVol->GetName()<<
" belongs to the set of sensitive detectors "<<volumeName);
90 if(
matchStrings( volumeName.data(), logVol->GetName() ) ){
99 " not found in G4LogicalVolumeStore.");
102 ATH_MSG_VERBOSE(
"Found " << numFound <<
" copies of LV " << volumeName <<
103 "; SD " << sd->GetName() <<
" assigned.");
111 ATH_MSG_ERROR(
"Failed to assign *any* volume to SD " << name() <<
112 " and expected at least one. Size of the volume store "<<G4LogicalVolumeStore::GetInstance()->size() );
113 return StatusCode::FAILURE;
117 return StatusCode::SUCCESS;
122#ifdef G4MULTITHREADED
124 const auto tid = std::this_thread::get_id();
126 auto sdPair = m_sdThreadMap.find(tid);
127 if(sdPair == m_sdThreadMap.end())
return nullptr;
128 return sdPair->second;
136#ifdef G4MULTITHREADED
137 const auto tid = std::this_thread::get_id();
138 ATH_MSG_DEBUG(
"Creating and registering SD " << sd <<
" in thread " << tid);
139 m_sdThreadMap.insert( std::make_pair(tid, sd) );
150 if (*first ==
'\0' && *second ==
'\0')
155 if(*first ==
'*' && *(first + 1) ==
'*')
159 if (*first ==
'*' && *(first + 1) !=
'\0' && *second ==
'\0')
163 if (*first == *second)
181 G4VSensitiveDetector* originalSD = logVol->GetSensitiveDetector();
182 if ( originalSD ==
nullptr )
184 logVol->SetSensitiveDetector(aSD);
188 G4MultiSensitiveDetector* msd =
dynamic_cast<G4MultiSensitiveDetector*
>(originalSD);
189 if ( msd !=
nullptr )
196 std::stringstream
ss;
198 const G4String msdname =
"/MultiSD_" + logVol->GetName() +
ss.str();
199 msd =
new G4MultiSensitiveDetector(std::move(msdname));
201 G4SDManager::GetSDMpointer()->AddNewDetector(msd);
202 msd->AddSD(originalSD);
204 logVol->SetSensitiveDetector(msd);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
StatusCode assignSD(std::unique_ptr< G4VSensitiveDetector > sd, const std::vector< std::string > &volumes) const
Assign SD to a list of volumes.
G4VSensitiveDetector * m_SD
The sensitive detector to which this thing corresponds.
Gaudi::Property< std::vector< std::string > > m_volumeNames
All the volumes to which this SD is assigned.
StatusCode initializeSD() override
Setup an SD in the current thread.
Gaudi::Property< bool > m_noVolumes
This SensitiveDetector has no volumes associated with it.
SensitiveDetectorBase(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
static bool matchStrings(const char *first, const char *second)
Match two strings with wildcard support.
G4VSensitiveDetector * getSD()
Retrieve the current SD.
void setSD(G4VSensitiveDetector *)
Set the current SD.
void SetSensitiveDetector(G4LogicalVolume *, G4VSensitiveDetector *) const
Method stolen from G4VUserDetectorConstruction in G4 10.2.