]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpDEManager.cxx
Work around for CINT bug in root 5.10/00, with gcc4.0.2
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpDEManager.cxx
CommitLineData
32f6e426 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$
6b87a46a 17// $MpId: AliMpDEManager.cxx,v 1.2 2006/03/02 16:30:09 ivana Exp $
32f6e426 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"
6b87a46a 29#include "AliMpIntPair.h"
32f6e426 30
31#include "AliLog.h"
32
33#include <Riostream.h>
34#include <TSystem.h>
35#include <TObjString.h>
36#include <TMap.h>
37
32f6e426 38const char AliMpDEManager::fgkNameSeparator = '_';
39const char AliMpDEManager::fgkCommentPrefix = '#';
40const Int_t AliMpDEManager::fgkCoefficient = 100;
6b87a46a 41AliMpExMap AliMpDEManager::fgDENamesMap(true);
42AliMpExMap AliMpDEManager::fgDECathBNBMap(true);
43
44ClassImp(AliMpDEManager)
32f6e426 45
46//______________________________________________________________________________
47AliMpDEManager::AliMpDEManager()
48 : TObject()
49{
50/// Protected default/standard constructor
51}
52
53//______________________________________________________________________________
54AliMpDEManager::AliMpDEManager(const AliMpDEManager& rhs)
55 : TObject(rhs)
56{
57/// Protected copy constructor
58
59 AliFatal("Not implemented.");
60}
61
62//______________________________________________________________________________
63
64AliMpDEManager::~AliMpDEManager()
65{
66/// Destructor
67}
68
69//______________________________________________________________________________
70AliMpDEManager& AliMpDEManager::operator=(const AliMpDEManager& rhs)
71{
72/// Protected assignement operator
73
74 if (this == &rhs) return *this;
75
76 AliFatal("Not implemented.");
77
78 return *this;
79}
80
81//
82// static private methods
83//
84
85//______________________________________________________________________________
86Bool_t AliMpDEManager::IsPlaneType(const TString& planeTypeName)
87{
88/// Return true if the planeTypeName corresponds to a valid plane type
89
90 if ( planeTypeName == PlaneTypeName(kBendingPlane) ||
91 planeTypeName == PlaneTypeName(kNonBendingPlane) )
92 return true;
93
94 return false;
95}
96
97//______________________________________________________________________________
98AliMpPlaneType AliMpDEManager::PlaneType(const TString& planeTypeName)
99{
100/// Return plane type for the given planeTypeName \n
101/// Fatal error if planeTypeName is wrong
102
103 if ( planeTypeName == PlaneTypeName(kBendingPlane) )
104 return kBendingPlane;
105
106 if ( planeTypeName == PlaneTypeName(kNonBendingPlane) )
107 return kNonBendingPlane;
108
109 // Should never reach this line
110 AliFatalClass(Form("No plane type defined for %s", planeTypeName.Data()));
111 return kBendingPlane;
112}
113
114//______________________________________________________________________________
115AliMpStationType AliMpDEManager::StationType(const TString& stationTypeName)
116{
117/// Return station type for the given stationTypeName \n
118/// Fatal error if stationTypeName is wrong
119
120 if ( stationTypeName == StationTypeName(kStation1) )
121 return kStation1;
122
123 if ( stationTypeName == StationTypeName(kStation2) )
124 return kStation2;
125
126 if ( stationTypeName == StationTypeName(kStation345) )
127 return kStation345;
128
129 if ( stationTypeName == StationTypeName(kStationTrigger) )
130 return kStationTrigger;
131
132 // Should never reach this line
133 AliFatalClass(Form("No station type defined for ", stationTypeName.Data()));
134 return kStation1;
135}
136
137//______________________________________________________________________________
138Bool_t
139AliMpDEManager::ReadDENames(AliMpStationType station)
140{
141/// Read det element names for cath = 0 from the file specified by name
142/// and fill the map
143
144 // Open file
145 TString filePath = AliMpFiles::DENamesFilePath(station);
146 std::ifstream in(filePath);
147 if (!in.good()) {
148 AliErrorClassStream() << "Cannot open file " << filePath << endl;;
149 return false;
150 }
151
152 // Read plane types per cathods
153 //
154 char line[80];
155 TString word;
156 TString cathName1, cathName2;
157 in >> word;
158 while ( ! in.eof() && cathName1.Length() == 0 ) {
159 if ( word[0] == '#' )
160 in.getline(line, 80);
161 else {
162 cathName1 = word;
163 in >> cathName2;
164 }
165 in >> word;
166 }
167
168 Bool_t isCathNameDefined = false;
169 if ( IsPlaneType(cathName1) && IsPlaneType(cathName2) )
170 isCathNameDefined = true;
171
172 // Read DE names
173 //
174 Int_t detElemId;
175 TString name1, name2;
6b87a46a 176 AliMpPlaneType planeForCathode[2];
177
178 while ( ! in.eof() )
179 {
32f6e426 180 if ( word[0] == '#' )
6b87a46a 181 {
32f6e426 182 in.getline(line, 80);
6b87a46a 183 }
184 else
185 {
32f6e426 186 detElemId = word.Atoi();
187 in >> name1;
6b87a46a 188 // warning : important to check non bending first (=nbp),
189 // as bp is contained within nbp...
190 if ( name1.Contains(PlaneTypeName(kNonBendingPlane)) )
191 {
192 planeForCathode[0] = kNonBendingPlane;
193 }
194 else
195 {
196 planeForCathode[0] = kBendingPlane;
197 }
198 if ( !isCathNameDefined )
199 {
32f6e426 200 in >> name2;
6b87a46a 201 // Other cathode is other plane...
202 if ( planeForCathode[0] == kBendingPlane )
203 {
204 planeForCathode[1]=kNonBendingPlane;
205 }
206 else
207 {
208 planeForCathode[1]=kBendingPlane;
209 }
210 }
211 else
212 {
32f6e426 213 name1 += fgkNameSeparator;
6b87a46a 214 name2 = name1;
32f6e426 215 name1 += cathName1;
216 name2 += cathName2;
6b87a46a 217 if ( name2.Contains(PlaneTypeName(kNonBendingPlane)) )
218 {
219 planeForCathode[1] = kNonBendingPlane;
220 }
221 else
222 {
223 planeForCathode[1] = kBendingPlane;
224 }
32f6e426 225 }
226
6b87a46a 227 if ( planeForCathode[0]==planeForCathode[1] )
228 {
229 AliFatalClass(Form("Got the same cathode type for both planes"
230 " of DetElemId %d",detElemId));
231 }
232
233 if ( ! fgDENamesMap.GetValue(detElemId) )
234 {
32f6e426 235 AliDebugClassStream(1)
6b87a46a 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]));
32f6e426 241 }
242 }
243 in >> word;
244 }
245
246 // Close file
247 in.close();
248
249 return true;
250}
251
252//______________________________________________________________________________
253void AliMpDEManager::FillDENames()
254{
255/// Fill DE names from files
256
257 Bool_t result1 = ReadDENames(kStation1);
258 Bool_t result2 = ReadDENames(kStation2);
259 Bool_t result3 = ReadDENames(kStation345);
260 Bool_t result4 = ReadDENames(kStationTrigger);
261
262 Bool_t result = result1 && result2 && result3 && result4;
263 if ( ! result ) {
264 AliErrorClassStream() << "Error in reading DE names files" << endl;
265 }
266}
267
268//
269// static public methods
270//
271
272//______________________________________________________________________________
273Bool_t AliMpDEManager::IsValidDetElemId(Int_t detElemId, Bool_t warn)
274{
275/// Return true if detElemId is valid
276/// (is present in the DE names files)
277
278 if ( fgDENamesMap.GetSize() == 0 ) FillDENames();
279
280 if ( fgDENamesMap.GetValue(detElemId) ) return true;
281
282 if (warn) {
283 AliErrorClassStream()
284 << "Detection element " << detElemId << " not defined." << endl;
285 }
286 return false;
287}
288
289//______________________________________________________________________________
290Bool_t AliMpDEManager::IsValidCathod(Int_t cath, Bool_t warn)
291{
292/// Return true if cath is 0 or 1
293/// (Better solution would be to use systematically enum)
294
295 if (cath == 0 || cath == 1 ) return true;
296
297 if (warn)
298 AliErrorClassStream() << "Wrong cathod number " << cath << endl;
299
300 return false;
301}
302
303
304//______________________________________________________________________________
305Bool_t AliMpDEManager::IsValid(Int_t detElemId, Int_t cath, Bool_t warn)
306{
307/// Return true if both detElemId and cathod number are valid
308
309 return ( IsValidDetElemId(detElemId, warn) && IsValidCathod(cath, warn) );
310}
311
312//______________________________________________________________________________
313Bool_t AliMpDEManager::IsValidModuleId(Int_t moduleId, Bool_t warn)
314{
315/// Return true if moduleId is valid
316
317 if ( moduleId >= 0 && moduleId < AliMpConstants::NCh() )
318 return true;
319
320 if (warn)
321 AliErrorClassStream() << "Wrong module Id " << moduleId << endl;
322
323 return false;
324}
325
6b87a46a 326//______________________________________________________________________________
327Int_t
328AliMpDEManager::GetCathod(Int_t detElemId, AliMpPlaneType planeType)
329{
490da820 330/// Return cathod number for given detElemId and planeType
331
6b87a46a 332 if ( !IsValidDetElemId(detElemId) ) return -1;
333 AliMpIntPair* pair =
334 static_cast<AliMpIntPair*>(fgDECathBNBMap.GetValue(detElemId));
335 if ( planeType == pair->GetFirst() )
336 {
337 return 0;
338 }
339 return 1;
340}
341
32f6e426 342//______________________________________________________________________________
343TString AliMpDEManager::GetDEName(Int_t detElemId, Int_t cath, Bool_t warn)
344{
345/// Return det element type name
346
347 if ( ! IsValid(detElemId, cath, warn) ) return "undefined";
348
349 TPair* namePair = (TPair*)fgDENamesMap.GetValue(detElemId);
350
351 if (cath == 0) return ((TObjString*)namePair->Key())->GetString();
352 if (cath == 1) return ((TObjString*)namePair->Value())->GetString();
353
354 return "undefined";
355}
356
357//______________________________________________________________________________
358TString AliMpDEManager::GetDETypeName(Int_t detElemId, Int_t cath, Bool_t warn)
359{
360/// Return det element type name
361
362 TString fullName = GetDEName(detElemId, cath, warn);
363
364 // cut plane type extension
365 Ssiz_t pos = fullName.First(fgkNameSeparator);
366 return fullName(0,pos);
367}
368
369//______________________________________________________________________________
370Int_t AliMpDEManager::GetModuleId(Int_t detElemId, Bool_t warn)
371{
372/// Return module Id for given detElemId
373
374 if ( ! IsValidDetElemId(detElemId, warn) ) return -1;
375
376 return detElemId/fgkCoefficient - 1;
377}
378
379//______________________________________________________________________________
380AliMpPlaneType AliMpDEManager::GetPlaneType(Int_t detElemId, Int_t cath)
381{
382/// Return plane type \n
383/// Failure causes Fatal error - as AliMpPlaneType has no possibility
384/// to return undefined value
385
386 if ( ! IsValid(detElemId, cath, true) ) {
387 AliFatalClass("Cannot return AliMpPlaneType value.");
388 return kBendingPlane;
389 }
390
391 TPair* namePair = (TPair*)fgDENamesMap.GetValue(detElemId);
392
393 TString fullName;
394 if (cath == 0) fullName = ((TObjString*)namePair->Key())->GetString();
395 if (cath == 1) fullName = ((TObjString*)namePair->Value())->GetString();
396
397 // Get plane type name
398 Ssiz_t pos = fullName.First(fgkNameSeparator);
399 TString planeTypeName = fullName(pos+1,fullName.Length()-pos);
400
401 return PlaneType(planeTypeName);
402}
403
404//______________________________________________________________________________
405AliMpStationType AliMpDEManager::GetStationType(Int_t detElemId)
406{
407/// Return station type \n
408/// Failure causes Fatal error - as AliMpStationType has no possibility
409/// to return undefined value
410
411 if ( ! IsValidDetElemId(detElemId, true) ) {
412 AliFatalClass("Cannot return AliMpStationType value.");
413 return kStation1;
414 }
415
416 Int_t moduleId = GetModuleId(detElemId, false);
417 if ( ! IsValidModuleId(moduleId, true) ) {
418 AliFatalClass("Cannot return AliMpStationType value.");
419 return kStation1;
420 }
421
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;
426
427 // Should never get to this line
428 AliFatalClass("Cannot return AliMpStationType value.");
429 return kStation1;
430}
431