Geant4
9.6.p02
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
geant4_9_6_p02
source
digits_hits
detector
src
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$
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
38
G4SDManager
* G4SDManager::fSDManager = 0;
39
40
G4SDManager
*
G4SDManager::GetSDMpointer
()
41
{
42
if
(!fSDManager)
43
{
44
fSDManager =
new
G4SDManager
;
45
}
46
return
fSDManager;
47
}
48
49
G4SDManager
*
G4SDManager::GetSDMpointerIfExist
()
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
60
G4SDManager::~G4SDManager
()
61
{
62
delete
theMessenger;
63
delete
HCtable;
64
delete
treeTop;
65
}
66
67
void
G4SDManager::AddNewDetector
(
G4VSensitiveDetector
*aSD)
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
88
void
G4SDManager::AddNewCollection
(
G4String
SDname,
G4String
DCname)
89
{
90
G4int
i = HCtable->
Registor
(SDname,DCname);
91
if
(verboseLevel>0)
92
{
93
if
(i<0) {
94
G4ExceptionDescription
ED;
95
ED <<
"G4SDManager::AddNewCollection : the collection <"
96
<< SDname <<
"/"
<< DCname <<
"> has already been reginstered."
<<
G4endl
;
97
G4Exception
(
"G4SDManager::AddNewCollection"
,
"Det0001"
,
JustWarning
,ED);
98
}
99
else
100
{
101
G4cout
<<
"G4SDManager::AddNewCollection : the collection <"
102
<< SDname <<
"/"
<< DCname <<
"> is registered at "
<< i <<
G4endl
;
103
}
104
}
105
}
106
107
G4HCofThisEvent
*
G4SDManager::PrepareNewEvent
()
108
{
109
G4HCofThisEvent
* HCE =
new
G4HCofThisEvent
(HCtable->
entries
());
110
treeTop->
Initialize
(HCE);
111
return
HCE;
112
}
113
114
void
G4SDManager::TerminateCurrentEvent
(
G4HCofThisEvent
* HCE)
115
{
116
treeTop->
Terminate
(HCE);
117
}
118
119
void
G4SDManager::Activate
(
G4String
dName,
G4bool
activeFlag)
120
{
121
G4String
pathName = dName;
122
if
( pathName(0) !=
'/'
) pathName.
prepend
(
"/"
);
123
treeTop->
Activate
(pathName,activeFlag);
124
}
125
126
G4VSensitiveDetector
*
G4SDManager::FindSensitiveDetector
(
G4String
dName,
G4bool
warning)
127
{
128
G4String
pathName = dName;
129
if
( pathName(0) !=
'/'
) pathName.
prepend
(
"/"
);
130
return
treeTop->
FindSensitiveDetector
(pathName, warning);
131
}
132
133
G4int
G4SDManager::GetCollectionID
(
G4String
colName)
134
{
135
G4int
id
= HCtable->
GetCollectionID
(colName);
136
if
(
id
==-1)
137
{
G4cout
<<
"<"
<< colName <<
"> is not found."
<<
G4endl
; }
138
else
if
(
id
==-2)
139
{
G4cout
<<
"<"
<< colName <<
"> is ambiguous."
<<
G4endl
; }
140
return
id;
141
}
142
143
G4int
G4SDManager::GetCollectionID
(
G4VHitsCollection
* aHC)
144
{
145
G4String
HCname = aHC->
GetSDname
();
146
HCname +=
"/"
;
147
HCname += aHC->
GetName
();
148
return
GetCollectionID
(HCname);
149
}
150
151
Generated on Sat May 25 2013 14:33:03 for Geant4 by
1.8.4