]>
Commit | Line | Data |
---|---|---|
2f310734 | 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); | |
26074cdd | 81 | fMessenger.Update(); |
2f310734 | 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 | ||
b9d0a01d | 198 | if (nofSwitchedDets == G4int(fDetSwitchVector.size())) svList = "ALL: " + svList; |
2f310734 | 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; | |
b9d0a01d | 239 | if (iv < (*it)->GetNofVersions()-1) |
240 | svList += "/"; | |
241 | else if (id++ < G4int(fDetSwitchVector.size())-1) | |
242 | svList += ", "; | |
2f310734 | 243 | } |
244 | ||
245 | return svList; | |
246 | } | |
247 | ||
248 | //_____________________________________________________________________________ | |
249 | G4String AliDetSwitchVector::GetDetNamesList() const | |
250 | { | |
251 | // Returns list of detector names. | |
252 | // --- | |
253 | ||
254 | G4String svList = ""; | |
255 | DetSwitchConstIterator it; | |
256 | ||
257 | for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++) { | |
258 | svList += (*it)->GetDetName(); | |
259 | svList += " "; | |
260 | } | |
261 | ||
262 | return svList; | |
263 | } | |
264 | ||
265 | //_____________________________________________________________________________ | |
266 | G4String AliDetSwitchVector::GetDetNamesListWithCommas() const | |
267 | { | |
268 | // Returns list of detector names with commas. | |
269 | // --- | |
270 | ||
271 | G4String svList = ""; | |
272 | G4int id =0; | |
273 | DetSwitchConstIterator it; | |
274 | ||
275 | for (it = fDetSwitchVector.begin(); it != fDetSwitchVector.end(); it++) { | |
276 | svList += (*it)->GetDetName(); | |
b9d0a01d | 277 | if (id++ < G4int(fDetSwitchVector.size())-1) |
278 | svList += ", "; | |
2f310734 | 279 | } |
280 | ||
281 | return svList; | |
282 | } | |
283 |