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::fgDECathBNBMap(true);
48 //______________________________________________________________________________
50 AliMpDEManager::~AliMpDEManager()
56 // static private methods
59 //______________________________________________________________________________
60 Bool_t AliMpDEManager::IsPlaneType(const TString& planeTypeName)
62 /// Return true if the planeTypeName corresponds to a valid plane type
64 if ( planeTypeName == PlaneTypeName(kBendingPlane) ||
65 planeTypeName == PlaneTypeName(kNonBendingPlane) )
71 //______________________________________________________________________________
72 AliMpPlaneType AliMpDEManager::PlaneType(const TString& planeTypeName)
74 /// Return plane type for the given planeTypeName \n
75 /// Fatal error if planeTypeName is wrong
77 if ( planeTypeName == PlaneTypeName(kBendingPlane) )
80 if ( planeTypeName == PlaneTypeName(kNonBendingPlane) )
81 return kNonBendingPlane;
83 // Should never reach this line
84 AliFatalClass(Form("No plane type defined for %s", planeTypeName.Data()));
88 //______________________________________________________________________________
89 AliMpStationType AliMpDEManager::StationType(const TString& stationTypeName)
91 /// Return station type for the given stationTypeName \n
92 /// Fatal error if stationTypeName is wrong
94 if ( stationTypeName == StationTypeName(kStation1) )
97 if ( stationTypeName == StationTypeName(kStation2) )
100 if ( stationTypeName == StationTypeName(kStation345) )
103 if ( stationTypeName == StationTypeName(kStationTrigger) )
104 return kStationTrigger;
106 // Should never reach this line
107 AliFatalClass(Form("No station type defined for ", stationTypeName.Data()));
111 //______________________________________________________________________________
113 AliMpDEManager::ReadDENames(AliMpStationType station)
115 /// Read det element names for cath = 0 from the file specified by name
119 TString filePath = AliMpFiles::DENamesFilePath(station);
120 std::ifstream in(filePath);
122 AliErrorClassStream() << "Cannot open file " << filePath << endl;;
126 // Read plane types per cathods
130 TString cathName1, cathName2;
132 while ( ! in.eof() && cathName1.Length() == 0 ) {
133 if ( word[0] == '#' )
134 in.getline(line, 80);
142 Bool_t isCathNameDefined = false;
143 if ( IsPlaneType(cathName1) && IsPlaneType(cathName2) )
144 isCathNameDefined = true;
149 TString name1, name2;
150 AliMpPlaneType planeForCathode[2];
154 if ( word[0] == '#' )
156 in.getline(line, 80);
160 detElemId = word.Atoi();
162 // warning : important to check non bending first (=nbp),
163 // as bp is contained within nbp...
164 if ( name1.Contains(PlaneTypeName(kNonBendingPlane)) )
166 planeForCathode[0] = kNonBendingPlane;
170 planeForCathode[0] = kBendingPlane;
172 if ( !isCathNameDefined )
175 // Other cathode is other plane...
176 if ( planeForCathode[0] == kBendingPlane )
178 planeForCathode[1]=kNonBendingPlane;
182 planeForCathode[1]=kBendingPlane;
187 name1 += fgkNameSeparator;
191 if ( name2.Contains(PlaneTypeName(kNonBendingPlane)) )
193 planeForCathode[1] = kNonBendingPlane;
197 planeForCathode[1] = kBendingPlane;
201 if ( planeForCathode[0]==planeForCathode[1] )
203 AliFatalClass(Form("Got the same cathode type for both planes"
204 " of DetElemId %d",detElemId));
207 if ( ! fgDENamesMap.GetValue(detElemId) )
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]));
226 //______________________________________________________________________________
227 void AliMpDEManager::FillDENames()
229 /// Fill DE names from files
231 Bool_t result1 = ReadDENames(kStation1);
232 Bool_t result2 = ReadDENames(kStation2);
233 Bool_t result3 = ReadDENames(kStation345);
234 Bool_t result4 = ReadDENames(kStationTrigger);
236 Bool_t result = result1 && result2 && result3 && result4;
238 AliErrorClassStream() << "Error in reading DE names files" << endl;
243 // static public methods
246 //______________________________________________________________________________
247 Bool_t AliMpDEManager::IsValidDetElemId(Int_t detElemId, Bool_t warn)
249 /// Return true if detElemId is valid
250 /// (is present in the DE names files)
252 if ( fgDENamesMap.GetSize() == 0 ) FillDENames();
254 if ( fgDENamesMap.GetValue(detElemId) ) return true;
257 AliErrorClassStream()
258 << "Detection element " << detElemId << " not defined." << endl;
263 //______________________________________________________________________________
264 Bool_t AliMpDEManager::IsValidCathod(Int_t cath, Bool_t warn)
266 /// Return true if cath is 0 or 1
267 /// (Better solution would be to use systematically enum)
269 if (cath == 0 || cath == 1 ) return true;
272 AliErrorClassStream() << "Wrong cathod number " << cath << endl;
278 //______________________________________________________________________________
279 Bool_t AliMpDEManager::IsValid(Int_t detElemId, Int_t cath, Bool_t warn)
281 /// Return true if both detElemId and cathod number are valid
283 return ( IsValidDetElemId(detElemId, warn) && IsValidCathod(cath, warn) );
286 //______________________________________________________________________________
287 Bool_t AliMpDEManager::IsValidModuleId(Int_t moduleId, Bool_t warn)
289 /// Return true if moduleId is valid
291 if ( moduleId >= 0 && moduleId < AliMpConstants::NCh() )
295 AliErrorClassStream() << "Wrong module Id " << moduleId << endl;
300 //______________________________________________________________________________
302 AliMpDEManager::GetCathod(Int_t detElemId, AliMpPlaneType planeType)
304 /// Return cathod number for given detElemId and planeType
306 if ( !IsValidDetElemId(detElemId) ) return -1;
308 static_cast<AliMpIntPair*>(fgDECathBNBMap.GetValue(detElemId));
309 if ( planeType == pair->GetFirst() )
316 //______________________________________________________________________________
317 TString AliMpDEManager::GetDEName(Int_t detElemId, Int_t cath, Bool_t warn)
319 /// Return det element type name
321 if ( ! IsValid(detElemId, cath, warn) ) return "undefined";
323 TPair* namePair = (TPair*)fgDENamesMap.GetValue(detElemId);
325 if (cath == 0) return ((TObjString*)namePair->Key())->GetString();
326 if (cath == 1) return ((TObjString*)namePair->Value())->GetString();
331 //______________________________________________________________________________
332 TString AliMpDEManager::GetDETypeName(Int_t detElemId, Int_t cath, Bool_t warn)
334 /// Return det element type name
336 TString fullName = GetDEName(detElemId, cath, warn);
338 // cut plane type extension
339 Ssiz_t pos = fullName.First(fgkNameSeparator);
340 return fullName(0,pos);
343 //______________________________________________________________________________
344 Int_t AliMpDEManager::GetModuleId(Int_t detElemId, Bool_t warn)
346 /// Return module Id for given detElemId
348 if ( ! IsValidDetElemId(detElemId, warn) ) return -1;
350 return detElemId/fgkCoefficient - 1;
353 //______________________________________________________________________________
354 AliMpPlaneType AliMpDEManager::GetPlaneType(Int_t detElemId, Int_t cath)
356 /// Return plane type \n
357 /// Failure causes Fatal error - as AliMpPlaneType has no possibility
358 /// to return undefined value
360 if ( ! IsValid(detElemId, cath, true) ) {
361 AliFatalClass("Cannot return AliMpPlaneType value.");
362 return kBendingPlane;
365 TPair* namePair = (TPair*)fgDENamesMap.GetValue(detElemId);
368 if (cath == 0) fullName = ((TObjString*)namePair->Key())->GetString();
369 if (cath == 1) fullName = ((TObjString*)namePair->Value())->GetString();
371 // Get plane type name
372 Ssiz_t pos = fullName.First(fgkNameSeparator);
373 TString planeTypeName = fullName(pos+1,fullName.Length()-pos);
375 return PlaneType(planeTypeName);
378 //______________________________________________________________________________
379 AliMpStationType AliMpDEManager::GetStationType(Int_t detElemId)
381 /// Return station type \n
382 /// Failure causes Fatal error - as AliMpStationType has no possibility
383 /// to return undefined value
385 if ( ! IsValidDetElemId(detElemId, true) ) {
386 AliFatalClass("Cannot return AliMpStationType value.");
390 Int_t moduleId = GetModuleId(detElemId, false);
391 if ( ! IsValidModuleId(moduleId, true) ) {
392 AliFatalClass("Cannot return AliMpStationType value.");
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;
401 // Should never get to this line
402 AliFatalClass("Cannot return AliMpStationType value.");