1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpSegmentation.cxx,v 1.7 2006/05/24 13:58:34 ivana Exp $
18 // Category: management
20 //-----------------------------------------------------------------------------
21 // Class AliMpSegmentation
22 // -----------------------
23 // Singleton container class for mapping segmentations
24 // Authors: Ivana Hrivnacova, IPN Orsay
25 // Laurent Aphecetche, SUBATECH
26 //-----------------------------------------------------------------------------
28 #include "AliMpSegmentation.h"
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"
53 #include <Riostream.h>
55 #include <TObjString.h>
62 ClassImp(AliMpSegmentation)
65 AliMpSegmentation* AliMpSegmentation::fgInstance = 0;
71 //______________________________________________________________________________
72 AliMpSegmentation* AliMpSegmentation::Instance(Bool_t warn)
74 /// Return its instance
76 if ( ! fgInstance && warn ) {
77 AliWarningClass("Segmentation has not been loaded");
83 //______________________________________________________________________________
84 AliMpSegmentation* AliMpSegmentation::ReadData(const AliMpDataStreams& dataStreams,
87 /// Load the sementation from ASCII data files
88 /// and return its instance
92 AliWarningClass("Segmentation has been already loaded");
96 if ( dataStreams.GetReadFromFiles() )
97 AliInfoClass("Reading segmentation from ASCII files.");
99 fgInstance = new AliMpSegmentation(dataStreams);
107 //______________________________________________________________________________
108 AliMpSegmentation::AliMpSegmentation(const AliMpDataStreams& dataStreams)
110 fkDataStreams(dataStreams),
112 fMpSegmentations(true),
114 fSlatMotifMap(new AliMpSlatMotifMap)
116 /// Standard constructor - segmentation is loaded from ASCII data files
120 fElCardsMap.SetOwner(kTRUE);
123 if ( ! AliMpDEStore::Instance(false) )
124 AliMpDEStore::ReadData(dataStreams);
125 fDetElements = AliMpDEStore::Instance();
127 // Create mapping segmentations for all detection elements
129 for ( it.First(); ! it.IsDone(); it.Next() )
133 for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; ++cath )
135 if ( CreateMpSegmentation(it.CurrentDEId(), AliMp::GetCathodType(cath)) ) ++n;
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
141 // Fill el cards map for all detection elements
142 // of tracking chambers
143 FillElCardsMap(it.CurrentDEId());
148 //______________________________________________________________________________
149 AliMpSegmentation::AliMpSegmentation(TRootIOCtor* ioCtor)
151 fkDataStreams(ioCtor),
157 /// Constructor for IO
164 //______________________________________________________________________________
165 AliMpSegmentation::~AliMpSegmentation()
173 // Segmentations are deleted with fMpSegmentations
174 // El cards arrays are deleted with fElCardsMap
176 delete fSlatMotifMap;
185 //______________________________________________________________________________
187 AliMpSegmentation::CreateMpSegmentation(Int_t detElemId, AliMp::CathodType cath)
189 /// Create mapping segmentation for given detElemId and cath
190 /// or return it if it was already built
192 // Check detElemId & cath
193 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, true) ) return 0;
195 // If segmentation is already built, just return it
197 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
198 TString deSegName = detElement->GetSegName(cath);
199 TObject* object = fMpSegmentations.Get(deSegName);
200 if ( object ) return (AliMpVSegmentation*)object;
203 << "Creating segmentation for detElemId=" << detElemId
204 << " cath=" << cath << endl;
206 // Read mapping data and create segmentation
208 AliMp::StationType stationType = detElement->GetStationType();
209 AliMp::PlaneType planeType = detElement->GetPlaneType(cath);
210 TString deTypeName = detElement->GetSegType();
212 AliMpVSegmentation* mpSegmentation = 0;
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));
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));
225 else if ( stationType == AliMp::kStationTrigger ) {
226 AliMpTriggerReader reader(fkDataStreams,fSlatMotifMap);
227 AliMpTrigger* trigger = reader.ReadSlat(deTypeName, planeType);
228 mpSegmentation = new AliMpTriggerSegmentation(trigger, true);
231 AliErrorStream() << "Unknown station type" << endl;
233 if ( mpSegmentation ) fMpSegmentations.Add(deSegName, mpSegmentation);
235 // StdoutToAliDebug(3, fSlatMotifMap.Print(););
237 return mpSegmentation;
240 //_____________________________________________________________________________
242 AliMpSegmentation::FillElCardsMap(Int_t detElemId)
244 /// Fill the map of electronic cards IDs to segmentations for
247 AliDebugStream(2) << "detElemId=" << detElemId << endl;;
249 AliMpExMap* mde = new AliMpExMap;
250 mde->SetOwner(kFALSE);
251 fElCardsMap.Add(detElemId,mde);
253 const AliMpVSegmentation* seg[2];
256 for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++cathode )
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 )
262 mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode]));
266 assert( mde->GetSize() > 0 );
276 //______________________________________________________________________________
277 const AliMpVSegmentation*
278 AliMpSegmentation::GetMpSegmentation(
279 Int_t detElemId, AliMp::CathodType cath, Bool_t warn) const
281 /// Return mapping segmentation for given detElemId and cath
283 // Check detElemId & cath
284 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, false) ) {
288 << "Invalid detElemId " << detElemId << endl;
293 // If segmentation is already built, just return it
295 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
296 TString deSegName = detElement->GetSegName(cath);
297 TObject* object = fMpSegmentations.Get(deSegName);
299 // Should never happen
301 << "Segmentation for detElemId/cathod "
302 << detElemId << ", " << cath << " not defined" << endl;
306 return static_cast<AliMpVSegmentation*>(object);
309 //_____________________________________________________________________________
310 const AliMpVSegmentation*
311 AliMpSegmentation::GetMpSegmentationByElectronics(
312 Int_t detElemId, Int_t ecId, Bool_t warn) const
314 /// Return mapping segmentation for given detElemId and electronic card Id
315 /// (motif position Id)
317 AliMpExMap* m = static_cast<AliMpExMap*>(fElCardsMap.GetValue(detElemId));
320 // Should never happen
322 << "Cannot find the el cards map for detElemId " << detElemId << endl;
326 TObject* object = m->GetValue(ecId);
330 << "Segmentation for electronic card "
331 << ecId << " not found" << endl;
336 return static_cast<AliMpVSegmentation*>(object);
339 //_____________________________________________________________________________
341 AliMpSegmentation::GetSector(const AliMpVSegmentation* kSegmentation,
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).
348 if ( ! kSegmentation ) return 0;
350 if ( kSegmentation->StationType() != AliMp::kStation12 ) {
353 << "Segmentation is not of sector type" << endl;
358 // If fast segmentation
359 const AliMpFastSegmentation* fseg
360 = dynamic_cast<const AliMpFastSegmentation*>(kSegmentation);
363 static_cast<const AliMpSectorSegmentation*>(fseg->GetHelper())->GetSector();
366 // If fast segmentation V2
368 const AliMpFastSegmentationV2* fsegV2
369 = dynamic_cast<const AliMpFastSegmentationV2*>(kSegmentation);
372 static_cast<const AliMpSectorSegmentation*>(fsegV2->GetHelper())->GetSector();
375 // If sector segmentation
376 const AliMpSectorSegmentation* sseg
377 = dynamic_cast<const AliMpSectorSegmentation*>(kSegmentation);
379 return sseg->GetSector();
382 // Should not get to this line
383 AliErrorStream() << "Segemntation type not identified." << endl;
387 //_____________________________________________________________________________
389 AliMpSegmentation::GetSector(Int_t detElemId, AliMp::CathodType cath,
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).
396 return GetSector(GetMpSegmentation(detElemId, cath, warn), warn);
399 //_____________________________________________________________________________
401 AliMpSegmentation::GetSectorByElectronics(Int_t detElemId, Int_t elCardID,
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).
408 return GetSector(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn);
411 //_____________________________________________________________________________
413 AliMpSegmentation::GetSlat(const AliMpVSegmentation* kSegmentation,
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).
420 if ( ! kSegmentation ) return 0;
422 if ( kSegmentation->StationType() != AliMp::kStation345 ) {
425 << "Segmentation is not of slat type" << endl;
430 // If fast segmentation
431 const AliMpFastSegmentation* fseg
432 = dynamic_cast<const AliMpFastSegmentation*>(kSegmentation);
435 static_cast<const AliMpSlatSegmentation*>(fseg->GetHelper())->Slat();
438 // If fast segmentation V2
440 const AliMpFastSegmentationV2* fsegV2
441 = dynamic_cast<const AliMpFastSegmentationV2*>(kSegmentation);
444 static_cast<const AliMpSlatSegmentation*>(fsegV2->GetHelper())->Slat();
447 // If slat segmentation
448 const AliMpSlatSegmentation* sseg
449 = dynamic_cast<const AliMpSlatSegmentation*>(kSegmentation);
455 // Should not get to this line
456 AliErrorStream() << "Segemntation type not identified." << endl;
460 //_____________________________________________________________________________
462 AliMpSegmentation::GetSlat(Int_t detElemId, AliMp::CathodType cath,
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).
469 return GetSlat(GetMpSegmentation(detElemId, cath, warn), warn);
472 //_____________________________________________________________________________
474 AliMpSegmentation::GetSlatByElectronics(Int_t detElemId, Int_t elCardID,
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).
481 return GetSlat(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn);
484 //_____________________________________________________________________________
486 AliMpSegmentation::GetTrigger(const AliMpVSegmentation* kSegmentation,
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).
493 if ( ! kSegmentation ) return 0;
495 if ( kSegmentation->StationType() != AliMp::kStationTrigger ) {
498 << "Segmentation is not of trigger type" << endl;
503 // If slat segmentation
504 const AliMpTriggerSegmentation* tseg
505 = dynamic_cast<const AliMpTriggerSegmentation*>(kSegmentation);
510 // If fast segmentation
511 const AliMpFastSegmentation* fseg
512 = dynamic_cast<const AliMpFastSegmentation*>(kSegmentation);
516 static_cast<const AliMpTriggerSegmentation*>(fseg->GetHelper())->Slat();
519 // If fast segmentation V2
521 const AliMpFastSegmentationV2* fsegV2
522 = dynamic_cast<const AliMpFastSegmentationV2*>(kSegmentation);
526 static_cast<const AliMpTriggerSegmentation*>(fsegV2->GetHelper())->Slat();
530 // Should not get to this line
531 AliErrorStream() << "Segemntation type not identified." << endl;
535 //_____________________________________________________________________________
537 AliMpSegmentation::GetTrigger(Int_t detElemId, AliMp::CathodType cath,
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).
544 return GetTrigger(GetMpSegmentation(detElemId, cath, warn), warn);
547 //_____________________________________________________________________________
549 AliMpSegmentation::GetTriggerByElectronics(Int_t detElemId, Int_t elCardID,
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).
556 return GetTrigger(GetMpSegmentationByElectronics(detElemId, elCardID, warn), warn);