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
27 #include "AliMpSegmentation.h"
29 #include "AliMpDEManager.h"
30 #include "AliMpDEIterator.h"
31 #include "AliMpExMap.h"
32 #include "AliMpSector.h"
33 #include "AliMpSectorReader.h"
34 #include "AliMpSectorSegmentation.h"
35 #include "AliMpSlat.h"
36 #include "AliMpSlatSegmentation.h"
37 #include "AliMpSt345Reader.h"
38 #include "AliMpTrigger.h"
39 #include "AliMpTriggerReader.h"
40 #include "AliMpTriggerSegmentation.h"
44 #include <Riostream.h>
46 #include <TObjString.h>
50 ClassImp(AliMpSegmentation)
53 AliMpSegmentation* AliMpSegmentation::fgInstance = 0;
59 //______________________________________________________________________________
60 AliMpSegmentation* AliMpSegmentation::Instance()
62 /// Create the sementation if it does not yet exist
63 /// and return its instance
66 fgInstance = new AliMpSegmentation();
75 //______________________________________________________________________________
76 AliMpSegmentation::AliMpSegmentation()
78 fMpSegmentations(true),
81 /// Standard constructor
84 fElCardsMap.SetOwner(true);
86 // Create mapping segmentations for all detection elements
87 for ( Int_t cath = 0; cath < 2; cath ++ ) {
89 for ( it.First(); ! it.IsDone(); it.Next() ) {
90 //if ( AliMpDEManager::GetChamberId(it.CurrentDE()) >= 4 ) break;
91 CreateMpSegmentation(it.CurrentDE(), cath);
95 // Fill el cards map for all detection elements
96 // of tracking chambers
98 for ( it.First(); ! it.IsDone(); it.Next() ) {
99 //if ( AliMpDEManager::GetChamberId(it.CurrentDE()) >= 4 ) break;
100 if ( AliMpDEManager::GetChamberId(it.CurrentDE()) >= 10 ) break;
101 FillElCardsMap(it.CurrentDE());
105 //______________________________________________________________________________
106 AliMpSegmentation::AliMpSegmentation(TRootIOCtor* /*ioCtor*/)
111 /// Constructor for IO
116 //______________________________________________________________________________
117 AliMpSegmentation::~AliMpSegmentation()
123 // Segmentations are deleted with fMpSegmentations
124 // El cards arrays are deleted with fElCardsMap
133 //______________________________________________________________________________
135 AliMpSegmentation::CreateMpSegmentation(Int_t detElemId, Int_t cath)
137 /// Create mapping segmentation for given detElemId and cath
138 /// or return it if it was already built
140 // Check detElemId & cath
141 if ( ! AliMpDEManager::IsValid(detElemId, cath, true) ) return 0;
143 // If segmentation is already built, just return it
145 TString deName = AliMpDEManager::GetDEName(detElemId, cath);
146 TObject* object = fMpSegmentations.Get(deName);
147 if ( object ) return (AliMpVSegmentation*)object;
150 << "Creating segmentation for detElemId=" << detElemId
151 << " cath=" << cath << endl;
153 // Read mapping data and create segmentation
155 AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
156 AliMpPlaneType planeType = AliMpDEManager::GetPlaneType(detElemId, cath);
157 TString deTypeName = AliMpDEManager::GetDETypeName(detElemId, cath);
159 AliMpVSegmentation* mpSegmentation = 0;
161 if ( stationType == kStation1 || stationType == kStation2 ) {
162 AliMpSectorReader reader(stationType, planeType);
163 AliMpSector* sector = reader.BuildSector();
164 mpSegmentation = new AliMpSectorSegmentation(sector, true);
166 else if ( stationType == kStation345 ) {
167 AliMpSlat* slat = AliMpSt345Reader::ReadSlat(deTypeName, planeType);
168 mpSegmentation = new AliMpSlatSegmentation(slat, true);
170 else if ( stationType == kStationTrigger ) {
171 AliMpTrigger* trigger = AliMpTriggerReader::ReadSlat(deTypeName, planeType);
172 mpSegmentation = new AliMpTriggerSegmentation(trigger, true);
175 AliErrorStream() << "Unknown station type" << endl;
177 fMpSegmentations.Add(deName, mpSegmentation);
178 return mpSegmentation;
181 //_____________________________________________________________________________
183 AliMpSegmentation::FillElCardsMap(Int_t detElemId)
185 /// Fill the map of electronic cards IDs to segmentations for
188 AliDebugStream(2) << "detElemId=" << detElemId << endl;;
190 AliMpExMap* mde = new AliMpExMap(true);
191 mde->SetOwner(kFALSE);
192 fElCardsMap.Add(detElemId,mde);
194 const AliMpVSegmentation* seg[2];
197 // Do it in 2 steps to be able to set the AliMpExMap size once for all,
198 // to avoid annoying warning message in case of dynamical resizing.
200 for ( Int_t cathode = 0; cathode < 2; ++cathode )
202 seg[cathode] = GetMpSegmentation(detElemId,cathode);
203 seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]);
206 mde->SetSize(ecn[0].GetSize()+ecn[1].GetSize());
208 for ( Int_t cathode = 0; cathode < 2; ++ cathode )
210 for ( Int_t i = 0; i < ecn[cathode].GetSize(); ++i )
212 mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode]));
223 //______________________________________________________________________________
224 const AliMpVSegmentation*
225 AliMpSegmentation::GetMpSegmentation(
226 Int_t detElemId, Int_t cath, Bool_t warn) const
228 /// Return mapping segmentation for given detElemId and cath
230 // Check detElemId & cath
231 if ( ! AliMpDEManager::IsValid(detElemId, cath, false) ) {
235 << "Invalid detElemId/cathod ("
236 << detElemId << ", " << cath << ")" << endl;
241 TString deName = AliMpDEManager::GetDEName(detElemId, cath);
242 TObject* object = fMpSegmentations.Get(deName);
244 // Should never happen
246 << "Segmentation for detElemId/cathod "
247 << detElemId << ", " << cath << " not defined" << endl;
251 return static_cast<AliMpVSegmentation*>(object);
254 //_____________________________________________________________________________
255 const AliMpVSegmentation*
256 AliMpSegmentation::GetMpSegmentationByElectronics(
257 Int_t detElemId, Int_t ecId, Bool_t warn) const
259 /// Return mapping segmentation for given detElemId and electronic card Id
260 /// (motif position Id)
262 AliMpExMap* m = static_cast<AliMpExMap*>(fElCardsMap.GetValue(detElemId));
265 // Should never happen
267 << "Cannot find the el cards map for detElemId " << detElemId << endl;
271 TObject* object = m->GetValue(ecId);
275 << "Segmentation for electronic card "
276 << ecId << " not found" << endl;
281 return static_cast<AliMpVSegmentation*>(object);