Geant4 11.1.1
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 33 of file G4SDStructure.cc.

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

◆ ~G4SDStructure()

G4SDStructure::~G4SDStructure ( )

Definition at line 48 of file G4SDStructure.cc.

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

Member Function Documentation

◆ Activate()

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

Definition at line 141 of file G4SDStructure.cc.

142{
143 G4String aPath = aName;
144 aPath.erase(0, pathName.length());
145 if(aPath.find('/') != std::string::npos)
146 { // Command is ordered for a subdirectory.
147 G4String subD = ExtractDirName(aPath);
148 G4SDStructure* tgtSDS = FindSubDirectory(subD);
149 if(tgtSDS == nullptr)
150 { // The subdirectory is not found
151 G4cout << subD << " is not found in " << pathName << G4endl;
152 }
153 else
154 {
155 tgtSDS->Activate(aName, sensitiveFlag);
156 }
157 }
158 else if(aPath.empty())
159 { // Command is ordered for all detectors in this directory.
160 for(auto det : detector)
161 det->Activate(sensitiveFlag);
162 for(auto st : structure)
163 st->Activate(G4String("/"), sensitiveFlag);
164 }
165 else
166 { // Command is ordered to a particular detector.
167 G4VSensitiveDetector* tgtSD = GetSD(aPath);
168 if(tgtSD == nullptr)
169 { // The detector is not found.
170 G4cout << aPath << " is not found in " << pathName << G4endl;
171 }
172 else
173 {
174 tgtSD->Activate(sensitiveFlag);
175 }
176 }
177}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4VSensitiveDetector * GetSD(const G4String &aName)
void Activate(const G4String &aName, G4bool sensitiveFlag)
void Activate(G4bool activeFlag)

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

◆ AddNewDetector()

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

Definition at line 63 of file G4SDStructure.cc.

65{
66 G4String remainingPath = treeStructure;
67 remainingPath.erase(0, pathName.length());
68 if(!remainingPath.empty())
69 { // The detector should be kept in subdirectory.
70 // First, check if the subdirectoy exists.
71 G4String subD = ExtractDirName(remainingPath);
72 G4SDStructure* tgtSDS = FindSubDirectory(subD);
73 if(tgtSDS == nullptr)
74 { // Subdirectory not found. Create a new directory.
75 subD.insert(0, pathName);
76 tgtSDS = new G4SDStructure(subD);
77 structure.push_back(tgtSDS);
78 }
79 tgtSDS->AddNewDetector(aSD, treeStructure);
80 }
81 else
82 { // The sensitive detector should be kept in this directory.
83 G4VSensitiveDetector* tgtSD = GetSD(aSD->GetName());
84 if(!tgtSD)
85 {
86 detector.push_back(aSD);
87 }
88 else if(tgtSD != aSD)
89 {
90#ifdef G4VERBOSE
92 ed << aSD->GetName() << " had already been stored in " << pathName
93 << ". Object pointer is overwritten.\n";
94 ed << "It's users' responsibility to delete the old sensitive detector "
95 "object.";
96 G4Exception("G4SDStructure::AddNewDetector()", "DET1010", JustWarning,
97 ed);
98#endif
99 RemoveSD(tgtSD);
100 detector.push_back(aSD);
101 }
102 }
103}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
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 179 of file G4SDStructure.cc.

181{
182 G4String aPath = aName;
183 aPath.erase(0, pathName.length());
184 if(aPath.find('/') != std::string::npos)
185 { // SD exists in sub-directory
186 G4String subD = ExtractDirName(aPath);
187 G4SDStructure* tgtSDS = FindSubDirectory(subD);
188 if(tgtSDS == nullptr)
189 { // The subdirectory is not found
190 if(warning)
191 G4cout << subD << " is not found in " << pathName << G4endl;
192 return nullptr;
193 }
194 else
195 {
196 return tgtSDS->FindSensitiveDetector(aName, warning);
197 }
198 }
199 else
200 { // SD must exist in this directory
201 G4VSensitiveDetector* tgtSD = GetSD(aPath);
202 if(tgtSD == nullptr)
203 { // The detector is not found.
204 if(warning)
205 G4cout << aPath << " is not found in " << pathName << G4endl;
206 }
207 return tgtSD;
208 }
209}
G4VSensitiveDetector * FindSensitiveDetector(const G4String &aName, G4bool warning=true)

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

◆ GetSD()

G4VSensitiveDetector * G4SDStructure::GetSD ( const G4String aName)

Definition at line 115 of file G4SDStructure.cc.

116{
117 for(auto det : detector)
118 {
119 if(aSDName == det->GetName())
120 return det;
121 }
122 return nullptr;
123}

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

◆ Initialize()

void G4SDStructure::Initialize ( G4HCofThisEvent HCE)

Definition at line 211 of file G4SDStructure.cc.

212{
213 // Broadcast to subdirectories.
214 for(auto st : structure)
215 {
216 st->Initialize(HCE);
217 }
218 // Initialize all detectors in this directory.
219 for(auto dt : detector)
220 {
221 if(dt->isActive())
222 dt->Initialize(HCE);
223 }
224}

Referenced by G4SDManager::PrepareNewEvent().

◆ ListTree()

void G4SDStructure::ListTree ( )

Definition at line 241 of file G4SDStructure.cc.

242{
243 G4cout << pathName << G4endl;
244 for(auto sd : detector)
245 {
246 G4cout << pathName << sd->GetName();
247 if(sd->isActive())
248 {
249 G4cout << " *** Active ";
250 }
251 else
252 {
253 G4cout << " XXX Inactive ";
254 }
255 G4cout << G4endl;
256 }
257 for(auto st : structure)
258 st->ListTree();
259}

Referenced by G4SDManager::ListTree().

◆ operator==()

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

Definition at line 58 of file G4SDStructure.cc.

59{
60 return (this == &right);
61}

◆ SetVerboseLevel()

void G4SDStructure::SetVerboseLevel ( G4int  vl)
inline

Definition at line 76 of file G4SDStructure.hh.

77 {
78 verboseLevel = vl;
79 for(size_t i = 0; i < structure.size(); i++)
80 {
81 structure[i]->SetVerboseLevel(vl);
82 }
83 for(size_t j = 0; j < detector.size(); j++)
84 {
85 detector[j]->SetVerboseLevel(vl);
86 }
87 };

Referenced by G4SDManager::SetVerboseLevel().

◆ Terminate()

void G4SDStructure::Terminate ( G4HCofThisEvent HCE)

Definition at line 226 of file G4SDStructure.cc.

227{
228 // Broadcast to subdirectories.
229 for(auto st : structure)
230 {
231 st->Terminate(HCE);
232 }
233 // Terminate all detectors in this directory.
234 for(auto dt : detector)
235 {
236 if(dt->isActive())
237 dt->EndOfEvent(HCE);
238 }
239}

Referenced by G4SDManager::TerminateCurrentEvent().


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