]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpUID.cxx
Go from pointer to ifstream to ifstream.
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpUID.cxx
CommitLineData
0b936dc0 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
26///
27/// station/chamber/de/bp/manu
28///
29/// station/chamber/pcb/manu
30
b80faac0 31using std::cout;
32using std::endl;
0b936dc0 33ClassImp(AliMpUID)
34
35namespace
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//_____________________________________________________________________________
55AliMpUID::AliMpUID()
56:
57fCathodeId(-1),
58fStationId(-1),
59fChamberId(-1),
60fDetElemId(-1),
61fBusPatchId(-1),
62fManuId(-1),
63fPCBId(-1)
64{
65 /// empty ctor
66}
67
68//_____________________________________________________________________________
69AliMpUID::AliMpUID(AliMp::CathodType cathodeType, Int_t station, Int_t chamber, Int_t de, Int_t bp, Int_t manu, Int_t pcb)
70:
71fCathodeId(cathodeType),
72fStationId(station),
73fChamberId(chamber),
74fDetElemId(de),
75fBusPatchId(bp),
76fManuId(manu),
77fPCBId(pcb)
78{
79 /// default ctor
80}
81
82//_____________________________________________________________________________
83AliMpUID::AliMpUID(AliMp::CathodType cathodeType, const AliMpUID& b)
84:
85fCathodeId(cathodeType),
86fStationId(b.StationId()),
87fChamberId(b.ChamberId()),
88fDetElemId(b.DetElemId()),
89fBusPatchId(b.BusPatchId()),
90fManuId(b.ManuId()),
91fPCBId(b.PCBId())
92{
93 /// build the id from b, but using the given cathodeType
94}
95
96//_____________________________________________________________________________
97AliMpUID::AliMpUID(AliMp::CathodType cathodeType, const char* pathname)
98:
99fCathodeId(cathodeType),
100fStationId(-1),
101fChamberId(-1),
102fDetElemId(-1),
103fBusPatchId(-1),
104fManuId(-1),
105fPCBId(-1)
106{
107 /// build id from path, but using the given cathodeType
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//_____________________________________________________________________________
121AliMpUID::AliMpUID(const char* pathname)
122:
123fCathodeId(2),
124fStationId(-1),
125fChamberId(-1),
126fDetElemId(-1),
127fBusPatchId(-1),
128fManuId(-1),
129fPCBId(-1)
130{
131 /// Build id from path
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//_____________________________________________________________________________
144TString
145AliMpUID::BaseName() const
146{
147 /// Get the basename
148 return gSystem->BaseName(PathName().Data());
149}
150
151//_____________________________________________________________________________
152AliMp::CathodType
153AliMpUID::CathodeId() const
154{
155 /// return cathode id (not always valid)
156 return AliMp::GetCathodType(fCathodeId);
157}
158
159//_____________________________________________________________________________
160Bool_t
161AliMpUID::CheckTemplate(const char* name, const char* pathTemplateName, Int_t& value)
162{
163 /// Check a name against a template
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//_____________________________________________________________________________
180TString
181AliMpUID::DirName() const
182{
183 /// Get dirname
184 return gSystem->DirName(PathName().Data());
185}
186
187//_____________________________________________________________________________
188Bool_t
189AliMpUID::IsStation() const
190{
191 /// Whether we identify a station
192 return fCathodeId >= 0 && fStationId >= 0 && fChamberId == -1 ;
193}
194
195//_____________________________________________________________________________
196Bool_t
197AliMpUID::IsChamber() const
198{
199 /// Whether we identify a chamber
200
201 return fCathodeId >= 0 && fStationId >= 0 && fChamberId >= 0 && fDetElemId == -1;
202}
203
204//_____________________________________________________________________________
205Bool_t
206AliMpUID::IsDetectionElement() const
207{
208 /// whether we identify a detection element
209 return fCathodeId >= 0 && fStationId >= 0 && fChamberId >= 0 && fDetElemId >= 0 && fBusPatchId==-1 && fPCBId == -1;
210}
211
212//_____________________________________________________________________________
213Bool_t
214AliMpUID::IsBusPatch() const
215{
216 /// whether we identify a bus patch
217 return fCathodeId >= 0 && fStationId >= 0 && fChamberId >= 0 && fDetElemId >= 0 && fBusPatchId>=0 && fManuId ==-1;
218}
219
220//_____________________________________________________________________________
221Bool_t AliMpUID::IsManu() const
222{
223 /// whether we identify a manu
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//_____________________________________________________________________________
234Bool_t AliMpUID::IsPCB() const
235{
236 /// Whether we identify a PCB
237 return fCathodeId >= 0 && fPCBId >= 0 && fManuId == -1;
238}
239
240//_____________________________________________________________________________
241Bool_t AliMpUID::IsValid() const
242{
243 /// Whether we're a valid UID...
244 return IsStation() || IsChamber() || IsDetectionElement() || IsBusPatch() || IsManu() || IsPCB();
245}
246
247//_____________________________________________________________________________
248TString
249AliMpUID::Name() const
250{
251 /// Get our name
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//_____________________________________________________________________________
286TString
287AliMpUID::PathName() const
288{
289 /// Get our pathname
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//_____________________________________________________________________________
331void
332AliMpUID::Print(Option_t*) const
333{
334 /// Printout
335 cout << Name().Data() << " (" << PathName().Data() << ")" << endl;
336}
337
338//_____________________________________________________________________________
339TString
340AliMpUID::StripCathode(const char* name) const
341{
342 /// Remove cathode information if both cathodes are present
343
344 TString rv(name);
345
346 if ( fCathodeId == 2 )
347 {
348 rv.ReplaceAll("Cathode2/","");
349 }
350
351 return rv;
352}
353
354//_____________________________________________________________________________
355TString
356AliMpUID::Type() const
357{
358 /// Remove cathode information if both cathodes are present
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