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: AliMpSegFactory.cxx,v 1.5 2006/03/13 12:22:15 ivana Exp $
18 // Category: management
20 // -----------------------
21 // Class AliMpSegFactory
22 // -----------------------
23 // The factory for building mapping segmentations
24 // Authors: Ivana Hrivnacova, IPN Orsay
26 #include "AliMpSegFactory.h"
29 #include "AliMpDEManager.h"
30 #include "AliMpExMap.h"
31 #include "AliMpSector.h"
32 #include "AliMpSectorReader.h"
33 #include "AliMpSectorSegmentation.h"
34 #include "AliMpSlat.h"
35 #include "AliMpSlatSegmentation.h"
36 #include "AliMpSt345Reader.h"
37 #include "AliMpTrigger.h"
38 #include "AliMpTriggerReader.h"
39 #include "AliMpTriggerSegmentation.h"
40 #include <Riostream.h>
42 #include <TObjString.h>
45 ClassImp(AliMpSegFactory)
47 //______________________________________________________________________________
48 AliMpSegFactory::AliMpSegFactory()
51 fMpMap(new AliMpExMap(true))
53 /// Standard constructor
55 fMpMap->SetOwner(true);
58 //______________________________________________________________________________
59 AliMpSegFactory::AliMpSegFactory(const AliMpSegFactory& rhs)
62 /// Protected copy constructor
64 AliFatal("Not implemented.");
67 //______________________________________________________________________________
69 AliMpSegFactory::~AliMpSegFactory()
73 // The segmentations is supposed to be deleted in the client code
77 //______________________________________________________________________________
78 AliMpSegFactory& AliMpSegFactory::operator=(const AliMpSegFactory& rhs)
80 // Protected assignement operator
82 if (this == &rhs) return *this;
84 AliFatal("Not implemented.");
93 //_____________________________________________________________________________
95 AliMpSegFactory::FillMpMap(Int_t detElemId)
97 /// Fill the map of electronic cards IDs to segmentations for
100 AliDebug(1,Form("detElemId=%d",detElemId));
102 AliMpExMap* mde = new AliMpExMap(true);
103 mde->SetOwner(kFALSE);
104 fMpMap->Add(detElemId,mde);
106 AliMpVSegmentation* seg[2];
109 // Do it in 2 steps to be able to set the AliMpExMap size once for all,
110 // to avoid annoying warning message in case of dynamical resizing.
112 for ( Int_t cathode = 0; cathode < 2; ++cathode )
114 seg[cathode] = CreateMpSegmentation(detElemId,cathode);
115 seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]);
118 mde->SetSize(ecn[0].GetSize()+ecn[1].GetSize());
120 for ( Int_t cathode = 0; cathode < 2; ++ cathode )
122 for ( Int_t i = 0; i < ecn[cathode].GetSize(); ++i )
124 mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode]));
135 //______________________________________________________________________________
137 AliMpSegFactory::CreateMpSegmentation(Int_t detElemId, Int_t cath)
139 /// Create mapping segmentation for given detElemId and cath
140 /// or return it if it was already built
142 // Check detElemId & cath
143 if ( ! AliMpDEManager::IsValid(detElemId, cath, true) ) return 0;
145 // If segmentation is already built, just return it
147 TString deName = AliMpDEManager::GetDEName(detElemId, cath);
148 TObject* object = fMpSegmentations.Get(deName);
149 if ( object ) return (AliMpVSegmentation*)object;
151 AliDebug(1,Form("Creating segmentation for detElemId=%d cath=%d",
154 // Read mapping data and create segmentation
156 AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
157 AliMpPlaneType planeType = AliMpDEManager::GetPlaneType(detElemId, cath);
158 TString deTypeName = AliMpDEManager::GetDETypeName(detElemId, cath);
160 AliMpVSegmentation* mpSegmentation = 0;
162 if ( stationType == kStation1 || stationType == kStation2 ) {
163 AliMpSectorReader reader(stationType, planeType);
164 AliMpSector* sector = reader.BuildSector();
165 mpSegmentation = new AliMpSectorSegmentation(sector);
167 else if ( stationType == kStation345 ) {
168 AliMpSlat* slat = AliMpSt345Reader::ReadSlat(deTypeName, planeType);
169 mpSegmentation = new AliMpSlatSegmentation(slat);
171 else if ( stationType == kStationTrigger ) {
172 AliMpTrigger* trigger = AliMpTriggerReader::ReadSlat(deTypeName, planeType);
173 mpSegmentation = new AliMpTriggerSegmentation(trigger);
176 AliErrorStream() << "Unknown station type" << endl;
178 fMpSegmentations.Add(deName, mpSegmentation);
179 return mpSegmentation;
182 //_____________________________________________________________________________
184 AliMpSegFactory::CreateMpSegmentationByElectronics(Int_t detElemId,
187 /// Create mapping segmentation for given detElemId and electronic card Id
188 /// (motif position Id) or return it if it was already built
190 AliMpExMap* m = static_cast<AliMpExMap*>(fMpMap->GetValue(detElemId));
194 m = FillMpMap(detElemId);
197 return static_cast<AliMpVSegmentation*>(m->GetValue(ecId));
200 //______________________________________________________________________________
201 void AliMpSegFactory::DeleteSegmentations()
203 /// Delete all segmentations created with this manager
205 AliDebug(1,"deleting mpSegmentations");
206 fMpSegmentations.Clear();
207 AliDebug(1,"deleting mpMap");