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().

00034                                           :verboseLevel(0)
00035 {
00036   pathName = aPath;
00037   dirName = aPath;
00038   G4int i = dirName.length();
00039   if( i > 1 )
00040   {
00041     dirName.remove(i-1);
00042     G4int isl = dirName.last('/');
00043     dirName.remove(0,isl+1);
00044     dirName += "/";
00045   }
00046 }

G4SDStructure::~G4SDStructure (  ) 

Definition at line 48 of file G4SDStructure.cc.

00049 {
00050   size_t nTree = structure.size();
00051   for(size_t iTree=0;iTree<nTree;iTree++)
00052   { delete structure[iTree]; }
00053   size_t nDet = detector.size();
00054   for(size_t iDet=0;iDet<nDet;iDet++)
00055   { delete detector[iDet]; }
00056 }


Member Function Documentation

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

Definition at line 123 of file G4SDStructure.cc.

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

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

00124 {
00125   G4String aPath = aName;
00126   aPath.remove(0,pathName.length());
00127   if( aPath.first('/') != G4int(std::string::npos) )
00128   {  // Command is ordered for a subdirectory.
00129     G4String subD = ExtractDirName(aPath);
00130     G4SDStructure* tgtSDS = FindSubDirectory(subD);
00131     if( tgtSDS == 0 )
00132     {  // The subdirectory is not found
00133       G4cout << subD << " is not found in " << pathName << G4endl;
00134     }
00135     else
00136     { 
00137       tgtSDS->Activate(aName,sensitiveFlag);
00138     }
00139   }
00140   else if( aPath.isNull() )
00141   {  // Command is ordered for all detectors in this directory.
00142     for( size_t i=0; i<detector.size(); i++)
00143     { 
00144       detector[i]->Activate(sensitiveFlag);
00145     }
00146     for( size_t j=0;j<structure.size(); j++)
00147     {
00148       structure[j]->Activate(G4String("/"),sensitiveFlag);
00149     }
00150   }
00151   else
00152   {  // Command is ordered to a particular detector.
00153     G4VSensitiveDetector* tgtSD = GetSD(aPath);
00154     if( tgtSD == 0 )
00155     {  // The detector is not found.
00156       G4cout << aPath << " is not found in " << pathName << G4endl;
00157     }
00158     else
00159     {
00160       tgtSD->Activate(sensitiveFlag);
00161     }
00162   }
00163 }

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

Definition at line 63 of file G4SDStructure.cc.

References AddNewDetector(), G4cout, G4endl, G4SDStructure(), G4VSensitiveDetector::GetName(), GetSD(), G4String::isNull(), and G4String::remove().

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

00065 {
00066   G4String remainingPath = treeStructure;
00067   remainingPath.remove(0,pathName.length());
00068   if( ! remainingPath.isNull() )
00069   {  // The detector should be kept in subdirectory.
00070      // First, check if the subdirectoy exists.
00071     G4String subD = ExtractDirName( remainingPath );
00072     G4SDStructure* tgtSDS = FindSubDirectory(subD);
00073     if( tgtSDS == 0 )
00074     { // Subdirectory not found. Create a new directory.
00075       subD.prepend(pathName);
00076       tgtSDS = new G4SDStructure(subD);
00077       structure.push_back( tgtSDS );
00078     }
00079     tgtSDS->AddNewDetector(aSD,treeStructure);
00080   }
00081   else
00082   { // The sensitive detector should be kept in this directory.
00083     G4VSensitiveDetector* tgtSD = GetSD( aSD->GetName() );
00084     if( tgtSD != 0 )
00085     {
00086       G4cout << aSD->GetName() << " had already stored in "
00087            << pathName << G4endl;
00088     }
00089     else
00090     {
00091       detector.push_back( aSD );
00092     }
00093   }
00094 }

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

Definition at line 165 of file G4SDStructure.cc.

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

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

