Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions
G4SDStructure Class Reference

#include <G4SDStructure.hh>

Public Member Functions

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

Detailed Description

Definition at line 47 of file G4SDStructure.hh.

Constructor & Destructor Documentation

G4SDStructure::G4SDStructure ( G4String  aPath)

Definition at line 34 of file G4SDStructure.cc.

References G4String::last(), and G4String::remove().

Referenced by AddNewDetector().

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

Definition at line 48 of file G4SDStructure.cc.

49 {
50  size_t nTree = structure.size();
51  for(size_t iTree=0;iTree<nTree;iTree++)
52  { delete structure[iTree]; }
53  size_t nDet = detector.size();
54  for(size_t iDet=0;iDet<nDet;iDet++)
55  { delete detector[iDet]; }
56 }

Member Function Documentation

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

Definition at line 140 of file G4SDStructure.cc.

References Activate(), G4VSensitiveDetector::Activate(), G4String::first(), G4cout, G4endl, GetSD(), G4String::isNull(), and G4String::remove().

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

141 {
142  G4String aPath = aName;
143  aPath.remove(0,pathName.length());
144  if( aPath.first('/') != G4int(std::string::npos) )
145  { // Command is ordered for a subdirectory.
146  G4String subD = ExtractDirName(aPath);
147  G4SDStructure* tgtSDS = FindSubDirectory(subD);
148  if( tgtSDS == 0 )
149  { // The subdirectory is not found
150  G4cout << subD << " is not found in " << pathName << G4endl;
151  }
152  else
153  {
154  tgtSDS->Activate(aName,sensitiveFlag);
155  }
156  }
157  else if( aPath.isNull() )
158  { // Command is ordered for all detectors in this directory.
159  for( size_t i=0; i<detector.size(); i++)
160  {
161  detector[i]->Activate(sensitiveFlag);
162  }
163  for( size_t j=0;j<structure.size(); j++)
164  {
165  structure[j]->Activate(G4String("/"),sensitiveFlag);
166  }
167  }
168  else
169  { // Command is ordered to a particular detector.
170  G4VSensitiveDetector* tgtSD = GetSD(aPath);
171  if( tgtSD == 0 )
172  { // The detector is not found.
173  G4cout << aPath << " is not found in " << pathName << G4endl;
174  }
175  else
176  {
177  tgtSD->Activate(sensitiveFlag);
178  }
179  }
180 }
void Activate(G4bool activeFlag)
G4String & remove(str_size)
G4int first(char) const
void Activate(G4String aName, G4bool sensitiveFlag)
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
G4VSensitiveDetector * GetSD(G4String aName)
#define G4endl
Definition: G4ios.hh:61
G4bool isNull() const
void G4SDStructure::AddNewDetector ( G4VSensitiveDetector aSD,
G4String  treeStructure 
)

Definition at line 63 of file G4SDStructure.cc.

References AddNewDetector(), G4Exception(), G4SDStructure(), G4VSensitiveDetector::GetName(), GetSD(), G4String::isNull(), JustWarning, G4String::prepend(), and G4String::remove().

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

65 {
66  G4String remainingPath = treeStructure;
67  remainingPath.remove(0,pathName.length());
68  if( ! remainingPath.isNull() )
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 == 0 )
74  { // Subdirectory not found. Create a new directory.
75  subD.prepend(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  { detector.push_back( aSD ); }
86  else if( tgtSD != aSD )
87  {
88 #ifdef G4VERBOSE
90  ed << aSD->GetName() << " had already been stored in "
91  << pathName << ". Object pointer is overwitten.\n";
92  ed << "It's users' responsibility to delete the old sensitive detector object.";
93  G4Exception("G4SDStructure::AddNewDetector()","DET1010",JustWarning,ed);
94 #endif
95  RemoveSD( tgtSD );
96  detector.push_back( aSD );
97  }
98  }
99 }
void AddNewDetector(G4VSensitiveDetector *aSD, G4String treeStructure)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4String & remove(str_size)
G4String & prepend(const char *)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4VSensitiveDetector * GetSD(G4String aName)
G4SDStructure(G4String aPath)
G4bool isNull() const
G4VSensitiveDetector * G4SDStructure::FindSensitiveDetector ( G4String  aName,
G4bool  warning = true 
)

Definition at line 182 of file G4SDStructure.cc.

