Line data Source code
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 18 : 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 393092 : if ( ! fgInstance && warn ) {
77 0 : AliWarningClass("Segmentation has not been loaded");
78 0 : }
79 :
80 393087 : 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 3 : if ( fgInstance ) {
91 0 : if ( warn )
92 0 : AliWarningClass("Segmentation has been already loaded");
93 0 : return fgInstance;
94 : }
95 :
96 3 : if ( dataStreams.GetReadFromFiles() )
97 0 : AliInfoClass("Reading segmentation from ASCII files.");
98 :
99 6 : fgInstance = new AliMpSegmentation(dataStreams);
100 3 : return fgInstance;
101 3 : }
102 :
103 : //
104 : // ctors, dtor
105 : //
106 :
107 : //______________________________________________________________________________
108 : AliMpSegmentation::AliMpSegmentation(const AliMpDataStreams& dataStreams)
109 3 : : TObject(),
110 3 : fDetElements(0),
111 3 : fMpSegmentations(true),
112 3 : fElCardsMap(),
113 9 : fSlatMotifMap(new AliMpSlatMotifMap)
114 15 : {
115 : /// Standard constructor - segmentation is loaded from ASCII data files
116 :
117 15 : AliDebug(1,"");
118 :
119 3 : fElCardsMap.SetOwner(kTRUE);
120 :
121 : // Load DE data
122 6 : if ( ! AliMpDEStore::Instance(false) )
123 3 : AliMpDEStore::ReadData(dataStreams);
124 6 : fDetElements = AliMpDEStore::Instance();
125 :
126 : // Create mapping segmentations for all detection elements
127 3 : AliMpDEIterator it;
128 2061 : for ( it.First(); ! it.IsDone(); it.Next() )
129 : {
130 : Int_t n(0);
131 :
132 4104 : for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; ++cath )
133 : {
134 2736 : if ( CreateMpSegmentation(dataStreams,
135 4104 : it.CurrentDEId(), AliMp::GetCathodType(cath)) ) ++n;
136 : }
137 :
138 1368 : if ( n == 2 && // should always be the case except when we play with the CreateMpSegmentation method...
139 2052 : AliMpDEManager::GetStationType(it.CurrentDEId()) != AliMp::kStationTrigger ) // only for tracker
140 : {
141 : // Fill el cards map for all detection elements
142 : // of tracking chambers
143 936 : FillElCardsMap(it.CurrentDEId());
144 : }
145 : }
146 6 : }
147 :
148 : //______________________________________________________________________________
149 : AliMpSegmentation::AliMpSegmentation(TRootIOCtor* ioCtor)
150 0 : : TObject(),
151 0 : fDetElements(0),
152 0 : fMpSegmentations(),
153 0 : fElCardsMap(ioCtor),
154 0 : fSlatMotifMap(0)
155 0 : {
156 : /// Constructor for IO
157 :
158 0 : AliDebug(1,"");
159 :
160 0 : fgInstance = this;
161 0 : }
162 :
163 : //______________________________________________________________________________
164 : AliMpSegmentation::~AliMpSegmentation()
165 12 : {
166 : /// Destructor
167 :
168 10 : AliDebug(1,"");
169 :
170 4 : delete fDetElements;
171 :
172 : // Segmentations are deleted with fMpSegmentations
173 : // El cards arrays are deleted with fElCardsMap
174 :
175 4 : delete fSlatMotifMap;
176 :
177 2 : fgInstance = 0;
178 6 : }
179 :
180 : //
181 : // private methods
182 : //
183 :
184 : //______________________________________________________________________________
185 : AliMpVSegmentation*
186 : AliMpSegmentation::CreateMpSegmentation(const AliMpDataStreams& dataStreams,
187 : 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 2736 : if ( ! AliMpDEManager::IsValidDetElemId(detElemId, true) ) return 0;
194 :
195 : // If segmentation is already built, just return it
196 : //
197 1368 : AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
198 1368 : TString deSegName = detElement->GetSegName(cath);
199 1368 : TObject* object = fMpSegmentations.Get(deSegName);
200 2178 : if ( object ) return (AliMpVSegmentation*)object;
201 :
202 1116 : AliDebugStream(3)
203 1116 : << "Creating segmentation for detElemId=" << detElemId
204 1674 : << " cath=" << cath << endl;
205 :
206 : // Read mapping data and create segmentation
207 : //
208 558 : AliMp::StationType stationType = detElement->GetStationType();
209 558 : AliMp::PlaneType planeType = detElement->GetPlaneType(cath);
210 558 : TString deTypeName = detElement->GetSegType();
211 :
212 : AliMpVSegmentation* mpSegmentation = 0;
213 :
214 558 : if ( stationType == AliMp::kStation12 ) {
215 12 : AliMq::Station12Type station12Type = detElement->GetStation12Type();
216 12 : AliMpSectorReader reader(station12Type, planeType);
217 12 : AliMpSector* sector = reader.BuildSector(dataStreams);
218 60 : mpSegmentation = new AliMpFastSegmentation(new AliMpSectorSegmentation(sector, true));
219 12 : }
220 546 : else if ( stationType == AliMp::kStation345 ) {
221 114 : AliMpSt345Reader reader(fSlatMotifMap);
222 228 : AliMpSlat* slat = reader.ReadSlat(dataStreams, deTypeName, planeType);
223 570 : mpSegmentation = new AliMpFastSegmentation(new AliMpSlatSegmentation(slat, true));
224 114 : }
225 432 : else if ( stationType == AliMp::kStationTrigger ) {
226 432 : AliMpTriggerReader reader(fSlatMotifMap);
227 864 : AliMpTrigger* trigger = reader.ReadSlat(dataStreams, deTypeName, planeType);
228 1296 : mpSegmentation = new AliMpTriggerSegmentation(trigger, true);
229 432 : }
230 : else
231 0 : AliErrorStream() << "Unknown station type" << endl;
232 :
233 1116 : if ( mpSegmentation ) fMpSegmentations.Add(deSegName, mpSegmentation);
234 :
235 : // StdoutToAliDebug(3, fSlatMotifMap.Print(););
236 :
237 : return mpSegmentation;
238 3294 : }
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 936 : AliDebugStream(2) << "detElemId=" << detElemId << endl;;
248 :
249 468 : AliMpExMap* mde = new AliMpExMap;
250 468 : mde->SetOwner(kFALSE);
251 468 : fElCardsMap.Add(detElemId,mde);
252 :
253 468 : const AliMpVSegmentation* seg[2];
254 2340 : TArrayI ecn[2];
255 :
256 2808 : for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++cathode )
257 : {
258 2808 : seg[cathode] = GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
259 936 : seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]);
260 102840 : for ( Int_t i = 0; i < ecn[cathode].GetSize(); ++i )
261 : {
262 100968 : mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode]));
263 : }
264 : }
265 :
266 936 : assert( mde->GetSize() > 0 );
267 :
268 : return mde;
269 :
270 1872 : }
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 237343 : if ( ! AliMpDEManager::IsValidDetElemId(detElemId, false) ) {
285 :
286 0 : if ( warn ) {
287 0 : AliWarningStream()
288 0 : << "Invalid detElemId " << detElemId << endl;
289 0 : }
290 0 : return 0;
291 : }
292 :
293 : // If segmentation is already built, just return it
294 : //
295 237343 : AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
296 237343 : TString deSegName = detElement->GetSegName(cath);
297 237343 : TObject* object = fMpSegmentations.Get(deSegName);
298 237343 : if ( ! object ) {
299 : // Should never happen
300 0 : AliErrorStream()
301 0 : << "Segmentation for detElemId/cathod "
302 0 : << detElemId << ", " << cath << " not defined" << endl;
303 0 : return 0;
304 : }
305 :
306 237343 : return static_cast<AliMpVSegmentation*>(object);
307 474686 : }
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 155980 : AliMpExMap* m = static_cast<AliMpExMap*>(fElCardsMap.GetValue(detElemId));
318 :
319 155980 : if (!m) {
320 : // Should never happen
321 0 : AliErrorStream()
322 0 : << "Cannot find the el cards map for detElemId " << detElemId << endl;
323 0 : return 0;
324 : }
325 :
326 155980 : TObject* object = m->GetValue(ecId);
327 155980 : if ( ! object ) {
328 0 : if ( warn ) {
329 0 : AliErrorStream()
330 0 : << "Segmentation for electronic card "
331 0 : << ecId << " not found" << endl;
332 0 : }
333 0 : return 0;
334 : }
335 :
336 155980 : return static_cast<AliMpVSegmentation*>(object);
337 155980 : }
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 21556 : if ( ! kSegmentation ) return 0;
349 :
350 21556 : if ( kSegmentation->StationType() != AliMp::kStation12 ) {
351 0 : if ( warn ) {
352 0 : AliErrorStream()
353 0 : << "Segmentation is not of sector type" << endl;
354 0 : }
355 0 : return 0;
356 : }
357 :
358 : // If fast segmentation
359 : const AliMpFastSegmentation* fseg
360 64668 : = dynamic_cast<const AliMpFastSegmentation*>(kSegmentation);
361 21556 : if ( fseg ) {
362 21556 : return
363 21556 : 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 0 : = dynamic_cast<const AliMpSectorSegmentation*>(kSegmentation);
378 0 : if ( sseg ) {
379 0 : return sseg->GetSector();
380 : }
381 :
382 : // Should not get to this line
383 0 : AliErrorStream() << "Segemntation type not identified." << endl;
384 0 : return 0;
385 21556 : }
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 4 : 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 21552 : 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 53804 : if ( ! kSegmentation ) return 0;
421 :
422 53804 : if ( kSegmentation->StationType() != AliMp::kStation345 ) {
423 0 : if ( warn ) {
424 0 : AliErrorStream()
425 0 : << "Segmentation is not of slat type" << endl;
426 0 : }
427 0 : return 0;
428 : }
429 :
430 : // If fast segmentation
431 : const AliMpFastSegmentation* fseg
432 161412 : = dynamic_cast<const AliMpFastSegmentation*>(kSegmentation);
433 53804 : if ( fseg ) {
434 53804 : return
435 53804 : 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 0 : = dynamic_cast<const AliMpSlatSegmentation*>(kSegmentation);
450 :
451 0 : if ( sseg ) {
452 0 : return sseg->Slat();
453 : }
454 :
455 : // Should not get to this line
456 0 : AliErrorStream() << "Segemntation type not identified." << endl;
457 0 : return 0;
458 53804 : }
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 4224 : 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 49580 : 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 684 : if ( ! kSegmentation ) return 0;
494 :
495 684 : if ( kSegmentation->StationType() != AliMp::kStationTrigger ) {
496 0 : if ( warn ) {
497 0 : AliErrorStream()
498 0 : << "Segmentation is not of trigger type" << endl;
499 0 : }
500 0 : return 0;
501 : }
502 :
503 : // If slat segmentation
504 : const AliMpTriggerSegmentation* tseg
505 2052 : = dynamic_cast<const AliMpTriggerSegmentation*>(kSegmentation);
506 684 : if ( tseg ) {
507 684 : return tseg->Slat();
508 : }
509 :
510 : // If fast segmentation
511 : const AliMpFastSegmentation* fseg
512 0 : = dynamic_cast<const AliMpFastSegmentation*>(kSegmentation);
513 :
514 0 : if ( fseg ) {
515 0 : return
516 0 : 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 0 : AliErrorStream() << "Segemntation type not identified." << endl;
532 0 : return 0;
533 684 : }
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 0 : 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 0 : return GetTrigger(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn);
557 : }
|