]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSegFactory.cxx
Adding local CVS Id (MpId) and/or category
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSegFactory.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 // $Id$
17 // $MpId: AliMpSegFactory.cxx,v 1.5 2006/03/13 12:22:15 ivana Exp $
18 // Category: management
19
20 // -----------------------
21 // Class AliMpSegFactory
22 // -----------------------
23 // The factory for building mapping segmentations
24 // Authors: Ivana Hrivnacova, IPN Orsay
25
26 #include "AliMpSegFactory.h"
27
28 #include "AliLog.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>
41 #include <TMap.h>
42 #include <TObjString.h>
43 #include <TSystem.h>
44
45 ClassImp(AliMpSegFactory)
46
47 //______________________________________________________________________________
48 AliMpSegFactory::AliMpSegFactory()
49 : TObject(),
50   fMpSegmentations(),
51   fMpMap(new AliMpExMap(true))
52 {  
53     /// Standard constructor
54     AliDebug(1,"");
55     fMpMap->SetOwner(true);
56 }
57
58 //______________________________________________________________________________
59 AliMpSegFactory::AliMpSegFactory(const AliMpSegFactory& rhs)
60  : TObject(rhs)
61 {
62 /// Protected copy constructor
63
64   AliFatal("Not implemented.");
65 }
66
67 //______________________________________________________________________________
68
69 AliMpSegFactory::~AliMpSegFactory()
70 {
71 /// Destructor
72
73   // The segmentations is supposed to be deleted in the client code
74   AliDebug(1,"");
75 }
76
77 //______________________________________________________________________________
78 AliMpSegFactory&  AliMpSegFactory::operator=(const AliMpSegFactory& rhs)
79 {
80   // Protected assignement operator
81
82   if (this == &rhs) return *this;
83
84   AliFatal("Not implemented.");
85     
86   return *this;  
87 }    
88           
89 //
90 // private methods
91 //
92
93 //_____________________________________________________________________________
94 AliMpExMap*
95 AliMpSegFactory::FillMpMap(Int_t detElemId)
96 {
97 /// Fill the map of electronic cards IDs to segmentations for
98 /// given detElemId
99
100   AliDebug(1,Form("detElemId=%d",detElemId));
101   
102   AliMpExMap* mde = new AliMpExMap(true);
103   mde->SetOwner(kFALSE);
104   fMpMap->Add(detElemId,mde);
105   
106   AliMpVSegmentation* seg[2];
107   TArrayI ecn[2];
108   
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.
111   // (not critical).
112   for ( Int_t cathode = 0; cathode < 2; ++cathode )
113   {
114     seg[cathode] = CreateMpSegmentation(detElemId,cathode);
115     seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]);
116   }
117   
118   mde->SetSize(ecn[0].GetSize()+ecn[1].GetSize());
119   
120   for ( Int_t cathode = 0; cathode < 2; ++ cathode )
121   {
122     for ( Int_t i = 0; i < ecn[cathode].GetSize(); ++i )
123     {
124       mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode]));
125     }
126   }
127   
128   return mde;
129 }
130
131 //
132 // public methods
133 //
134
135 //______________________________________________________________________________
136 AliMpVSegmentation* 
137 AliMpSegFactory::CreateMpSegmentation(Int_t detElemId, Int_t cath)
138 {
139 /// Create mapping segmentation for given detElemId and cath
140 /// or return it if it was already built
141
142   // Check detElemId & cath  
143   if ( ! AliMpDEManager::IsValid(detElemId, cath, true) ) return 0;
144
145   // If segmentation is already built, just return it
146   //
147   TString deName = AliMpDEManager::GetDEName(detElemId, cath);
148   TObject* object = fMpSegmentations.Get(deName);
149   if ( object ) return (AliMpVSegmentation*)object;
150
151   AliDebug(1,Form("Creating segmentation for detElemId=%d cath=%d",
152                   detElemId,cath));
153   
154   // Read mapping data and create segmentation
155   //
156   AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
157   AliMpPlaneType planeType = AliMpDEManager::GetPlaneType(detElemId, cath);
158   TString deTypeName = AliMpDEManager::GetDETypeName(detElemId, cath);
159
160   AliMpVSegmentation* mpSegmentation = 0;
161
162   if ( stationType == kStation1 || stationType == kStation2 ) {
163     AliMpSectorReader reader(stationType, planeType);
164     AliMpSector* sector = reader.BuildSector();
165     mpSegmentation = new AliMpSectorSegmentation(sector);
166   }
167   else if ( stationType == kStation345 ) { 
168     AliMpSlat* slat = AliMpSt345Reader::ReadSlat(deTypeName, planeType);
169     mpSegmentation =  new AliMpSlatSegmentation(slat);
170   }
171   else if ( stationType == kStationTrigger ) {
172     AliMpTrigger* trigger = AliMpTriggerReader::ReadSlat(deTypeName, planeType);
173     mpSegmentation = new AliMpTriggerSegmentation(trigger);
174   }
175   else   
176     AliErrorStream() << "Unknown station type" << endl;
177
178   fMpSegmentations.Add(deName, mpSegmentation); 
179   return mpSegmentation;
180
181
182 //_____________________________________________________________________________
183 AliMpVSegmentation* 
184 AliMpSegFactory::CreateMpSegmentationByElectronics(Int_t detElemId,
185                                                    Int_t ecId)
186 {
187 /// Create mapping segmentation for given detElemId and electronic card Id
188 /// (motif position Id) or return it if it was already built
189
190   AliMpExMap* m = static_cast<AliMpExMap*>(fMpMap->GetValue(detElemId));
191   
192   if (!m)
193   {
194     m = FillMpMap(detElemId);
195   }
196   
197   return static_cast<AliMpVSegmentation*>(m->GetValue(ecId));
198 }
199     
200 //______________________________________________________________________________
201 void AliMpSegFactory::DeleteSegmentations()
202 {
203 /// Delete all segmentations created with this manager
204
205   AliDebug(1,"deleting mpSegmentations");
206   fMpSegmentations.Clear();
207   AliDebug(1,"deleting mpMap");
208   delete fMpMap;
209   fMpMap = 0; 
210   AliDebug(1,"done");
211 }
212