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