1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpDEManager.cxx,v 1.4 2006/05/24 13:58:34 ivana Exp $
18 // Category: management
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
26 #include "AliMpDEManager.h"
27 #include "AliMpConstants.h"
28 #include "AliMpFiles.h"
29 #include "AliMpIntPair.h"
33 #include <Riostream.h>
35 #include <TObjString.h>
39 ClassImp(AliMpDEManager)
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());
50 //______________________________________________________________________________
52 AliMpDEManager::~AliMpDEManager()
58 // static private methods
61 //______________________________________________________________________________
62 Bool_t AliMpDEManager::IsPlaneType(const TString& planeTypeName)
64 /// Return true if the planeTypeName corresponds to a valid plane type
66 if ( planeTypeName == PlaneTypeName(kBendingPlane) ||
67 planeTypeName == PlaneTypeName(kNonBendingPlane) )
73 //______________________________________________________________________________
74 AliMpPlaneType AliMpDEManager::PlaneType(const TString& planeTypeName)
76 /// Return plane type for the given planeTypeName \n
77 /// Fatal error if planeTypeName is wrong
79 if ( planeTypeName == PlaneTypeName(kBendingPlane) )
82 if ( planeTypeName == PlaneTypeName(kNonBendingPlane) )
83 return kNonBendingPlane;
85 // Should never reach this line
86 AliFatalClass(Form("No plane type defined for %s", planeTypeName.Data()));
90 //______________________________________________________________________________
91 AliMpStationType AliMpDEManager::StationType(const TString& stationTypeName)
93 /// Return station type for the given stationTypeName \n
94 /// Fatal error if stationTypeName is wrong
96 if ( stationTypeName == StationTypeName(kStation1) )
99 if ( stationTypeName == StationTypeName(kStation2) )
102 if ( stationTypeName == StationTypeName(kStation345) )
105 if ( stationTypeName == StationTypeName(kStationTrigger) )
106 return kStationTrigger;
108 // Should never reach this line
109 AliFatalClass(Form("No station type defined for ", stationTypeName.Data()));
113 //______________________________________________________________________________
115 AliMpDEManager::ReadDENames(AliMpStationType station)
117 /// Read det element names for cath = 0 from the file specified by name
121 TString filePath = AliMpFiles::DENamesFilePath(station);
122 std::ifstream in(filePath);
124 AliErrorClassStream() << "Cannot open file " << filePath << endl;;
128 // Read plane types per cathods
132 TString cathName1, cathName2;
134 while ( ! in.eof() && cathName1.Length() == 0 ) {
135 if ( word[0] == '#' )
136 in.getline(line, 80);
144 Bool_t isCathNameDefined = false;
145 if ( IsPlaneType(cathName1) && IsPlaneType(cathName2) )
146 isCathNameDefined = true;
151 TString name, name1, name2;
152 AliMpPlaneType planeForCathode[2];
156 if ( word[0] == '#' )
158 in.getline(line, 80);
162 detElemId = word.Atoi();
165 // warning : important to check non bending first (=nbp),
166 // as bp is contained within nbp...
167 if ( name1.Contains(PlaneTypeName(kNonBendingPlane)) )
169 planeForCathode[0] = kNonBendingPlane;
173 planeForCathode[0] = kBendingPlane;
175 if ( !isCathNameDefined )
178 // Other cathode is other plane...
179 if ( planeForCathode[0] == kBendingPlane )
181 planeForCathode[1]=kNonBendingPlane;
185 planeForCathode[1]=kBendingPlane;
190 name1 += fgkNameSeparator;
194 if ( name2.Contains(PlaneTypeName(kNonBendingPlane)) )
196 planeForCathode[1] = kNonBendingPlane;
200 planeForCathode[1] = kBendingPlane;
204 if ( planeForCathode[0]==planeForCathode[1] )
206 AliFatalClass(Form("Got the same cathode type for both planes"
207 " of DetElemId %d",detElemId));
210 if ( ! fgDENamesMap.GetValue(detElemId) )
212 AliDebugClassStream(3)
213 << "Adding DE name " << detElemId << " " << name << endl;
214 fgDENamesMap.Add(detElemId, new TObjString(name));
218 AliWarningClassStream()
219 << "DE name " << detElemId << " " << name << " already defined." << endl;
222 if ( ! fgDESegNamesMap.GetValue(detElemId) )
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)]++;
234 AliWarningClassStream()
235 << "DE seg. names " << detElemId << " " << name1 << " " << name2
236 << " already defined." << endl;
248 //______________________________________________________________________________
249 void AliMpDEManager::FillDENames()
251 /// Fill DE names from files
253 Bool_t result1 = ReadDENames(kStation1);
254 Bool_t result2 = ReadDENames(kStation2);
255 Bool_t result3 = ReadDENames(kStation345);
256 Bool_t result4 = ReadDENames(kStationTrigger);
258 Bool_t result = result1 && result2 && result3 && result4;
260 AliErrorClassStream() << "Error in reading DE names files" << endl;
265 // static public methods
268 //______________________________________________________________________________
269 Bool_t AliMpDEManager::IsValidDetElemId(Int_t detElemId, Bool_t warn)
271 /// Return true if detElemId is valid
272 /// (is present in the DE names files)
274 if ( fgDENamesMap.GetSize() == 0 ) FillDENames();
276 if ( fgDENamesMap.GetValue(detElemId) ) return true;
279 AliErrorClassStream()
280 << "Detection element " << detElemId << " not defined." << endl;
285 //______________________________________________________________________________
286 Bool_t AliMpDEManager::IsValidCathod(Int_t cath, Bool_t warn)
288 /// Return true if cath is 0 or 1
289 /// (Better solution would be to use systematically enum)
291 if (cath == 0 || cath == 1 ) return true;
294 AliErrorClassStream() << "Wrong cathod number " << cath << endl;
300 //______________________________________________________________________________
301 Bool_t AliMpDEManager::IsValid(Int_t detElemId, Int_t cath, Bool_t warn)
303 /// Return true if both detElemId and cathod number are valid
305 return ( IsValidDetElemId(detElemId, warn) && IsValidCathod(cath, warn) );
308 //______________________________________________________________________________
309 Bool_t AliMpDEManager::IsValidChamberId(Int_t chamberId, Bool_t warn)
311 /// Return true if chamberId is valid
313 if ( chamberId >= 0 && chamberId < AliMpConstants::NofChambers() )
317 AliErrorClassStream() << "Wrong chamber Id " << chamberId << endl;
322 //______________________________________________________________________________
323 Bool_t AliMpDEManager::IsValidGeomModuleId(Int_t moduleId, Bool_t warn)
325 /// Return true if moduleId is valid
327 if ( moduleId >= 0 && moduleId < AliMpConstants::NofGeomModules() )
331 AliErrorClassStream() << "Wrong module Id " << moduleId << endl;
336 //______________________________________________________________________________
338 AliMpDEManager::GetCathod(Int_t detElemId, AliMpPlaneType planeType)
340 /// Return cathod number for given detElemId and planeType
342 if ( !IsValidDetElemId(detElemId) ) return -1;
344 static_cast<AliMpIntPair*>(fgDECathBNBMap.GetValue(detElemId));
345 if ( planeType == pair->GetFirst() )
352 //______________________________________________________________________________
353 TString AliMpDEManager::GetDEName(Int_t detElemId, Bool_t warn)
355 /// Return det element name
357 if ( !IsValidDetElemId(detElemId, warn) ) return "undefined";
359 TObjString* name = (TObjString*)fgDENamesMap.GetValue(detElemId);
361 return name->GetString();
364 //______________________________________________________________________________
365 TString AliMpDEManager::GetDESegName(Int_t detElemId, Int_t cath, Bool_t warn)
367 /// Return det element segmentation name (segmentation type + plane type)
369 if ( ! IsValid(detElemId, cath, warn) ) return "undefined";
371 TPair* namePair = (TPair*)fgDESegNamesMap.GetValue(detElemId);
373 if (cath == 0) return ((TObjString*)namePair->Key())->GetString();
374 if (cath == 1) return ((TObjString*)namePair->Value())->GetString();
379 //______________________________________________________________________________
380 TString AliMpDEManager::GetDETypeName(Int_t detElemId, Int_t cath, Bool_t warn)
382 /// Return det element segmentation type
384 TString fullName = GetDESegName(detElemId, cath, warn);
386 // cut plane type extension
387 Ssiz_t pos = fullName.First(fgkNameSeparator);
388 return fullName(0,pos);
391 //______________________________________________________________________________
392 Int_t AliMpDEManager::GetChamberId(Int_t detElemId, Bool_t warn)
394 /// Return chamber Id for given detElemId
396 if ( ! IsValidDetElemId(detElemId, warn) ) return -1;
398 return detElemId/fgkCoefficient - 1;
401 //______________________________________________________________________________
402 Int_t AliMpDEManager::GetGeomModuleId(Int_t detElemId, Bool_t warn)
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
429 if ( ! IsValidDetElemId(detElemId, warn) ) return -1;
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;
440 //______________________________________________________________________________
441 AliMpPlaneType AliMpDEManager::GetPlaneType(Int_t detElemId, Int_t cath)
443 /// Return plane type \n
444 /// Failure causes Fatal error - as AliMpPlaneType has no possibility
445 /// to return undefined value
447 if ( ! IsValid(detElemId, cath, true) ) {
448 AliFatalClass("Cannot return AliMpPlaneType value.");
449 return kBendingPlane;
452 TPair* namePair = (TPair*)fgDESegNamesMap.GetValue(detElemId);
455 if (cath == 0) fullName = ((TObjString*)namePair->Key())->GetString();
456 if (cath == 1) fullName = ((TObjString*)namePair->Value())->GetString();
458 // Get plane type name
459 Ssiz_t pos = fullName.First(fgkNameSeparator);
460 TString planeTypeName = fullName(pos+1,fullName.Length()-pos);
462 return PlaneType(planeTypeName);
465 //______________________________________________________________________________
466 AliMpStationType AliMpDEManager::GetStationType(Int_t detElemId)
468 /// Return station type \n
469 /// Failure causes Fatal error - as AliMpStationType has no possibility
470 /// to return undefined value
472 if ( ! IsValidDetElemId(detElemId, true) ) {
473 AliFatalClass("Cannot return AliMpStationType value.");
477 Int_t chamberId = GetChamberId(detElemId, false);
478 if ( ! IsValidChamberId(chamberId, true) ) {
479 AliFatalClass("Cannot return AliMpStationType value.");
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;
488 // Should never get to this line
489 AliFatalClass("Cannot return AliMpStationType value.");
493 //______________________________________________________________________________
494 Int_t AliMpDEManager::GetNofDEInChamber(Int_t chamberId, Bool_t warn)
496 /// Return the number of detection elements in the chamber with the given
499 if ( fgDENamesMap.GetSize() == 0 ) FillDENames();
500 if (!IsValidChamberId(chamberId,warn) ) return 0;
501 return fgNofDEPerChamber[chamberId];