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