]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliDetSwitchVector.cxx
initial version - added with redesign of detector construction classes (see AliGeant4...
[u/mrichter/AliRoot.git] / AliGeant4 / AliDetSwitchVector.cxx
1 // $Id$
2 // Category: geometry
3 //
4 // Author: I. Hrivnacova
5 //
6 // Class AliDetSwitchVector
7 // ---------------------------
8 // See the class description in the header file.
9
10 #include "AliDetSwitchVector.h"
11 #include "AliDetSwitch.h"
12 #include "AliGlobals.h"
13 #include "AliFiles.h"
14
15 //_____________________________________________________________________________
16 AliDetSwitchVector::AliDetSwitchVector()
17   : fMessenger(this)
18 {
19 //
20 }
21
22 //_____________________________________________________________________________
23 AliDetSwitchVector::AliDetSwitchVector(const AliDetSwitchVector& right)
24   : fMessenger(this)
25 {
26 //
27   AliGlobals::Exception("AliDetSwitchVector is protected from copying.");  
28 }
29
30 //_____________________________________________________________________________
31 AliDetSwitchVector::~AliDetSwitchVector() {
32 //   
33   // destroy det switch vector
34   DetSwitchIterator it;
35   for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++)
36     delete *it; 
37 }
38
39 // operators
40
41 //_____________________________________________________________________________
42 AliDetSwitchVector& 
43 AliDetSwitchVector::operator=(const AliDetSwitchVector& right)
44 {
45   // check assignement to self
46   if (this == &right) return *this;
47   
48   AliGlobals::Exception("AliDetSwitchVector is protected from assigning.");  
49
50   return *this;  
51 }    
52           
53 // protected methods
54
55 //_____________________________________________________________________________
56 AliDetSwitch* 
57 AliDetSwitchVector::GetDetSwitch(const G4String& moduleName) const
58 {
59 // Returns the detector switch with given detector name.
60 // ---
61
62   DetSwitchConstIterator it;
63   for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++)
64     if ((*it)->GetDetName() == moduleName) return *it; 
65
66   G4String text = "AliDetSwitchVector::GetDetSwitch:\n";
67   text = text + "Wrong detector name for " + moduleName;   
68   AliGlobals::Exception(text);
69   return 0;  
70
71
72 // public methods
73
74 //_____________________________________________________________________________
75 void AliDetSwitchVector::Add(AliDetSwitch* detSwitch)
76 {
77 // Adds detSwitch to the detSwitch vector.
78 // ---
79
80   fDetSwitchVector.push_back(detSwitch);
81   fMessenger.SetCandidates();
82 }  
83   
84 //_____________________________________________________________________________
85 void AliDetSwitchVector::SwitchDetOn(const G4String& moduleNameVer)
86
87 // Switchs on module specified by name and version.
88 // ---
89
90   DetSwitchIterator it;
91
92   if (moduleNameVer == "ALL") {
93     for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++)
94       (*it)->SwitchOnDefault(); 
95   }
96   else if (moduleNameVer == "NONE") {
97     for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++)
98       (*it)->SwitchOff(); 
99   }
100   else {
101     // get version number
102     G4int len = moduleNameVer.length();
103     G4String moduleName = moduleNameVer.substr(0, len-1);
104     G4String version = moduleNameVer.substr(len-1, 1);
105     G4int iVersion = AliGlobals::StringToInt(version);
106
107     if (iVersion < 0) {
108       // in case the version number is not provided
109       // the default one is set
110       SwitchDetOnDefault(moduleNameVer);
111     }  
112     else 
113       SwitchDetOn(moduleName, iVersion);
114   }
115 }
116
117 //_____________________________________________________________________________
118 void AliDetSwitchVector::SwitchDetOn(const G4String& moduleName, 
119                                      G4int version)
120
121 // Switchs on module specified by name and version.
122 // ---
123
124   GetDetSwitch(moduleName)->SwitchOn(version);
125 }
126
127 //_____________________________________________________________________________
128 void AliDetSwitchVector::SwitchDetOnDefault(const G4String& moduleName)
129
130 // Switchs on module specified by name with default version.
131 // ---
132
133   GetDetSwitch(moduleName)->SwitchOnDefault();
134 }
135
136 //_____________________________________________________________________________
137 void AliDetSwitchVector::SwitchDetOff(const G4String& moduleName)
138
139 // Switchs off module specified by name.
140 // ---
141
142   if (moduleName == "ALL") {
143     DetSwitchIterator it;
144     for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++)
145       (*it)->SwitchOff(); 
146   }
147   else 
148     GetDetSwitch(moduleName)->SwitchOff();
149 }
150
151 //_____________________________________________________________________________
152 void AliDetSwitchVector::PrintSwitchedDets() const
153
154 // Lists switched detectors.
155 // ---
156
157   G4String svList = GetSwitchedDetsList();
158     
159   G4cout << "Switched Alice detectors: " << G4endl;
160   G4cout << "--------------------------" << G4endl;
161   G4cout << svList << G4endl;
162 }
163
164 //_____________________________________________________________________________
165 void AliDetSwitchVector::PrintAvailableDets() const
166
167 // Lists available detectors.
168 // ---
169
170   G4String avList = GetAvailableDetsList();
171     
172   G4cout << "Available Alice detectors: " << G4endl;
173   G4cout << "---------------------------" << G4endl;
174   G4cout << avList << G4endl;
175 }
176
177 //_____________________________________________________________________________
178 G4String AliDetSwitchVector::GetSwitchedDetsList() const
179
180 // Returns list of switched detectors.
181 // ---
182
183   G4String svList = "";  
184   G4int nofSwitchedDets = 0;
185   DetSwitchConstIterator it;
186   
187   for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++) {
188     G4int iVersion = (*it)->GetSwitchedVersion();
189     if (iVersion > -1) {
190       nofSwitchedDets++;
191       G4String moduleNameVer = (*it)->GetDetName();
192       AliGlobals::AppendNumberToString(moduleNameVer, iVersion);
193       svList += moduleNameVer;
194       svList += " "; 
195     }
196   }
197
198   if (nofSwitchedDets == fDetSwitchVector.size()) svList = "ALL: " + svList;
199   if (nofSwitchedDets == 0) svList = "NONE";   
200
201   return svList;
202 }
203
204 //_____________________________________________________________________________
205 G4String AliDetSwitchVector::GetAvailableDetsList() const
206
207 // Returns list of available detectors.
208 // ---
209
210   G4String svList = "";
211   DetSwitchConstIterator it;
212   
213   for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++)
214     for (G4int iv=0; iv<(*it)->GetNofVersions(); iv++) {
215       G4String moduleNameVer = (*it)->GetDetName();
216       AliGlobals::AppendNumberToString(moduleNameVer, iv);
217       svList += moduleNameVer;
218       svList += " ";
219     } 
220
221   return svList;
222 }
223
224 //_____________________________________________________________________________
225 G4String AliDetSwitchVector::GetAvailableDetsListWithCommas() const
226
227 // Returns list of available detectors with commas.
228 // ---
229
230   G4String svList = "";
231   G4int id =0;
232   DetSwitchConstIterator it;
233
234   for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++)
235     for (G4int iv=0; iv<(*it)->GetNofVersions(); iv++) {
236       G4String moduleNameVer = (*it)->GetDetName();
237       AliGlobals::AppendNumberToString(moduleNameVer, iv);
238       svList += moduleNameVer;
239       if (iv < (*it)->GetNofVersions()-1)        svList += "/";
240       else if (id++ < fDetSwitchVector.size()-1) svList += ", ";
241     }
242
243   return svList;
244 }
245
246 //_____________________________________________________________________________
247 G4String AliDetSwitchVector::GetDetNamesList() const
248
249 // Returns list of detector names.
250 // ---
251
252   G4String svList = "";
253   DetSwitchConstIterator it;
254   
255   for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++) {
256     svList += (*it)->GetDetName();
257     svList += " ";
258   }
259
260   return svList;
261 }
262
263 //_____________________________________________________________________________
264 G4String AliDetSwitchVector::GetDetNamesListWithCommas() const
265
266 // Returns list of detector names with commas.
267 // ---
268
269   G4String svList = "";
270   G4int id =0;
271   DetSwitchConstIterator it;
272
273   for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++) {
274     svList += (*it)->GetDetName();
275     if (id++ < fDetSwitchVector.size()-1) svList += ", ";
276   }
277
278   return svList;
279 }
280