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