Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4SDStructure Class Reference

#include <G4SDStructure.hh>

Public Member Functions

 G4SDStructure (const G4String &aPath)
 
 ~G4SDStructure ()
 
G4bool operator== (const G4SDStructure &right) const
 
void AddNewDetector (G4VSensitiveDetector *aSD, const G4String &treeStructure)
 
void Activate (const G4String &aName, G4bool sensitiveFlag)
 
void Initialize (G4HCofThisEvent *HCE)
 
void Terminate (G4HCofThisEvent *HCE)
 
G4VSensitiveDetectorFindSensitiveDetector (const G4String &aName, G4bool warning=true)
 
G4VSensitiveDetectorGetSD (const G4String &aName)
 
void ListTree ()
 
void SetVerboseLevel (G4int vl)
 

Detailed Description

Definition at line 46 of file G4SDStructure.hh.

Constructor & Destructor Documentation

◆ G4SDStructure()

G4SDStructure::G4SDStructure ( const G4String & aPath)

Definition at line 34 of file G4SDStructure.cc.

35{
36 pathName = aPath;
37 dirName = aPath;
38 auto i = dirName.length();
39 if (i > 1) {
40 dirName.erase(i - 1);
41 auto isl = dirName.rfind('/');
42 dirName.erase(0, isl + 1);
43 dirName += "/";
44 }
45}

Referenced by AddNewDetector().

◆ ~G4SDStructure()

G4SDStructure::~G4SDStructure ( )

Definition at line 47 of file G4SDStructure.cc.

48{
49 for (auto st : structure)
50 delete st;
51 structure.clear();
52 for (auto dt : detector)
53 delete dt;
54 detector.clear();
55}

Member Function Documentation

◆ Activate()

void G4SDStructure::Activate ( const G4String & aName,
G4bool sensitiveFlag )

Definition at line 124 of file G4SDStructure.cc.

125{
126 G4String aPath = aName;
127 aPath.erase(0, pathName.length());
128 if (aPath.find('/') != std::string::npos) { // Command is ordered for a subdirectory.
129 G4String subD = ExtractDirName(aPath);
130 G4SDStructure* tgtSDS = FindSubDirectory(subD);
131 if (tgtSDS == nullptr) { // The subdirectory is not found
132 G4cout << subD << " is not found in " << pathName << G4endl;
133 }
134 else {
135 tgtSDS->Activate(aName, sensitiveFlag);
136 }
137 }
138 else if (aPath.empty()) { // Command is ordered for all detectors in this directory.
139 for (auto det : detector)
140 det->Activate(sensitiveFlag);
141 for (auto st : structure)
142 st->Activate(G4String("/"), sensitiveFlag);
143 }
144 else { // Command is ordered to a particular detector.
145 G4VSensitiveDetector* tgtSD = GetSD(aPath);
146 if (tgtSD == nullptr) { // The detector is not found.
147 G4cout << aPath << " is not found in " << pathName << G4endl;
148 }
149 else {
150 tgtSD->Activate(sensitiveFlag);
151 }
152 }
153}
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
G4VSensitiveDetector * GetSD(const G4String &aName)
void Activate(const G4String &aName, G4bool sensitiveFlag)
void Activate(G4bool activeFlag)

Referenced by G4SDManager::Activate(), and Activate().

◆ AddNewDetector()

void G4SDStructure::AddNewDetector ( G4VSensitiveDetector * aSD,
const G4String & treeStructure )

Definition at line 59 of file G4SDStructure.cc.

60{
61 G4String remainingPath = treeStructure;
62 remainingPath.erase(0, pathName.length());
63 if (! remainingPath.empty()) { // The detector should be kept in subdirectory.
64 // First, check if the subdirectoy exists.
65 G4String subD = ExtractDirName(remainingPath);
66 G4SDStructure* tgtSDS = FindSubDirectory(subD);
67 if (tgtSDS == nullptr) { // Subdirectory not found. Create a new directory.
68 subD.insert(0, pathName);
69 tgtSDS = new G4SDStructure(subD);
70 structure.push_back(tgtSDS);
71 }
72 tgtSDS->AddNewDetector(aSD, treeStructure);
73 }
74 else { // The sensitive detector should be kept in this directory.
75 G4VSensitiveDetector* tgtSD = GetSD(aSD->GetName());
76 if (tgtSD == nullptr) {
77 detector.push_back(aSD);
78 }
79 else if (tgtSD != aSD) {
80#ifdef G4VERBOSE
82 ed << aSD->GetName() << " had already been stored in " << pathName
83 << ". Object pointer is overwritten.\n";
84 ed << "It's users' responsibility to delete the old sensitive detector "
85 "object.";
86 G4Exception("G4SDStructure::AddNewDetector()", "DET1010", JustWarning, ed);
87#endif
88 RemoveSD(tgtSD);
89 detector.push_back(aSD);
90 }
91 }
92}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4SDStructure(const G4String &aPath)
void AddNewDetector(G4VSensitiveDetector *aSD, const G4String &treeStructure)

