]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSegmentation.cxx
Updated/added comments for Doxygen
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSegmentation.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: AliMpSegmentation.cxx,v 1.7 2006/05/24 13:58:34 ivana Exp $
18 // Category: management
19
20 // -----------------------
21 // Class AliMpSegmentation
22 // -----------------------
23 // Singleton container class for mapping segmentations
24 // Authors: Ivana Hrivnacova, IPN Orsay
25 //          Laurent Aphecetche, SUBATECH
26
27 #include "AliMpSegmentation.h"
28
29 #include "AliMpDetElement.h"
30 #include "AliMpDEManager.h"
31 #include "AliMpDEIterator.h"
32 #include "AliMpExMap.h"
33 #include "AliMpSector.h"
34 #include "AliMpSectorReader.h"
35 #include "AliMpSectorSegmentation.h"
36 #include "AliMpSlat.h"
37 #include "AliMpSlatSegmentation.h"
38 #include "AliMpSt345Reader.h"
39 #include "AliMpTrigger.h"
40 #include "AliMpTriggerReader.h"
41 #include "AliMpTriggerSegmentation.h"
42 #include "AliMpCathodType.h"
43
44 #include "AliLog.h"
45
46 #include <Riostream.h>
47 #include <TMap.h>
48 #include <TObjString.h>
49 #include <TSystem.h>
50
51 /// \cond CLASSIMP
52 ClassImp(AliMpSegmentation)
53 /// \endcond
54
55 AliMpSegmentation* AliMpSegmentation::fgInstance = 0;
56
57 //
58 // static methods
59 //
60
61 //______________________________________________________________________________
62 AliMpSegmentation* AliMpSegmentation::Instance()
63 {
64 /// Create the sementation if it does not yet exist
65 /// and return its instance
66
67   if ( ! fgInstance )
68     fgInstance = new AliMpSegmentation();
69     
70   return fgInstance;
71 }    
72
73 //
74 // ctors, dtor
75 //
76
77 //______________________________________________________________________________
78 AliMpSegmentation::AliMpSegmentation()
79 : TObject(),
80   fMpSegmentations(true),
81   fElCardsMap(true),
82   fSlatMotifMap()
83 {  
84 /// Standard constructor
85
86   AliDebug(1,"");
87   fElCardsMap.SetOwner(true);
88
89   // Create mapping segmentations for all detection elements
90   for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; cath ++ ) { 
91     AliMpDEIterator it;
92     for ( it.First(); ! it.IsDone(); it.Next() ) {
93       CreateMpSegmentation(it.CurrentDEId(), AliMp::GetCathodType(cath));
94     } 
95   }  
96
97   // Fill el cards map for all detection elements
98   // of tracking chambers
99   AliMpDEIterator it;
100   for ( it.First(); ! it.IsDone(); it.Next() ) { 
101     if ( AliMpDEManager::GetStationType(it.CurrentDEId()) != AliMp::kStationTrigger ) {
102       FillElCardsMap(it.CurrentDEId());
103     }
104   }  
105 }
106
107 //______________________________________________________________________________
108 AliMpSegmentation::AliMpSegmentation(TRootIOCtor* /*ioCtor*/)
109 : TObject(),
110   fMpSegmentations(),
111   fElCardsMap(),
112   fSlatMotifMap()
113 {  
114 /// Constructor for IO
115
116   AliDebug(1,"");
117
118   fgInstance = this;
119 }
120
121 //______________________________________________________________________________
122 AliMpSegmentation::~AliMpSegmentation()
123 {
124 /// Destructor
125
126   AliDebug(1,"");
127
128   // Segmentations are deleted with fMpSegmentations 
129   // El cards arrays are deleted with fElCardsMap
130   
131   fgInstance = 0;
132 }
133
134 //
135 // private methods
136 //
137
138 //______________________________________________________________________________
139 AliMpVSegmentation* 
140 AliMpSegmentation::CreateMpSegmentation(Int_t detElemId, AliMp::CathodType cath)
141 {
142 /// Create mapping segmentation for given detElemId and cath
143 /// or return it if it was already built
144
145   // Check detElemId & cath  
146   if ( ! AliMpDEManager::IsValidDetElemId(detElemId, true) ) return 0;
147
148   // If segmentation is already built, just return it
149   //
150   AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
151   TString deSegName = detElement->GetSegName(cath);
152   TObject* object = fMpSegmentations.Get(deSegName);
153   if ( object ) return (AliMpVSegmentation*)object;
154
155   AliDebugStream(3)
156     << "Creating segmentation for detElemId=" << detElemId 
157     << " cath=" << cath << endl;
158   
159   // Read mapping data and create segmentation
160   //
161   AliMp::StationType stationType = detElement->GetStationType();
162   AliMp::PlaneType planeType = detElement->GetPlaneType(cath);
163   TString deTypeName = detElement->GetSegType();
164
165   AliMpVSegmentation* mpSegmentation = 0;
166
167   if ( stationType == AliMp::kStation1 || stationType == AliMp::kStation2 ) {
168     AliMpSectorReader reader(stationType, planeType);
169     AliMpSector* sector = reader.BuildSector();
170     mpSegmentation = new AliMpSectorSegmentation(sector, true);
171   }
172   else if ( stationType == AliMp::kStation345 ) { 
173     AliMpSt345Reader reader(fSlatMotifMap);
174     AliMpSlat* slat = reader.ReadSlat(deTypeName, planeType);
175     mpSegmentation =  new AliMpSlatSegmentation(slat, true);
176   }
177   else if ( stationType == AliMp::kStationTrigger ) {
178     AliMpTriggerReader reader(fSlatMotifMap);
179     AliMpTrigger* trigger = reader.ReadSlat(deTypeName, planeType);
180     mpSegmentation = new AliMpTriggerSegmentation(trigger, true);
181   }
182   else   
183     AliErrorStream() << "Unknown station type" << endl;
184
185   fMpSegmentations.Add(deSegName, mpSegmentation); 
186   
187 //  StdoutToAliDebug(3, fSlatMotifMap.Print(););
188   
189   return mpSegmentation;
190
191
192 //_____________________________________________________________________________
193 AliMpExMap*
194 AliMpSegmentation::FillElCardsMap(Int_t detElemId)
195 {
196 /// Fill the map of electronic cards IDs to segmentations for
197 /// given detElemId
198
199   AliDebugStream(2) << "detElemId=" << detElemId << endl;;
200   
201   AliMpExMap* mde = new AliMpExMap(true);
202   mde->SetOwner(kFALSE);
203   fElCardsMap.Add(detElemId,mde);
204
205   const AliMpVSegmentation* seg[2];
206   TArrayI ecn[2];
207   
208   // Do it in 2 steps to be able to set the AliMpExMap size once for all,
209   // to avoid annoying warning message in case of dynamical resizing.
210   // (not critical).
211   for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++cathode )
212   {
213     seg[cathode] = GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
214     seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]);
215   }
216   
217   mde->SetSize(ecn[0].GetSize()+ecn[1].GetSize());
218   
219   for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++ cathode )
220   {
221     for ( Int_t i = 0; i < ecn[cathode].GetSize(); ++i )
222     {
223       mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode]));
224     }
225   }
226   
227   return mde;
228 }
229
230 //
231 // public methods
232 //
233
234 //______________________________________________________________________________
235 const AliMpVSegmentation* 
236 AliMpSegmentation::GetMpSegmentation(
237                       Int_t detElemId, AliMp::CathodType cath, Bool_t warn) const
238 {
239 /// Return mapping segmentation for given detElemId and cath
240
241   // Check detElemId & cath  
242   if ( ! AliMpDEManager::IsValidDetElemId(detElemId, false) ) {
243     
244     if ( warn ) {
245       AliWarningStream() 
246         << "Invalid detElemId " << detElemId << endl;
247     }   
248     return 0;
249   }  
250
251   // If segmentation is already built, just return it
252   //
253   AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
254   TString deSegName = detElement->GetSegName(cath);
255   TObject* object = fMpSegmentations.Get(deSegName);
256   if ( ! object ) {
257     // Should never happen
258     AliErrorStream() 
259       << "Segmentation for detElemId/cathod " 
260         << detElemId << ", " << cath << " not defined" << endl;
261     return 0;
262   }  
263   
264   return static_cast<AliMpVSegmentation*>(object);
265
266
267 //_____________________________________________________________________________
268 const AliMpVSegmentation* 
269 AliMpSegmentation::GetMpSegmentationByElectronics(
270                       Int_t detElemId, Int_t ecId, Bool_t warn) const
271 {
272 /// Return mapping segmentation for given detElemId and electronic card Id
273 /// (motif position Id)
274
275   AliMpExMap* m = static_cast<AliMpExMap*>(fElCardsMap.GetValue(detElemId));
276   
277   if (!m) {
278     // Should never happen
279     AliErrorStream() 
280       << "Cannot find the el cards map for detElemId " << detElemId << endl;
281     return 0;
282   }  
283
284   TObject* object = m->GetValue(ecId);
285   if ( ! object ) {
286     if ( warn ) {
287       AliErrorStream() 
288         << "Segmentation for electronic card " 
289         << ecId << " not found" << endl;
290     }   
291     return 0;
292   }  
293    
294   return static_cast<AliMpVSegmentation*>(object);
295 }