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 **************************************************************************/
21 #include "Riostream.h"
22 #include "TObjArray.h"
23 #include "TObjString.h"
27 /// station/chamber/de/bp/manu
29 /// station/chamber/pcb/manu
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";
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";
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";
54 //_____________________________________________________________________________
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)
71 fCathodeId(cathodeType),
82 //_____________________________________________________________________________
83 AliMpUID::AliMpUID(AliMp::CathodType cathodeType, const AliMpUID& b)
85 fCathodeId(cathodeType),
86 fStationId(b.StationId()),
87 fChamberId(b.ChamberId()),
88 fDetElemId(b.DetElemId()),
89 fBusPatchId(b.BusPatchId()),
93 /// build the id from b, but using the given cathodeType
96 //_____________________________________________________________________________
97 AliMpUID::AliMpUID(AliMp::CathodType cathodeType, const char* pathname)
99 fCathodeId(cathodeType),
107 /// build id from path, but using the given cathodeType
109 if ( CheckTemplate(pathname,pathTemplateMANUPCB,fPCBId) && fPCBId >= 0 ) return;
110 if ( CheckTemplate(pathname,pathTemplatePCB,fPCBId) && fPCBId >= 0 ) return;
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;
120 //_____________________________________________________________________________
121 AliMpUID::AliMpUID(const char* pathname)
131 /// Build id from path
133 if ( CheckTemplate(pathname,pathTemplateMANUPCB,fPCBId) && fPCBId >= 0 ) return;
134 if ( CheckTemplate(pathname,pathTemplatePCB,fPCBId) && fPCBId >= 0 ) return;
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;
143 //_____________________________________________________________________________
145 AliMpUID::BaseName() const
148 return gSystem->BaseName(PathName().Data());
151 //_____________________________________________________________________________
153 AliMpUID::CathodeId() const
155 /// return cathode id (not always valid)
156 return AliMp::GetCathodType(fCathodeId);
159 //_____________________________________________________________________________
161 AliMpUID::CheckTemplate(const char* name, const char* pathTemplateName, Int_t& value)
163 /// Check a name against a template
165 if ( TString(name).Contains("Cathode") )
167 sscanf(name,pathTemplateName,&fCathodeId,&fStationId,&fChamberId,&fDetElemId,&value,&fManuId);
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);
179 //_____________________________________________________________________________
181 AliMpUID::DirName() const
184 return gSystem->DirName(PathName().Data());
187 //_____________________________________________________________________________
189 AliMpUID::IsStation() const
191 /// Whether we identify a station
192 return fCathodeId >= 0 && fStationId >= 0 && fChamberId == -1 ;
195 //_____________________________________________________________________________
197 AliMpUID::IsChamber() const
199 /// Whether we identify a chamber
201 return fCathodeId >= 0 && fStationId >= 0 && fChamberId >= 0 && fDetElemId == -1;
204 //_____________________________________________________________________________
206 AliMpUID::IsDetectionElement() const
208 /// whether we identify a detection element
209 return fCathodeId >= 0 && fStationId >= 0 && fChamberId >= 0 && fDetElemId >= 0 && fBusPatchId==-1 && fPCBId == -1;
212 //_____________________________________________________________________________
214 AliMpUID::IsBusPatch() const
216 /// whether we identify a bus patch
217 return fCathodeId >= 0 && fStationId >= 0 && fChamberId >= 0 && fDetElemId >= 0 && fBusPatchId>=0 && fManuId ==-1;
220 //_____________________________________________________________________________
221 Bool_t AliMpUID::IsManu() const
223 /// whether we identify a manu
229 ( fBusPatchId>=0 || fPCBId >=0 ) &&
233 //_____________________________________________________________________________
234 Bool_t AliMpUID::IsPCB() const
236 /// Whether we identify a PCB
237 return fCathodeId >= 0 && fPCBId >= 0 && fManuId == -1;
240 //_____________________________________________________________________________
241 Bool_t AliMpUID::IsValid() const
243 /// Whether we're a valid UID...
244 return IsStation() || IsChamber() || IsDetectionElement() || IsBusPatch() || IsManu() || IsPCB();
247 //_____________________________________________________________________________
249 AliMpUID::Name() const
254 return Form(nameTemplateMANU,ManuId());
259 return Form(nameTemplatePCB,PCBId());
264 return Form(nameTemplateBP,BusPatchId());
267 if ( IsDetectionElement() )
269 return Form(nameTemplateDE,DetElemId());
274 return Form(nameTemplateCHAMBER,ChamberId());
279 return Form(nameTemplateSTATION,StationId());
282 return "INVALID NAME";
285 //_____________________________________________________________________________
287 AliMpUID::PathName() const
294 return StripCathode(Form(pathTemplateMANUPCB,CathodeId(),StationId(),ChamberId(),DetElemId(),PCBId(),ManuId()));
298 return StripCathode(Form(pathTemplateMANU,CathodeId(),StationId(),ChamberId(),DetElemId(),BusPatchId(),ManuId()));
304 return StripCathode(Form(pathTemplatePCB,CathodeId(),StationId(),ChamberId(),DetElemId(),PCBId()));
309 return StripCathode(Form(pathTemplateBP,CathodeId(),StationId(),ChamberId(),DetElemId(),BusPatchId()));
312 if ( IsDetectionElement() )
314 return StripCathode(Form(pathTemplateDE,CathodeId(),StationId(),ChamberId(),DetElemId()));
319 return StripCathode(Form(pathTemplateCHAMBER,CathodeId(),StationId(),ChamberId()));
324 return StripCathode(Form(pathTemplateSTATION,CathodeId(),StationId()));
327 return "INVALID PATHNAME";
330 //_____________________________________________________________________________
332 AliMpUID::Print(Option_t*) const
335 cout << Name().Data() << " (" << PathName().Data() << ")" << endl;
338 //_____________________________________________________________________________
340 AliMpUID::StripCathode(const char* name) const
342 /// Remove cathode information if both cathodes are present
346 if ( fCathodeId == 2 )
348 rv.ReplaceAll("Cathode2/","");
354 //_____________________________________________________________________________
356 AliMpUID::Type() const
358 /// Remove cathode information if both cathodes are present
360 TObjArray* s = n.Tokenize(" ");
361 TString rv(static_cast<TObjString*>(s->At(0))->String());