Geant4  10.00.p02
G4SDManager.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4SDManager.cc 73819 2013-09-12 15:52:52Z gcosmo $
28 //
29 
30 #include "G4SDManager.hh"
31 #include "G4SDmessenger.hh"
32 #include "G4HCofThisEvent.hh"
33 #include "G4VHitsCollection.hh"
34 #include "G4VSensitiveDetector.hh"
35 #include "G4ios.hh"
36 
37 
39 
41 {
42  if(!fSDManager)
43  {
44  fSDManager = new G4SDManager;
45  }
46  return fSDManager;
47 }
48 
50 { return fSDManager; }
51 
52 G4SDManager::G4SDManager():verboseLevel(0)
53 {
54  G4String topName = "/";
55  treeTop = new G4SDStructure(topName);
56  theMessenger = new G4SDmessenger(this);
57  HCtable = new G4HCtable;
58 }
59 
61 {
62  delete theMessenger;
63  delete HCtable;
64  delete treeTop;
65 }
66 
68 {
69  G4int numberOfCollections = aSD->GetNumberOfCollections();
70  G4String pathName = aSD->GetPathName();
71  if( pathName(0) != '/' ) pathName.prepend("/");
72  if( pathName(pathName.length()-1) != '/' ) pathName += "/";
73  treeTop->AddNewDetector(aSD,pathName);
74  if(numberOfCollections<1) return;
75  for(G4int i=0;i<numberOfCollections;i++)
76  {
77  G4String SDname = aSD->GetName();
78  G4String DCname = aSD->GetCollectionName(i);
79  AddNewCollection(SDname,DCname);
80  }
81  if( verboseLevel > 0 )
82  {
83  G4cout << "New sensitive detector <" << aSD->GetName()
84  << "> is registored at " << pathName << G4endl;
85  }
86 }
87 
89 {
90  G4int i = HCtable->Registor(SDname,DCname);
91  if(verboseLevel>0)
92  {
93  if(i<0) {
94  if(verboseLevel>1) G4cout << "G4SDManager::AddNewCollection : the collection <"
95  << SDname << "/" << DCname << "> has already been reginstered." << G4endl;
96  }
97  else
98  {
99  G4cout << "G4SDManager::AddNewCollection : the collection <"
100  << SDname << "/" << DCname << "> is registered at " << i << G4endl;
101  }
102  }
103 }
104 
106 {
108  treeTop->Initialize(HCE);
109  return HCE;
110 }
111 
113 {
114  treeTop->Terminate(HCE);
115 }
116 
117 void G4SDManager::Activate(G4String dName, G4bool activeFlag)
118 {
119  G4String pathName = dName;
120  if( pathName(0) != '/' ) pathName.prepend("/");
121  treeTop->Activate(pathName,activeFlag);
122 }
123 
125 {
126  G4String pathName = dName;
127  if( pathName(0) != '/' ) pathName.prepend("/");
128  return treeTop->FindSensitiveDetector(pathName, warning);
129 }
130 
132 {
133  G4int id = HCtable->GetCollectionID(colName);
134  if(id==-1)
135  { G4cout << "<" << colName << "> is not found." << G4endl; }
136  else if(id==-2)
137  { G4cout << "<" << colName << "> is ambiguous." << G4endl; }
138  return id;
139 }
140 
142 {
143  G4String HCname = aHC->GetSDname();
144  HCname += "/";
145  HCname += aHC->GetName();
146  return GetCollectionID(HCname);
147 }
148 
149 
G4int GetCollectionID(G4String HCname) const
Definition: G4HCtable.cc:46
void AddNewDetector(G4VSensitiveDetector *aSD, G4String treeStructure)
void AddNewCollection(G4String SDname, G4String DCname)
Definition: G4SDManager.cc:88
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:131
void Initialize(G4HCofThisEvent *HCE)
G4SDStructure * treeTop
Definition: G4SDManager.hh:84
void Activate(G4String aName, G4bool sensitiveFlag)
#define G4ThreadLocal
Definition: tls.hh:52
G4HCtable * HCtable
Definition: G4SDManager.hh:86
int G4int
Definition: G4Types.hh:78
void TerminateCurrentEvent(G4HCofThisEvent *HCE)
Definition: G4SDManager.cc:112
G4String & prepend(const char *)
G4int Registor(G4String SDname, G4String HCname)
Definition: G4HCtable.cc:37
G4GLOB_DLL std::ostream G4cout
void Terminate(G4HCofThisEvent *HCE)
void Activate(G4String dName, G4bool activeFlag)
Definition: G4SDManager.cc:117
bool G4bool
Definition: G4Types.hh:79
G4SDmessenger * theMessenger
Definition: G4SDManager.hh:87
G4VSensitiveDetector * FindSensitiveDetector(G4String dName, G4bool warning=true)
Definition: G4SDManager.cc:124
void AddNewDetector(G4VSensitiveDetector *aSD)
Definition: G4SDManager.cc:67
G4HCofThisEvent * PrepareNewEvent()
Definition: G4SDManager.cc:105
static G4ThreadLocal G4SDManager * fSDManager
Definition: G4SDManager.hh:83
G4int GetNumberOfCollections() const
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
G4int entries() const
Definition: G4HCtable.hh:66
#define G4endl
Definition: G4ios.hh:61
G4int verboseLevel
Definition: G4SDManager.hh:85
G4String GetCollectionName(G4int id) const
G4String GetPathName() const
static G4SDManager * GetSDMpointerIfExist()
Definition: G4SDManager.cc:49
G4VSensitiveDetector * FindSensitiveDetector(G4String aName, G4bool warning=true)