]>
Commit | Line | Data |
---|---|---|
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: AliMpSegmentation.cxx,v 1.7 2006/05/24 13:58:34 ivana Exp $ | |
18 | // Category: management | |
19 | ||
20 | //----------------------------------------------------------------------------- | |
21 | // Class AliMpSegmentation | |
22 | // ----------------------- | |
23 | // Singleton container class for mapping segmentations | |
24 | // Authors: Ivana Hrivnacova, IPN Orsay | |
25 | // Laurent Aphecetche, SUBATECH | |
26 | //----------------------------------------------------------------------------- | |
27 | ||
28 | #include "AliMpSegmentation.h" | |
29 | ||
30 | #include "AliMpDataStreams.h" | |
31 | #include "AliMpDetElement.h" | |
32 | #include "AliMpDEStore.h" | |
33 | #include "AliMpDEManager.h" | |
34 | #include "AliMpDEIterator.h" | |
35 | #include "AliMpExMap.h" | |
36 | #include "AliMpFastSegmentation.h" | |
37 | //#include "AliMpFastSegmentationV2.h" | |
38 | #include "AliMpSector.h" | |
39 | #include "AliMpSectorReader.h" | |
40 | #include "AliMpSectorSegmentation.h" | |
41 | #include "AliMpSlat.h" | |
42 | #include "AliMpSlatSegmentation.h" | |
43 | #include "AliMpSt345Reader.h" | |
44 | #include "AliMpTrigger.h" | |
45 | #include "AliMpTriggerReader.h" | |
46 | #include "AliMpTriggerSegmentation.h" | |
47 | #include "AliMpCathodType.h" | |
48 | #include "AliMpSlatMotifMap.h" | |
49 | ||
50 | ||
51 | #include "AliLog.h" | |
52 | ||
53 | #include <Riostream.h> | |
54 | #include <TMap.h> | |
55 | #include <TObjString.h> | |
56 | #include <TSystem.h> | |
57 | #include <TClass.h> | |
58 | ||
59 | #include <cassert> | |
60 | ||
61 | /// \cond CLASSIMP | |
62 | ClassImp(AliMpSegmentation) | |
63 | /// \endcond | |
64 | ||
65 | AliMpSegmentation* AliMpSegmentation::fgInstance = 0; | |
66 | ||
67 | // | |
68 | // static methods | |
69 | // | |
70 | ||
71 | //______________________________________________________________________________ | |
72 | AliMpSegmentation* AliMpSegmentation::Instance(Bool_t warn) | |
73 | { | |
74 | /// Return its instance | |
75 | ||
76 | if ( ! fgInstance && warn ) { | |
77 | AliWarningClass("Segmentation has not been loaded"); | |
78 | } | |
79 | ||
80 | return fgInstance; | |
81 | } | |
82 | ||
83 | //______________________________________________________________________________ | |
84 | AliMpSegmentation* AliMpSegmentation::ReadData(const AliMpDataStreams& dataStreams, | |
85 | Bool_t warn) | |
86 | { | |
87 | /// Load the sementation from ASCII data files | |
88 | /// and return its instance | |
89 | ||
90 | if ( fgInstance ) { | |
91 | if ( warn ) | |
92 | AliWarningClass("Segmentation has been already loaded"); | |
93 | return fgInstance; | |
94 | } | |
95 | ||
96 | if ( dataStreams.GetReadFromFiles() ) | |
97 | AliInfoClass("Reading segmentation from ASCII files."); | |
98 | ||
99 | fgInstance = new AliMpSegmentation(dataStreams); | |
100 | return fgInstance; | |
101 | } | |
102 | ||
103 | // | |
104 | // ctors, dtor | |
105 | // | |
106 | ||
107 | //______________________________________________________________________________ | |
108 | AliMpSegmentation::AliMpSegmentation(const AliMpDataStreams& dataStreams) | |
109 | : TObject(), | |
110 | fkDataStreams(dataStreams), | |
111 | fDetElements(0), | |
112 | fMpSegmentations(true), | |
113 | fElCardsMap(), | |
114 | fSlatMotifMap(new AliMpSlatMotifMap) | |
115 | { | |
116 | /// Standard constructor - segmentation is loaded from ASCII data files | |
117 | ||
118 | AliDebug(1,""); | |
119 | ||
120 | fElCardsMap.SetOwner(kTRUE); | |
121 | ||
122 | // Load DE data | |
123 | if ( ! AliMpDEStore::Instance(false) ) | |
124 | AliMpDEStore::ReadData(dataStreams); | |
125 | fDetElements = AliMpDEStore::Instance(); | |
126 | ||
127 | // Create mapping segmentations for all detection elements | |
128 | AliMpDEIterator it; | |
129 | for ( it.First(); ! it.IsDone(); it.Next() ) | |
130 | { | |
131 | Int_t n(0); | |
132 | ||
133 | for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; ++cath ) | |
134 | { | |
135 | if ( CreateMpSegmentation(it.CurrentDEId(), AliMp::GetCathodType(cath)) ) ++n; | |
136 | } | |
137 | ||
138 | if ( n == 2 && // should always be the case except when we play with the CreateMpSegmentation method... | |
139 | AliMpDEManager::GetStationType(it.CurrentDEId()) != AliMp::kStationTrigger ) // only for tracker | |
140 | { | |
141 | // Fill el cards map for all detection elements | |
142 | // of tracking chambers | |
143 | FillElCardsMap(it.CurrentDEId()); | |
144 | } | |
145 | } | |
146 | } | |
147 | ||
148 | //______________________________________________________________________________ | |
149 | AliMpSegmentation::AliMpSegmentation(TRootIOCtor* ioCtor) | |
150 | : TObject(), | |
151 | fkDataStreams(ioCtor), | |
152 | fDetElements(0), | |
153 | fMpSegmentations(), | |
154 | fElCardsMap(ioCtor), | |
155 | fSlatMotifMap(0) | |
156 | { | |
157 | /// Constructor for IO | |
158 | ||
159 | AliDebug(1,""); | |
160 | ||
161 | fgInstance = this; | |
162 | } | |
163 | ||
164 | //______________________________________________________________________________ | |
165 | AliMpSegmentation::~AliMpSegmentation() | |
166 | { | |
167 | /// Destructor | |
168 | ||
169 | AliDebug(1,""); | |
170 | ||
171 | delete fDetElements; | |
172 | ||
173 | // Segmentations are deleted with fMpSegmentations | |
174 | // El cards arrays are deleted with fElCardsMap | |
175 | ||
176 | delete fSlatMotifMap; | |
177 | ||
178 | fgInstance = 0; | |
179 | } | |
180 | ||
181 | // | |
182 | // private methods | |
183 | // | |
184 | ||
185 | //______________________________________________________________________________ | |
186 | AliMpVSegmentation* | |
187 | AliMpSegmentation::CreateMpSegmentation(Int_t detElemId, AliMp::CathodType cath) | |
188 | { | |
189 | /// Create mapping segmentation for given detElemId and cath | |
190 | /// or return it if it was already built | |
191 | ||
192 | // Check detElemId & cath | |
193 | if ( ! AliMpDEManager::IsValidDetElemId(detElemId, true) ) return 0; | |
194 | ||
195 | // If segmentation is already built, just return it | |
196 | // | |
197 | AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId); | |
198 | TString deSegName = detElement->GetSegName(cath); | |
199 | TObject* object = fMpSegmentations.Get(deSegName); | |
200 | if ( object ) return (AliMpVSegmentation*)object; | |
201 | ||
202 | AliDebugStream(3) | |
203 | << "Creating segmentation for detElemId=" << detElemId | |
204 | << " cath=" << cath << endl; | |
205 | ||
206 | // Read mapping data and create segmentation | |
207 | // | |
208 | AliMp::StationType stationType = detElement->GetStationType(); | |
209 | AliMp::PlaneType planeType = detElement->GetPlaneType(cath); | |
210 | TString deTypeName = detElement->GetSegType(); | |
211 | ||
212 | AliMpVSegmentation* mpSegmentation = 0; | |
213 | ||
214 | if ( stationType == AliMp::kStation12 ) { | |
215 | AliMq::Station12Type station12Type = detElement->GetStation12Type(); | |
216 | AliMpSectorReader reader(fkDataStreams, station12Type, planeType); | |
217 | AliMpSector* sector = reader.BuildSector(); | |
218 | mpSegmentation = new AliMpFastSegmentation(new AliMpSectorSegmentation(sector, true)); | |
219 | } | |
220 | else if ( stationType == AliMp::kStation345 ) { | |
221 | AliMpSt345Reader reader(fkDataStreams,fSlatMotifMap); | |
222 | AliMpSlat* slat = reader.ReadSlat(deTypeName, planeType); | |
223 | mpSegmentation = new AliMpFastSegmentation(new AliMpSlatSegmentation(slat, true)); | |
224 | } | |
225 | else if ( stationType == AliMp::kStationTrigger ) { | |
226 | AliMpTriggerReader reader(fkDataStreams,fSlatMotifMap); | |
227 | AliMpTrigger* trigger = reader.ReadSlat(deTypeName, planeType); | |
228 | mpSegmentation = new AliMpTriggerSegmentation(trigger, true); | |
229 | } | |
230 | else | |
231 | AliErrorStream() << "Unknown station type" << endl; | |
232 | ||
233 | if ( mpSegmentation ) fMpSegmentations.Add(deSegName, mpSegmentation); | |
234 | ||
235 | // StdoutToAliDebug(3, fSlatMotifMap.Print();); | |
236 | ||
237 | return mpSegmentation; | |
238 | } | |
239 | ||
240 | //_____________________________________________________________________________ | |
241 | AliMpExMap* | |
242 | AliMpSegmentation::FillElCardsMap(Int_t detElemId) | |
243 | { | |
244 | /// Fill the map of electronic cards IDs to segmentations for | |
245 | /// given detElemId | |
246 | ||
247 | AliDebugStream(2) << "detElemId=" << detElemId << endl;; | |
248 | ||
249 | AliMpExMap* mde = new AliMpExMap; | |
250 | mde->SetOwner(kFALSE); | |
251 | fElCardsMap.Add(detElemId,mde); | |
252 | ||
253 | const AliMpVSegmentation* seg[2]; | |
254 | TArrayI ecn[2]; | |
255 | ||
256 | for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++cathode ) | |
257 | { | |
258 | seg[cathode] = GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode)); | |
259 | seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]); | |
260 | for ( Int_t i = 0; i < ecn[cathode].GetSize(); ++i ) | |
261 | { | |
262 | mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode])); | |
263 | } | |
264 | } | |
265 | ||
266 | assert( mde->GetSize() > 0 ); | |
267 | ||
268 | return mde; | |
269 | ||
270 | } | |
271 | ||
272 | // | |
273 | // public methods | |
274 | // | |
275 | ||
276 | //______________________________________________________________________________ | |
277 | const AliMpVSegmentation* | |
278 | AliMpSegmentation::GetMpSegmentation( | |
279 | Int_t detElemId, AliMp::CathodType cath, Bool_t warn) const | |
280 | { | |
281 | /// Return mapping segmentation for given detElemId and cath | |
282 | ||
283 | // Check detElemId & cath | |
284 | if ( ! AliMpDEManager::IsValidDetElemId(detElemId, false) ) { | |
285 | ||
286 | if ( warn ) { | |
287 | AliWarningStream() | |
288 | << "Invalid detElemId " << detElemId << endl; | |
289 | } | |
290 | return 0; | |
291 | } | |
292 | ||
293 | // If segmentation is already built, just return it | |
294 | // | |
295 | AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId); | |
296 | TString deSegName = detElement->GetSegName(cath); | |
297 | TObject* object = fMpSegmentations.Get(deSegName); | |
298 | if ( ! object ) { | |
299 | // Should never happen | |
300 | AliErrorStream() | |
301 | << "Segmentation for detElemId/cathod " | |
302 | << detElemId << ", " << cath << " not defined" << endl; | |
303 | return 0; | |
304 | } | |
305 | ||
306 | return static_cast<AliMpVSegmentation*>(object); | |
307 | } | |
308 | ||
309 | //_____________________________________________________________________________ | |
310 | const AliMpVSegmentation* | |
311 | AliMpSegmentation::GetMpSegmentationByElectronics( | |
312 | Int_t detElemId, Int_t ecId, Bool_t warn) const | |
313 | { | |
314 | /// Return mapping segmentation for given detElemId and electronic card Id | |
315 | /// (motif position Id) | |
316 | ||
317 | AliMpExMap* m = static_cast<AliMpExMap*>(fElCardsMap.GetValue(detElemId)); | |
318 | ||
319 | if (!m) { | |
320 | // Should never happen | |
321 | AliErrorStream() | |
322 | << "Cannot find the el cards map for detElemId " << detElemId << endl; | |
323 | return 0; | |
324 | } | |
325 | ||
326 | TObject* object = m->GetValue(ecId); | |
327 | if ( ! object ) { | |
328 | if ( warn ) { | |
329 | AliErrorStream() | |
330 | << "Segmentation for electronic card " | |
331 | << ecId << " not found" << endl; | |
332 | } | |
333 | return 0; | |
334 | } | |
335 | ||
336 | return static_cast<AliMpVSegmentation*>(object); | |
337 | } | |
338 | ||
339 | //_____________________________________________________________________________ | |
340 | const AliMpSector* | |
341 | AliMpSegmentation::GetSector(const AliMpVSegmentation* kSegmentation, | |
342 | Bool_t warn) const | |
343 | { | |
344 | /// Return sector for given mapping segmentation. | |
345 | /// If segmentation is not of sector type, zero is returned | |
346 | /// and an Error is issued if warn is set true (default). | |
347 | ||
348 | if ( ! kSegmentation ) return 0; | |
349 | ||
350 | if ( kSegmentation->StationType() != AliMp::kStation12 ) { | |
351 | if ( warn ) { | |
352 | AliErrorStream() | |
353 | << "Segmentation is not of sector type" << endl; | |
354 | } | |
355 | return 0; | |
356 | } | |
357 | ||
358 | // If fast segmentation | |
359 | const AliMpFastSegmentation* fseg | |
360 | = dynamic_cast<const AliMpFastSegmentation*>(kSegmentation); | |
361 | if ( fseg ) { | |
362 | return | |
363 | static_cast<const AliMpSectorSegmentation*>(fseg->GetHelper())->GetSector(); | |
364 | } | |
365 | ||
366 | // If fast segmentation V2 | |
367 | /* | |
368 | const AliMpFastSegmentationV2* fsegV2 | |
369 | = dynamic_cast<const AliMpFastSegmentationV2*>(kSegmentation); | |
370 | if ( fsegV2 ) { | |
371 | return | |
372 | static_cast<const AliMpSectorSegmentation*>(fsegV2->GetHelper())->GetSector(); | |
373 | } | |
374 | */ | |
375 | // If sector segmentation | |
376 | const AliMpSectorSegmentation* sseg | |
377 | = dynamic_cast<const AliMpSectorSegmentation*>(kSegmentation); | |
378 | if ( sseg ) { | |
379 | return sseg->GetSector(); | |
380 | } | |
381 | ||
382 | // Should not get to this line | |
383 | AliErrorStream() << "Segemntation type not identified." << endl; | |
384 | return 0; | |
385 | } | |
386 | ||
387 | //_____________________________________________________________________________ | |
388 | const AliMpSector* | |
389 | AliMpSegmentation::GetSector(Int_t detElemId, AliMp::CathodType cath, | |
390 | Bool_t warn) const | |
391 | { | |
392 | /// Return sector for given detElemId and cath. | |
393 | /// If segmentation is not of sector type, zero is returned | |
394 | /// and an Error is issued if warn is set true (default). | |
395 | ||
396 | return GetSector(GetMpSegmentation(detElemId, cath, warn), warn); | |
397 | } | |
398 | ||
399 | //_____________________________________________________________________________ | |
400 | const AliMpSector* | |
401 | AliMpSegmentation::GetSectorByElectronics(Int_t detElemId, Int_t elCardID, | |
402 | Bool_t warn) const | |
403 | { | |
404 | /// Return sector for given detElemId and elCardID. | |
405 | /// If segmentation is not of sector type, zero is returned | |
406 | /// and an Error is issued if warn is set true (default). | |
407 | ||
408 | return GetSector(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn); | |
409 | } | |
410 | ||
411 | //_____________________________________________________________________________ | |
412 | const AliMpSlat* | |
413 | AliMpSegmentation::GetSlat(const AliMpVSegmentation* kSegmentation, | |
414 | Bool_t warn) const | |
415 | { | |
416 | /// Return slat for given mapping segmentation. | |
417 | /// If segmentation is not of slat type, zero is returned | |
418 | /// and an Error is issued if warn is set true (default). | |
419 | ||
420 | if ( ! kSegmentation ) return 0; | |
421 | ||
422 | if ( kSegmentation->StationType() != AliMp::kStation345 ) { | |
423 | if ( warn ) { | |
424 | AliErrorStream() | |
425 | << "Segmentation is not of slat type" << endl; | |
426 | } | |
427 | return 0; | |
428 | } | |
429 | ||
430 | // If fast segmentation | |
431 | const AliMpFastSegmentation* fseg | |
432 | = dynamic_cast<const AliMpFastSegmentation*>(kSegmentation); | |
433 | if ( fseg ) { | |
434 | return | |
435 | static_cast<const AliMpSlatSegmentation*>(fseg->GetHelper())->Slat(); | |
436 | } | |
437 | ||
438 | // If fast segmentation V2 | |
439 | /* | |
440 | const AliMpFastSegmentationV2* fsegV2 | |
441 | = dynamic_cast<const AliMpFastSegmentationV2*>(kSegmentation); | |
442 | if ( fsegV2 ) { | |
443 | return | |
444 | static_cast<const AliMpSlatSegmentation*>(fsegV2->GetHelper())->Slat(); | |
445 | } | |
446 | */ | |
447 | // If slat segmentation | |
448 | const AliMpSlatSegmentation* sseg | |
449 | = dynamic_cast<const AliMpSlatSegmentation*>(kSegmentation); | |
450 | ||
451 | if ( sseg ) { | |
452 | return sseg->Slat(); | |
453 | } | |
454 | ||
455 | // Should not get to this line | |
456 | AliErrorStream() << "Segemntation type not identified." << endl; | |
457 | return 0; | |
458 | } | |
459 | ||
460 | //_____________________________________________________________________________ | |
461 | const AliMpSlat* | |
462 | AliMpSegmentation::GetSlat(Int_t detElemId, AliMp::CathodType cath, | |
463 | Bool_t warn) const | |
464 | { | |
465 | /// Return slat for given detElemId and cath. | |
466 | /// If segmentation is not of slat type, zero is returned | |
467 | /// and an Error is issued if warn is set true (default). | |
468 | ||
469 | return GetSlat(GetMpSegmentation(detElemId, cath, warn), warn); | |
470 | } | |
471 | ||
472 | //_____________________________________________________________________________ | |
473 | const AliMpSlat* | |
474 | AliMpSegmentation::GetSlatByElectronics(Int_t detElemId, Int_t elCardID, | |
475 | Bool_t warn) const | |
476 | { | |
477 | /// Return slat for given detElemId and elCardID. | |
478 | /// If segmentation is not of slat type, zero is returned | |
479 | /// and an Error is issued if warn is set true (default). | |
480 | ||
481 | return GetSlat(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn); | |
482 | } | |
483 | ||
484 | //_____________________________________________________________________________ | |
485 | const AliMpTrigger* | |
486 | AliMpSegmentation::GetTrigger(const AliMpVSegmentation* kSegmentation, | |
487 | Bool_t warn) const | |
488 | { | |
489 | /// Return trigger for given mapping segmentation. | |
490 | /// If segmentation is not of trigger type, zero is returned | |
491 | /// and an Error is issued if warn is set true (default). | |
492 | ||
493 | if ( ! kSegmentation ) return 0; | |
494 | ||
495 | if ( kSegmentation->StationType() != AliMp::kStationTrigger ) { | |
496 | if ( warn ) { | |
497 | AliErrorStream() | |
498 | << "Segmentation is not of trigger type" << endl; | |
499 | } | |
500 | return 0; | |
501 | } | |
502 | ||
503 | // If slat segmentation | |
504 | const AliMpTriggerSegmentation* tseg | |
505 | = dynamic_cast<const AliMpTriggerSegmentation*>(kSegmentation); | |
506 | if ( tseg ) { | |
507 | return tseg->Slat(); | |
508 | } | |
509 | ||
510 | // If fast segmentation | |
511 | const AliMpFastSegmentation* fseg | |
512 | = dynamic_cast<const AliMpFastSegmentation*>(kSegmentation); | |
513 | ||
514 | if ( fseg ) { | |
515 | return | |
516 | static_cast<const AliMpTriggerSegmentation*>(fseg->GetHelper())->Slat(); | |
517 | } | |
518 | ||
519 | // If fast segmentation V2 | |
520 | /* | |
521 | const AliMpFastSegmentationV2* fsegV2 | |
522 | = dynamic_cast<const AliMpFastSegmentationV2*>(kSegmentation); | |
523 | ||
524 | if ( fsegV2 ) { | |
525 | return | |
526 | static_cast<const AliMpTriggerSegmentation*>(fsegV2->GetHelper())->Slat(); | |
527 | } | |
528 | */ | |
529 | ||
530 | // Should not get to this line | |
531 | AliErrorStream() << "Segemntation type not identified." << endl; | |
532 | return 0; | |
533 | } | |
534 | ||
535 | //_____________________________________________________________________________ | |
536 | const AliMpTrigger* | |
537 | AliMpSegmentation::GetTrigger(Int_t detElemId, AliMp::CathodType cath, | |
538 | Bool_t warn) const | |
539 | { | |
540 | /// Return trigger for given detElemId and cath. | |
541 | /// If segmentation is not of trigger type, zero is returned | |
542 | /// and an Error is issued if warn is set true (default). | |
543 | ||
544 | return GetTrigger(GetMpSegmentation(detElemId, cath, warn), warn); | |
545 | } | |
546 | ||
547 | //_____________________________________________________________________________ | |
548 | const AliMpTrigger* | |
549 | AliMpSegmentation::GetTriggerByElectronics(Int_t detElemId, Int_t elCardID, | |
550 | Bool_t warn) const | |
551 | { | |
552 | /// Return trigger for given detElemId and elCardID. | |
553 | /// If segmentation is not of trigger type, zero is returned | |
554 | /// and an Error is issued if warn is set true (default). | |
555 | ||
556 | return GetTrigger(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn); | |
557 | } |