]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpDEManager.cxx
Input list for testSlatPads.C macro (Laurent)
[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::fgDESegNamesMap(true);
47 AliMpExMap  AliMpDEManager::fgDECathBNBMap(true);
48 TArrayI     AliMpDEManager::fgNofDEPerChamber(AliMpConstants::NofChambers());
49
50 //______________________________________________________________________________
51
52 AliMpDEManager::~AliMpDEManager()
53 {
54 /// Destructor
55 }
56
57 //
58 // static private methods
59 //
60
61 //______________________________________________________________________________
62 Bool_t AliMpDEManager::IsPlaneType(const TString& planeTypeName)
63 {
64 /// Return true if the planeTypeName corresponds to a valid plane type
65
66   if ( planeTypeName == PlaneTypeName(kBendingPlane) ||
67        planeTypeName == PlaneTypeName(kNonBendingPlane) ) 
68     return true;   
69
70   return false;
71 }  
72
73 //______________________________________________________________________________
74 AliMpPlaneType AliMpDEManager::PlaneType(const TString& planeTypeName)
75 {
76 /// Return plane type for the given planeTypeName                            \n
77 /// Fatal error if planeTypeName is wrong 
78
79   if ( planeTypeName == PlaneTypeName(kBendingPlane) ) 
80     return kBendingPlane;
81
82   if ( planeTypeName == PlaneTypeName(kNonBendingPlane) ) 
83     return kNonBendingPlane;
84
85   // Should never reach this line
86   AliFatalClass(Form("No plane type defined for %s", planeTypeName.Data()));
87   return kBendingPlane;
88 }       
89
90 //______________________________________________________________________________
91 AliMpStationType AliMpDEManager::StationType(const TString& stationTypeName)
92 {
93 /// Return station type for the given stationTypeName                        \n
94 /// Fatal error if stationTypeName is wrong 
95
96   if ( stationTypeName == StationTypeName(kStation1) )
97     return kStation1;
98
99   if ( stationTypeName == StationTypeName(kStation2) )
100     return kStation2;
101
102   if ( stationTypeName == StationTypeName(kStation345) )
103     return kStation345;
104
105   if ( stationTypeName == StationTypeName(kStationTrigger) ) 
106     return kStationTrigger;
107
108   // Should never reach this line
109   AliFatalClass(Form("No station type defined for ", stationTypeName.Data()));
110   return kStation1;
111 }
112
113 //______________________________________________________________________________
114 Bool_t
115 AliMpDEManager::ReadDENames(AliMpStationType station)
116
117 /// Read det element names for cath = 0 from the file specified by name
118 /// and fill the map 
119
120   // Open file
121   TString filePath = AliMpFiles::DENamesFilePath(station);
122   std::ifstream in(filePath);
123   if (!in.good()) {
124     AliErrorClassStream() << "Cannot open file " << filePath << endl;;
125     return false;
126   }
127   
128   // Read plane types per cathods
129   //
130   char line[80];
131   TString word;
132   TString cathName1, cathName2;
133   in >> word;
134   while ( ! in.eof() && cathName1.Length() == 0 ) {
135     if ( word[0] == '#' ) 
136       in.getline(line, 80);
137     else { 
138       cathName1 = word;
139       in >> cathName2;
140     }
141     in >> word;
142   }
143   
144   Bool_t isCathNameDefined = false;
145   if ( IsPlaneType(cathName1) &&  IsPlaneType(cathName2) )
146     isCathNameDefined = true;
147     
148   // Read DE names
149   //
150   Int_t detElemId;
151   TString name, name1, name2;
152   AliMpPlaneType planeForCathode[2];
153   
154   while ( ! in.eof() ) 
155   {
156     if ( word[0] == '#' ) 
157     {
158       in.getline(line, 80);
159     }
160     else 
161     {  
162       detElemId = word.Atoi();
163       in >> name;
164       in >> name1;
165       // warning : important to check non bending first (=nbp),
166       // as bp is contained within nbp...
167       if ( name1.Contains(PlaneTypeName(kNonBendingPlane)) )
168       {
169         planeForCathode[0] = kNonBendingPlane;
170       }
171       else
172       {
173         planeForCathode[0] = kBendingPlane;
174       }
175       if ( !isCathNameDefined ) 
176       {       
177         in >> name2;
178         // Other cathode is other plane...
179         if ( planeForCathode[0] == kBendingPlane ) 
180         {
181           planeForCathode[1]=kNonBendingPlane;
182         }
183         else
184         {
185           planeForCathode[1]=kBendingPlane;
186         }
187       }
188       else 
189       {
190         name1 += fgkNameSeparator;
191         name2 = name1;
192         name1 += cathName1;
193         name2 += cathName2;
194         if ( name2.Contains(PlaneTypeName(kNonBendingPlane)) )
195         {
196           planeForCathode[1] = kNonBendingPlane;
197         }
198         else
199         {
200           planeForCathode[1] = kBendingPlane;
201         }        
202       }   
203
204       if ( planeForCathode[0]==planeForCathode[1] )
205       {
206         AliFatalClass(Form("Got the same cathode type for both planes"
207                       " of DetElemId %d",detElemId));
208       }
209       
210       if ( ! fgDENamesMap.GetValue(detElemId) ) 
211       {
212         AliDebugClassStream(3)  
213           << "Adding DE name "  << detElemId << "  " << name << endl;
214         fgDENamesMap.Add(detElemId, new TObjString(name)); 
215       } 
216       else 
217       {
218         AliWarningClassStream()
219           << "DE name "  << detElemId << "  " << name << " already defined." << endl;
220       }   
221
222       if ( ! fgDESegNamesMap.GetValue(detElemId) ) 
223       {
224         AliDebugClassStream(3)  
225         << "Adding DE seg. names  "  << detElemId << "  " << name1 << "  " << name2 << endl;
226         fgDESegNamesMap.Add(detElemId, 
227                          new TPair(new TObjString(name1), new TObjString(name2)));
228         fgDECathBNBMap.Add(detElemId,
229                            new AliMpIntPair(planeForCathode[0],planeForCathode[1]));
230         fgNofDEPerChamber[GetChamberId(detElemId)]++;
231       } 
232       else 
233       {
234         AliWarningClassStream()
235           << "DE seg. names "  << detElemId << "  " << name1 << "  " << name2 
236           << " already defined." << endl;
237       }   
238     } 
239     in >> word;
240   }
241
242   // Close file
243   in.close();
244   
245   return true;
246 }
247
248 //______________________________________________________________________________
249 void AliMpDEManager::FillDENames()
250 {
251 /// Fill DE names from files
252   AliDebugClass(2,"");
253   Bool_t result1 = ReadDENames(kStation1);
254   Bool_t result2 = ReadDENames(kStation2);
255   Bool_t result3 = ReadDENames(kStation345);
256   Bool_t result4 = ReadDENames(kStationTrigger);
257   
258   Bool_t result = result1 && result2 && result3 && result4;
259   if ( ! result ) {
260     AliErrorClassStream() << "Error in reading DE names files" << endl;
261   }  
262 }
263
264 //
265 // static public methods
266 //
267
268 //______________________________________________________________________________
269 Bool_t AliMpDEManager::IsValidDetElemId(Int_t detElemId, Bool_t warn)
270 {
271 /// Return true if detElemId is valid
272 /// (is present in the DE names files)
273
274   if ( fgDENamesMap.GetSize() == 0 ) FillDENames();
275
276   if ( fgDENamesMap.GetValue(detElemId) ) return true;
277
278   if (warn) {
279     AliErrorClassStream() 
280         << "Detection element " << detElemId << " not defined." << endl;
281   }     
282   return false;
283 }    
284
285 //______________________________________________________________________________
286 Bool_t AliMpDEManager::IsValidCathod(Int_t cath, Bool_t warn)
287 {
288 /// Return true if cath is 0 or 1 
289 /// (Better solution would be to use systematically enum)
290
291   if (cath == 0 || cath == 1 ) return true;  
292
293   if (warn)
294     AliErrorClassStream() << "Wrong cathod number " << cath << endl;
295      
296   return false;
297 }    
298
299
300 //______________________________________________________________________________
301 Bool_t AliMpDEManager::IsValid(Int_t detElemId, Int_t cath, Bool_t warn)
302 {
303 /// Return true if both detElemId and cathod number are valid
304
305   return ( IsValidDetElemId(detElemId, warn) && IsValidCathod(cath, warn) );
306 }    
307
308 //______________________________________________________________________________
309 Bool_t AliMpDEManager::IsValidChamberId(Int_t chamberId, Bool_t warn)
310 {
311 /// Return true if chamberId is valid
312
313   if ( chamberId >= 0 && chamberId < AliMpConstants::NofChambers() ) 
314     return true;
315  
316   if (warn) 
317     AliErrorClassStream() << "Wrong chamber Id " << chamberId << endl;
318   
319   return false;
320 }    
321
322 //______________________________________________________________________________
323 Bool_t AliMpDEManager::IsValidGeomModuleId(Int_t moduleId, Bool_t warn)
324 {
325 /// Return true if moduleId is valid
326
327   if ( moduleId >= 0 && moduleId < AliMpConstants::NofGeomModules() ) 
328     return true;
329  
330   if (warn) 
331     AliErrorClassStream() << "Wrong module Id " << moduleId << endl;
332   
333   return false;
334 }    
335
336 //______________________________________________________________________________
337 Int_t 
338 AliMpDEManager::GetCathod(Int_t detElemId, AliMpPlaneType planeType)
339 {
340 /// Return cathod number for given detElemId and planeType
341
342   if ( !IsValidDetElemId(detElemId) ) return -1;
343   AliMpIntPair* pair = 
344     static_cast<AliMpIntPair*>(fgDECathBNBMap.GetValue(detElemId));
345   if ( planeType == pair->GetFirst() )
346   {
347     return 0;
348   }
349   return 1;
350 }
351
352 //______________________________________________________________________________
353 TString AliMpDEManager::GetDEName(Int_t detElemId, Bool_t warn)
354 {
355 /// Return det element name 
356
357   if ( !IsValidDetElemId(detElemId, warn) ) return "undefined";
358
359   TObjString* name = (TObjString*)fgDENamesMap.GetValue(detElemId);
360
361   return name->GetString();
362 }    
363
364 //______________________________________________________________________________
365 TString AliMpDEManager::GetDESegName(Int_t detElemId, Int_t cath, Bool_t warn)
366 {
367 /// Return det element segmentation name (segmentation type + plane type)
368
369   if ( ! IsValid(detElemId, cath, warn) ) return "undefined";
370
371   TPair* namePair = (TPair*)fgDESegNamesMap.GetValue(detElemId);
372
373   if (cath == 0) return ((TObjString*)namePair->Key())->GetString();
374   if (cath == 1) return ((TObjString*)namePair->Value())->GetString();
375   
376   return "undefined";
377 }    
378
379 //______________________________________________________________________________
380 TString AliMpDEManager::GetDETypeName(Int_t detElemId, Int_t cath, Bool_t warn) 
381 {
382 /// Return det element segmentation type
383
384   TString fullName = GetDESegName(detElemId, cath, warn);  
385   
386   // cut plane type extension
387   Ssiz_t pos = fullName.First(fgkNameSeparator);
388   return fullName(0,pos);
389 }    
390
391 //______________________________________________________________________________
392 Int_t  AliMpDEManager::GetChamberId(Int_t detElemId, Bool_t warn)
393 {
394 /// Return chamber Id for given detElemId
395
396   if ( ! IsValidDetElemId(detElemId, warn) ) return -1;
397   
398   return detElemId/fgkCoefficient - 1;
399 }  
400
401 //______________________________________________________________________________
402 Int_t AliMpDEManager::GetGeomModuleId(Int_t detElemId, Bool_t warn)
403 {
404 /// <pre>
405 /// Get module Id from detection element Id                 
406 /// !!! moduleId != chamberId
407 /// Station 1:   Chamber:  1   Module:  0   Det elements:  100-103
408 ///              Chamber:  2   Module:  1   Det elements:  200-203
409 /// Station 2:   Chamber:  3   Module:  2   Det elements:  300-303
410 ///              Chamber:  4   Module:  3   Det elements:  400-403
411 /// Station 3:   Chamber:  5   Module:  4   Det elements:  500-504, 514-517
412 ///                            Module:  5   Det elements:  505-513,
413 ///              Chamber:  6   Module:  6   Det elements:  600-604, 614-617
414 ///                            Module:  7   Det elements:  605-613
415 /// Station 4:   Chamber:  7   Module:  8   Det elements:  700-706, 720-725
416 ///                            Module:  9   Det elements:  707-719
417 ///              Chamber:  8   Module: 10   Det elements:  800-806, 820-825
418 ///                            Module: 11   Det elements:  807-819
419 /// Station 5:   Chamber:  9   Module: 12   Det elements:  900-906, 920-925
420 ///                            Module: 13   Det elements:  907-919        
421 ///              Chamber: 10   Module: 14   Det elements: 1000-1006,1020-1025
422 ///                            Module: 15   Det elements: 1007-1019
423 /// Station 6:   Chamber: 11   Module: 16   Det elements: 1100-1117
424 ///              Chamber: 12   Module: 17   Det elements: 1200-1217
425 /// Station 7:   Chamber: 13   Module: 18   Det elements: 1300-1317
426 ///              Chamber: 14   Module: 19   Det elements: 1400-1417
427 /// </pre>
428
429   if ( ! IsValidDetElemId(detElemId, warn) ) return -1;
430   
431   return detElemId/fgkCoefficient 
432            + (detElemId >=  505 && detElemId <=  513 || detElemId >= 600 )
433            + (detElemId >=  605 && detElemId <=  613 || detElemId >= 700 )
434            + (detElemId >=  707 && detElemId <=  719 || detElemId >= 800 )
435            + (detElemId >=  807 && detElemId <=  819 || detElemId >= 900 )
436            + (detElemId >=  907 && detElemId <=  919 || detElemId >= 1000 )
437            + (detElemId >= 1007 && detElemId <= 1019 || detElemId >= 1100 ) - 1;
438 }  
439
440 //______________________________________________________________________________
441 AliMpPlaneType  AliMpDEManager::GetPlaneType(Int_t detElemId, Int_t cath)
442 {
443 /// Return plane type                                                      \n
444 /// Failure causes Fatal error - as AliMpPlaneType has no possibility
445 /// to return undefined value
446
447   if ( ! IsValid(detElemId, cath, true) ) {
448     AliFatalClass("Cannot return AliMpPlaneType value.");
449     return kBendingPlane;
450   }  
451
452   TPair* namePair = (TPair*)fgDESegNamesMap.GetValue(detElemId);
453
454   TString fullName;  
455   if (cath == 0) fullName = ((TObjString*)namePair->Key())->GetString();
456   if (cath == 1) fullName = ((TObjString*)namePair->Value())->GetString();
457   
458   // Get plane type name
459   Ssiz_t pos = fullName.First(fgkNameSeparator);
460   TString planeTypeName = fullName(pos+1,fullName.Length()-pos);
461   
462   return PlaneType(planeTypeName);
463 }    
464
465 //______________________________________________________________________________
466 AliMpStationType AliMpDEManager::GetStationType(Int_t detElemId)
467 {
468 /// Return station type                                                      \n
469 /// Failure causes Fatal error - as AliMpStationType has no possibility
470 /// to return undefined value
471
472   if ( ! IsValidDetElemId(detElemId, true) ) {
473     AliFatalClass("Cannot return AliMpStationType value.");
474     return kStation1;
475   }  
476   
477   Int_t chamberId = GetChamberId(detElemId, false);
478   if ( ! IsValidChamberId(chamberId, true) ) {
479     AliFatalClass("Cannot return AliMpStationType value.");
480     return kStation1;
481   }  
482   
483   if ( chamberId ==  0 || chamberId ==  1 )  return kStation1;
484   if ( chamberId ==  2 || chamberId ==  3 )  return kStation2;
485   if ( chamberId >=  4 && chamberId <=  9 )  return kStation345;
486   if ( chamberId >= 10 && chamberId <= 13 )  return kStationTrigger;
487
488   // Should never get to this line
489   AliFatalClass("Cannot return AliMpStationType value.");
490   return kStation1;
491 }
492
493 //______________________________________________________________________________
494 Int_t AliMpDEManager::GetNofDEInChamber(Int_t chamberId, Bool_t warn)
495 {
496 /// Return the number of detection elements in the chamber with the given 
497 /// chamberId
498
499   if ( fgDENamesMap.GetSize() == 0 ) FillDENames();
500   if (!IsValidChamberId(chamberId,warn) ) return 0;
501   return fgNofDEPerChamber[chamberId];
502 }
503