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.2 2006/03/02 16:30:09 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>
38 const char AliMpDEManager::fgkNameSeparator = '_';
39 const char AliMpDEManager::fgkCommentPrefix = '#';
40 const Int_t AliMpDEManager::fgkCoefficient = 100;
41 AliMpExMap AliMpDEManager::fgDENamesMap(true);
42 AliMpExMap AliMpDEManager::fgDECathBNBMap(true);
44 ClassImp(AliMpDEManager)
46 //______________________________________________________________________________
47 AliMpDEManager::AliMpDEManager()
50 /// Protected default/standard constructor
53 //______________________________________________________________________________
54 AliMpDEManager::AliMpDEManager(const AliMpDEManager& rhs)
57 /// Protected copy constructor
59 AliFatal("Not implemented.");
62 //______________________________________________________________________________
64 AliMpDEManager::~AliMpDEManager()
69 //______________________________________________________________________________
70 AliMpDEManager& AliMpDEManager::operator=(const AliMpDEManager& rhs)
72 /// Protected assignement operator
74 if (this == &rhs) return *this;
76 AliFatal("Not implemented.");
82 // static private methods
85 //______________________________________________________________________________
86 Bool_t AliMpDEManager::IsPlaneType(const TString& planeTypeName)
88 /// Return true if the planeTypeName corresponds to a valid plane type
90 if ( planeTypeName == PlaneTypeName(kBendingPlane) ||
91 planeTypeName == PlaneTypeName(kNonBendingPlane) )
97 //______________________________________________________________________________
98 AliMpPlaneType AliMpDEManager::PlaneType(const TString& planeTypeName)
100 /// Return plane type for the given planeTypeName \n
101 /// Fatal error if planeTypeName is wrong
103 if ( planeTypeName == PlaneTypeName(kBendingPlane) )
104 return kBendingPlane;
106 if ( planeTypeName == PlaneTypeName(kNonBendingPlane) )
107 return kNonBendingPlane;
109 // Should never reach this line
110 AliFatalClass(Form("No plane type defined for %s", planeTypeName.Data()));
111 return kBendingPlane;
114 //______________________________________________________________________________
115 AliMpStationType AliMpDEManager::StationType(const TString& stationTypeName)
117 /// Return station type for the given stationTypeName \n
118 /// Fatal error if stationTypeName is wrong
120 if ( stationTypeName == StationTypeName(kStation1) )
123 if ( stationTypeName == StationTypeName(kStation2) )
126 if ( stationTypeName == StationTypeName(kStation345) )
129 if ( stationTypeName == StationTypeName(kStationTrigger) )
130 return kStationTrigger;
132 // Should never reach this line
133 AliFatalClass(Form("No station type defined for ", stationTypeName.Data()));
137 //______________________________________________________________________________
139 AliMpDEManager::ReadDENames(AliMpStationType station)
141 /// Read det element names for cath = 0 from the file specified by name
145 TString filePath = AliMpFiles::DENamesFilePath(station);
146 std::ifstream in(filePath);
148 AliErrorClassStream() << "Cannot open file " << filePath << endl;;
152 // Read plane types per cathods
156 TString cathName1, cathName2;
158 while ( ! in.eof() && cathName1.Length() == 0 ) {
159 if ( word[0] == '#' )
160 in.getline(line, 80);
168 Bool_t isCathNameDefined = false;
169 if ( IsPlaneType(cathName1) && IsPlaneType(cathName2) )
170 isCathNameDefined = true;
175 TString name1, name2;
176 AliMpPlaneType planeForCathode[2];
180 if ( word[0] == '#' )
182 in.getline(line, 80);
186 detElemId = word.Atoi();
188 // warning : important to check non bending first (=nbp),
189 // as bp is contained within nbp...
190 if ( name1.Contains(PlaneTypeName(kNonBendingPlane)) )
192 planeForCathode[0] = kNonBendingPlane;
196 planeForCathode[0] = kBendingPlane;
198 if ( !isCathNameDefined )
201 // Other cathode is other plane...
202 if ( planeForCathode[0] == kBendingPlane )
204 planeForCathode[1]=kNonBendingPlane;
208 planeForCathode[1]=kBendingPlane;
213 name1 += fgkNameSeparator;
217 if ( name2.Contains(PlaneTypeName(kNonBendingPlane)) )
219 planeForCathode[1] = kNonBendingPlane;
223 planeForCathode[1] = kBendingPlane;
227 if ( planeForCathode[0]==planeForCathode[1] )
229 AliFatalClass(Form("Got the same cathode type for both planes"
230 " of DetElemId %d",detElemId));
233 if ( ! fgDENamesMap.GetValue(detElemId) )
235 AliDebugClassStream(1)
236 << "Adding " << detElemId << " " << name1 << " " << name2 << endl;
237 fgDENamesMap.Add(detElemId,
238 new TPair(new TObjString(name1), new TObjString(name2)));
239 fgDECathBNBMap.Add(detElemId,
240 new AliMpIntPair(planeForCathode[0],planeForCathode[1]));
252 //______________________________________________________________________________
253 void AliMpDEManager::FillDENames()
255 /// Fill DE names from files
257 Bool_t result1 = ReadDENames(kStation1);
258 Bool_t result2 = ReadDENames(kStation2);
259 Bool_t result3 = ReadDENames(kStation345);
260 Bool_t result4 = ReadDENames(kStationTrigger);
262 Bool_t result = result1 && result2 && result3 && result4;
264 AliErrorClassStream() << "Error in reading DE names files" << endl;
269 // static public methods
272 //______________________________________________________________________________
273 Bool_t AliMpDEManager::IsValidDetElemId(Int_t detElemId, Bool_t warn)
275 /// Return true if detElemId is valid
276 /// (is present in the DE names files)
278 if ( fgDENamesMap.GetSize() == 0 ) FillDENames();
280 if ( fgDENamesMap.GetValue(detElemId) ) return true;
283 AliErrorClassStream()
284 << "Detection element " << detElemId << " not defined." << endl;
289 //______________________________________________________________________________
290 Bool_t AliMpDEManager::IsValidCathod(Int_t cath, Bool_t warn)
292 /// Return true if cath is 0 or 1
293 /// (Better solution would be to use systematically enum)
295 if (cath == 0 || cath == 1 ) return true;
298 AliErrorClassStream() << "Wrong cathod number " << cath << endl;
304 //______________________________________________________________________________
305 Bool_t AliMpDEManager::IsValid(Int_t detElemId, Int_t cath, Bool_t warn)
307 /// Return true if both detElemId and cathod number are valid
309 return ( IsValidDetElemId(detElemId, warn) && IsValidCathod(cath, warn) );
312 //______________________________________________________________________________
313 Bool_t AliMpDEManager::IsValidModuleId(Int_t moduleId, Bool_t warn)
315 /// Return true if moduleId is valid
317 if ( moduleId >= 0 && moduleId < AliMpConstants::NCh() )
321 AliErrorClassStream() << "Wrong module Id " << moduleId << endl;
326 //______________________________________________________________________________
328 AliMpDEManager::GetCathod(Int_t detElemId, AliMpPlaneType planeType)
330 /// Return cathod number for given detElemId and planeType
332 if ( !IsValidDetElemId(detElemId) ) return -1;
334 static_cast<AliMpIntPair*>(fgDECathBNBMap.GetValue(detElemId));
335 if ( planeType == pair->GetFirst() )
342 //______________________________________________________________________________
343 TString AliMpDEManager::GetDEName(Int_t detElemId, Int_t cath, Bool_t warn)
345 /// Return det element type name
347 if ( ! IsValid(detElemId, cath, warn) ) return "undefined";
349 TPair* namePair = (TPair*)fgDENamesMap.GetValue(detElemId);
351 if (cath == 0) return ((TObjString*)namePair->Key())->GetString();
352 if (cath == 1) return ((TObjString*)namePair->Value())->GetString();
357 //______________________________________________________________________________
358 TString AliMpDEManager::GetDETypeName(Int_t detElemId, Int_t cath, Bool_t warn)
360 /// Return det element type name
362 TString fullName = GetDEName(detElemId, cath, warn);
364 // cut plane type extension
365 Ssiz_t pos = fullName.First(fgkNameSeparator);
366 return fullName(0,pos);
369 //______________________________________________________________________________
370 Int_t AliMpDEManager::GetModuleId(Int_t detElemId, Bool_t warn)
372 /// Return module Id for given detElemId
374 if ( ! IsValidDetElemId(detElemId, warn) ) return -1;
376 return detElemId/fgkCoefficient - 1;
379 //______________________________________________________________________________
380 AliMpPlaneType AliMpDEManager::GetPlaneType(Int_t detElemId, Int_t cath)
382 /// Return plane type \n
383 /// Failure causes Fatal error - as AliMpPlaneType has no possibility
384 /// to return undefined value
386 if ( ! IsValid(detElemId, cath, true) ) {
387 AliFatalClass("Cannot return AliMpPlaneType value.");
388 return kBendingPlane;
391 TPair* namePair = (TPair*)fgDENamesMap.GetValue(detElemId);
394 if (cath == 0) fullName = ((TObjString*)namePair->Key())->GetString();
395 if (cath == 1) fullName = ((TObjString*)namePair->Value())->GetString();
397 // Get plane type name
398 Ssiz_t pos = fullName.First(fgkNameSeparator);
399 TString planeTypeName = fullName(pos+1,fullName.Length()-pos);
401 return PlaneType(planeTypeName);
404 //______________________________________________________________________________
405 AliMpStationType AliMpDEManager::GetStationType(Int_t detElemId)
407 /// Return station type \n
408 /// Failure causes Fatal error - as AliMpStationType has no possibility
409 /// to return undefined value
411 if ( ! IsValidDetElemId(detElemId, true) ) {
412 AliFatalClass("Cannot return AliMpStationType value.");
416 Int_t moduleId = GetModuleId(detElemId, false);
417 if ( ! IsValidModuleId(moduleId, true) ) {
418 AliFatalClass("Cannot return AliMpStationType value.");
422 if ( moduleId == 0 || moduleId == 1 ) return kStation1;
423 if ( moduleId == 2 || moduleId == 3 ) return kStation2;
424 if ( moduleId >= 4 && moduleId <= 9 ) return kStation345;
425 if ( moduleId >= 10 && moduleId <= 13 ) return kStationTrigger;
427 // Should never get to this line
428 AliFatalClass("Cannot return AliMpStationType value.");