]>
Commit | Line | Data |
---|---|---|
f0c62051 | 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: AliMpDEStore.cxx,v 1.4 2006/05/24 13:58:34 ivana Exp $ | |
18 | // Category: management | |
3d1463c8 | 19 | |
20 | //----------------------------------------------------------------------------- | |
f0c62051 | 21 | // Class AliMpDEStore |
22 | // -------------------- | |
23 | // The container class for detection element objects | |
24 | // Authors: Ivana Hrivnacova, IPN Orsay | |
25 | // Laurent Aphecetche, Christian Finck, SUBATECH Nantes | |
3d1463c8 | 26 | //----------------------------------------------------------------------------- |
f0c62051 | 27 | |
28 | #include "AliMpDEStore.h" | |
29 | #include "AliMpDEManager.h" | |
30 | #include "AliMpDetElement.h" | |
31 | #include "AliMpConstants.h" | |
32 | #include "AliMpFiles.h" | |
33 | #include "AliMpHelper.h" | |
34 | #include "AliMpIntPair.h" | |
35 | #include "AliMpConstants.h" | |
36 | ||
37 | #include "AliLog.h" | |
38 | ||
39 | #include <Riostream.h> | |
a1e17193 | 40 | #include <TClass.h> |
f0c62051 | 41 | #include <TSystem.h> |
42 | #include <TObjString.h> | |
5954bf20 | 43 | #include <TObjArray.h> |
f0c62051 | 44 | #include <TMap.h> |
45 | ||
46 | /// \cond CLASSIMP | |
47 | ClassImp(AliMpDEStore) | |
48 | /// \endcond | |
49 | ||
50 | AliMpDEStore* AliMpDEStore::fgInstance = 0; | |
51 | const char AliMpDEStore::fgkCommentPrefix = '#'; | |
52 | ||
53 | // | |
54 | // static methods | |
55 | // | |
56 | ||
57 | //______________________________________________________________________________ | |
ac17c583 | 58 | AliMpDEStore* AliMpDEStore::Instance(Bool_t warn) |
f0c62051 | 59 | { |
60 | /// Create the DE store if it does not yet exist | |
61 | /// and return its instance | |
62 | ||
ac17c583 | 63 | if ( ! fgInstance && warn ) { |
64 | AliWarningClass("DE Store has not been loaded"); | |
65 | } | |
66 | ||
67 | return fgInstance; | |
68 | } | |
69 | ||
70 | //______________________________________________________________________________ | |
71 | AliMpDEStore* AliMpDEStore::ReadData(Bool_t warn) | |
72 | { | |
73 | /// Load the DE store data from ASCII data files | |
74 | /// and return its instance | |
75 | ||
76 | if ( fgInstance ) { | |
77 | if ( warn ) | |
78 | AliWarningClass("DE Store has been already loaded"); | |
79 | return fgInstance; | |
80 | } | |
81 | ||
82 | AliInfoClass("Reading DE Store from ASCII files."); | |
83 | ||
84 | fgInstance = new AliMpDEStore(); | |
f0c62051 | 85 | return fgInstance; |
86 | } | |
87 | ||
88 | // | |
89 | // ctors, dtor | |
90 | // | |
91 | ||
92 | //______________________________________________________________________________ | |
93 | AliMpDEStore::AliMpDEStore() | |
94 | : TObject(), | |
95 | fDetElements(true) | |
96 | { | |
97 | /// Standard constructor | |
98 | ||
99 | AliDebug(1,""); | |
100 | fDetElements.SetOwner(true); | |
101 | ||
102 | // Create all detection elements | |
103 | FillDEs(); | |
104 | } | |
105 | ||
106 | //______________________________________________________________________________ | |
107 | AliMpDEStore::AliMpDEStore(TRootIOCtor* /*ioCtor*/) | |
108 | : TObject(), | |
109 | fDetElements() | |
110 | { | |
111 | /// Constructor for IO | |
112 | ||
113 | AliDebug(1,""); | |
114 | ||
115 | fgInstance = this; | |
116 | } | |
117 | ||
118 | ||
119 | //______________________________________________________________________________ | |
120 | AliMpDEStore::~AliMpDEStore() | |
121 | { | |
122 | /// Destructor | |
123 | ||
124 | AliDebug(1,""); | |
125 | ||
126 | // Segmentations are deleted with fMpSegmentations | |
127 | // El cards arrays are deleted with fElCardsMap | |
128 | ||
129 | fgInstance = 0; | |
130 | } | |
131 | ||
132 | // | |
133 | // private methods | |
134 | // | |
135 | ||
136 | //______________________________________________________________________________ | |
137 | Bool_t AliMpDEStore::IsPlaneType(const TString& planeTypeName) | |
138 | { | |
139 | /// Return true if the planeTypeName corresponds to a valid plane type | |
140 | ||
141 | if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) || | |
142 | planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) ) | |
143 | return true; | |
144 | ||
145 | return false; | |
146 | } | |
147 | ||
148 | //______________________________________________________________________________ | |
149 | AliMp::PlaneType AliMpDEStore::PlaneType(const TString& planeTypeName) | |
150 | { | |
151 | /// Return plane type for the given planeTypeName \n | |
152 | /// Fatal error if planeTypeName is wrong | |
153 | ||
154 | if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) ) | |
155 | return AliMp::kBendingPlane; | |
156 | ||
157 | if ( planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) ) | |
158 | return AliMp::kNonBendingPlane; | |
159 | ||
160 | // Should never reach this line | |
161 | AliFatalClass(Form("No plane type defined for %s", planeTypeName.Data())); | |
162 | return AliMp::kBendingPlane; | |
163 | } | |
164 | ||
165 | //______________________________________________________________________________ | |
166 | AliMp::StationType AliMpDEStore::StationType(const TString& stationTypeName) | |
167 | { | |
168 | /// Return station type for the given stationTypeName \n | |
169 | /// Fatal error if stationTypeName is wrong | |
170 | ||
171 | if ( stationTypeName == StationTypeName(AliMp::kStation1) ) | |
172 | return AliMp::kStation1; | |
173 | ||
174 | if ( stationTypeName == StationTypeName(AliMp::kStation2) ) | |
175 | return AliMp::kStation2; | |
176 | ||
177 | if ( stationTypeName == StationTypeName(AliMp::kStation345) ) | |
178 | return AliMp::kStation345; | |
179 | ||
180 | if ( stationTypeName == StationTypeName(AliMp::kStationTrigger) ) | |
181 | return AliMp::kStationTrigger; | |
182 | ||
183 | // Should never reach this line | |
184 | AliFatalClass(Form("No station type defined for ", stationTypeName.Data())); | |
185 | return AliMp::kStation1; | |
186 | } | |
187 | ||
188 | //______________________________________________________________________________ | |
189 | Bool_t AliMpDEStore::ReadManuToSerialNbs(AliMpDetElement* detElement, | |
190 | AliMp::StationType stationType) | |
191 | { | |
192 | /// Read manu serial numbers for the given detection element | |
5954bf20 | 193 | static Int_t manuMask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane); |
194 | ||
f0c62051 | 195 | TString deName = detElement->GetDEName(); |
196 | ||
197 | TString infile = AliMpFiles::ManuToSerialPath(deName, stationType); | |
198 | ifstream in(infile, ios::in); | |
199 | ||
200 | // Change to Error when all files available | |
201 | //if ( !in.is_open() && stationType == AliMp::kStation345 ) { | |
202 | // AliWarningStream() << "File " << infile << " not found." << endl; | |
203 | // return false; | |
204 | //} | |
205 | ||
206 | char line[80]; | |
207 | ||
208 | while ( in.getline(line,80) ) { | |
209 | ||
210 | if ( line[0] == '#' ) continue; | |
211 | ||
212 | TString tmp(AliMpHelper::Normalize(line)); | |
213 | ||
5954bf20 | 214 | TObjArray* stringList = tmp.Tokenize(TString(" ")); |
f0c62051 | 215 | |
5954bf20 | 216 | Int_t manuId = atoi( ((TObjString*)stringList->At(0))->GetName()); |
217 | Int_t manuSerial = atoi( ((TObjString*)stringList->At(2))->GetName()); | |
f0c62051 | 218 | |
5954bf20 | 219 | TString sPlane = ((TObjString*)stringList->At(1))->GetString(); |
220 | ||
f0c62051 | 221 | // filling manuId <> manuSerial |
5954bf20 | 222 | if (!sPlane.CompareTo(PlaneTypeName(AliMp::kBendingPlane))) |
223 | detElement->AddManuSerial(manuId, manuSerial); | |
224 | else | |
225 | detElement->AddManuSerial(manuId + manuMask, manuSerial); | |
226 | ||
227 | delete stringList; | |
f0c62051 | 228 | } |
229 | ||
230 | in.close(); | |
231 | return true; | |
232 | } | |
233 | ||
234 | //______________________________________________________________________________ | |
235 | Bool_t | |
236 | AliMpDEStore::ReadDENames(AliMp::StationType station) | |
237 | { | |
238 | /// Read det element names for cath = 0 from the file specified by name | |
239 | /// and fill the map | |
240 | ||
241 | // Open file | |
242 | TString filePath = AliMpFiles::DENamesFilePath(station); | |
243 | std::ifstream in(filePath); | |
244 | if (!in.good()) { | |
245 | AliErrorClassStream() << "Cannot open file " << filePath << endl;; | |
246 | return false; | |
247 | } | |
248 | ||
249 | // Read plane types per cathods | |
250 | // | |
251 | char line[80]; | |
252 | TString word; | |
253 | TString cathName1, cathName2; | |
254 | in >> word; | |
255 | while ( ! in.eof() && cathName1.Length() == 0 ) { | |
256 | if ( word[0] == '#' ) | |
257 | in.getline(line, 80); | |
258 | else { | |
259 | cathName1 = word; | |
260 | in >> cathName2; | |
261 | } | |
262 | in >> word; | |
263 | } | |
264 | ||
265 | Bool_t isCathNameDefined = false; | |
266 | if ( IsPlaneType(cathName1) && IsPlaneType(cathName2) ) | |
267 | isCathNameDefined = true; | |
268 | ||
269 | // Read DE names | |
270 | // | |
271 | Int_t detElemId; | |
272 | TString name, name0, name1, name2; | |
273 | AliMp::PlaneType planeForCathode[2]; | |
274 | ||
275 | while ( ! in.eof() ) | |
276 | { | |
277 | if ( word[0] == '#' ) | |
278 | { | |
279 | in.getline(line, 80); | |
280 | } | |
281 | else | |
282 | { | |
283 | detElemId = word.Atoi(); | |
284 | in >> name; | |
285 | in >> name0; | |
286 | // warning : important to check non bending first (=nbp), | |
287 | // as bp is contained within nbp... | |
288 | if ( name0.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) ) | |
289 | { | |
290 | planeForCathode[0] = AliMp::kNonBendingPlane; | |
291 | } | |
292 | else | |
293 | { | |
294 | planeForCathode[0] = AliMp::kBendingPlane; | |
295 | } | |
296 | ||
297 | if ( !isCathNameDefined ) | |
298 | { | |
299 | in >> name2; | |
300 | name1 = name0; | |
301 | Ssiz_t pos = name1.First(AliMpDetElement::GetNameSeparator()); | |
302 | name0 = name1(0,pos); | |
303 | ||
304 | // Other cathode is other plane... | |
305 | planeForCathode[1] = OtherPlaneType(planeForCathode[0]); | |
306 | } | |
307 | else | |
308 | { | |
309 | name1 = name0 + AliMpDetElement::GetNameSeparator() + cathName1; | |
310 | name2 = name0 + AliMpDetElement::GetNameSeparator() + cathName2; | |
311 | if ( name2.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) ) | |
312 | { | |
313 | planeForCathode[1] = AliMp::kNonBendingPlane; | |
314 | } | |
315 | else | |
316 | { | |
317 | planeForCathode[1] = AliMp::kBendingPlane; | |
318 | } | |
319 | } | |
320 | ||
321 | if ( planeForCathode[0]==planeForCathode[1] ) | |
322 | { | |
323 | AliFatalClass(Form("Got the same cathode type for both planes" | |
324 | " of DetElemId %d",detElemId)); | |
325 | } | |
326 | ||
327 | AliMpDetElement* detElement | |
328 | = new AliMpDetElement(detElemId, name, name0, planeForCathode[0]); | |
329 | if ( ! fDetElements.GetValue(detElemId) ) | |
330 | { | |
331 | AliDebugClassStream(3) | |
332 | << "Adding DE name " << detElemId << " " << name << endl; | |
333 | fDetElements.Add(detElemId, detElement); | |
334 | ||
335 | // Read manu serial numbers for this det element | |
336 | ReadManuToSerialNbs(detElement, station); | |
337 | } | |
338 | else | |
339 | { | |
340 | AliWarningClassStream() | |
341 | << "Det element " << detElemId << " " << name << " already defined." << endl; | |
342 | } | |
343 | } | |
344 | in >> word; | |
345 | } | |
346 | ||
347 | // Close file | |
348 | in.close(); | |
349 | ||
350 | return true; | |
351 | } | |
352 | ||
353 | //______________________________________________________________________________ | |
354 | void AliMpDEStore::FillDEs() | |
355 | { | |
356 | /// Fill DE names from files | |
357 | AliDebugClass(2,""); | |
358 | Bool_t result1 = ReadDENames(AliMp::kStation1); | |
359 | Bool_t result2 = ReadDENames(AliMp::kStation2); | |
360 | Bool_t result3 = ReadDENames(AliMp::kStation345); | |
361 | Bool_t result4 = ReadDENames(AliMp::kStationTrigger); | |
362 | ||
363 | Bool_t result = result1 && result2 && result3 && result4; | |
364 | if ( ! result ) { | |
365 | AliErrorClassStream() << "Error in reading DE names files" << endl; | |
366 | } | |
367 | } | |
368 | ||
369 | // | |
370 | // public methods | |
371 | // | |
372 | ||
373 | ||
374 | //______________________________________________________________________________ | |
375 | AliMpDetElement* AliMpDEStore::GetDetElement(Int_t detElemId, Bool_t warn) const | |
376 | { | |
377 | /// Return det element for given detElemId | |
378 | ||
379 | AliMpDetElement* detElement | |
380 | = (AliMpDetElement*)fDetElements.GetValue(detElemId); | |
381 | ||
382 | if ( ! detElement && warn ) { | |
383 | AliErrorClassStream() | |
384 | << "Detection element " << detElemId << " not defined." << endl; | |
385 | } | |
386 | ||
387 | return detElement; | |
388 | } | |
389 | ||
2eee683c | 390 | //______________________________________________________________________________ |
391 | AliMpDetElement* AliMpDEStore::GetDetElement(const TString& deName, Bool_t warn) const | |
392 | { | |
393 | /// Return det element for given deName | |
394 | ||
395 | for ( Int_t i = 0; i < fDetElements.GetSize(); i++ ) { | |
396 | ||
397 | AliMpDetElement* detElement | |
398 | = (AliMpDetElement*)fDetElements.GetObject(i); | |
399 | ||
400 | if (deName.CompareTo(detElement->GetDEName()) == 0) | |
401 | ||
402 | return detElement; | |
403 | } | |
404 | ||
405 | if (warn) { | |
406 | AliErrorClassStream() | |
407 | << "Detection element with name" << deName.Data() << " not defined." << endl; | |
408 | } | |
409 | ||
410 | return 0x0; | |
411 | ||
412 | } | |
f0c62051 | 413 | //______________________________________________________________________________ |
414 | AliMpIntPair AliMpDEStore::GetDetElemIdManu(Int_t manuSerial) const | |
415 | { | |
416 | /// Return the detElemId and manuId for given serial manu number | |
417 | ||
418 | for ( Int_t i = 0; i < fDetElements.GetSize(); i++ ) { | |
419 | ||
420 | AliMpDetElement* detElement | |
421 | = (AliMpDetElement*)fDetElements.GetObject(i); | |
422 | ||
423 | Int_t manuId = detElement->GetManuIdFromSerial(manuSerial); | |
424 | if ( manuId ) return AliMpIntPair(detElement->GetId(), manuId); | |
425 | } | |
426 | ||
427 | // manu with this serial number does not exist | |
428 | return AliMpIntPair::Invalid(); | |
429 | } | |
2eee683c | 430 |