]>
Commit | Line | Data |
---|---|---|
32f6e426 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | // $Id$ | |
17 | // $MpId: AliMpDEManager.cxx,v 1.1 2006/01/11 10:24:44 ivana Exp $ | |
18 | // Category: management | |
19 | // | |
20 | // Class AliMpDEManager | |
21 | // -------------------- | |
22 | // The manager class for definition of detection element types | |
23 | // Authors: Ivana Hrivnacova, IPN Orsay | |
24 | // Laurent Aphecetche, SUBATECH Nantes | |
25 | ||
26 | #include "AliMpDEManager.h" | |
27 | #include "AliMpConstants.h" | |
28 | #include "AliMpFiles.h" | |
29 | ||
30 | #include "AliLog.h" | |
31 | ||
32 | #include <Riostream.h> | |
33 | #include <TSystem.h> | |
34 | #include <TObjString.h> | |
35 | #include <TMap.h> | |
36 | ||
37 | ClassImp(AliMpDEManager) | |
38 | ||
39 | const char AliMpDEManager::fgkNameSeparator = '_'; | |
40 | const char AliMpDEManager::fgkCommentPrefix = '#'; | |
41 | const Int_t AliMpDEManager::fgkCoefficient = 100; | |
42 | AliMpExMap AliMpDEManager::fgDENamesMap = AliMpExMap(true); | |
43 | ||
44 | //______________________________________________________________________________ | |
45 | AliMpDEManager::AliMpDEManager() | |
46 | : TObject() | |
47 | { | |
48 | /// Protected default/standard constructor | |
49 | } | |
50 | ||
51 | //______________________________________________________________________________ | |
52 | AliMpDEManager::AliMpDEManager(const AliMpDEManager& rhs) | |
53 | : TObject(rhs) | |
54 | { | |
55 | /// Protected copy constructor | |
56 | ||
57 | AliFatal("Not implemented."); | |
58 | } | |
59 | ||
60 | //______________________________________________________________________________ | |
61 | ||
62 | AliMpDEManager::~AliMpDEManager() | |
63 | { | |
64 | /// Destructor | |
65 | } | |
66 | ||
67 | //______________________________________________________________________________ | |
68 | AliMpDEManager& AliMpDEManager::operator=(const AliMpDEManager& rhs) | |
69 | { | |
70 | /// Protected assignement operator | |
71 | ||
72 | if (this == &rhs) return *this; | |
73 | ||
74 | AliFatal("Not implemented."); | |
75 | ||
76 | return *this; | |
77 | } | |
78 | ||
79 | // | |
80 | // static private methods | |
81 | // | |
82 | ||
83 | //______________________________________________________________________________ | |
84 | Bool_t AliMpDEManager::IsPlaneType(const TString& planeTypeName) | |
85 | { | |
86 | /// Return true if the planeTypeName corresponds to a valid plane type | |
87 | ||
88 | if ( planeTypeName == PlaneTypeName(kBendingPlane) || | |
89 | planeTypeName == PlaneTypeName(kNonBendingPlane) ) | |
90 | return true; | |
91 | ||
92 | return false; | |
93 | } | |
94 | ||
95 | //______________________________________________________________________________ | |
96 | AliMpPlaneType AliMpDEManager::PlaneType(const TString& planeTypeName) | |
97 | { | |
98 | /// Return plane type for the given planeTypeName \n | |
99 | /// Fatal error if planeTypeName is wrong | |
100 | ||
101 | if ( planeTypeName == PlaneTypeName(kBendingPlane) ) | |
102 | return kBendingPlane; | |
103 | ||
104 | if ( planeTypeName == PlaneTypeName(kNonBendingPlane) ) | |
105 | return kNonBendingPlane; | |
106 | ||
107 | // Should never reach this line | |
108 | AliFatalClass(Form("No plane type defined for %s", planeTypeName.Data())); | |
109 | return kBendingPlane; | |
110 | } | |
111 | ||
112 | //______________________________________________________________________________ | |
113 | AliMpStationType AliMpDEManager::StationType(const TString& stationTypeName) | |
114 | { | |
115 | /// Return station type for the given stationTypeName \n | |
116 | /// Fatal error if stationTypeName is wrong | |
117 | ||
118 | if ( stationTypeName == StationTypeName(kStation1) ) | |
119 | return kStation1; | |
120 | ||
121 | if ( stationTypeName == StationTypeName(kStation2) ) | |
122 | return kStation2; | |
123 | ||
124 | if ( stationTypeName == StationTypeName(kStation345) ) | |
125 | return kStation345; | |
126 | ||
127 | if ( stationTypeName == StationTypeName(kStationTrigger) ) | |
128 | return kStationTrigger; | |
129 | ||
130 | // Should never reach this line | |
131 | AliFatalClass(Form("No station type defined for ", stationTypeName.Data())); | |
132 | return kStation1; | |
133 | } | |
134 | ||
135 | //______________________________________________________________________________ | |
136 | Bool_t | |
137 | AliMpDEManager::ReadDENames(AliMpStationType station) | |
138 | { | |
139 | /// Read det element names for cath = 0 from the file specified by name | |
140 | /// and fill the map | |
141 | ||
142 | // Open file | |
143 | TString filePath = AliMpFiles::DENamesFilePath(station); | |
144 | std::ifstream in(filePath); | |
145 | if (!in.good()) { | |
146 | AliErrorClassStream() << "Cannot open file " << filePath << endl;; | |
147 | return false; | |
148 | } | |
149 | ||
150 | // Read plane types per cathods | |
151 | // | |
152 | char line[80]; | |
153 | TString word; | |
154 | TString cathName1, cathName2; | |
155 | in >> word; | |
156 | while ( ! in.eof() && cathName1.Length() == 0 ) { | |
157 | if ( word[0] == '#' ) | |
158 | in.getline(line, 80); | |
159 | else { | |
160 | cathName1 = word; | |
161 | in >> cathName2; | |
162 | } | |
163 | in >> word; | |
164 | } | |
165 | ||
166 | Bool_t isCathNameDefined = false; | |
167 | if ( IsPlaneType(cathName1) && IsPlaneType(cathName2) ) | |
168 | isCathNameDefined = true; | |
169 | ||
170 | // Read DE names | |
171 | // | |
172 | Int_t detElemId; | |
173 | TString name1, name2; | |
174 | while ( ! in.eof() ) { | |
175 | if ( word[0] == '#' ) | |
176 | in.getline(line, 80); | |
177 | else { | |
178 | detElemId = word.Atoi(); | |
179 | in >> name1; | |
180 | if ( ! isCathNameDefined ) | |
181 | in >> name2; | |
182 | else { | |
183 | name1 += fgkNameSeparator; | |
184 | name2 = name1; | |
185 | name1 += cathName1; | |
186 | name2 += cathName2; | |
187 | } | |
188 | ||
189 | if ( ! fgDENamesMap.GetValue(detElemId) ) { | |
190 | AliDebugClassStream(1) | |
191 | << "Adding " << detElemId << " " << name1 << " " << name2 << endl; | |
192 | fgDENamesMap.Add(detElemId, | |
193 | new TPair(new TObjString(name1), new TObjString(name2))); | |
194 | } | |
195 | } | |
196 | in >> word; | |
197 | } | |
198 | ||
199 | // Close file | |
200 | in.close(); | |
201 | ||
202 | return true; | |
203 | } | |
204 | ||
205 | //______________________________________________________________________________ | |
206 | void AliMpDEManager::FillDENames() | |
207 | { | |
208 | /// Fill DE names from files | |
209 | ||
210 | Bool_t result1 = ReadDENames(kStation1); | |
211 | Bool_t result2 = ReadDENames(kStation2); | |
212 | Bool_t result3 = ReadDENames(kStation345); | |
213 | Bool_t result4 = ReadDENames(kStationTrigger); | |
214 | ||
215 | Bool_t result = result1 && result2 && result3 && result4; | |
216 | if ( ! result ) { | |
217 | AliErrorClassStream() << "Error in reading DE names files" << endl; | |
218 | } | |
219 | } | |
220 | ||
221 | // | |
222 | // static public methods | |
223 | // | |
224 | ||
225 | //______________________________________________________________________________ | |
226 | Bool_t AliMpDEManager::IsValidDetElemId(Int_t detElemId, Bool_t warn) | |
227 | { | |
228 | /// Return true if detElemId is valid | |
229 | /// (is present in the DE names files) | |
230 | ||
231 | if ( fgDENamesMap.GetSize() == 0 ) FillDENames(); | |
232 | ||
233 | if ( fgDENamesMap.GetValue(detElemId) ) return true; | |
234 | ||
235 | if (warn) { | |
236 | AliErrorClassStream() | |
237 | << "Detection element " << detElemId << " not defined." << endl; | |
238 | } | |
239 | return false; | |
240 | } | |
241 | ||
242 | //______________________________________________________________________________ | |
243 | Bool_t AliMpDEManager::IsValidCathod(Int_t cath, Bool_t warn) | |
244 | { | |
245 | /// Return true if cath is 0 or 1 | |
246 | /// (Better solution would be to use systematically enum) | |
247 | ||
248 | if (cath == 0 || cath == 1 ) return true; | |
249 | ||
250 | if (warn) | |
251 | AliErrorClassStream() << "Wrong cathod number " << cath << endl; | |
252 | ||
253 | return false; | |
254 | } | |
255 | ||
256 | ||
257 | //______________________________________________________________________________ | |
258 | Bool_t AliMpDEManager::IsValid(Int_t detElemId, Int_t cath, Bool_t warn) | |
259 | { | |
260 | /// Return true if both detElemId and cathod number are valid | |
261 | ||
262 | return ( IsValidDetElemId(detElemId, warn) && IsValidCathod(cath, warn) ); | |
263 | } | |
264 | ||
265 | //______________________________________________________________________________ | |
266 | Bool_t AliMpDEManager::IsValidModuleId(Int_t moduleId, Bool_t warn) | |
267 | { | |
268 | /// Return true if moduleId is valid | |
269 | ||
270 | if ( moduleId >= 0 && moduleId < AliMpConstants::NCh() ) | |
271 | return true; | |
272 | ||
273 | if (warn) | |
274 | AliErrorClassStream() << "Wrong module Id " << moduleId << endl; | |
275 | ||
276 | return false; | |
277 | } | |
278 | ||
279 | //______________________________________________________________________________ | |
280 | TString AliMpDEManager::GetDEName(Int_t detElemId, Int_t cath, Bool_t warn) | |
281 | { | |
282 | /// Return det element type name | |
283 | ||
284 | if ( ! IsValid(detElemId, cath, warn) ) return "undefined"; | |
285 | ||
286 | TPair* namePair = (TPair*)fgDENamesMap.GetValue(detElemId); | |
287 | ||
288 | if (cath == 0) return ((TObjString*)namePair->Key())->GetString(); | |
289 | if (cath == 1) return ((TObjString*)namePair->Value())->GetString(); | |
290 | ||
291 | return "undefined"; | |
292 | } | |
293 | ||
294 | //______________________________________________________________________________ | |
295 | TString AliMpDEManager::GetDETypeName(Int_t detElemId, Int_t cath, Bool_t warn) | |
296 | { | |
297 | /// Return det element type name | |
298 | ||
299 | TString fullName = GetDEName(detElemId, cath, warn); | |
300 | ||
301 | // cut plane type extension | |
302 | Ssiz_t pos = fullName.First(fgkNameSeparator); | |
303 | return fullName(0,pos); | |
304 | } | |
305 | ||
306 | //______________________________________________________________________________ | |
307 | Int_t AliMpDEManager::GetModuleId(Int_t detElemId, Bool_t warn) | |
308 | { | |
309 | /// Return module Id for given detElemId | |
310 | ||
311 | if ( ! IsValidDetElemId(detElemId, warn) ) return -1; | |
312 | ||
313 | return detElemId/fgkCoefficient - 1; | |
314 | } | |
315 | ||
316 | //______________________________________________________________________________ | |
317 | AliMpPlaneType AliMpDEManager::GetPlaneType(Int_t detElemId, Int_t cath) | |
318 | { | |
319 | /// Return plane type \n | |
320 | /// Failure causes Fatal error - as AliMpPlaneType has no possibility | |
321 | /// to return undefined value | |
322 | ||
323 | if ( ! IsValid(detElemId, cath, true) ) { | |
324 | AliFatalClass("Cannot return AliMpPlaneType value."); | |
325 | return kBendingPlane; | |
326 | } | |
327 | ||
328 | TPair* namePair = (TPair*)fgDENamesMap.GetValue(detElemId); | |
329 | ||
330 | TString fullName; | |
331 | if (cath == 0) fullName = ((TObjString*)namePair->Key())->GetString(); | |
332 | if (cath == 1) fullName = ((TObjString*)namePair->Value())->GetString(); | |
333 | ||
334 | // Get plane type name | |
335 | Ssiz_t pos = fullName.First(fgkNameSeparator); | |
336 | TString planeTypeName = fullName(pos+1,fullName.Length()-pos); | |
337 | ||
338 | return PlaneType(planeTypeName); | |
339 | } | |
340 | ||
341 | //______________________________________________________________________________ | |
342 | AliMpStationType AliMpDEManager::GetStationType(Int_t detElemId) | |
343 | { | |
344 | /// Return station type \n | |
345 | /// Failure causes Fatal error - as AliMpStationType has no possibility | |
346 | /// to return undefined value | |
347 | ||
348 | if ( ! IsValidDetElemId(detElemId, true) ) { | |
349 | AliFatalClass("Cannot return AliMpStationType value."); | |
350 | return kStation1; | |
351 | } | |
352 | ||
353 | Int_t moduleId = GetModuleId(detElemId, false); | |
354 | if ( ! IsValidModuleId(moduleId, true) ) { | |
355 | AliFatalClass("Cannot return AliMpStationType value."); | |
356 | return kStation1; | |
357 | } | |
358 | ||
359 | if ( moduleId == 0 || moduleId == 1 ) return kStation1; | |
360 | if ( moduleId == 2 || moduleId == 3 ) return kStation2; | |
361 | if ( moduleId >= 4 && moduleId <= 9 ) return kStation345; | |
362 | if ( moduleId >= 10 && moduleId <= 13 ) return kStationTrigger; | |
363 | ||
364 | // Should never get to this line | |
365 | AliFatalClass("Cannot return AliMpStationType value."); | |
366 | return kStation1; | |
367 | } | |
368 |