]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpUID.cxx
Fix coverity defect
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpUID.cxx
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
31 ClassImp(AliMpUID)
32
33 namespace
34 {
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";
41   
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";
47
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";
50 }
51
52 //_____________________________________________________________________________
53 AliMpUID::AliMpUID()
54
55 fCathodeId(-1),
56 fStationId(-1),
57 fChamberId(-1),
58 fDetElemId(-1),
59 fBusPatchId(-1),
60 fManuId(-1),
61 fPCBId(-1)
62 {
63   /// empty ctor
64 }
65
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)
68
69 fCathodeId(cathodeType),
70 fStationId(station),
71 fChamberId(chamber),
72 fDetElemId(de),
73 fBusPatchId(bp),
74 fManuId(manu),
75 fPCBId(pcb)
76 {
77   /// default ctor
78 }
79
80 //_____________________________________________________________________________
81 AliMpUID::AliMpUID(AliMp::CathodType cathodeType, const AliMpUID& b)
82
83 fCathodeId(cathodeType),
84 fStationId(b.StationId()),
85 fChamberId(b.ChamberId()),
86 fDetElemId(b.DetElemId()),
87 fBusPatchId(b.BusPatchId()),
88 fManuId(b.ManuId()),
89 fPCBId(b.PCBId())
90 {
91   /// build the id from b, but using the given cathodeType
92 }
93
94 //_____________________________________________________________________________
95 AliMpUID::AliMpUID(AliMp::CathodType cathodeType, const char* pathname)
96 :
97 fCathodeId(cathodeType),
98 fStationId(-1),
99 fChamberId(-1),
100 fDetElemId(-1),
101 fBusPatchId(-1),
102 fManuId(-1),
103 fPCBId(-1)
104 {
105   /// build id from path, but using the given cathodeType
106   
107   if ( CheckTemplate(pathname,pathTemplateMANUPCB,fPCBId) && fPCBId >= 0 ) return;
108   if ( CheckTemplate(pathname,pathTemplatePCB,fPCBId) && fPCBId >= 0 ) return;
109   
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;
115 }
116
117
118 //_____________________________________________________________________________
119 AliMpUID::AliMpUID(const char* pathname)
120 :
121 fCathodeId(2),
122 fStationId(-1),
123 fChamberId(-1),
124 fDetElemId(-1),
125 fBusPatchId(-1),
126 fManuId(-1),
127 fPCBId(-1)
128 {
129   /// Build id from path
130   
131   if ( CheckTemplate(pathname,pathTemplateMANUPCB,fPCBId) && fPCBId >= 0 ) return;
132   if ( CheckTemplate(pathname,pathTemplatePCB,fPCBId) && fPCBId >= 0 ) return;
133   
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;
139 }
140
141 //_____________________________________________________________________________
142 TString
143 AliMpUID::BaseName() const
144 {
145   /// Get the basename
146   return gSystem->BaseName(PathName().Data());
147 }
148
149 //_____________________________________________________________________________
150 AliMp::CathodType 
151 AliMpUID::CathodeId() const
152 {
153   /// return cathode id (not always valid)
154   return AliMp::GetCathodType(fCathodeId);
155 }
156
157 //_____________________________________________________________________________
158 Bool_t
159 AliMpUID::CheckTemplate(const char* name, const char* pathTemplateName, Int_t& value)
160 {
161   /// Check a name against a template
162   
163   if ( TString(name).Contains("Cathode") ) 
164   {
165     sscanf(name,pathTemplateName,&fCathodeId,&fStationId,&fChamberId,&fDetElemId,&value,&fManuId);
166   }
167   else
168   {
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);
173   }
174   return IsValid();
175 }
176
177 //_____________________________________________________________________________
178 TString
179 AliMpUID::DirName() const
180 {
181   /// Get dirname
182   return gSystem->DirName(PathName().Data());
183 }
184
185 //_____________________________________________________________________________
186 Bool_t 
187 AliMpUID::IsStation() const
188 {
189   /// Whether we identify a station
190   return fCathodeId >= 0 && fStationId >= 0 && fChamberId == -1 ;
191 }
192
193 //_____________________________________________________________________________
194 Bool_t 
195 AliMpUID::IsChamber() const
196 {
197   /// Whether we identify a chamber
198
199   return fCathodeId >= 0 && fStationId >= 0 && fChamberId >= 0 && fDetElemId == -1;
200 }
201
202 //_____________________________________________________________________________
203 Bool_t 
204 AliMpUID::IsDetectionElement() const
205 {
206   /// whether we identify a detection element
207   return fCathodeId >= 0 &&  fStationId >= 0 && fChamberId >= 0 && fDetElemId >= 0 && fBusPatchId==-1 && fPCBId == -1;
208 }
209
210 //_____________________________________________________________________________
211 Bool_t 
212 AliMpUID::IsBusPatch() const
213 {
214   /// whether we identify a bus patch
215   return fCathodeId >= 0 && fStationId >= 0 && fChamberId >= 0 && fDetElemId >= 0 && fBusPatchId>=0 && fManuId ==-1;
216 }
217
218 //_____________________________________________________________________________
219 Bool_t AliMpUID::IsManu() const
220 {
221   /// whether we identify a manu
222   return 
223   fCathodeId >= 0 && 
224   fStationId >= 0 && 
225   fChamberId >= 0 && 
226   fDetElemId >= 0 && 
227   ( fBusPatchId>=0 || fPCBId >=0 ) && 
228   fManuId >=0;
229 }
230
231 //_____________________________________________________________________________
232 Bool_t AliMpUID::IsPCB() const
233 {
234   /// Whether we identify a PCB
235   return fCathodeId >= 0 && fPCBId >= 0 && fManuId == -1;
236 }
237
238 //_____________________________________________________________________________
239 Bool_t AliMpUID::IsValid() const
240 {
241   /// Whether we're a valid UID...
242   return IsStation() || IsChamber() || IsDetectionElement() || IsBusPatch() || IsManu() || IsPCB();
243 }
244
245 //_____________________________________________________________________________
246 TString 
247 AliMpUID::Name() const
248 {
249   /// Get our name
250   if ( IsManu() ) 
251   {
252     return Form(nameTemplateMANU,ManuId());
253   }
254   
255   if ( IsPCB() ) 
256   {
257     return Form(nameTemplatePCB,PCBId());
258   }
259   
260   if ( IsBusPatch() ) 
261   {
262     return Form(nameTemplateBP,BusPatchId());
263   }
264   
265   if ( IsDetectionElement() ) 
266   {
267     return Form(nameTemplateDE,DetElemId());
268   }
269   
270   if ( IsChamber() ) 
271   {
272     return Form(nameTemplateCHAMBER,ChamberId());
273   }
274   
275   if ( IsStation() ) 
276   {
277     return Form(nameTemplateSTATION,StationId());
278   }
279   
280   return "INVALID NAME";
281 }
282
283 //_____________________________________________________________________________
284 TString 
285 AliMpUID::PathName() const
286 {
287   /// Get our pathname
288   if ( IsManu() ) 
289   {
290     if ( fPCBId >= 0 ) 
291     {
292       return StripCathode(Form(pathTemplateMANUPCB,CathodeId(),StationId(),ChamberId(),DetElemId(),PCBId(),ManuId()));
293     }
294     else
295     {
296       return StripCathode(Form(pathTemplateMANU,CathodeId(),StationId(),ChamberId(),DetElemId(),BusPatchId(),ManuId()));
297     }
298   }
299   
300   if ( IsPCB() ) 
301   {
302     return StripCathode(Form(pathTemplatePCB,CathodeId(),StationId(),ChamberId(),DetElemId(),PCBId()));
303   }
304   
305   if ( IsBusPatch() ) 
306   {
307     return StripCathode(Form(pathTemplateBP,CathodeId(),StationId(),ChamberId(),DetElemId(),BusPatchId()));
308   }
309   
310   if ( IsDetectionElement() ) 
311   {
312     return StripCathode(Form(pathTemplateDE,CathodeId(),StationId(),ChamberId(),DetElemId()));
313   }
314   
315   if ( IsChamber() ) 
316   {
317     return StripCathode(Form(pathTemplateCHAMBER,CathodeId(),StationId(),ChamberId()));
318   }
319   
320   if ( IsStation() ) 
321   {
322     return StripCathode(Form(pathTemplateSTATION,CathodeId(),StationId()));
323   }
324   
325   return "INVALID PATHNAME";
326 }
327
328 //_____________________________________________________________________________
329 void 
330 AliMpUID::Print(Option_t*) const
331 {
332   /// Printout
333   cout << Name().Data() << " (" << PathName().Data() << ")" << endl;
334 }
335
336 //_____________________________________________________________________________
337 TString
338 AliMpUID::StripCathode(const char* name) const
339 {
340   /// Remove cathode information if both cathodes are present
341   
342   TString rv(name);
343   
344   if ( fCathodeId == 2 ) 
345   {
346     rv.ReplaceAll("Cathode2/","");
347   }
348   
349   return rv;
350 }
351
352 //_____________________________________________________________________________
353 TString
354 AliMpUID::Type() const
355 {
356   /// Remove cathode information if both cathodes are present
357   TString n(Name());
358   TObjArray* s = n.Tokenize(" ");
359   TString rv(static_cast<TObjString*>(s->At(0))->String());
360   delete s;
361   return rv;
362 }
363