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 "AliMpDetElement.h"
31 #include "AliMpDEStore.h"
32 #include "AliMpDEManager.h"
33 #include "AliMpDEIterator.h"
34 #include "AliMpExMap.h"
35 #include "AliMpSector.h"
36 #include "AliMpSectorReader.h"
37 #include "AliMpSectorSegmentation.h"
38 #include "AliMpSlat.h"
39 #include "AliMpSlatSegmentation.h"
40 #include "AliMpSt345Reader.h"
41 #include "AliMpTrigger.h"
42 #include "AliMpTriggerReader.h"
43 #include "AliMpTriggerSegmentation.h"
44 #include "AliMpCathodType.h"
45 #include "AliMpSlatMotifMap.h"
50 #include <Riostream.h>
52 #include <TObjString.h>
57 ClassImp(AliMpSegmentation)
60 AliMpSegmentation* AliMpSegmentation::fgInstance = 0;
66 //______________________________________________________________________________
67 AliMpSegmentation* AliMpSegmentation::Instance(Bool_t warn)
69 /// Return its instance
71 if ( ! fgInstance && warn ) {
72 AliWarningClass("Segmentation has not been loaded");
78 //______________________________________________________________________________
79 AliMpSegmentation* AliMpSegmentation::ReadData(Bool_t warn)
81 /// Load the sementation from ASCII data files
82 /// and return its instance
86 AliWarningClass("Segmentation has been already loaded");
90 AliInfoClass("Reading segmentation from ASCII files.");
92 fgInstance = new AliMpSegmentation();
100 //______________________________________________________________________________
101 AliMpSegmentation::AliMpSegmentation()
104 fMpSegmentations(true),
106 fSlatMotifMap(AliMpSlatMotifMap::Instance())
108 /// Standard constructor - segmentation is loaded from ASCII data files
111 fElCardsMap.SetOwner(true);
114 if ( ! AliMpDEStore::Instance(false) )
115 AliMpDEStore::ReadData();
116 fDetElements = AliMpDEStore::Instance();
118 // Create mapping segmentations for all detection elements
119 for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; cath ++ ) {
121 for ( it.First(); ! it.IsDone(); it.Next() ) {
122 CreateMpSegmentation(it.CurrentDEId(), AliMp::GetCathodType(cath));
126 // Fill el cards map for all detection elements
127 // of tracking chambers
129 for ( it.First(); ! it.IsDone(); it.Next() ) {
130 if ( AliMpDEManager::GetStationType(it.CurrentDEId()) != AliMp::kStationTrigger ) {
131 FillElCardsMap(it.CurrentDEId());
136 //______________________________________________________________________________
137 AliMpSegmentation::AliMpSegmentation(TRootIOCtor* /*ioCtor*/)
144 /// Constructor for IO
151 //______________________________________________________________________________
152 AliMpSegmentation::~AliMpSegmentation()
160 // Segmentations are deleted with fMpSegmentations
161 // El cards arrays are deleted with fElCardsMap
170 //______________________________________________________________________________
172 AliMpSegmentation::CreateMpSegmentation(Int_t detElemId, AliMp::CathodType cath)
174 /// Create mapping segmentation for given detElemId and cath
175 /// or return it if it was already built
177 // Check detElemId & cath
178 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, true) ) return 0;
180 // If segmentation is already built, just return it
182 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
183 TString deSegName = detElement->GetSegName(cath);
184 TObject* object = fMpSegmentations.Get(deSegName);
185 if ( object ) return (AliMpVSegmentation*)object;
188 << "Creating segmentation for detElemId=" << detElemId
189 << " cath=" << cath << endl;
191 // Read mapping data and create segmentation
193 AliMp::StationType stationType = detElement->GetStationType();
194 AliMp::PlaneType planeType = detElement->GetPlaneType(cath);
195 TString deTypeName = detElement->GetSegType();
197 AliMpVSegmentation* mpSegmentation = 0;
199 if ( stationType == AliMp::kStation1 || stationType == AliMp::kStation2 ) {
200 AliMpSectorReader reader(stationType, planeType);
201 AliMpSector* sector = reader.BuildSector();
202 mpSegmentation = new AliMpSectorSegmentation(sector, true);
204 else if ( stationType == AliMp::kStation345 ) {
205 AliMpSt345Reader reader;
206 AliMpSlat* slat = reader.ReadSlat(deTypeName, planeType);
207 mpSegmentation = new AliMpSlatSegmentation(slat, true);
209 else if ( stationType == AliMp::kStationTrigger ) {
210 AliMpTriggerReader reader;
211 AliMpTrigger* trigger = reader.ReadSlat(deTypeName, planeType);
212 mpSegmentation = new AliMpTriggerSegmentation(trigger, true);
215 AliErrorStream() << "Unknown station type" << endl;
217 fMpSegmentations.Add(deSegName, mpSegmentation);
219 // StdoutToAliDebug(3, fSlatMotifMap.Print(););
221 return mpSegmentation;
224 //_____________________________________________________________________________
226 AliMpSegmentation::FillElCardsMap(Int_t detElemId)
228 /// Fill the map of electronic cards IDs to segmentations for
231 AliDebugStream(2) << "detElemId=" << detElemId << endl;;
233 AliMpExMap* mde = new AliMpExMap(true);
234 mde->SetOwner(kFALSE);
235 fElCardsMap.Add(detElemId,mde);
237 const AliMpVSegmentation* seg[2];
240 // Do it in 2 steps to be able to set the AliMpExMap size once for all,
241 // to avoid annoying warning message in case of dynamical resizing.
243 for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++cathode )
245 seg[cathode] = GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
246 seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]);
249 mde->SetSize(ecn[0].GetSize()+ecn[1].GetSize());
251 for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++ cathode )
253 for ( Int_t i = 0; i < ecn[cathode].GetSize(); ++i )
255 mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode]));
266 //______________________________________________________________________________
267 const AliMpVSegmentation*
268 AliMpSegmentation::GetMpSegmentation(
269 Int_t detElemId, AliMp::CathodType cath, Bool_t warn) const
271 /// Return mapping segmentation for given detElemId and cath
273 // Check detElemId & cath
274 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, false) ) {
278 << "Invalid detElemId " << detElemId << endl;
283 // If segmentation is already built, just return it
285 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
286 TString deSegName = detElement->GetSegName(cath);
287 TObject* object = fMpSegmentations.Get(deSegName);
289 // Should never happen
291 << "Segmentation for detElemId/cathod "
292 << detElemId << ", " << cath << " not defined" << endl;
296 return static_cast<AliMpVSegmentation*>(object);
299 //_____________________________________________________________________________
300 const AliMpVSegmentation*
301 AliMpSegmentation::GetMpSegmentationByElectronics(
302 Int_t detElemId, Int_t ecId, Bool_t warn) const
304 /// Return mapping segmentation for given detElemId and electronic card Id
305 /// (motif position Id)
307 AliMpExMap* m = static_cast<AliMpExMap*>(fElCardsMap.GetValue(detElemId));
310 // Should never happen
312 << "Cannot find the el cards map for detElemId " << detElemId << endl;
316 TObject* object = m->GetValue(ecId);
320 << "Segmentation for electronic card "
321 << ecId << " not found" << endl;
326 return static_cast<AliMpVSegmentation*>(object);