]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TGeant4/TG4ProcessControlMap.cxx
New TTask based method to do Digits To clusters. Works with files of multiple
[u/mrichter/AliRoot.git] / TGeant4 / TG4ProcessControlMap.cxx
1 // $Id$
2 // Category: physics
3 //
4 // Author: I. Hrivnacova
5 //
6 // Class TG4ProcessControlMap
7 // --------------------------
8 // See the class description in the header file.
9
10 #include "TG4ProcessControlMap.h"
11 #include "TG4G3ControlVector.h"
12 #include "TG4Globals.h"
13
14 #include <G4VProcess.hh>
15 #include "g4std/iomanip"
16 #include "globals.hh"
17
18 TG4ProcessControlMap* TG4ProcessControlMap::fgInstance = 0;
19
20 //_____________________________________________________________________________
21 TG4ProcessControlMap::TG4ProcessControlMap() {
22 //
23   if (fgInstance) {
24     TG4Globals::Exception(
25       "TG4ProcessControlMap: attempt to create two instances of singleton.");
26   }
27       
28   fgInstance = this;  
29 }
30
31 //_____________________________________________________________________________
32 TG4ProcessControlMap::TG4ProcessControlMap(const TG4ProcessControlMap& right) {
33 //
34   TG4Globals::Exception(    
35     "Attempt to copy TG4ProcessControlMap singleton.");
36 }  
37
38 //_____________________________________________________________________________
39 TG4ProcessControlMap::~TG4ProcessControlMap() {
40 //
41 }
42
43 // operators
44
45 //_____________________________________________________________________________
46 TG4ProcessControlMap& TG4ProcessControlMap::operator=(const TG4ProcessControlMap& right)
47 {
48   // check assignement to self
49   if (this == &right) return *this;
50
51   TG4Globals::Exception(
52     "Attempt to assign TG4ProcessControlMap singleton.");
53     
54   return *this;  
55 }    
56           
57 // private methods
58
59 //_____________________________________________________________________________
60 G4bool TG4ProcessControlMap::IsDefined(const G4String& processName)
61 {
62 // Returns true if the first is already in the map.
63 // ---
64
65   if (fMap.find(processName) == fMap.end()) 
66     return false;
67   else                 
68     return true;
69 }
70
71 // public methods
72
73 //_____________________________________________________________________________
74 G4bool TG4ProcessControlMap::Add(G4VProcess* process, TG4G3Control control)
75 {  
76 // Adds the pair to the map.
77 // ---
78
79   if (!process) return false;
80
81   return Add(process->GetProcessName(), control); 
82 }
83
84 //_____________________________________________________________________________
85 G4bool TG4ProcessControlMap::Add(G4String processName, TG4G3Control control)
86 {  
87 // Adds the pair to the map.
88 // ---
89
90   if (!IsDefined(processName)) {
91     // insert into map 
92     // only in case it is not yet here
93     fMap[processName] = control;
94     return true;
95   }
96   return false;  
97 }
98
99 //_____________________________________________________________________________
100 void TG4ProcessControlMap::PrintAll() const
101 {
102 // Dumps all map.
103 // ---
104
105   if (fMap.size()) {
106     G4cout << "Dump of TG4ProcessControlMap - " << fMap.size() << " entries:" << G4endl;
107     G4int counter = 0;
108     for (MapConstIterator i=fMap.begin(); i != fMap.end(); i++) {
109       G4String processName = (*i).first;
110       TG4G3Control control = (*i).second;
111       G4cout << "Map element " << G4std::setw(3) << counter++ << "   " 
112              << processName << "   " 
113              << TG4G3ControlVector::GetControlName(control)
114              << G4endl;
115     }
116   }
117 }
118
119 //_____________________________________________________________________________
120 void TG4ProcessControlMap::Clear() 
121 {
122 // Clears the map.
123 // ---
124
125   fMap.clear();
126 }  
127
128 //_____________________________________________________________________________
129 TG4G3Control 
130 TG4ProcessControlMap::GetControl(const G4VProcess* process)
131 {
132 // Returns the G3 process control for the process with a given name.
133 // ---
134
135   if (!process) return kNoG3Controls;
136
137   return GetControl(process->GetProcessName());
138 }
139
140 //_____________________________________________________________________________
141 TG4G3Control 
142 TG4ProcessControlMap::GetControl(const G4String& processName)
143 {
144 // Returns the G3 process control for the process with a given name.
145 // ---
146
147   MapIterator i = fMap.find(processName);
148   if (i == fMap.end()) 
149     return kNoG3Controls;
150   else                 
151     return (*i).second;
152 }
153
154 //_____________________________________________________________________________
155 const G4String& 
156 TG4ProcessControlMap::GetControlName(const G4VProcess* process)
157 {
158 // Returns the G3 process control name for the process with a given name.
159 // ---
160
161   if (!process) 
162     return TG4G3ControlVector::GetControlName(kNoG3Controls);
163
164   return GetControlName(process->GetProcessName());
165 }
166             
167 //_____________________________________________________________________________
168 const G4String& 
169 TG4ProcessControlMap::GetControlName(const G4String& processName)
170 {
171 // Returns the G3 process control name for the process with a given name.
172 // ---
173
174   return TG4G3ControlVector::GetControlName(GetControl(processName));
175 }
176