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"
48 #include <Riostream.h>
50 #include <TObjString.h>
55 ClassImp(AliMpSegmentation)
58 AliMpSegmentation* AliMpSegmentation::fgInstance = 0;
64 //______________________________________________________________________________
65 AliMpSegmentation* AliMpSegmentation::Instance(Bool_t warn)
67 /// Return its instance
69 if ( ! fgInstance && warn ) {
70 AliWarningClass("Segmentation has not been loaded");
76 //______________________________________________________________________________
77 AliMpSegmentation* AliMpSegmentation::ReadData(Bool_t warn)
79 /// Load the sementation from ASCII data files
80 /// and return its instance
84 AliWarningClass("Segmentation has been already loaded");
88 AliInfoClass("Reading segmentation from ASCII files.");
90 fgInstance = new AliMpSegmentation();
98 //______________________________________________________________________________
99 AliMpSegmentation::AliMpSegmentation()
102 fMpSegmentations(true),
106 /// Standard constructor - segmentation is loaded from ASCII data files
109 fElCardsMap.SetOwner(true);
112 if ( ! AliMpDEStore::Instance(false) )
113 AliMpDEStore::ReadData();
114 fDetElements = AliMpDEStore::Instance();
116 // Create mapping segmentations for all detection elements
117 for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; cath ++ ) {
119 for ( it.First(); ! it.IsDone(); it.Next() ) {
120 CreateMpSegmentation(it.CurrentDEId(), AliMp::GetCathodType(cath));
124 // Fill el cards map for all detection elements
125 // of tracking chambers
127 for ( it.First(); ! it.IsDone(); it.Next() ) {
128 if ( AliMpDEManager::GetStationType(it.CurrentDEId()) != AliMp::kStationTrigger ) {
129 FillElCardsMap(it.CurrentDEId());
134 //______________________________________________________________________________
135 AliMpSegmentation::AliMpSegmentation(TRootIOCtor* /*ioCtor*/)
142 /// Constructor for IO
149 //______________________________________________________________________________
150 AliMpSegmentation::~AliMpSegmentation()
158 // Segmentations are deleted with fMpSegmentations
159 // El cards arrays are deleted with fElCardsMap
168 //______________________________________________________________________________
170 AliMpSegmentation::CreateMpSegmentation(Int_t detElemId, AliMp::CathodType cath)
172 /// Create mapping segmentation for given detElemId and cath
173 /// or return it if it was already built
175 // Check detElemId & cath
176 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, true) ) return 0;
178 // If segmentation is already built, just return it
180 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
181 TString deSegName = detElement->GetSegName(cath);
182 TObject* object = fMpSegmentations.Get(deSegName);
183 if ( object ) return (AliMpVSegmentation*)object;
186 << "Creating segmentation for detElemId=" << detElemId
187 << " cath=" << cath << endl;
189 // Read mapping data and create segmentation
191 AliMp::StationType stationType = detElement->GetStationType();
192 AliMp::PlaneType planeType = detElement->GetPlaneType(cath);
193 TString deTypeName = detElement->GetSegType();
195 AliMpVSegmentation* mpSegmentation = 0;
197 if ( stationType == AliMp::kStation1 || stationType == AliMp::kStation2 ) {
198 AliMpSectorReader reader(stationType, planeType);
199 AliMpSector* sector = reader.BuildSector();
200 mpSegmentation = new AliMpSectorSegmentation(sector, true);
202 else if ( stationType == AliMp::kStation345 ) {
203 AliMpSt345Reader reader(fSlatMotifMap);
204 AliMpSlat* slat = reader.ReadSlat(deTypeName, planeType);
205 mpSegmentation = new AliMpSlatSegmentation(slat, true);
207 else if ( stationType == AliMp::kStationTrigger ) {
208 AliMpTriggerReader reader(fSlatMotifMap);
209 AliMpTrigger* trigger = reader.ReadSlat(deTypeName, planeType);
210 mpSegmentation = new AliMpTriggerSegmentation(trigger, true);
213 AliErrorStream() << "Unknown station type" << endl;
215 fMpSegmentations.Add(deSegName, mpSegmentation);
217 // StdoutToAliDebug(3, fSlatMotifMap.Print(););
219 return mpSegmentation;
222 //_____________________________________________________________________________
224 AliMpSegmentation::FillElCardsMap(Int_t detElemId)
226 /// Fill the map of electronic cards IDs to segmentations for
229 AliDebugStream(2) << "detElemId=" << detElemId << endl;;
231 AliMpExMap* mde = new AliMpExMap(true);
232 mde->SetOwner(kFALSE);
233 fElCardsMap.Add(detElemId,mde);
235 const AliMpVSegmentation* seg[2];
238 // Do it in 2 steps to be able to set the AliMpExMap size once for all,
239 // to avoid annoying warning message in case of dynamical resizing.
241 for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++cathode )
243 seg[cathode] = GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
244 seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]);
247 mde->SetSize(ecn[0].GetSize()+ecn[1].GetSize());
249 for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++ cathode )
251 for ( Int_t i = 0; i < ecn[cathode].GetSize(); ++i )
253 mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode]));
264 //______________________________________________________________________________
265 const AliMpVSegmentation*
266 AliMpSegmentation::GetMpSegmentation(
267 Int_t detElemId, AliMp::CathodType cath, Bool_t warn) const
269 /// Return mapping segmentation for given detElemId and cath
271 // Check detElemId & cath
272 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, false) ) {
276 << "Invalid detElemId " << detElemId << endl;
281 // If segmentation is already built, just return it
283 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
284 TString deSegName = detElement->GetSegName(cath);
285 TObject* object = fMpSegmentations.Get(deSegName);
287 // Should never happen
289 << "Segmentation for detElemId/cathod "
290 << detElemId << ", " << cath << " not defined" << endl;
294 return static_cast<AliMpVSegmentation*>(object);
297 //_____________________________________________________________________________
298 const AliMpVSegmentation*
299 AliMpSegmentation::GetMpSegmentationByElectronics(
300 Int_t detElemId, Int_t ecId, Bool_t warn) const
302 /// Return mapping segmentation for given detElemId and electronic card Id
303 /// (motif position Id)
305 AliMpExMap* m = static_cast<AliMpExMap*>(fElCardsMap.GetValue(detElemId));
308 // Should never happen
310 << "Cannot find the el cards map for detElemId " << detElemId << endl;
314 TObject* object = m->GetValue(ecId);
318 << "Segmentation for electronic card "
319 << ecId << " not found" << endl;
324 return static_cast<AliMpVSegmentation*>(object);