]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpDEManager.cxx
Removing implementation of protected copy constructor &
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpDEManager.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: AliMpDEManager.cxx,v 1.4 2006/05/24 13:58:34 ivana Exp $
18 // Category: management
19 //
20 // Class AliMpDEManager
21 // --------------------
22 // The manager class for definition of detection element types
23 // Authors: Ivana Hrivnacova, IPN Orsay
24 //          Laurent Aphecetche, SUBATECH Nantes
25
26 #include "AliMpDEManager.h"
27 #include "AliMpConstants.h"
28 #include "AliMpFiles.h"
29 #include "AliMpIntPair.h"
30
31 #include "AliLog.h"
32
33 #include <Riostream.h>
34 #include <TSystem.h>
35 #include <TObjString.h>
36 #include <TMap.h>
37
38 /// \cond CLASSIMP
39 ClassImp(AliMpDEManager)
40 /// \endcond
41
42 const char  AliMpDEManager::fgkNameSeparator = '_'; 
43 const char  AliMpDEManager::fgkCommentPrefix = '#'; 
44 const Int_t AliMpDEManager::fgkCoefficient = 100;
45 AliMpExMap  AliMpDEManager::fgDENamesMap(true);
46 AliMpExMap  AliMpDEManager::fgDECathBNBMap(true);
47
48 //______________________________________________________________________________
49
50 AliMpDEManager::~AliMpDEManager()
51 {
52 /// Destructor
53 }
54
55 //
56 // static private methods
57 //
58
59 //______________________________________________________________________________
60 Bool_t AliMpDEManager::IsPlaneType(const TString& planeTypeName)
61 {
62 /// Return true if the planeTypeName corresponds to a valid plane type
63
64   if ( planeTypeName == PlaneTypeName(kBendingPlane) ||
65        planeTypeName == PlaneTypeName(kNonBendingPlane) ) 
66     return true;   
67
68   return false;
69 }  
70
71 //______________________________________________________________________________
72 AliMpPlaneType AliMpDEManager::PlaneType(const TString& planeTypeName)
73 {
74 /// Return plane type for the given planeTypeName                            \n
75 /// Fatal error if planeTypeName is wrong 
76
77   if ( planeTypeName == PlaneTypeName(kBendingPlane) ) 
78     return kBendingPlane;
79
80   if ( planeTypeName == PlaneTypeName(kNonBendingPlane) ) 
81     return kNonBendingPlane;
82
83   // Should never reach this line
84   AliFatalClass(Form("No plane type defined for %s", planeTypeName.Data()));
85   return kBendingPlane;
86 }       
87
88 //______________________________________________________________________________
89 AliMpStationType AliMpDEManager::StationType(const TString& stationTypeName)
90 {
91 /// Return station type for the given stationTypeName                        \n
92 /// Fatal error if stationTypeName is wrong 
93
94   if ( stationTypeName == StationTypeName(kStation1) )
95     return kStation1;
96
97   if ( stationTypeName == StationTypeName(kStation2) )
98     return kStation2;
99
100   if ( stationTypeName == StationTypeName(kStation345) )
101     return kStation345;
102
103   if ( stationTypeName == StationTypeName(kStationTrigger) ) 
104     return kStationTrigger;
105
106   // Should never reach this line
107   AliFatalClass(Form("No station type defined for ", stationTypeName.Data()));
108   return kStation1;
109 }
110
111 //______________________________________________________________________________
112 Bool_t
113 AliMpDEManager::ReadDENames(AliMpStationType station)
114
115 /// Read det element names for cath = 0 from the file specified by name
116 /// and fill the map 
117
118   // Open file
119   TString filePath = AliMpFiles::DENamesFilePath(station);
120   std::ifstream in(filePath);
121   if (!in.good()) {
122     AliErrorClassStream() << "Cannot open file " << filePath << endl;;
123     return false;
124   }
125   
126   // Read plane types per cathods
127   //
128   char line[80];
129   TString word;
130   TString cathName1, cathName2;
131   in >> word;
132   while ( ! in.eof() && cathName1.Length() == 0 ) {
133     if ( word[0] == '#' ) 
134       in.getline(line, 80);
135     else { 
136       cathName1 = word;
137       in >> cathName2;
138     }
139     in >> word;
140   }
141   
142   Bool_t isCathNameDefined = false;
143   if ( IsPlaneType(cathName1) &&  IsPlaneType(cathName2) )
144     isCathNameDefined = true;
145     
146   // Read DE names
147   //
148   Int_t detElemId;
149   TString name1, name2;
150   AliMpPlaneType planeForCathode[2];
151   
152   while ( ! in.eof() ) 
153   {
154     if ( word[0] == '#' ) 
155     {
156       in.getline(line, 80);
157     }
158     else 
159     {  
160       detElemId = word.Atoi();
161       in >> name1;
162       // warning : important to check non bending first (=nbp),
163       // as bp is contained within nbp...
164       if ( name1.Contains(PlaneTypeName(kNonBendingPlane)) )
165       {
166         planeForCathode[0] = kNonBendingPlane;
167       }
168       else
169       {
170         planeForCathode[0] = kBendingPlane;
171       }
172       if ( !isCathNameDefined ) 
173       {       
174         in >> name2;
175         // Other cathode is other plane...
176         if ( planeForCathode[0] == kBendingPlane ) 
177         {
178           planeForCathode[1]=kNonBendingPlane;
179         }
180         else
181         {
182           planeForCathode[1]=kBendingPlane;
183         }
184       }
185       else 
186       {
187         name1 += fgkNameSeparator;
188         name2 = name1;
189         name1 += cathName1;
190         name2 += cathName2;
191         if ( name2.Contains(PlaneTypeName(kNonBendingPlane)) )
192         {
193           planeForCathode[1] = kNonBendingPlane;
194         }
195         else
196         {
197           planeForCathode[1] = kBendingPlane;
198         }        
199       }   
200
201       if ( planeForCathode[0]==planeForCathode[1] )
202       {
203         AliFatalClass(Form("Got the same cathode type for both planes"
204                       " of DetElemId %d",detElemId));
205       }
206       
207       if ( ! fgDENamesMap.GetValue(detElemId) ) 
208       {
209         AliDebugClassStream(1)  
210         << "Adding  "  << detElemId << "  " << name1 << "  " << name2 << endl;
211         fgDENamesMap.Add(detElemId, 
212                          new TPair(new TObjString(name1), new TObjString(name2)));
213         fgDECathBNBMap.Add(detElemId,
214                            new AliMpIntPair(planeForCathode[0],planeForCathode[1]));
215       } 
216     } 
217     in >> word;
218   }
219
220   // Close file
221   in.close();
222   
223   return true;
224 }
225
226 //______________________________________________________________________________
227 void AliMpDEManager::FillDENames()
228 {
229 /// Fill DE names from files
230
231   Bool_t result1 = ReadDENames(kStation1);
232   Bool_t result2 = ReadDENames(kStation2);
233   Bool_t result3 = ReadDENames(kStation345);
234   Bool_t result4 = ReadDENames(kStationTrigger);
235   
236   Bool_t result = result1 && result2 && result3 && result4;
237   if ( ! result ) {
238     AliErrorClassStream() << "Error in reading DE names files" << endl;
239   }  
240 }
241
242 //
243 // static public methods
244 //
245
246 //______________________________________________________________________________
247 Bool_t AliMpDEManager::IsValidDetElemId(Int_t detElemId, Bool_t warn)
248 {
249 /// Return true if detElemId is valid
250 /// (is present in the DE names files)
251
252   if ( fgDENamesMap.GetSize() == 0 ) FillDENames();
253
254   if ( fgDENamesMap.GetValue(detElemId) ) return true;
255
256   if (warn) {
257     AliErrorClassStream() 
258         << "Detection element " << detElemId << " not defined." << endl;
259   }     
260   return false;
261 }    
262
263 //______________________________________________________________________________
264 Bool_t AliMpDEManager::IsValidCathod(Int_t cath, Bool_t warn)
265 {
266 /// Return true if cath is 0 or 1 
267 /// (Better solution would be to use systematically enum)
268
269   if (cath == 0 || cath == 1 ) return true;  
270
271   if (warn)
272     AliErrorClassStream() << "Wrong cathod number " << cath << endl;
273      
274   return false;
275 }    
276
277
278 //______________________________________________________________________________
279 Bool_t AliMpDEManager::IsValid(Int_t detElemId, Int_t cath, Bool_t warn)
280 {
281 /// Return true if both detElemId and cathod number are valid
282
283   return ( IsValidDetElemId(detElemId, warn) && IsValidCathod(cath, warn) );
284 }    
285
286 //______________________________________________________________________________
287 Bool_t AliMpDEManager::IsValidModuleId(Int_t moduleId, Bool_t warn)
288 {
289 /// Return true if moduleId is valid
290
291   if ( moduleId >= 0 && moduleId < AliMpConstants::NCh() ) 
292     return true;
293  
294   if (warn) 
295     AliErrorClassStream() << "Wrong module Id " << moduleId << endl;
296   
297   return false;
298 }    
299
300 //______________________________________________________________________________
301 Int_t 
302 AliMpDEManager::GetCathod(Int_t detElemId, AliMpPlaneType planeType)
303 {
304 /// Return cathod number for given detElemId and planeType
305
306   if ( !IsValidDetElemId(detElemId) ) return -1;
307   AliMpIntPair* pair = 
308     static_cast<AliMpIntPair*>(fgDECathBNBMap.GetValue(detElemId));
309   if ( planeType == pair->GetFirst() )
310   {
311     return 0;
312   }
313   return 1;
314 }
315
316 //______________________________________________________________________________
317 TString AliMpDEManager::GetDEName(Int_t detElemId, Int_t cath, Bool_t warn)
318 {
319 /// Return det element type name
320
321   if ( ! IsValid(detElemId, cath, warn) ) return "undefined";
322
323   TPair* namePair = (TPair*)fgDENamesMap.GetValue(detElemId);
324
325   if (cath == 0) return ((TObjString*)namePair->Key())->GetString();
326   if (cath == 1) return ((TObjString*)namePair->Value())->GetString();
327   
328   return "undefined";
329 }    
330
331 //______________________________________________________________________________
332 TString AliMpDEManager::GetDETypeName(Int_t detElemId, Int_t cath, Bool_t warn) 
333 {
334 /// Return det element type name
335
336   TString fullName = GetDEName(detElemId, cath, warn);  
337   
338   // cut plane type extension
339   Ssiz_t pos = fullName.First(fgkNameSeparator);
340   return fullName(0,pos);
341 }    
342
343 //______________________________________________________________________________
344 Int_t  AliMpDEManager::GetModuleId(Int_t detElemId, Bool_t warn)
345 {
346 /// Return module Id for given detElemId
347
348   if ( ! IsValidDetElemId(detElemId, warn) ) return -1;
349   
350   return detElemId/fgkCoefficient - 1;
351 }  
352
353 //______________________________________________________________________________
354 AliMpPlaneType  AliMpDEManager::GetPlaneType(Int_t detElemId, Int_t cath)
355 {
356 /// Return plane type                                                      \n
357 /// Failure causes Fatal error - as AliMpPlaneType has no possibility
358 /// to return undefined value
359
360   if ( ! IsValid(detElemId, cath, true) ) {
361     AliFatalClass("Cannot return AliMpPlaneType value.");
362     return kBendingPlane;
363   }  
364
365   TPair* namePair = (TPair*)fgDENamesMap.GetValue(detElemId);
366
367   TString fullName;  
368   if (cath == 0) fullName = ((TObjString*)namePair->Key())->GetString();
369   if (cath == 1) fullName = ((TObjString*)namePair->Value())->GetString();
370   
371   // Get plane type name
372   Ssiz_t pos = fullName.First(fgkNameSeparator);
373   TString planeTypeName = fullName(pos+1,fullName.Length()-pos);
374   
375   return PlaneType(planeTypeName);
376 }    
377
378 //______________________________________________________________________________
379 AliMpStationType AliMpDEManager::GetStationType(Int_t detElemId)
380 {
381 /// Return station type                                                      \n
382 /// Failure causes Fatal error - as AliMpStationType has no possibility
383 /// to return undefined value
384
385   if ( ! IsValidDetElemId(detElemId, true) ) {
386     AliFatalClass("Cannot return AliMpStationType value.");
387     return kStation1;
388   }  
389   
390   Int_t moduleId = GetModuleId(detElemId, false);
391   if ( ! IsValidModuleId(moduleId, true) ) {
392     AliFatalClass("Cannot return AliMpStationType value.");
393     return kStation1;
394   }  
395   
396   if ( moduleId ==  0 || moduleId ==  1 )  return kStation1;
397   if ( moduleId ==  2 || moduleId ==  3 )  return kStation2;
398   if ( moduleId >=  4 && moduleId <=  9 )  return kStation345;
399   if ( moduleId >= 10 && moduleId <= 13 )  return kStationTrigger;
400
401   // Should never get to this line
402   AliFatalClass("Cannot return AliMpStationType value.");
403   return kStation1;
404 }
405