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 "AliMpDetElement.h"
30 #include "AliMpDEManager.h"
31 #include "AliMpDEIterator.h"
32 #include "AliMpExMap.h"
33 #include "AliMpSector.h"
34 #include "AliMpSectorReader.h"
35 #include "AliMpSectorSegmentation.h"
36 #include "AliMpSlat.h"
37 #include "AliMpSlatSegmentation.h"
38 #include "AliMpSt345Reader.h"
39 #include "AliMpTrigger.h"
40 #include "AliMpTriggerReader.h"
41 #include "AliMpTriggerSegmentation.h"
42 #include "AliMpCathodType.h"
46 #include <Riostream.h>
48 #include <TObjString.h>
52 ClassImp(AliMpSegmentation)
55 AliMpSegmentation* AliMpSegmentation::fgInstance = 0;
61 //______________________________________________________________________________
62 AliMpSegmentation* AliMpSegmentation::Instance()
64 /// Create the sementation if it does not yet exist
65 /// and return its instance
68 fgInstance = new AliMpSegmentation();
77 //______________________________________________________________________________
78 AliMpSegmentation::AliMpSegmentation()
80 fMpSegmentations(true),
84 /// Standard constructor
87 fElCardsMap.SetOwner(true);
89 // Create mapping segmentations for all detection elements
90 for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; cath ++ ) {
92 for ( it.First(); ! it.IsDone(); it.Next() ) {
93 CreateMpSegmentation(it.CurrentDEId(), AliMp::GetCathodType(cath));
97 // Fill el cards map for all detection elements
98 // of tracking chambers
100 for ( it.First(); ! it.IsDone(); it.Next() ) {
101 if ( AliMpDEManager::GetStationType(it.CurrentDEId()) != AliMp::kStationTrigger ) {
102 FillElCardsMap(it.CurrentDEId());
107 //______________________________________________________________________________
108 AliMpSegmentation::AliMpSegmentation(TRootIOCtor* /*ioCtor*/)
114 /// Constructor for IO
121 //______________________________________________________________________________
122 AliMpSegmentation::~AliMpSegmentation()
128 // Segmentations are deleted with fMpSegmentations
129 // El cards arrays are deleted with fElCardsMap
138 //______________________________________________________________________________
140 AliMpSegmentation::CreateMpSegmentation(Int_t detElemId, AliMp::CathodType cath)
142 /// Create mapping segmentation for given detElemId and cath
143 /// or return it if it was already built
145 // Check detElemId & cath
146 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, true) ) return 0;
148 // If segmentation is already built, just return it
150 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
151 TString deSegName = detElement->GetSegName(cath);
152 TObject* object = fMpSegmentations.Get(deSegName);
153 if ( object ) return (AliMpVSegmentation*)object;
156 << "Creating segmentation for detElemId=" << detElemId
157 << " cath=" << cath << endl;
159 // Read mapping data and create segmentation
161 AliMp::StationType stationType = detElement->GetStationType();
162 AliMp::PlaneType planeType = detElement->GetPlaneType(cath);
163 TString deTypeName = detElement->GetSegType();
165 AliMpVSegmentation* mpSegmentation = 0;
167 if ( stationType == AliMp::kStation1 || stationType == AliMp::kStation2 ) {
168 AliMpSectorReader reader(stationType, planeType);
169 AliMpSector* sector = reader.BuildSector();
170 mpSegmentation = new AliMpSectorSegmentation(sector, true);
172 else if ( stationType == AliMp::kStation345 ) {
173 AliMpSt345Reader reader(fSlatMotifMap);
174 AliMpSlat* slat = reader.ReadSlat(deTypeName, planeType);
175 mpSegmentation = new AliMpSlatSegmentation(slat, true);
177 else if ( stationType == AliMp::kStationTrigger ) {
178 AliMpTriggerReader reader(fSlatMotifMap);
179 AliMpTrigger* trigger = reader.ReadSlat(deTypeName, planeType);
180 mpSegmentation = new AliMpTriggerSegmentation(trigger, true);
183 AliErrorStream() << "Unknown station type" << endl;
185 fMpSegmentations.Add(deSegName, mpSegmentation);
187 // StdoutToAliDebug(3, fSlatMotifMap.Print(););
189 return mpSegmentation;
192 //_____________________________________________________________________________
194 AliMpSegmentation::FillElCardsMap(Int_t detElemId)
196 /// Fill the map of electronic cards IDs to segmentations for
199 AliDebugStream(2) << "detElemId=" << detElemId << endl;;
201 AliMpExMap* mde = new AliMpExMap(true);
202 mde->SetOwner(kFALSE);
203 fElCardsMap.Add(detElemId,mde);
205 const AliMpVSegmentation* seg[2];
208 // Do it in 2 steps to be able to set the AliMpExMap size once for all,
209 // to avoid annoying warning message in case of dynamical resizing.
211 for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++cathode )
213 seg[cathode] = GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
214 seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]);
217 mde->SetSize(ecn[0].GetSize()+ecn[1].GetSize());
219 for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++ cathode )
221 for ( Int_t i = 0; i < ecn[cathode].GetSize(); ++i )
223 mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode]));
234 //______________________________________________________________________________
235 const AliMpVSegmentation*
236 AliMpSegmentation::GetMpSegmentation(
237 Int_t detElemId, AliMp::CathodType cath, Bool_t warn) const
239 /// Return mapping segmentation for given detElemId and cath
241 // Check detElemId & cath
242 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, false) ) {
246 << "Invalid detElemId " << detElemId << endl;
251 // If segmentation is already built, just return it
253 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
254 TString deSegName = detElement->GetSegName(cath);
255 TObject* object = fMpSegmentations.Get(deSegName);
257 // Should never happen
259 << "Segmentation for detElemId/cathod "
260 << detElemId << ", " << cath << " not defined" << endl;
264 return static_cast<AliMpVSegmentation*>(object);
267 //_____________________________________________________________________________
268 const AliMpVSegmentation*
269 AliMpSegmentation::GetMpSegmentationByElectronics(
270 Int_t detElemId, Int_t ecId, Bool_t warn) const
272 /// Return mapping segmentation for given detElemId and electronic card Id
273 /// (motif position Id)
275 AliMpExMap* m = static_cast<AliMpExMap*>(fElCardsMap.GetValue(detElemId));
278 // Should never happen
280 << "Cannot find the el cards map for detElemId " << detElemId << endl;
284 TObject* object = m->GetValue(ecId);
288 << "Segmentation for electronic card "
289 << ecId << " not found" << endl;
294 return static_cast<AliMpVSegmentation*>(object);