Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4DigiManager.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//
28
29#include "G4DigiManager.hh"
30#include "G4Event.hh"
31#include "G4VHitsCollection.hh"
32#include "G4VDigiCollection.hh"
33#include "G4DMmessenger.hh"
34#include "G4DCofThisEvent.hh"
35#include "G4RunManager.hh"
36#include "G4SDManager.hh"
37#include "G4ios.hh"
38
39
40G4ThreadLocal G4DigiManager* G4DigiManager::fDManager = 0;
41
43{
44 if(!fDManager)
45 {
46 fDManager = new G4DigiManager;
47 }
48 return fDManager;
49}
50
52{ return fDManager; }
53
55{
56 theMessenger = new G4DMmessenger(this);
57 runManager = G4RunManager::GetRunManager();
58 SDManager = G4SDManager::GetSDMpointer();
59 DCtable = new G4DCtable;
60}
61
63{
64 //DMtable.clearAndDestroy();
65 for(G4int i=0;i<int(DMtable.size());i++)
66 { delete DMtable[i]; }
67 DMtable.clear();
68 delete DCtable;
69 delete theMessenger;
70}
71
73{
74 G4String DMname = DM->GetName();
75 for(int j=0;j<int(DMtable.size());j++)
76 {
77 if(DMtable[j]==DM)
78 {
79 G4cout << "<" << DMname << "> has already been registered." << G4endl;
80 return;
81 }
82 }
83 if( verboseLevel > 0 )
84 {
85 G4cout << "New DigitizerModule <" << DMname
86 << "> is registered." << G4endl;
87 }
88 DMtable.push_back(DM);
89
90 G4int numberOfCollections = DM->GetNumberOfCollections();
91 for(int i=0;i<numberOfCollections;i++)
92 {
93 G4String DCname = DM->GetCollectionName(i);
94 if( DCtable->Registor(DMname,DCname) < 0 )
95 {
96 G4cout << "DigiCollection <" << DCname
97 << "> has already been registered with "
98 << DMname << " DigitizerModule." << G4endl;
99 }
100 else if( verboseLevel > 0 )
101 {
102 G4cout << "DigiCollection " << DCname
103 << " is registered. " << G4endl;
104 }
105 }
106
107 runManager->SetDCtable(DCtable);
108}
109
111{
113 if(aDM)
114 { aDM->Digitize(); }
115 else
116 { G4cout << "Unknown digitizer module <" << mName << ">. Digitize() ignored." << G4endl; }
117}
118
120{
121 for(G4int i=0;i<int(DMtable.size());i++)
122 {
123 if(DMtable[i]->GetName() == mName) return DMtable[i];
124 }
125 return NULL;
126}
127
129{
130 const G4Event* evt = NULL;
131 if(eventID==0)
132 { evt = runManager->GetCurrentEvent(); }
133 else
134 { evt = runManager->GetPreviousEvent(eventID); }
135 if(evt==NULL) return NULL;
136
137 G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
138 if(HCE==NULL) return NULL;
139
140 return HCE->GetHC(HCID);
141}
142
144{
145 const G4Event* evt = NULL;
146 if(eventID==0)
147 { evt = runManager->GetCurrentEvent(); }
148 else
149 { evt = runManager->GetPreviousEvent(eventID); }
150 if(evt==NULL) return NULL;
151
152 G4DCofThisEvent* DCE = evt->GetDCofThisEvent();
153 if(DCE==NULL) return NULL;
154
155 return DCE->GetDC(DCID);
156}
157
159{
160 return SDManager->GetCollectionID(HCname);
161}
162
164{
165 G4int i = DCtable->GetCollectionID(DCname);
166 if(i==-2)
167 { G4cout << "< " << DCname << "> is ambegious." << G4endl; }
168 return i;
169}
170
172{
173 const G4Event* consEvt = runManager->GetCurrentEvent();
174 if(consEvt==NULL)
175 {
176 G4cout << "G4DigiManager::SetDigiCollection --- "
177 << "Event object is not available." << G4endl;
178 return;
179 }
180
181 G4Event* evt = (G4Event*)consEvt;
182 G4DCofThisEvent* DCE = evt->GetDCofThisEvent();
183 if(DCE==NULL)
184 {
185 DCE = new G4DCofThisEvent(DCtable->entries());
186 evt->SetDCofThisEvent(DCE);
187 if(verboseLevel>0)
188 { G4cout << "DCofThisEvent object is added to current G4Event." << G4endl; }
189 }
190
191 DCE->AddDigiCollection(DCID,aDC);
192
193 if(verboseLevel>0)
194 {
195 G4cout << aDC->GetName() << " is stored at " << DCID
196 << "-th slot of G4DCofThisEvent." << G4endl;
197 }
198}
199
201{
202 verboseLevel = val;
203 for(G4int i=0;i<int(DMtable.size());i++)
204 { DMtable[i]->SetVerboseLevel(val); }
205}
206
208{
209 for(G4int i=0;i<int(DMtable.size());i++)
210 { G4cout << " " << i << " : " << DMtable[i]->GetName() << G4endl; }
211}
212
213
214
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4VDigiCollection * GetDC(G4int i) const
void AddDigiCollection(G4int DCID, G4VDigiCollection *aDC)
G4int entries() const
Definition: G4DCtable.hh:66
G4int Registor(G4String SDname, G4String DCname)
Definition: G4DCtable.cc:36
G4int GetCollectionID(G4String DCname) const
Definition: G4DCtable.cc:45
void List() const
void AddNewModule(G4VDigitizerModule *DM)
G4int GetDigiCollectionID(G4String DCname)
const G4VHitsCollection * GetHitsCollection(G4int HCID, G4int eventID=0)
G4int GetHitsCollectionID(G4String HCname)
G4VDigitizerModule * FindDigitizerModule(G4String mName)
static G4DigiManager * GetDMpointer()
void SetVerboseLevel(G4int vl)
void Digitize(G4String mName)
void SetDigiCollection(G4int DCID, G4VDigiCollection *aDC)
const G4VDigiCollection * GetDigiCollection(G4int DCID, G4int eventID=0)
static G4DigiManager * GetDMpointerIfExist()
G4HCofThisEvent * GetHCofThisEvent() const
Definition: G4Event.hh:156
void SetDCofThisEvent(G4DCofThisEvent *value)
Definition: G4Event.hh:84
G4DCofThisEvent * GetDCofThisEvent() const
Definition: G4Event.hh:158
G4VHitsCollection * GetHC(G4int i)
const G4Event * GetPreviousEvent(G4int i) const
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:84
void SetDCtable(G4DCtable *DCtbl)
const G4Event * GetCurrentEvent() const
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:39
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:135
const G4String & GetName() const
G4int GetNumberOfCollections() const
G4String GetName() const
virtual void Digitize()=0
G4String GetCollectionName(G4int i) const
#define G4ThreadLocal
Definition: tls.hh:77