00166 {
00167   G4String aPath = aName;
00168   aPath.remove(0,pathName.length());
00169   if( aPath.first('/') != G4int(std::string::npos) )
00170   { // SD exists in sub-directory
00171     G4String subD = ExtractDirName(aPath);
00172     G4SDStructure* tgtSDS = FindSubDirectory(subD);
00173     if( tgtSDS == 0 )
00174     {  // The subdirectory is not found
00175       if (warning)
00176         G4cout << subD << " is not found in " << pathName << G4endl;
00177       return 0;
00178     }
00179     else
00180     {
00181       return tgtSDS->FindSensitiveDetector(aName);
00182     }
00183   }
00184   else
00185   { // SD must exist in this directory
00186     G4VSensitiveDetector* tgtSD = GetSD(aPath);
00187     if( tgtSD == 0 )
00188     {  // The detector is not found.
00189       if (warning)
00190         G4cout << aPath << " is not found in " << pathName << G4endl;
00191     }
00192     return tgtSD;
00193   }
00194 }

G4VSensitiveDetector * G4SDStructure::GetSD ( G4String  aName  ) 

Definition at line 105 of file G4SDStructure.cc.

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

00106 {
00107   for( size_t i=0; i<detector.size(); i++ )
00108   {
00109     G4VSensitiveDetector* tgtSD = detector[i];
00110     if( aSDName == tgtSD->GetName() ) return tgtSD;
00111   }
00112   return 0;
00113 }

void G4SDStructure::Initialize ( G4HCofThisEvent HCE  ) 

Definition at line 196 of file G4SDStructure.cc.

Referenced by G4SDManager::PrepareNewEvent().

00197 {
00198   size_t i;
00199   // Broadcast to subdirectories.
00200   for( i=0; i<structure.size(); i++ )
00201   {
00202     structure[i]->Initialize(HCE);
00203   }
00204   // Initialize all detectors in this directory.
00205   for( i=0; i<detector.size(); i++ )
00206   {
00207     if(detector[i]->isActive()) detector[i]->Initialize(HCE);
00208   }
00209 }

void G4SDStructure::ListTree (  ) 

Definition at line 226 of file G4SDStructure.cc.

References G4cout, and G4endl.

Referenced by G4SDManager::ListTree().

00227 {
00228   G4cout << pathName << G4endl;
00229   for(size_t i=0; i<detector.size(); i++)
00230   {
00231     G4VSensitiveDetector* sd = detector[i];
00232     G4cout << pathName << sd->GetName();
00233     if( sd->isActive() )
00234     { G4cout << "   *** Active "; }
00235     else
00236     { G4cout << "   XXX Inactive "; }
00237     G4cout << G4endl;
00238   }
00239   for(size_t j=0; j<structure.size(); j++)
00240   { structure[j]->ListTree(); }
00241 }

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

Definition at line 58 of file G4SDStructure.cc.

00059 {
00060   return (this==&right);
00061 }

void G4SDStructure::SetVerboseLevel ( G4int  vl  )  [inline]

Definition at line 75 of file G4SDStructure.hh.

Referenced by G4SDManager::SetVerboseLevel().

00076       {
00077         verboseLevel = vl;
00078         for(size_t i=0; i<structure.size(); i++)
00079         { structure[i]->SetVerboseLevel(vl); }
00080         for(size_t j=0; j<detector.size(); j++)
00081         { detector[j]->SetVerboseLevel(vl); }
00082       };

void G4SDStructure::Terminate ( G4HCofThisEvent HCE  ) 

Definition at line 211 of file G4SDStructure.cc.

Referenced by G4SDManager::TerminateCurrentEvent().

00212 {
00213   size_t i;
00214   // Broadcast to subdirectories.
00215   for( i=0; i<structure.size(); i++ )
00216   {
00217     structure[i]->Terminate(HCE);
00218   }
00219   // Initialize all detectors in this directory.
00220   for( i=0; i<detector.size(); i++ )
00221   {
00222     if(detector[i]->isActive()) detector[i]->EndOfEvent(HCE);
00223   }
00224 }


The documentation for this class was generated from the following files:
Generated on Mon May 27 17:53:22 2013 for Geant4 by  doxygen 1.4.7