References FindSensitiveDetector(), G4String::first(), G4cout, G4endl, GetSD(), and G4String::remove().

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

183 {
184  G4String aPath = aName;
185  aPath.remove(0,pathName.length());
186  if( aPath.first('/') != G4int(std::string::npos) )
187  { // SD exists in sub-directory
188  G4String subD = ExtractDirName(aPath);
189  G4SDStructure* tgtSDS = FindSubDirectory(subD);
190  if( tgtSDS == 0 )
191  { // The subdirectory is not found
192  if (warning)
193  G4cout << subD << " is not found in " << pathName << G4endl;
194  return 0;
195  }
196  else
197  {
198  return tgtSDS->FindSensitiveDetector(aName);
199  }
200  }
201  else
202  { // SD must exist in this directory
203  G4VSensitiveDetector* tgtSD = GetSD(aPath);
204  if( tgtSD == 0 )
205  { // The detector is not found.
206  if (warning)
207  G4cout << aPath << " is not found in " << pathName << G4endl;
208  }
209  return tgtSD;
210  }
211 }
G4String & remove(str_size)
G4int first(char) const
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
G4VSensitiveDetector * GetSD(G4String aName)
#define G4endl
Definition: G4ios.hh:61
G4VSensitiveDetector * FindSensitiveDetector(G4String aName, G4bool warning=true)
G4VSensitiveDetector * G4SDStructure::GetSD ( G4String  aName)

Definition at line 110 of file G4SDStructure.cc.

References G4VSensitiveDetector::GetName().

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

111 {
112  for( size_t i=0; i<detector.size(); i++ )
113  {
114  G4VSensitiveDetector* tgtSD = detector[i];
115  if( aSDName == tgtSD->GetName() ) return tgtSD;
116  }
117  return 0;
118 }
void G4SDStructure::Initialize ( G4HCofThisEvent HCE)

Definition at line 213 of file G4SDStructure.cc.

Referenced by G4SDManager::PrepareNewEvent().

214 {
215  size_t i;
216  // Broadcast to subdirectories.
217  for( i=0; i<structure.size(); i++ )
218  {
219  structure[i]->Initialize(HCE);
220  }
221  // Initialize all detectors in this directory.
222  for( i=0; i<detector.size(); i++ )
223  {
224  if(detector[i]->isActive()) detector[i]->Initialize(HCE);
225  }
226 }
void Initialize(G4HCofThisEvent *HCE)
void G4SDStructure::ListTree ( )

Definition at line 243 of file G4SDStructure.cc.

References G4cout, G4endl, G4VSensitiveDetector::GetName(), and G4VSensitiveDetector::isActive().

Referenced by G4SDManager::ListTree().

244 {
245  G4cout << pathName << G4endl;
246  for(size_t i=0; i<detector.size(); i++)
247  {
248  G4VSensitiveDetector* sd = detector[i];
249  G4cout << pathName << sd->GetName();
250  if( sd->isActive() )
251  { G4cout << " *** Active "; }
252  else
253  { G4cout << " XXX Inactive "; }
254  G4cout << G4endl;
255  }
256  for(size_t j=0; j<structure.size(); j++)
257  { structure[j]->ListTree(); }
258 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
G4int G4SDStructure::operator== ( const G4SDStructure right) const

Definition at line 58 of file G4SDStructure.cc.

59 {
60  return (this==&right);
61 }
void G4SDStructure::SetVerboseLevel ( G4int  vl)
inline

Definition at line 76 of file G4SDStructure.hh.

Referenced by G4SDManager::SetVerboseLevel().

77  {
78  verboseLevel = vl;
79  for(size_t i=0; i<structure.size(); i++)
80  { structure[i]->SetVerboseLevel(vl); }
81  for(size_t j=0; j<detector.size(); j++)
82  { detector[j]->SetVerboseLevel(vl); }
83  };
void G4SDStructure::Terminate ( G4HCofThisEvent HCE)

Definition at line 228 of file G4SDStructure.cc.

Referenced by G4SDManager::TerminateCurrentEvent().

229 {
230  size_t i;
231  // Broadcast to subdirectories.
232  for( i=0; i<structure.size(); i++ )
233  {
234  structure[i]->Terminate(HCE);
235  }
236  // Initialize all detectors in this directory.
237  for( i=0; i<detector.size(); i++ )
238  {
239  if(detector[i]->isActive()) detector[i]->EndOfEvent(HCE);
240  }
241 }

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