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