Geant4-11
Public Member Functions | Private Member Functions | Private Attributes
G4SDStructure Class Reference

#include <G4SDStructure.hh>

Public Member Functions

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

Private Member Functions

G4String ExtractDirName (const G4String &aPath)
 
G4SDStructureFindSubDirectory (const G4String &subD)
 
void RemoveSD (G4VSensitiveDetector *)
 

Private Attributes

std::vector< G4VSensitiveDetector * > detector
 
G4String dirName
 
G4String pathName
 
std::vector< G4SDStructure * > structure
 
G4int verboseLevel
 

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 G4int i = dirName.length();
39 if(i > 1)
40 {
41 dirName.erase(i - 1);
42 G4int isl = dirName.rfind('/');
43 dirName.erase(0, isl + 1);
44 dirName += "/";
45 }
46}
int G4int
Definition: G4Types.hh:85
G4String dirName
G4String pathName

References dirName, and pathName.

Referenced by AddNewDetector().

◆ ~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}
std::vector< G4VSensitiveDetector * > detector
std::vector< G4SDStructure * > structure

References detector, and structure.

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
G4String ExtractDirName(const G4String &aPath)
G4VSensitiveDetector * GetSD(const G4String &aName)
void Activate(const G4String &aName, G4bool sensitiveFlag)
G4SDStructure * FindSubDirectory(const G4String &subD)
void Activate(G4bool activeFlag)

References Activate(), G4VSensitiveDetector::Activate(), detector, ExtractDirName(), FindSubDirectory(), G4cout, G4endl, GetSD(), pathName, and structure.

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:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
void RemoveSD(G4VSensitiveDetector *)
G4SDStructure(const G4String &aPath)
void AddNewDetector(G4VSensitiveDetector *aSD, const G4String &treeStructure)

References AddNewDetector(), detector, ExtractDirName(), FindSubDirectory(), G4Exception(), G4SDStructure(), G4VSensitiveDetector::GetName(), GetSD(), JustWarning, pathName, RemoveSD(), and structure.

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

◆ ExtractDirName()

G4String G4SDStructure::ExtractDirName ( const G4String aPath)
private

Definition at line 132 of file G4SDStructure.cc.

133{
134 G4String subD = aName;
135 auto i = aName.find('/');
136 if(i != G4String::npos)
137 subD.erase(i + 1);
138 return subD;
139}

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

◆ 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)

References ExtractDirName(), FindSensitiveDetector(), FindSubDirectory(), G4cout, G4endl, GetSD(), and pathName.

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

◆ FindSubDirectory()

G4SDStructure * G4SDStructure::FindSubDirectory ( const G4String subD)
private

Definition at line 105 of file G4SDStructure.cc.

106{
107 for(auto st : structure)
108 {
109 if(subD == st->dirName)
110 return st;
111 }
112 return nullptr;
113}

References structure.

Referenced by Activate(), AddNewDetector(), and 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}

References detector.

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}

References detector, and structure.

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}

References detector, G4cout, G4endl, pathName, and structure.

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}

◆ RemoveSD()

void G4SDStructure::RemoveSD ( G4VSensitiveDetector sd)
private

Definition at line 125 of file G4SDStructure.cc.

126{
127 auto det = std::find(detector.begin(), detector.end(), sd);
128 if(det != detector.end())
129 detector.erase(det);
130}

References detector.

Referenced by AddNewDetector().

◆ 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 };

References detector, structure, and verboseLevel.

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}

References detector, and structure.

Referenced by G4SDManager::TerminateCurrentEvent().

Field Documentation

◆ detector

std::vector<G4VSensitiveDetector*> G4SDStructure::detector
private

◆ dirName

G4String G4SDStructure::dirName
private

Definition at line 72 of file G4SDStructure.hh.

Referenced by G4SDStructure().

◆ pathName

G4String G4SDStructure::pathName
private

◆ structure

std::vector<G4SDStructure*> G4SDStructure::structure
private

◆ verboseLevel

G4int G4SDStructure::verboseLevel
private

Definition at line 73 of file G4SDStructure.hh.

Referenced by SetVerboseLevel().


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