]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpMotifType.cxx
- Reordering includes and/or
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifType.cxx
CommitLineData
dee1d5f1 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
5f91c9e8 16// $Id$
63ed9c6b 17// $MpId: AliMpMotifType.cxx,v 1.8 2006/03/02 16:37:27 ivana Exp $
5f91c9e8 18// Category: motif
19//
20// Class AliMpMotifType
21// --------------------
22// Class that defines the motif properties.
dbe945cc 23// Included in AliRoot: 2003/05/02
5f91c9e8 24// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
25
5f91c9e8 26#include "AliMpMotifType.h"
27#include "AliMpMotifTypePadIterator.h"
28#include "AliMpConnection.h"
29
63ed9c6b 30#include <Riostream.h>
31
32#include <stdlib.h>
5f91c9e8 33
34const Int_t AliMpMotifType::fgkPadNumForA = 65;
5f91c9e8 35
63ed9c6b 36ClassImp(AliMpMotifType)
37
5f91c9e8 38//______________________________________________________________________________
39AliMpMotifType::AliMpMotifType(const TString &id)
40 : TObject(),
41 fID(id),
42 fNofPadsX(0),
43 fNofPadsY(0),
44 fVerboseLevel(0),
5006ec94 45#ifdef WITH_STL
5f91c9e8 46 fConnections()
5006ec94 47#endif
48#ifdef WITH_ROOT
49 fConnections(true)
50#endif
5f91c9e8 51{
dee1d5f1 52 /// Standard constructor
5f91c9e8 53}
54
55//______________________________________________________________________________
56AliMpMotifType::AliMpMotifType()
57 : TObject(),
58 fID(""),
59 fNofPadsX(0),
60 fNofPadsY(0),
61 fVerboseLevel(0),
62 fConnections()
63{
dee1d5f1 64 /// Default constructor
5f91c9e8 65}
66
67//______________________________________________________________________________
dee1d5f1 68AliMpMotifType::~AliMpMotifType()
69{
70/// Destructor
5f91c9e8 71
f79c58a5 72#ifdef WITH_STL
2f2452f8 73 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 74 i!=fConnections.end();++i)
75 delete i->second;
76
77 fConnections.erase(fConnections.begin(),fConnections.end());
f79c58a5 78#endif
5f91c9e8 79}
80
81//______________________________________________________________________________
82AliMpVPadIterator* AliMpMotifType::CreateIterator() const
83{
dee1d5f1 84/// Create new motif type iterator
85
5f91c9e8 86 return new AliMpMotifTypePadIterator(this);
87}
88
89//______________________________________________________________________________
90void AliMpMotifType::SetNofPads(Int_t nofPadsX, Int_t nofPadsY)
91{
dee1d5f1 92 /// Change the number of pads in this motif
5f91c9e8 93
94 fNofPadsX = nofPadsX;
95 fNofPadsY = nofPadsY;
96}
97
98
99//______________________________________________________________________________
100Int_t AliMpMotifType::PadNum(const TString &padName) const
101{
dee1d5f1 102 /// Transform a pad name into the equivalent pad number
103
5f91c9e8 104 if ( (padName[0]>='A') && (padName[0]<='Z') )
105 return fgkPadNumForA+padName[0]-'A';
106 else
107 return atoi(padName.Data());
108}
109
110//______________________________________________________________________________
111TString AliMpMotifType::PadName(Int_t padNum) const
112{
dee1d5f1 113 /// Transform a pad number into its equivalent pad name
114
5f91c9e8 115 if (padNum<fgkPadNumForA)
116 return Form("%d",padNum);
117 else
118 return char('A'+padNum-fgkPadNumForA);
119}
120
121//______________________________________________________________________________
122void AliMpMotifType::AddConnection(const AliMpIntPair &localIndices,
123 AliMpConnection* connection)
124{
dee1d5f1 125 /// Add the connection to the map
5f91c9e8 126
f79c58a5 127#ifdef WITH_STL
5f91c9e8 128 fConnections[localIndices]=connection;
f79c58a5 129#endif
130
131#ifdef WITH_ROOT
5006ec94 132 fConnections.Add(localIndices, connection);
f79c58a5 133#endif
134
5f91c9e8 135 connection->SetOwner(this);
136}
f79c58a5 137
5f91c9e8 138//______________________________________________________________________________
139AliMpConnection *AliMpMotifType::FindConnectionByPadNum(Int_t padNum) const
140{
dee1d5f1 141 /// Retrieve the AliMpConnection pointer from its pad num
142
f79c58a5 143#ifdef WITH_STL
2f2452f8 144 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 145 i!=fConnections.end();++i)
146 if (i->second->GetPadNum()==padNum) return i->second;
147 return 0;
f79c58a5 148#endif
149
150#ifdef WITH_ROOT
5006ec94 151 TExMapIter i = fConnections.GetIterator();
f79c58a5 152 Long_t key, value;
153 while ( i.Next(key, value) ) {
154 AliMpConnection* connection = (AliMpConnection*)value;
155 if (connection->GetPadNum()==padNum) return connection;
156 }
157 return 0;
158#endif
5f91c9e8 159}
160
161//______________________________________________________________________________
162AliMpConnection *AliMpMotifType::FindConnectionByLocalIndices(
2f2452f8 163 const AliMpIntPair& localIndices) const
5f91c9e8 164{
dee1d5f1 165 /// Retrieve the AliMpConnection pointer from its position (in pad unit)
166
5f91c9e8 167 if (!localIndices.IsValid()) return 0;
168
f79c58a5 169#ifdef WITH_STL
2f2452f8 170 ConnectionMapCIterator i = fConnections.find(localIndices);
5f91c9e8 171 if (i != fConnections.end())
172 return i->second;
173 else return 0;
f79c58a5 174#endif
175
176#ifdef WITH_ROOT
5006ec94 177 return (AliMpConnection*)fConnections.GetValue(localIndices);
f79c58a5 178#endif
5f91c9e8 179}
180
181//______________________________________________________________________________
182AliMpConnection *AliMpMotifType::FindConnectionByGassiNum(Int_t gassiNum) const
183{
dee1d5f1 184 /// Return the connection for the given gassiplex number
185
f79c58a5 186#ifdef WITH_STL
2f2452f8 187 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 188 i!=fConnections.end();++i)
189 if (i->second->GetGassiNum()==gassiNum) return i->second;
190 return 0;
f79c58a5 191#endif
192
193#ifdef WITH_ROOT
5006ec94 194 TExMapIter i = fConnections.GetIterator();
f79c58a5 195 Long_t key, value;
196 while ( i.Next(key, value) ) {
197 AliMpConnection* connection = (AliMpConnection*)value;
198 if (connection->GetGassiNum()==gassiNum) return connection;
199 }
200 return 0;
201#endif
5f91c9e8 202}
f79c58a5 203
5f91c9e8 204//______________________________________________________________________________
205AliMpConnection *AliMpMotifType::FindConnectionByKaptonNum(Int_t kaptonNum) const
206{
dee1d5f1 207 /// Give the connection related to the given kapton number
208
f79c58a5 209#ifdef WITH_STL
2f2452f8 210 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 211 i!=fConnections.end();++i)
212 if (i->second->GetKaptonNum()==kaptonNum) return i->second;
213 return 0;
f79c58a5 214#endif
215
216#ifdef WITH_ROOT
5006ec94 217 TExMapIter i = fConnections.GetIterator();
f79c58a5 218 Long_t key, value;
219 while ( i.Next(key, value) ) {
220 AliMpConnection* connection = (AliMpConnection*)value;
221 if (connection->GetKaptonNum()==kaptonNum) return connection;
222 }
223 return 0;
224#endif
5f91c9e8 225}
226//______________________________________________________________________________
227AliMpConnection *AliMpMotifType::FindConnectionByBergNum(Int_t bergNum) const
228{
dee1d5f1 229 /// Retrieve the connection from a Berg connector number
230
f79c58a5 231#ifdef WITH_STL
2f2452f8 232 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 233 i!=fConnections.end();++i)
234 if (i->second->GetBergNum()==bergNum) return i->second;
235 return 0;
f79c58a5 236#endif
237
238#ifdef WITH_ROOT
5006ec94 239 TExMapIter i = fConnections.GetIterator();
f79c58a5 240 Long_t key, value;
241 while ( i.Next(key, value) ) {
242 AliMpConnection* connection = (AliMpConnection*)value;
243 if (connection->GetBergNum()==bergNum) return connection;
244 }
245 return 0;
246#endif
5f91c9e8 247}
248
249
250//______________________________________________________________________________
251AliMpIntPair AliMpMotifType::FindLocalIndicesByConnection(
f79c58a5 252 const AliMpConnection* connection) const
5f91c9e8 253{
dee1d5f1 254 /// Retrieve the pad position from the connection pointer.
255 /// Not to be used widely, since it use a search in the
256 /// connection list...
5f91c9e8 257
f79c58a5 258#ifdef WITH_STL
2f2452f8 259 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 260 i!=fConnections.end();++i)
261 if (i->second==connection) return i->first;
f79c58a5 262#endif
263
264#ifdef WITH_ROOT
5006ec94 265 TExMapIter i = fConnections.GetIterator();
f79c58a5 266 Long_t key, value;
267 while ( i.Next(key, value) ) {
268 AliMpConnection* aConnection = (AliMpConnection*)value;
5006ec94 269 if (aConnection == connection) return AliMpExMap::GetPair(key);
f79c58a5 270 }
271#endif
272
273 return AliMpIntPair::Invalid();
5f91c9e8 274}
275
276//______________________________________________________________________________
277AliMpIntPair AliMpMotifType::FindLocalIndicesByPadNum(Int_t padNum) const
278{
dee1d5f1 279 /// Retrieve the AliMpConnection pointer from its pad num
280
f79c58a5 281#ifdef WITH_STL
2f2452f8 282 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 283 i!=fConnections.end();++i)
284 if (i->second->GetPadNum()==padNum) return i->first;
f79c58a5 285#endif
5f91c9e8 286
f79c58a5 287#ifdef WITH_ROOT
5006ec94 288 TExMapIter i = fConnections.GetIterator();
f79c58a5 289 Long_t key, value;
290 while ( i.Next(key, value) ) {
291 AliMpConnection* connection = (AliMpConnection*)value;
5006ec94 292 if (connection->GetPadNum() == padNum) return AliMpExMap::GetPair(key);
f79c58a5 293 }
294#endif
5f91c9e8 295 return AliMpIntPair::Invalid();
296}
297
298//______________________________________________________________________________
299AliMpIntPair AliMpMotifType::FindLocalIndicesByGassiNum(Int_t gassiNum) const
300{
dee1d5f1 301 /// Return the connection for the given gassiplex number
302
f79c58a5 303#ifdef WITH_STL
2f2452f8 304 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 305 i!=fConnections.end();++i)
306 if (i->second->GetGassiNum()==gassiNum) return i->first;
f79c58a5 307#endif
308
309#ifdef WITH_ROOT
5006ec94 310 TExMapIter i = fConnections.GetIterator();
f79c58a5 311 Long_t key, value;
312 while ( i.Next(key, value) ) {
313 AliMpConnection* connection = (AliMpConnection*)value;
5006ec94 314 if (connection->GetGassiNum()==gassiNum) return AliMpExMap::GetPair(key);
f79c58a5 315 }
316#endif
5f91c9e8 317
318 return AliMpIntPair::Invalid();
319}
320
321//______________________________________________________________________________
322AliMpIntPair AliMpMotifType::FindLocalIndicesByKaptonNum(Int_t kaptonNum) const
323{
dee1d5f1 324 /// Give the connection related to the given kapton number
325
f79c58a5 326#ifdef WITH_STL
2f2452f8 327 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 328 i!=fConnections.end();++i)
329 if (i->second->GetKaptonNum()==kaptonNum) return i->first;
f79c58a5 330#endif
331
332#ifdef WITH_ROOT
5006ec94 333 TExMapIter i = fConnections.GetIterator();
f79c58a5 334 Long_t key, value;
335 while ( i.Next(key, value) ) {
336 AliMpConnection* connection = (AliMpConnection*)value;
5006ec94 337 if (connection->GetKaptonNum()==kaptonNum) return AliMpExMap::GetPair(key);
f79c58a5 338 }
339#endif
5f91c9e8 340
341 return AliMpIntPair::Invalid();
342}
343
344//______________________________________________________________________________
345AliMpIntPair AliMpMotifType::FindLocalIndicesByBergNum(Int_t bergNum) const
346{
dee1d5f1 347 /// Retrieve the connection from a Berg connector number
348
f79c58a5 349#ifdef WITH_STL
2f2452f8 350 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 351 i!=fConnections.end();++i)
352 if (i->second->GetBergNum()==bergNum) return i->first;
f79c58a5 353#endif
354
355#ifdef WITH_ROOT
5006ec94 356 TExMapIter i = fConnections.GetIterator();
f79c58a5 357 Long_t key, value;
358 while ( i.Next(key, value) ) {
359 AliMpConnection* connection = (AliMpConnection*)value;
5006ec94 360 if (connection->GetBergNum()==bergNum) return AliMpExMap::GetPair(key);
f79c58a5 361 }
362#endif
5f91c9e8 363
364 return AliMpIntPair::Invalid();
365}
366
f79c58a5 367//______________________________________________________________________________
368Int_t AliMpMotifType::GetNofPads() const
369{
dee1d5f1 370/// Return the number of pads
f79c58a5 371
372#ifdef WITH_STL
373 return fConnections.size();
374#endif
375
376#ifdef WITH_ROOT
377 return fConnections.GetSize();
378#endif
379}
380
5f91c9e8 381//______________________________________________________________________________
382Bool_t AliMpMotifType::HasPad(const AliMpIntPair& localIndices) const
383{
dee1d5f1 384 /// Return true if the pad indexed by <localIndices> has a connection
385
5006ec94 386 //cout << "AliMpMotifType::HasPad: " << localIndices
387 // << "Connections size: " << fConnections.size() << endl;
388
5f91c9e8 389 if (!localIndices.IsValid()) return false;
390
f79c58a5 391#ifdef WITH_STL
5f91c9e8 392 return fConnections.find(localIndices)!=fConnections.end();
f79c58a5 393#endif
5f91c9e8 394
f79c58a5 395#ifdef WITH_ROOT
5006ec94 396 TObject* value = fConnections.GetValue(localIndices);
f79c58a5 397 return value!=0;
398#endif
5f91c9e8 399}
400
401//______________________________________________________________________________
402void AliMpMotifType::Print(Option_t *option) const
403{
dee1d5f1 404 /// Print the map of the motif. In each cell, the value
405 /// printed depends of option, as the following:
406 /// - option="N" the "name" of the pad is written
407 /// - option="K" the Kapton connect. number attached to the pad is written
408 /// - option="B" the Berg connect. number attached to the pad is written
409 /// - option="G" the Gassiplex channel number attached to the pad is written
410 /// otherwise the number of the pad is written
411 ///
412 /// NOTE : this method is really not optimized, in case 'N' or '',
413 /// but the Print() this should not be very important in a Print() method
5f91c9e8 414
415 switch (option[0]){
416 case 'N':cout<<"Name mapping";
417 break;
418 case 'K':cout<<"Kapton mapping";
419 break;
420 case 'B':cout<<"Berg mapping";
421 break;
422 case 'G':cout<<"Gassiplex number mapping";
423 break;
424 default:cout<<"Pad mapping";
425 }
426 cout<<" in the motif "<<fID<<endl;
427 cout<<"-----------------------------------"<<endl;
428
429 for (Int_t j=fNofPadsY-1;j>=0;j--){
430 for (Int_t i=0;i<fNofPadsX;i++){
431 AliMpConnection *connexion = FindConnectionByLocalIndices(AliMpIntPair(i,j));
432 TString str;
433 if (connexion){
434 switch (option[0]){
435 case 'N':str=PadName(connexion->GetPadNum());
436 break;
437 case 'K':str=Form("%d",connexion->GetKaptonNum());
438 break;
439 case 'B':str=Form("%d",connexion->GetBergNum());
440 break;
441 case 'G':str=Form("%d",connexion->GetGassiNum());
442 break;
443 default:str= Form("%d",connexion->GetPadNum());
444 }
445 cout<<setw(2)<<str;
446 } else cout<<setw(2)<<"--";
447 cout<<" ";
448 }
449 cout<<endl;
450 }
451}