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
35 const char* nameTemplateMANU = "MANU %d";
36 const char* nameTemplateDE = "DE %d";
37 const char* nameTemplateBP = "BusPatch %d";
38 const char* nameTemplateCHAMBER = "Chamber %d";
39 const char* nameTemplateSTATION = "Station %d";
40 const char* nameTemplatePCB = "PCB %d";
42 const char* pathTemplateMANU = "Cathode%d/Station%d/Chamber%d/DE%04d/BUSPATCH%04d/MANU%04d";
43 const char* pathTemplateBP = "Cathode%d/Station%d/Chamber%d/DE%04d/BUSPATCH%04d";
44 const char* pathTemplateDE = "Cathode%d/Station%d/Chamber%d/DE%04d";
45 const char* pathTemplateCHAMBER = "Cathode%d/Station%d/Chamber%d";
46 const char* pathTemplateSTATION = "Cathode%d/Station%d";
48 const char* pathTemplateMANUPCB = "Cathode%d/Station%d/Chamber%d/DE%04d/PCB%d/MANU%04d";
49 const char* pathTemplatePCB = "Cathode%d/Station%d/Chamber%d/DE%04d/PCB%d";
52 //_____________________________________________________________________________
66 //_____________________________________________________________________________
67 AliMpUID::AliMpUID(AliMp::CathodType cathodeType, Int_t station, Int_t chamber, Int_t de, Int_t bp, Int_t manu, Int_t pcb)
69 fCathodeId(cathodeType),
80 //_____________________________________________________________________________
81 AliMpUID::AliMpUID(AliMp::CathodType cathodeType, const AliMpUID& b)
83 fCathodeId(cathodeType),
84 fStationId(b.StationId()),
85 fChamberId(b.ChamberId()),
86 fDetElemId(b.DetElemId()),
87 fBusPatchId(b.BusPatchId()),
91 /// build the id from b, but using the given cathodeType
94 //_____________________________________________________________________________
95 AliMpUID::AliMpUID(AliMp::CathodType cathodeType, const char* pathname)
97 fCathodeId(cathodeType),
105 /// build id from path, but using the given cathodeType
107 if ( CheckTemplate(pathname,pathTemplateMANUPCB,fPCBId) && fPCBId >= 0 ) return;
108 if ( CheckTemplate(pathname,pathTemplatePCB,fPCBId) && fPCBId >= 0 ) return;
110 if ( CheckTemplate(pathname,pathTemplateMANU,fBusPatchId) ) return;
111 if ( CheckTemplate(pathname,pathTemplateBP,fBusPatchId) ) return;
112 if ( CheckTemplate(pathname,pathTemplateDE,fBusPatchId) ) return;
113 if ( CheckTemplate(pathname,pathTemplateCHAMBER,fBusPatchId) ) return;
114 if ( CheckTemplate(pathname,pathTemplateSTATION,fBusPatchId) ) return;
118 //_____________________________________________________________________________
119 AliMpUID::AliMpUID(const char* pathname)
129 /// Build id from path
131 if ( CheckTemplate(pathname,pathTemplateMANUPCB,fPCBId) && fPCBId >= 0 ) return;
132 if ( CheckTemplate(pathname,pathTemplatePCB,fPCBId) && fPCBId >= 0 ) return;
134 if ( CheckTemplate(pathname,pathTemplateMANU,fBusPatchId) ) return;
135 if ( CheckTemplate(pathname,pathTemplateBP,fBusPatchId) ) return;
136 if ( CheckTemplate(pathname,pathTemplateDE,fBusPatchId) ) return;
137 if ( CheckTemplate(pathname,pathTemplateCHAMBER,fBusPatchId) ) return;
138 if ( CheckTemplate(pathname,pathTemplateSTATION,fBusPatchId) ) return;
141 //_____________________________________________________________________________
143 AliMpUID::BaseName() const
146 return gSystem->BaseName(PathName().Data());
149 //_____________________________________________________________________________
151 AliMpUID::CathodeId() const
153 /// return cathode id (not always valid)
154 return AliMp::GetCathodType(fCathodeId);
157 //_____________________________________________________________________________
159 AliMpUID::CheckTemplate(const char* name, const char* pathTemplateName, Int_t& value)
161 /// Check a name against a template
163 if ( TString(name).Contains("Cathode") )
165 sscanf(name,pathTemplateName,&fCathodeId,&fStationId,&fChamberId,&fDetElemId,&value,&fManuId);
169 TString templ(pathTemplateName);
170 Int_t i = templ.Index("/");
171 templ = templ(i+1,templ.Length()-i-1);
172 sscanf(name,templ.Data(),&fStationId,&fChamberId,&fDetElemId,&value,&fManuId);
177 //_____________________________________________________________________________
179 AliMpUID::DirName() const
182 return gSystem->DirName(PathName().Data());
185 //_____________________________________________________________________________
187 AliMpUID::IsStation() const
189 /// Whether we identify a station
190 return fCathodeId >= 0 && fStationId >= 0 && fChamberId == -1 ;
193 //_____________________________________________________________________________
195 AliMpUID::IsChamber() const
197 /// Whether we identify a chamber
199 return fCathodeId >= 0 && fStationId >= 0 && fChamberId >= 0 && fDetElemId == -1;
202 //_____________________________________________________________________________
204 AliMpUID::IsDetectionElement() const
206 /// whether we identify a detection element
207 return fCathodeId >= 0 && fStationId >= 0 && fChamberId >= 0 && fDetElemId >= 0 && fBusPatchId==-1 && fPCBId == -1;
210 //_____________________________________________________________________________
212 AliMpUID::IsBusPatch() const
214 /// whether we identify a bus patch
215 return fCathodeId >= 0 && fStationId >= 0 && fChamberId >= 0 && fDetElemId >= 0 && fBusPatchId>=0 && fManuId ==-1;
218 //_____________________________________________________________________________
219 Bool_t AliMpUID::IsManu() const
221 /// whether we identify a manu
227 ( fBusPatchId>=0 || fPCBId >=0 ) &&
231 //_____________________________________________________________________________
232 Bool_t AliMpUID::IsPCB() const
234 /// Whether we identify a PCB
235 return fCathodeId >= 0 && fPCBId >= 0 && fManuId == -1;
238 //_____________________________________________________________________________
239 Bool_t AliMpUID::IsValid() const
241 /// Whether we're a valid UID...
242 return IsStation() || IsChamber() || IsDetectionElement() || IsBusPatch() || IsManu() || IsPCB();
245 //_____________________________________________________________________________
247 AliMpUID::Name() const
252 return Form(nameTemplateMANU,ManuId());
257 return Form(nameTemplatePCB,PCBId());
262 return Form(nameTemplateBP,BusPatchId());
265 if ( IsDetectionElement() )
267 return Form(nameTemplateDE,DetElemId());
272 return Form(nameTemplateCHAMBER,ChamberId());
277 return Form(nameTemplateSTATION,StationId());
280 return "INVALID NAME";
283 //_____________________________________________________________________________
285 AliMpUID::PathName() const
292 return StripCathode(Form(pathTemplateMANUPCB,CathodeId(),StationId(),ChamberId(),DetElemId(),PCBId(),ManuId()));
296 return StripCathode(Form(pathTemplateMANU,CathodeId(),StationId(),ChamberId(),DetElemId(),BusPatchId(),ManuId()));
302 return StripCathode(Form(pathTemplatePCB,CathodeId(),StationId(),ChamberId(),DetElemId(),PCBId()));
307 return StripCathode(Form(pathTemplateBP,CathodeId(),StationId(),ChamberId(),DetElemId(),BusPatchId()));
310 if ( IsDetectionElement() )
312 return StripCathode(Form(pathTemplateDE,CathodeId(),StationId(),ChamberId(),DetElemId()));
317 return StripCathode(Form(pathTemplateCHAMBER,CathodeId(),StationId(),ChamberId()));
322 return StripCathode(Form(pathTemplateSTATION,CathodeId(),StationId()));
325 return "INVALID PATHNAME";
328 //_____________________________________________________________________________
330 AliMpUID::Print(Option_t*) const
333 cout << Name().Data() << " (" << PathName().Data() << ")" << endl;
336 //_____________________________________________________________________________
338 AliMpUID::StripCathode(const char* name) const
340 /// Remove cathode information if both cathodes are present
344 if ( fCathodeId == 2 )
346 rv.ReplaceAll("Cathode2/","");
352 //_____________________________________________________________________________
354 AliMpUID::Type() const
356 /// Remove cathode information if both cathodes are present
358 TObjArray* s = n.Tokenize(" ");
359 TString rv(static_cast<TObjString*>(s->At(0))->String());