]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSegmentation.cxx
AliMUONDigitCalibrator
[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
28 #include "AliMpSegmentation.h"
29
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"
45 #include "AliMpSlatMotifMap.h"
46
47
48 #include "AliLog.h"
49
50 #include <Riostream.h>
51 #include <TMap.h>
52 #include <TObjString.h>
53 #include <TSystem.h>
54 #include <TClass.h>
55
56 #include <cassert>
57
58 /// \cond CLASSIMP
59 ClassImp(AliMpSegmentation)
60 /// \endcond
61
62 AliMpSegmentation* AliMpSegmentation::fgInstance = 0;
63
64 //
65 // static methods
66 //
67
68 //______________________________________________________________________________
69 AliMpSegmentation* AliMpSegmentation::Instance(Bool_t warn)
70 {
71 /// Return its instance
72
73   if ( ! fgInstance && warn ) {
74     AliWarningClass("Segmentation has not been loaded");
75   }  
76     
77   return fgInstance;
78 }    
79
80 //______________________________________________________________________________
81 AliMpSegmentation* AliMpSegmentation::ReadData(Bool_t warn)
82 {
83 /// Load the sementation from ASCII data files
84 /// and return its instance
85
86   if ( fgInstance ) {
87     if ( warn )
88       AliWarningClass("Segmentation has been already loaded");
89     return fgInstance;
90   }  
91   
92   AliInfoClass("Reading segmentation from ASCII files.");
93
94   fgInstance = new AliMpSegmentation();
95   return fgInstance;
96 }    
97
98 //
99 // ctors, dtor
100 //
101
102 //______________________________________________________________________________
103 AliMpSegmentation::AliMpSegmentation()
104 : TObject(),
105   fDetElements(0),
106   fMpSegmentations(),
107   fElCardsMap(),
108   fSlatMotifMap(AliMpSlatMotifMap::Instance())
109 {  
110 /// Standard constructor - segmentation is loaded from ASCII data files
111
112   AliDebug(1,"");
113   
114   // Load DE data
115   if ( ! AliMpDEStore::Instance(false) )  
116     AliMpDEStore::ReadData();
117   fDetElements = AliMpDEStore::Instance();  
118
119   // Create mapping segmentations for all detection elements
120   AliMpDEIterator it;
121   for ( it.First(); ! it.IsDone(); it.Next() ) 
122   {
123     Int_t n(0);
124     
125     for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; ++cath ) 
126     { 
127       if ( CreateMpSegmentation(it.CurrentDEId(), AliMp::GetCathodType(cath)) ) ++n;
128     }
129      
130     if ( n == 2 &&  // should always be the case except when we play with the CreateMpSegmentation method...
131         AliMpDEManager::GetStationType(it.CurrentDEId()) != AliMp::kStationTrigger ) // only for tracker
132     {
133         // Fill el cards map for all detection elements
134         // of tracking chambers
135         FillElCardsMap(it.CurrentDEId());
136     }      
137   } 
138 }
139
140 //______________________________________________________________________________
141 AliMpSegmentation::AliMpSegmentation(TRootIOCtor* ioCtor)
142 : TObject(),
143   fDetElements(0),
144   fMpSegmentations(),
145   fElCardsMap(ioCtor),
146   fSlatMotifMap(0)
147 {  
148 /// Constructor for IO
149
150   AliDebug(1,"");
151
152   fgInstance = this;
153 }
154
155 //______________________________________________________________________________
156 AliMpSegmentation::~AliMpSegmentation()
157 {
158 /// Destructor
159
160   AliDebug(1,"");
161
162   delete fDetElements;
163
164   // Segmentations are deleted with fMpSegmentations 
165   // El cards arrays are deleted with fElCardsMap
166   
167   fgInstance = 0;
168 }
169
170 //
171 // private methods
172 //
173
174 //______________________________________________________________________________
175 AliMpVSegmentation* 
176 AliMpSegmentation::CreateMpSegmentation(Int_t detElemId, AliMp::CathodType cath)
177 {
178 /// Create mapping segmentation for given detElemId and cath
179 /// or return it if it was already built
180
181   // Check detElemId & cath  
182   if ( ! AliMpDEManager::IsValidDetElemId(detElemId, true) ) return 0;
183
184   // If segmentation is already built, just return it
185   //
186   AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
187   TString deSegName = detElement->GetSegName(cath);
188   TObject* object = fMpSegmentations.Get(deSegName);
189   if ( object ) return (AliMpVSegmentation*)object;
190
191   AliDebugStream(3)
192     << "Creating segmentation for detElemId=" << detElemId 
193     << " cath=" << cath << endl;
194   
195   // Read mapping data and create segmentation
196   //
197   AliMp::StationType stationType = detElement->GetStationType();
198   AliMp::PlaneType planeType = detElement->GetPlaneType(cath);
199   TString deTypeName = detElement->GetSegType();
200
201   AliMpVSegmentation* mpSegmentation = 0;
202
203   if ( stationType == AliMp::kStation1 || stationType == AliMp::kStation2 ) {
204     AliMpSectorReader reader(stationType, planeType);
205     AliMpSector* sector = reader.BuildSector();
206     mpSegmentation = new AliMpSectorSegmentation(sector, true);
207   }
208   else if ( stationType == AliMp::kStation345 ) { 
209     AliMpSt345Reader reader;
210     AliMpSlat* slat = reader.ReadSlat(deTypeName, planeType);
211     mpSegmentation =  new AliMpSlatSegmentation(slat, true);
212   }
213   else if ( stationType == AliMp::kStationTrigger ) {
214     AliMpTriggerReader reader;
215     AliMpTrigger* trigger = reader.ReadSlat(deTypeName, planeType);
216     mpSegmentation = new AliMpTriggerSegmentation(trigger, true);
217   }
218   else   
219     AliErrorStream() << "Unknown station type" << endl;
220
221   if ( mpSegmentation ) fMpSegmentations.Add(deSegName, mpSegmentation); 
222   
223 //  StdoutToAliDebug(3, fSlatMotifMap.Print(););
224   
225   return mpSegmentation;
226
227
228 //_____________________________________________________________________________
229 AliMpExMap*
230 AliMpSegmentation::FillElCardsMap(Int_t detElemId)
231 {
232 /// Fill the map of electronic cards IDs to segmentations for
233 /// given detElemId
234
235   AliDebugStream(2) << "detElemId=" << detElemId << endl;;
236   
237   AliMpExMap* mde = new AliMpExMap;
238   mde->SetOwner(kFALSE);
239   fElCardsMap.Add(detElemId,mde);
240
241   const AliMpVSegmentation* seg[2];
242   TArrayI ecn[2];
243   
244   for ( Int_t cathode = AliMp::kCath0; cathode <= AliMp::kCath1; ++cathode )
245   {
246     seg[cathode] = GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
247     seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]);
248     for ( Int_t i = 0; i < ecn[cathode].GetSize(); ++i )
249     {
250       mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode]));
251     }
252   }
253   
254   assert( mde->GetSize() > 0 );
255   
256   return mde;
257   
258 }
259
260 //
261 // public methods
262 //
263
264 //______________________________________________________________________________
265 const AliMpVSegmentation* 
266 AliMpSegmentation::GetMpSegmentation(
267                       Int_t detElemId, AliMp::CathodType cath, Bool_t warn) const
268 {
269 /// Return mapping segmentation for given detElemId and cath
270
271   // Check detElemId & cath  
272   if ( ! AliMpDEManager::IsValidDetElemId(detElemId, false) ) {
273     
274     if ( warn ) {
275       AliWarningStream() 
276         << "Invalid detElemId " << detElemId << endl;
277     }   
278     return 0;
279   }  
280
281   // If segmentation is already built, just return it
282   //
283   AliMpDetElement* detElement = AliMpDEManager::GetDetElement(detElemId);
284   TString deSegName = detElement->GetSegName(cath);
285   TObject* object = fMpSegmentations.Get(deSegName);
286   if ( ! object ) {
287     // Should never happen
288     AliErrorStream() 
289       << "Segmentation for detElemId/cathod " 
290         << detElemId << ", " << cath << " not defined" << endl;
291     return 0;
292   }  
293   
294   return static_cast<AliMpVSegmentation*>(object);
295
296
297 //_____________________________________________________________________________
298 const AliMpVSegmentation* 
299 AliMpSegmentation::GetMpSegmentationByElectronics(
300                       Int_t detElemId, Int_t ecId, Bool_t warn) const
301 {
302 /// Return mapping segmentation for given detElemId and electronic card Id
303 /// (motif position Id)
304
305   AliMpExMap* m = static_cast<AliMpExMap*>(fElCardsMap.GetValue(detElemId));
306   
307   if (!m) {
308     // Should never happen
309     AliErrorStream() 
310       << "Cannot find the el cards map for detElemId " << detElemId << endl;
311     return 0;
312   }  
313
314   TObject* object = m->GetValue(ecId);
315   if ( ! object ) {
316     if ( warn ) {
317       AliErrorStream() 
318         << "Segmentation for electronic card " 
319         << ecId << " not found" << endl;
320     }   
321     return 0;
322   }  
323    
324   return static_cast<AliMpVSegmentation*>(object);
325 }