Referenced by G4SDManager::AddNewDetector(), and AddNewDetector().

◆ FindSensitiveDetector()

G4VSensitiveDetector * G4SDStructure::FindSensitiveDetector ( const G4String & aName,
G4bool warning = true )

Definition at line 155 of file G4SDStructure.cc.

156{
157 G4String aPath = aName;
158 aPath.erase(0, pathName.length());
159 if (aPath.find('/') != std::string::npos) { // SD exists in sub-directory
160 G4String subD = ExtractDirName(aPath);
161 G4SDStructure* tgtSDS = FindSubDirectory(subD);
162 if (tgtSDS == nullptr) { // The subdirectory is not found
163 if (warning) G4cout << subD << " is not found in " << pathName << G4endl;
164 return nullptr;
165 }
166
167 return tgtSDS->FindSensitiveDetector(aName, warning);
168 }
169
170 // SD must exist in this directory
171 G4VSensitiveDetector* tgtSD = GetSD(aPath);
172 if (tgtSD == nullptr) { // The detector is not found.
173 if (warning) G4cout << aPath << " is not found in " << pathName << G4endl;
174 }
175 return tgtSD;
176}
G4VSensitiveDetector * FindSensitiveDetector(const G4String &aName, G4bool warning=true)

Referenced by G4SDManager::FindSensitiveDetector(), and FindSensitiveDetector().

◆ GetSD()

G4VSensitiveDetector * G4SDStructure::GetSD ( const G4String & aName)

Definition at line 102 of file G4SDStructure.cc.

103{
104 for (auto det : detector) {
105 if (aSDName == det->GetName()) return det;
106 }
107 return nullptr;
108}

Referenced by Activate(), AddNewDetector(), and FindSensitiveDetector().

◆ Initialize()

void G4SDStructure::Initialize ( G4HCofThisEvent * HCE)

Definition at line 178 of file G4SDStructure.cc.

179{
180 // Broadcast to subdirectories.
181 for (auto st : structure) {
182 st->Initialize(HCE);
183 }
184 // Initialize all detectors in this directory.
185 for (auto dt : detector) {
186 if (dt->isActive()) dt->Initialize(HCE);
187 }
188}

Referenced by G4SDManager::PrepareNewEvent().

◆ ListTree()

void G4SDStructure::ListTree ( )

Definition at line 202 of file G4SDStructure.cc.

203{
204 G4cout << pathName << G4endl;
205 for (auto sd : detector) {
206 G4cout << pathName << sd->GetName();
207 if (sd->isActive()) {
208 G4cout << " *** Active ";
209 }
210 else {
211 G4cout << " XXX Inactive ";
212 }
213 G4cout << G4endl;
214 }
215 for (auto st : structure)
216 st->ListTree();
217}

Referenced by G4SDManager::ListTree().

◆ operator==()

G4bool G4SDStructure::operator== ( const G4SDStructure & right) const

Definition at line 57 of file G4SDStructure.cc.

57{ return (this == &right); }

◆ SetVerboseLevel()

void G4SDStructure::SetVerboseLevel ( G4int vl)
inline

Definition at line 62 of file G4SDStructure.hh.

63 {
64 verboseLevel = vl;
65 for (auto& i : structure) {
66 i->SetVerboseLevel(vl);
67 }
68 for (auto& j : detector) {
69 j->SetVerboseLevel(vl);
70 }
71 };

Referenced by G4SDManager::SetVerboseLevel().

◆ Terminate()

void G4SDStructure::Terminate ( G4HCofThisEvent * HCE)

Definition at line 190 of file G4SDStructure.cc.

191{
192 // Broadcast to subdirectories.
193 for (auto st : structure) {
194 st->Terminate(HCE);
195 }
196 // Terminate all detectors in this directory.
197 for (auto dt : detector) {
198 if (dt->isActive()) dt->EndOfEvent(HCE);
199 }
200}

Referenced by G4SDManager::TerminateCurrentEvent().


The documentation for this class was generated from the following files: