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 "AliMpSector.h"
37 #include "AliMpSectorReader.h"
38 #include "AliMpSectorSegmentation.h"
39 #include "AliMpSlat.h"
40 #include "AliMpSlatSegmentation.h"
41 #include "AliMpSt345Reader.h"
42 #include "AliMpTrigger.h"
43 #include "AliMpTriggerReader.h"
44 #include "AliMpTriggerSegmentation.h"
45 #include "AliMpCathodType.h"
46 #include "AliMpSlatMotifMap.h"
51 #include <Riostream.h>
53 #include <TObjString.h>
60 ClassImp(AliMpSegmentation)
63 AliMpSegmentation* AliMpSegmentation::fgInstance = 0;
69 //______________________________________________________________________________
70 AliMpSegmentation* AliMpSegmentation::Instance(Bool_t warn)
72 /// Return its instance
74 if ( ! fgInstance && warn ) {
75 AliWarningClass("Segmentation has not been loaded");
81 //______________________________________________________________________________
82 AliMpSegmentation* AliMpSegmentation::ReadData(const AliMpDataStreams& dataStreams,
85 /// Load the sementation from ASCII data files
86 /// and return its instance
90 AliWarningClass("Segmentation has been already loaded");
94 if ( dataStreams.GetReadFromFiles() )
95 AliInfoClass("Reading segmentation from ASCII files.");
97 fgInstance = new AliMpSegmentation(dataStreams);
105 //______________________________________________________________________________
106 AliMpSegmentation::AliMpSegmentation(const AliMpDataStreams& dataStreams)
108 fDataStreams(dataStreams),
112 fSlatMotifMap(AliMpSlatMotifMap::Instance())
114 /// Standard constructor - segmentation is loaded from ASCII data files
119 if ( ! AliMpDEStore::Instance(false) )
120 AliMpDEStore::ReadData(dataStreams);
121 fDetElements = AliMpDEStore::Instance();
123 // Create mapping segmentations for all detection elements
125 for ( it.First(); ! it.IsDone(); it.Next() )
129 for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; ++cath )
131 if ( CreateMpSegmentation(it.CurrentDEId(), AliMp::GetCathodType(cath)) ) ++n;
134 if ( n == 2 && // should always be the case except when we play with the CreateMpSegmentation method...
135 AliMpDEManager::GetStationType(it.CurrentDEId()) != AliMp::kStationTrigger ) // only for tracker
137 // Fill el cards map for all detection elements
138 // of tracking chambers
139 FillElCardsMap(it.CurrentDEId());
144 //______________________________________________________________________________
145 AliMpSegmentation::AliMpSegmentation(TRootIOCtor* ioCtor)
147 fDataStreams(ioCtor),
153 /// Constructor for IO
160 //______________________________________________________________________________
161 AliMpSegmentation::~AliMpSegmentation()
169 // Segmentations are deleted with fMpSegmentations
170 // El cards arrays are deleted with fElCardsMap
179 //______________________________________________________________________________
181 AliMpSegmentation::CreateMpSegmentation(Int_t detElemId, AliMp::CathodType cath)
183 /// Create mapping segmentation for given detElemId and cath
184 /// or return it if it was already built
186 // Check detElemId & cath
187 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, true) ) return 0;
189 // If segmentation is already built, just return it
191 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
192 TString deSegName = detElement->GetSegName(cath);
193 TObject* object = fMpSegmentations.Get(deSegName);
194 if ( object ) return (AliMpVSegmentation*)object;
197 << "Creating segmentation for detElemId=" << detElemId
198 << " cath=" << cath << endl;
200 // Read mapping data and create segmentation
202 AliMp::StationType stationType = detElement->GetStationType();
203 AliMp::PlaneType planeType = detElement->GetPlaneType(cath);
204 TString deTypeName = detElement->GetSegType();
206 AliMpVSegmentation* mpSegmentation = 0;
208 if ( stationType == AliMp::kStation1 || stationType == AliMp::kStation2 ) {
209 AliMpSectorReader reader(fDataStreams, stationType, planeType);
210 AliMpSector* sector = reader.BuildSector();
211 mpSegmentation = new AliMpSectorSegmentation(sector, true);
213 else if ( stationType == AliMp::kStation345 ) {
214 AliMpSt345Reader reader(fDataStreams);
215 AliMpSlat* slat = reader.ReadSlat(deTypeName, planeType);
216 mpSegmentation = new AliMpSlatSegmentation(slat, true);
218 else if ( stationType == AliMp::kStationTrigger ) {
219 AliMpTriggerReader reader(fDataStreams);
220 AliMpTrigger* trigger = reader.ReadSlat(deTypeName, planeType);
221 mpSegmentation = new AliMpTriggerSegmentation(trigger, true);
224 AliErrorStream() << "Unknown station type" << endl;
226 if ( mpSegmentation ) fMpSegmentations.Add(deSegName, mpSegmentation);
228 // StdoutToAliDebug(3, fSlatMotifMap.Print(););
230 return mpSegmentation;
233 //_____________________________________________________________________________
235 AliMpSegmentation::FillElCardsMap(Int_t detElemId)
237 /// Fill the map of electronic cards IDs to segmentations for
240 AliDebugStream(2) << "detElemId=" << detElemId << endl;;
242 AliMpExMap* mde = new AliMpExMap;
243 mde->SetOwner(kFALSE);
244 fElCardsMap.Add(detElemId,mde);
246 const AliMpVSegmentation* seg[2];
249 for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++cathode )
251 seg[cathode] = GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
252 seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]);
253 for ( Int_t i = 0; i < ecn[cathode].GetSize(); ++i )
255 mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode]));
259 assert( mde->GetSize() > 0 );
269 //______________________________________________________________________________
270 const AliMpVSegmentation*
271 AliMpSegmentation::GetMpSegmentation(
272 Int_t detElemId, AliMp::CathodType cath, Bool_t warn) const
274 /// Return mapping segmentation for given detElemId and cath
276 // Check detElemId & cath
277 if ( ! AliMpDEManager::IsValidDetElemId(detElemId, false) ) {
281 << "Invalid detElemId " << detElemId << endl;
286 // If segmentation is already built, just return it
288 AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
289 TString deSegName = detElement->GetSegName(cath);
290 TObject* object = fMpSegmentations.Get(deSegName);
292 // Should never happen
294 << "Segmentation for detElemId/cathod "
295 << detElemId << ", " << cath << " not defined" << endl;
299 return static_cast<AliMpVSegmentation*>(object);
302 //_____________________________________________________________________________
303 const AliMpVSegmentation*
304 AliMpSegmentation::GetMpSegmentationByElectronics(
305 Int_t detElemId, Int_t ecId, Bool_t warn) const
307 /// Return mapping segmentation for given detElemId and electronic card Id
308 /// (motif position Id)
310 AliMpExMap* m = static_cast<AliMpExMap*>(fElCardsMap.GetValue(detElemId));
313 // Should never happen
315 << "Cannot find the el cards map for detElemId " << detElemId << endl;
319 TObject* object = m->GetValue(ecId);
323 << "Segmentation for electronic card "
324 << ecId << " not found" << endl;
329 return static_cast<AliMpVSegmentation*>(object);