AliRoot Core  a565103 (a565103)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMpUID.cxx
Go to the documentation of this file.
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$
17 
18 #include "AliMpUID.h"
19 
20 #include "AliLog.h"
21 #include "Riostream.h"
22 #include "TObjArray.h"
23 #include "TObjString.h"
24 #include "TSystem.h"
25 
30 
31 using std::cout;
32 using std::endl;
34 
35 namespace
36 {
37  const char* nameTemplateMANU = "MANU %d";
38  const char* nameTemplateDE = "DE %d";
39  const char* nameTemplateBP = "BusPatch %d";
40  const char* nameTemplateCHAMBER = "Chamber %d";
41  const char* nameTemplateSTATION = "Station %d";
42  const char* nameTemplatePCB = "PCB %d";
43 
44  const char* pathTemplateMANU = "Cathode%d/Station%d/Chamber%d/DE%04d/BUSPATCH%04d/MANU%04d";
45  const char* pathTemplateBP = "Cathode%d/Station%d/Chamber%d/DE%04d/BUSPATCH%04d";
46  const char* pathTemplateDE = "Cathode%d/Station%d/Chamber%d/DE%04d";
47  const char* pathTemplateCHAMBER = "Cathode%d/Station%d/Chamber%d";
48  const char* pathTemplateSTATION = "Cathode%d/Station%d";
49 
50  const char* pathTemplateMANUPCB = "Cathode%d/Station%d/Chamber%d/DE%04d/PCB%d/MANU%04d";
51  const char* pathTemplatePCB = "Cathode%d/Station%d/Chamber%d/DE%04d/PCB%d";
52 }
53 
54 //_____________________________________________________________________________
56 :
57 fCathodeId(-1),
58 fStationId(-1),
59 fChamberId(-1),
60 fDetElemId(-1),
61 fBusPatchId(-1),
62 fManuId(-1),
63 fPCBId(-1)
64 {
66 }
67 
68 //_____________________________________________________________________________
69 AliMpUID::AliMpUID(AliMp::CathodType cathodeType, Int_t station, Int_t chamber, Int_t de, Int_t bp, Int_t manu, Int_t pcb)
70 :
71 fCathodeId(cathodeType),
72 fStationId(station),
73 fChamberId(chamber),
74 fDetElemId(de),
75 fBusPatchId(bp),
76 fManuId(manu),
77 fPCBId(pcb)
78 {
80 }
81 
82 //_____________________________________________________________________________
84 :
85 fCathodeId(cathodeType),
86 fStationId(b.StationId()),
87 fChamberId(b.ChamberId()),
88 fDetElemId(b.DetElemId()),
89 fBusPatchId(b.BusPatchId()),
90 fManuId(b.ManuId()),
91 fPCBId(b.PCBId())
92 {
94 }
95 
96 //_____________________________________________________________________________
97 AliMpUID::AliMpUID(AliMp::CathodType cathodeType, const char* pathname)
98 :
99 fCathodeId(cathodeType),
100 fStationId(-1),
101 fChamberId(-1),
102 fDetElemId(-1),
103 fBusPatchId(-1),
104 fManuId(-1),
105 fPCBId(-1)
106 {
108 
109  if ( CheckTemplate(pathname,pathTemplateMANUPCB,fPCBId) && fPCBId >= 0 ) return;
110  if ( CheckTemplate(pathname,pathTemplatePCB,fPCBId) && fPCBId >= 0 ) return;
111 
112  if ( CheckTemplate(pathname,pathTemplateMANU,fBusPatchId) ) return;
113  if ( CheckTemplate(pathname,pathTemplateBP,fBusPatchId) ) return;
114  if ( CheckTemplate(pathname,pathTemplateDE,fBusPatchId) ) return;
115  if ( CheckTemplate(pathname,pathTemplateCHAMBER,fBusPatchId) ) return;
116  if ( CheckTemplate(pathname,pathTemplateSTATION,fBusPatchId) ) return;
117 }
118 
119 
120 //_____________________________________________________________________________
121 AliMpUID::AliMpUID(const char* pathname)
122 :
123 fCathodeId(2),
124 fStationId(-1),
125 fChamberId(-1),
126 fDetElemId(-1),
127 fBusPatchId(-1),
128 fManuId(-1),
129 fPCBId(-1)
130 {
132 
133  if ( CheckTemplate(pathname,pathTemplateMANUPCB,fPCBId) && fPCBId >= 0 ) return;
134  if ( CheckTemplate(pathname,pathTemplatePCB,fPCBId) && fPCBId >= 0 ) return;
135 
136  if ( CheckTemplate(pathname,pathTemplateMANU,fBusPatchId) ) return;
137  if ( CheckTemplate(pathname,pathTemplateBP,fBusPatchId) ) return;
138  if ( CheckTemplate(pathname,pathTemplateDE,fBusPatchId) ) return;
139  if ( CheckTemplate(pathname,pathTemplateCHAMBER,fBusPatchId) ) return;
140  if ( CheckTemplate(pathname,pathTemplateSTATION,fBusPatchId) ) return;
141 }
142 
143 //_____________________________________________________________________________
144 TString
146 {
148  return gSystem->BaseName(PathName().Data());
149 }
150 
151 //_____________________________________________________________________________
154 {
157 }
158 
159 //_____________________________________________________________________________
160 Bool_t
161 AliMpUID::CheckTemplate(const char* name, const char* pathTemplateName, Int_t& value)
162 {
164 
165  if ( TString(name).Contains("Cathode") )
166  {
167  sscanf(name,pathTemplateName,&fCathodeId,&fStationId,&fChamberId,&fDetElemId,&value,&fManuId);
168  }
169  else
170  {
171  TString templ(pathTemplateName);
172  Int_t i = templ.Index("/");
173  templ = templ(i+1,templ.Length()-i-1);
174  sscanf(name,templ.Data(),&fStationId,&fChamberId,&fDetElemId,&value,&fManuId);
175  }
176  return IsValid();
177 }
178 
179 //_____________________________________________________________________________
180 TString
182 {
184  return gSystem->DirName(PathName().Data());
185 }
186 
187 //_____________________________________________________________________________
188 Bool_t
190 {
192  return fCathodeId >= 0 && fStationId >= 0 && fChamberId == -1 ;
193 }
194 
195 //_____________________________________________________________________________
196 Bool_t
198 {
200 
201  return fCathodeId >= 0 && fStationId >= 0 && fChamberId >= 0 && fDetElemId == -1;
202 }
203 
204 //_____________________________________________________________________________
205 Bool_t
207 {
209  return fCathodeId >= 0 && fStationId >= 0 && fChamberId >= 0 && fDetElemId >= 0 && fBusPatchId==-1 && fPCBId == -1;
210 }
211 
212 //_____________________________________________________________________________
213 Bool_t
215 {
217  return fCathodeId >= 0 && fStationId >= 0 && fChamberId >= 0 && fDetElemId >= 0 && fBusPatchId>=0 && fManuId ==-1;
218 }
219 
220 //_____________________________________________________________________________
221 Bool_t AliMpUID::IsManu() const
222 {
224  return
225  fCathodeId >= 0 &&
226  fStationId >= 0 &&
227  fChamberId >= 0 &&
228  fDetElemId >= 0 &&
229  ( fBusPatchId>=0 || fPCBId >=0 ) &&
230  fManuId >=0;
231 }
232 
233 //_____________________________________________________________________________
234 Bool_t AliMpUID::IsPCB() const
235 {
237  return fCathodeId >= 0 && fPCBId >= 0 && fManuId == -1;
238 }
239 
240 //_____________________________________________________________________________
241 Bool_t AliMpUID::IsValid() const
242 {
244  return IsStation() || IsChamber() || IsDetectionElement() || IsBusPatch() || IsManu() || IsPCB();
245 }
246 
247 //_____________________________________________________________________________
248 TString
250 {
252  if ( IsManu() )
253  {
254  return Form(nameTemplateMANU,ManuId());
255  }
256 
257  if ( IsPCB() )
258  {
259  return Form(nameTemplatePCB,PCBId());
260  }
261 
262  if ( IsBusPatch() )
263  {
264  return Form(nameTemplateBP,BusPatchId());
265  }
266 
267  if ( IsDetectionElement() )
268  {
269  return Form(nameTemplateDE,DetElemId());
270  }
271 
272  if ( IsChamber() )
273  {
274  return Form(nameTemplateCHAMBER,ChamberId());
275  }
276 
277  if ( IsStation() )
278  {
279  return Form(nameTemplateSTATION,StationId());
280  }
281 
282  return "INVALID NAME";
283 }
284 
285 //_____________________________________________________________________________
286 TString
288 {
290  if ( IsManu() )
291  {
292  if ( fPCBId >= 0 )
293  {
294  return StripCathode(Form(pathTemplateMANUPCB,CathodeId(),StationId(),ChamberId(),DetElemId(),PCBId(),ManuId()));
295  }
296  else
297  {
298  return StripCathode(Form(pathTemplateMANU,CathodeId(),StationId(),ChamberId(),DetElemId(),BusPatchId(),ManuId()));
299  }
300  }
301 
302  if ( IsPCB() )
303  {
304  return StripCathode(Form(pathTemplatePCB,CathodeId(),StationId(),ChamberId(),DetElemId(),PCBId()));
305  }
306 
307  if ( IsBusPatch() )
308  {
309  return StripCathode(Form(pathTemplateBP,CathodeId(),StationId(),ChamberId(),DetElemId(),BusPatchId()));
310  }
311 
312  if ( IsDetectionElement() )
313  {
314  return StripCathode(Form(pathTemplateDE,CathodeId(),StationId(),ChamberId(),DetElemId()));
315  }
316 
317  if ( IsChamber() )
318  {
319  return StripCathode(Form(pathTemplateCHAMBER,CathodeId(),StationId(),ChamberId()));
320  }
321 
322  if ( IsStation() )
323  {
324  return StripCathode(Form(pathTemplateSTATION,CathodeId(),StationId()));
325  }
326 
327  return "INVALID PATHNAME";
328 }
329 
330 //_____________________________________________________________________________
331 void
332 AliMpUID::Print(Option_t*) const
333 {
335  cout << Name().Data() << " (" << PathName().Data() << ")" << endl;
336 }
337 
338 //_____________________________________________________________________________
339 TString
340 AliMpUID::StripCathode(const char* name) const
341 {
343 
344  TString rv(name);
345 
346  if ( fCathodeId == 2 )
347  {
348  rv.ReplaceAll("Cathode2/","");
349  }
350 
351  return rv;
352 }
353 
354 //_____________________________________________________________________________
355 TString
357 {
359  TString n(Name());
360  TObjArray* s = n.Tokenize(" ");
361  TString rv(static_cast<TObjString*>(s->At(0))->String());
362  delete s;
363  return rv;
364 }
365 
Bool_t IsDetectionElement() const
Definition: AliMpUID.cxx:206
TString Name() const
Definition: AliMpUID.cxx:249
Int_t fDetElemId
Detection element id.
Definition: AliMpUID.h:79
Bool_t IsChamber() const
Definition: AliMpUID.cxx:197
Bool_t IsStation() const
Definition: AliMpUID.cxx:189
TString PathName() const
Definition: AliMpUID.cxx:287
virtual void Print(Option_t *opt="") const
Definition: AliMpUID.cxx:332
Int_t DetElemId() const
Return detection element Id.
Definition: AliMpUID.h:57
#define TObjArray
Global (string-eable) ID of a tracker channel.
Definition: AliMpUID.h:25
TString DirName() const
Definition: AliMpUID.cxx:181
static int templ(TVector par, Double_t x, Double_t dy, Double_t dz, const AliTPCSector *sec, int s, int rf=0)
Definition: template.cxx:61
Int_t fStationId
Station id.
Definition: AliMpUID.h:77
AliMpUID()
Definition: AliMpUID.cxx:55
ClassImp(AliMpUID) namespace
Definition: AliMpUID.cxx:33
AliMp::CathodType CathodeId() const
Definition: AliMpUID.cxx:153
Bool_t IsBusPatch() const
Definition: AliMpUID.cxx:214
TString BaseName() const
Definition: AliMpUID.cxx:145
AliMp::CathodType GetCathodType(Int_t cathodNumber)
Convert integer number in enum;.
Int_t PCBId() const
Return PCB Id.
Definition: AliMpUID.h:63
Int_t fBusPatchId
Bus patch id.
Definition: AliMpUID.h:80
Int_t fManuId
Manu id.
Definition: AliMpUID.h:81
Int_t BusPatchId() const
Return bus patch Id.
Definition: AliMpUID.h:59
Bool_t IsManu() const
Definition: AliMpUID.cxx:221
Int_t ManuId() const
Return manu Id.
Definition: AliMpUID.h:61
TString StripCathode(const char *name) const
Definition: AliMpUID.cxx:340
Int_t fPCBId
PCB id.
Definition: AliMpUID.h:82
Bool_t CheckTemplate(const char *name, const char *templateName, Int_t &value)
Definition: AliMpUID.cxx:161
Int_t ChamberId() const
Return chamber Id.
Definition: AliMpUID.h:55
Int_t StationId() const
Return station Id.
Definition: AliMpUID.h:53
Int_t fChamberId
Chamber id.
Definition: AliMpUID.h:78
Bool_t IsValid() const
Definition: AliMpUID.cxx:241
Bool_t IsPCB() const
Definition: AliMpUID.cxx:234
Int_t fCathodeId
Cathode number.
Definition: AliMpUID.h:76
TString Type() const
Return our type (e.g. PCB, Chamber, DE, MANU, etc...)
Definition: AliMpUID.cxx:356