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.1 2006/01/11 10:24:44 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"
32 #include <Riostream.h>
34 #include <TObjString.h>
37 ClassImp(AliMpDEManager)
39 const char AliMpDEManager::fgkNameSeparator = '_';
40 const char AliMpDEManager::fgkCommentPrefix = '#';
41 const Int_t AliMpDEManager::fgkCoefficient = 100;
42 AliMpExMap AliMpDEManager::fgDENamesMap = AliMpExMap(true);
44 //______________________________________________________________________________
45 AliMpDEManager::AliMpDEManager()
48 /// Protected default/standard constructor
51 //______________________________________________________________________________
52 AliMpDEManager::AliMpDEManager(const AliMpDEManager& rhs)
55 /// Protected copy constructor
57 AliFatal("Not implemented.");
60 //______________________________________________________________________________
62 AliMpDEManager::~AliMpDEManager()
67 //______________________________________________________________________________
68 AliMpDEManager& AliMpDEManager::operator=(const AliMpDEManager& rhs)
70 /// Protected assignement operator
72 if (this == &rhs) return *this;
74 AliFatal("Not implemented.");
80 // static private methods
83 //______________________________________________________________________________
84 Bool_t AliMpDEManager::IsPlaneType(const TString& planeTypeName)
86 /// Return true if the planeTypeName corresponds to a valid plane type
88 if ( planeTypeName == PlaneTypeName(kBendingPlane) ||
89 planeTypeName == PlaneTypeName(kNonBendingPlane) )
95 //______________________________________________________________________________
96 AliMpPlaneType AliMpDEManager::PlaneType(const TString& planeTypeName)
98 /// Return plane type for the given planeTypeName \n
99 /// Fatal error if planeTypeName is wrong
101 if ( planeTypeName == PlaneTypeName(kBendingPlane) )
102 return kBendingPlane;
104 if ( planeTypeName == PlaneTypeName(kNonBendingPlane) )
105 return kNonBendingPlane;
107 // Should never reach this line
108 AliFatalClass(Form("No plane type defined for %s", planeTypeName.Data()));
109 return kBendingPlane;
112 //______________________________________________________________________________
113 AliMpStationType AliMpDEManager::StationType(const TString& stationTypeName)
115 /// Return station type for the given stationTypeName \n
116 /// Fatal error if stationTypeName is wrong
118 if ( stationTypeName == StationTypeName(kStation1) )
121 if ( stationTypeName == StationTypeName(kStation2) )
124 if ( stationTypeName == StationTypeName(kStation345) )
127 if ( stationTypeName == StationTypeName(kStationTrigger) )
128 return kStationTrigger;
130 // Should never reach this line
131 AliFatalClass(Form("No station type defined for ", stationTypeName.Data()));
135 //______________________________________________________________________________
137 AliMpDEManager::ReadDENames(AliMpStationType station)
139 /// Read det element names for cath = 0 from the file specified by name
143 TString filePath = AliMpFiles::DENamesFilePath(station);
144 std::ifstream in(filePath);
146 AliErrorClassStream() << "Cannot open file " << filePath << endl;;
150 // Read plane types per cathods
154 TString cathName1, cathName2;
156 while ( ! in.eof() && cathName1.Length() == 0 ) {
157 if ( word[0] == '#' )
158 in.getline(line, 80);
166 Bool_t isCathNameDefined = false;
167 if ( IsPlaneType(cathName1) && IsPlaneType(cathName2) )
168 isCathNameDefined = true;
173 TString name1, name2;
174 while ( ! in.eof() ) {
175 if ( word[0] == '#' )
176 in.getline(line, 80);
178 detElemId = word.Atoi();
180 if ( ! isCathNameDefined )
183 name1 += fgkNameSeparator;
189 if ( ! fgDENamesMap.GetValue(detElemId) ) {
190 AliDebugClassStream(1)
191 << "Adding " << detElemId << " " << name1 << " " << name2 << endl;
192 fgDENamesMap.Add(detElemId,
193 new TPair(new TObjString(name1), new TObjString(name2)));
205 //______________________________________________________________________________
206 void AliMpDEManager::FillDENames()
208 /// Fill DE names from files
210 Bool_t result1 = ReadDENames(kStation1);
211 Bool_t result2 = ReadDENames(kStation2);
212 Bool_t result3 = ReadDENames(kStation345);
213 Bool_t result4 = ReadDENames(kStationTrigger);
215 Bool_t result = result1 && result2 && result3 && result4;
217 AliErrorClassStream() << "Error in reading DE names files" << endl;
222 // static public methods
225 //______________________________________________________________________________
226 Bool_t AliMpDEManager::IsValidDetElemId(Int_t detElemId, Bool_t warn)
228 /// Return true if detElemId is valid
229 /// (is present in the DE names files)
231 if ( fgDENamesMap.GetSize() == 0 ) FillDENames();
233 if ( fgDENamesMap.GetValue(detElemId) ) return true;
236 AliErrorClassStream()
237 << "Detection element " << detElemId << " not defined." << endl;
242 //______________________________________________________________________________
243 Bool_t AliMpDEManager::IsValidCathod(Int_t cath, Bool_t warn)
245 /// Return true if cath is 0 or 1
246 /// (Better solution would be to use systematically enum)
248 if (cath == 0 || cath == 1 ) return true;
251 AliErrorClassStream() << "Wrong cathod number " << cath << endl;
257 //______________________________________________________________________________
258 Bool_t AliMpDEManager::IsValid(Int_t detElemId, Int_t cath, Bool_t warn)
260 /// Return true if both detElemId and cathod number are valid
262 return ( IsValidDetElemId(detElemId, warn) && IsValidCathod(cath, warn) );
265 //______________________________________________________________________________
266 Bool_t AliMpDEManager::IsValidModuleId(Int_t moduleId, Bool_t warn)
268 /// Return true if moduleId is valid
270 if ( moduleId >= 0 && moduleId < AliMpConstants::NCh() )
274 AliErrorClassStream() << "Wrong module Id " << moduleId << endl;
279 //______________________________________________________________________________
280 TString AliMpDEManager::GetDEName(Int_t detElemId, Int_t cath, Bool_t warn)
282 /// Return det element type name
284 if ( ! IsValid(detElemId, cath, warn) ) return "undefined";
286 TPair* namePair = (TPair*)fgDENamesMap.GetValue(detElemId);
288 if (cath == 0) return ((TObjString*)namePair->Key())->GetString();
289 if (cath == 1) return ((TObjString*)namePair->Value())->GetString();
294 //______________________________________________________________________________
295 TString AliMpDEManager::GetDETypeName(Int_t detElemId, Int_t cath, Bool_t warn)
297 /// Return det element type name
299 TString fullName = GetDEName(detElemId, cath, warn);
301 // cut plane type extension
302 Ssiz_t pos = fullName.First(fgkNameSeparator);
303 return fullName(0,pos);
306 //______________________________________________________________________________
307 Int_t AliMpDEManager::GetModuleId(Int_t detElemId, Bool_t warn)
309 /// Return module Id for given detElemId
311 if ( ! IsValidDetElemId(detElemId, warn) ) return -1;
313 return detElemId/fgkCoefficient - 1;
316 //______________________________________________________________________________
317 AliMpPlaneType AliMpDEManager::GetPlaneType(Int_t detElemId, Int_t cath)
319 /// Return plane type \n
320 /// Failure causes Fatal error - as AliMpPlaneType has no possibility
321 /// to return undefined value
323 if ( ! IsValid(detElemId, cath, true) ) {
324 AliFatalClass("Cannot return AliMpPlaneType value.");
325 return kBendingPlane;
328 TPair* namePair = (TPair*)fgDENamesMap.GetValue(detElemId);
331 if (cath == 0) fullName = ((TObjString*)namePair->Key())->GetString();
332 if (cath == 1) fullName = ((TObjString*)namePair->Value())->GetString();
334 // Get plane type name
335 Ssiz_t pos = fullName.First(fgkNameSeparator);
336 TString planeTypeName = fullName(pos+1,fullName.Length()-pos);
338 return PlaneType(planeTypeName);
341 //______________________________________________________________________________
342 AliMpStationType AliMpDEManager::GetStationType(Int_t detElemId)
344 /// Return station type \n
345 /// Failure causes Fatal error - as AliMpStationType has no possibility
346 /// to return undefined value
348 if ( ! IsValidDetElemId(detElemId, true) ) {
349 AliFatalClass("Cannot return AliMpStationType value.");
353 Int_t moduleId = GetModuleId(detElemId, false);
354 if ( ! IsValidModuleId(moduleId, true) ) {
355 AliFatalClass("Cannot return AliMpStationType value.");
359 if ( moduleId == 0 || moduleId == 1 ) return kStation1;
360 if ( moduleId == 2 || moduleId == 3 ) return kStation2;
361 if ( moduleId >= 4 && moduleId <= 9 ) return kStation345;
362 if ( moduleId >= 10 && moduleId <= 13 ) return kStationTrigger;
364 // Should never get to this line
365 AliFatalClass("Cannot return AliMpStationType value.");