Geant4 10.7.0
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.

33 :verboseLevel(0)
34{
35 pathName = aPath;
36 dirName = aPath;
37 G4int i = dirName.length();
38 if( i > 1 )
39 {
40 dirName.remove(i-1);
41 G4int isl = dirName.last('/');
42 dirName.remove(0,isl+1);
43 dirName += "/";
44 }
45}
int G4int
Definition: G4Types.hh:85
G4String & remove(str_size)
std::size_t last(char) const

◆ ~G4SDStructure()

G4SDStructure::~G4SDStructure ( )

Definition at line 47 of file G4SDStructure.cc.

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

Member Function Documentation

◆ Activate()

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

Definition at line 126 of file G4SDStructure.cc.

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

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

◆ AddNewDetector()

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

Definition at line 60 of file G4SDStructure.cc.

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

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

◆ FindSensitiveDetector()

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

Definition at line 162 of file G4SDStructure.cc.

163{
164 G4String aPath = aName;
165 aPath.remove(0,pathName.length());
166 if( aPath.first('/') != std::string::npos )
167 { // SD exists in sub-directory
168 G4String subD = ExtractDirName(aPath);
169 G4SDStructure* tgtSDS = FindSubDirectory(subD);
170 if( tgtSDS == nullptr )
171 { // The subdirectory is not found
172 if (warning)
173 G4cout << subD << " is not found in " << pathName << G4endl;
174 return nullptr;
175 }
176 else
177 {
178 return tgtSDS->FindSensitiveDetector(aName,warning);
179 }
180 }
181 else
182 { // SD must exist in this directory
183 G4VSensitiveDetector* tgtSD = GetSD(aPath);
184 if( tgtSD == nullptr )
185 { // The detector is not found.
186 if (warning)
187 G4cout << aPath << " is not found in " << pathName << G4endl;
188 }
189 return tgtSD;
190 }
191}
G4VSensitiveDetector * FindSensitiveDetector(const G4String &aName, G4bool warning=true)

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

◆ GetSD()

G4VSensitiveDetector * G4SDStructure::GetSD ( const G4String aName)

Definition at line 105 of file G4SDStructure.cc.

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

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

◆ Initialize()

void G4SDStructure::Initialize ( G4HCofThisEvent HCE)

Definition at line 193 of file G4SDStructure.cc.

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

Referenced by G4SDManager::PrepareNewEvent().

◆ ListTree()

void G4SDStructure::ListTree ( )

Definition at line 213 of file G4SDStructure.cc.

214{
215 G4cout << pathName << G4endl;
216 for(auto sd : detector)
217 {
218 G4cout << pathName << sd->GetName();
219 if( sd->isActive() )
220 { G4cout << " *** Active "; }
221 else
222 { G4cout << " XXX Inactive "; }
223 G4cout << G4endl;
224 }
225 for(auto st : structure) st->ListTree();
226}

Referenced by G4SDManager::ListTree().

◆ operator==()

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

Definition at line 55 of file G4SDStructure.cc.

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

◆ SetVerboseLevel()

void G4SDStructure::SetVerboseLevel ( G4int  vl)
inline

Definition at line 75 of file G4SDStructure.hh.

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

Referenced by G4SDManager::SetVerboseLevel().

◆ Terminate()

void G4SDStructure::Terminate ( G4HCofThisEvent HCE)

Definition at line 203 of file G4SDStructure.cc.

204{
205 // Broadcast to subdirectories.
206 for(auto st : structure)
207 { st->Terminate(HCE); }
208 // Terminate all detectors in this directory.
209 for(auto dt : detector)
210 { if(dt->isActive()) dt->EndOfEvent(HCE); }
211}

Referenced by G4SDManager::TerminateCurrentEvent().


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