]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - MUON/mapping/AliMpMotifType.cxx
Changing Digit by VDigit (Laurent)
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifType.cxx
... / ...
CommitLineData
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// $MpId: AliMpMotifType.cxx,v 1.10 2006/05/24 13:58:41 ivana Exp $
18// Category: motif
19//
20// Class AliMpMotifType
21// --------------------
22// Class that defines the motif properties.
23// Included in AliRoot: 2003/05/02
24// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
25
26#include "AliMpMotifType.h"
27#include "AliMpMotifTypePadIterator.h"
28#include "AliMpConnection.h"
29
30#include "AliLog.h"
31#include "AliMpFiles.h"
32#include "TSystem.h"
33
34#include <Riostream.h>
35
36/// \cond CLASSIMP
37ClassImp(AliMpMotifType)
38/// \endcond
39
40const Int_t AliMpMotifType::fgkPadNumForA = 65;
41
42//______________________________________________________________________________
43AliMpMotifType::AliMpMotifType(const TString &id)
44 : TObject(),
45 fID(id),
46 fNofPadsX(0),
47 fNofPadsY(0),
48#ifdef WITH_STL
49 fConnections()
50#endif
51#ifdef WITH_ROOT
52 fConnections(true)
53#endif
54{
55 /// Standard constructor \n
56 /// Please note that id should be of the form %s for station 1,2,
57 // %s-%e-%e for station345 and %sx%e for stationTrigger
58
59 AliDebug(1,Form("this=%p id=%s",this,id.Data()));
60}
61
62//______________________________________________________________________________
63AliMpMotifType::AliMpMotifType()
64 : TObject(),
65 fID(""),
66 fNofPadsX(0),
67 fNofPadsY(0),
68 fConnections()
69{
70 /// Default constructor
71 AliDebug(1,Form("this=%p",this));
72}
73
74//______________________________________________________________________________
75AliMpMotifType::AliMpMotifType(const AliMpMotifType& rhs)
76: TObject(),
77 fID(""),
78 fNofPadsX(0),
79 fNofPadsY(0),
80 fConnections()
81{
82 /// Copy constructor
83
84 AliDebug(1,Form("this=%p (copy ctor)",this));
85 rhs.Copy(*this);
86}
87
88//______________________________________________________________________________
89AliMpMotifType&
90AliMpMotifType::operator=(const AliMpMotifType& rhs)
91{
92 /// Assignment operator
93
94 TObject::operator=(rhs);
95 rhs.Copy(*this);
96 return *this;
97}
98
99//______________________________________________________________________________
100TObject*
101AliMpMotifType::Clone(const char* /*newname*/) const
102{
103 /// Returns a full copy of this object
104 return new AliMpMotifType(*this);
105}
106
107//______________________________________________________________________________
108void
109AliMpMotifType::Copy(TObject& object) const
110{
111 /// Copy object
112
113 TObject::Copy(object);
114 AliMpMotifType& mt = static_cast<AliMpMotifType&>(object);
115 mt.fID = fID;
116 mt.fNofPadsX = fNofPadsX;
117 mt.fNofPadsY = fNofPadsY;
118 mt.fConnections = fConnections;
119}
120
121//______________________________________________________________________________
122AliMpMotifType::~AliMpMotifType()
123{
124/// Destructor
125
126#ifdef WITH_STL
127 for(ConnectionMapCIterator i = fConnections.begin();
128 i!=fConnections.end();++i)
129 delete i->second;
130
131 fConnections.erase(fConnections.begin(),fConnections.end());
132#endif
133
134 AliDebug(1,Form("this=%p",this));
135// StdoutToAliDebug(1,this->Print(););
136}
137
138//______________________________________________________________________________
139AliMpVPadIterator* AliMpMotifType::CreateIterator() const
140{
141/// Create new motif type iterator
142
143 return new AliMpMotifTypePadIterator(this);
144}
145
146//______________________________________________________________________________
147void AliMpMotifType::SetNofPads(Int_t nofPadsX, Int_t nofPadsY)
148{
149 /// Change the number of pads in this motif
150
151 fNofPadsX = nofPadsX;
152 fNofPadsY = nofPadsY;
153}
154
155
156//______________________________________________________________________________
157Int_t AliMpMotifType::PadNum(const TString &padName) const
158{
159 /// Transform a pad name into the equivalent pad number
160
161 if ( (padName[0]>='A') && (padName[0]<='Z') )
162 return fgkPadNumForA+padName[0]-'A';
163 else
164 return atoi(padName.Data());
165}
166
167//______________________________________________________________________________
168TString AliMpMotifType::PadName(Int_t padNum) const
169{
170 /// Transform a pad number into its equivalent pad name
171
172 if (padNum<fgkPadNumForA)
173 return Form("%d",padNum);
174 else
175 return char('A'+padNum-fgkPadNumForA);
176}
177
178//______________________________________________________________________________
179void AliMpMotifType::AddConnection(const AliMpIntPair &localIndices,
180 AliMpConnection* connection)
181{
182 /// Add the connection to the map
183
184#ifdef WITH_STL
185 fConnections[localIndices]=connection;
186#endif
187
188#ifdef WITH_ROOT
189 fConnections.Add(localIndices, connection);
190#endif
191
192 connection->SetOwner(this);
193}
194
195//______________________________________________________________________________
196AliMpConnection *AliMpMotifType::FindConnectionByPadNum(Int_t padNum) const
197{
198 /// Retrieve the AliMpConnection pointer from its pad num
199
200#ifdef WITH_STL
201 for(ConnectionMapCIterator i = fConnections.begin();
202 i!=fConnections.end();++i)
203 if (i->second->GetPadNum()==padNum) return i->second;
204 return 0;
205#endif
206
207#ifdef WITH_ROOT
208 TExMapIter i = fConnections.GetIterator();
209 Long_t key, value;
210 while ( i.Next(key, value) ) {
211 AliMpConnection* connection = (AliMpConnection*)value;
212 if (connection->GetPadNum()==padNum) return connection;
213 }
214 return 0;
215#endif
216}
217
218//______________________________________________________________________________
219AliMpConnection *AliMpMotifType::FindConnectionByLocalIndices(
220 const AliMpIntPair& localIndices) const
221{
222 /// Retrieve the AliMpConnection pointer from its position (in pad unit)
223
224 if (!localIndices.IsValid()) return 0;
225
226#ifdef WITH_STL
227 ConnectionMapCIterator i = fConnections.find(localIndices);
228 if (i != fConnections.end())
229 return i->second;
230 else return 0;
231#endif
232
233#ifdef WITH_ROOT
234 return (AliMpConnection*)fConnections.GetValue(localIndices);
235#endif
236}
237
238//______________________________________________________________________________
239AliMpConnection *AliMpMotifType::FindConnectionByGassiNum(Int_t gassiNum) const
240{
241 /// Return the connection for the given gassiplex number
242
243#ifdef WITH_STL
244 for(ConnectionMapCIterator i = fConnections.begin();
245 i!=fConnections.end();++i)
246 if (i->second->GetGassiNum()==gassiNum) return i->second;
247 return 0;
248#endif
249
250#ifdef WITH_ROOT
251 TExMapIter i = fConnections.GetIterator();
252 Long_t key, value;
253 while ( i.Next(key, value) ) {
254 AliMpConnection* connection = (AliMpConnection*)value;
255 if (connection->GetGassiNum()==gassiNum) return connection;
256 }
257 return 0;
258#endif
259}
260
261//______________________________________________________________________________
262AliMpConnection *AliMpMotifType::FindConnectionByKaptonNum(Int_t kaptonNum) const
263{
264 /// Give the connection related to the given kapton number
265
266#ifdef WITH_STL
267 for(ConnectionMapCIterator i = fConnections.begin();
268 i!=fConnections.end();++i)
269 if (i->second->GetKaptonNum()==kaptonNum) return i->second;
270 return 0;
271#endif
272
273#ifdef WITH_ROOT
274 TExMapIter i = fConnections.GetIterator();
275 Long_t key, value;
276 while ( i.Next(key, value) ) {
277 AliMpConnection* connection = (AliMpConnection*)value;
278 if (connection->GetKaptonNum()==kaptonNum) return connection;
279 }
280 return 0;
281#endif
282}
283//______________________________________________________________________________
284AliMpConnection *AliMpMotifType::FindConnectionByBergNum(Int_t bergNum) const
285{
286 /// Retrieve the connection from a Berg connector number
287
288#ifdef WITH_STL
289 for(ConnectionMapCIterator i = fConnections.begin();
290 i!=fConnections.end();++i)
291 if (i->second->GetBergNum()==bergNum) return i->second;
292 return 0;
293#endif
294
295#ifdef WITH_ROOT
296 TExMapIter i = fConnections.GetIterator();
297 Long_t key, value;
298 while ( i.Next(key, value) ) {
299 AliMpConnection* connection = (AliMpConnection*)value;
300 if (connection->GetBergNum()==bergNum) return connection;
301 }
302 return 0;
303#endif
304}
305
306
307//______________________________________________________________________________
308AliMpIntPair AliMpMotifType::FindLocalIndicesByConnection(
309 const AliMpConnection* connection) const
310{
311 /// Retrieve the pad position from the connection pointer.
312 /// Not to be used widely, since it use a search in the
313 /// connection list...
314
315#ifdef WITH_STL
316 for(ConnectionMapCIterator i = fConnections.begin();
317 i!=fConnections.end();++i)
318 if (i->second==connection) return i->first;
319#endif
320
321#ifdef WITH_ROOT
322 TExMapIter i = fConnections.GetIterator();
323 Long_t key, value;
324 while ( i.Next(key, value) ) {
325 AliMpConnection* aConnection = (AliMpConnection*)value;
326 if (aConnection == connection) return AliMpExMap::GetPair(key);
327 }
328#endif
329
330 return AliMpIntPair::Invalid();
331}
332
333//______________________________________________________________________________
334AliMpIntPair AliMpMotifType::FindLocalIndicesByPadNum(Int_t padNum) const
335{
336 /// Retrieve the AliMpConnection pointer from its pad num
337
338#ifdef WITH_STL
339 for(ConnectionMapCIterator i = fConnections.begin();
340 i!=fConnections.end();++i)
341 if (i->second->GetPadNum()==padNum) return i->first;
342#endif
343
344#ifdef WITH_ROOT
345 TExMapIter i = fConnections.GetIterator();
346 Long_t key, value;
347 while ( i.Next(key, value) ) {
348 AliMpConnection* connection = (AliMpConnection*)value;
349 if (connection->GetPadNum() == padNum) return AliMpExMap::GetPair(key);
350 }
351#endif
352 return AliMpIntPair::Invalid();
353}
354
355//______________________________________________________________________________
356AliMpIntPair AliMpMotifType::FindLocalIndicesByGassiNum(Int_t gassiNum) const
357{
358 /// Return the connection for the given gassiplex number
359
360#ifdef WITH_STL
361 for(ConnectionMapCIterator i = fConnections.begin();
362 i!=fConnections.end();++i)
363 if (i->second->GetGassiNum()==gassiNum) return i->first;
364#endif
365
366#ifdef WITH_ROOT
367 TExMapIter i = fConnections.GetIterator();
368 Long_t key, value;
369 while ( i.Next(key, value) ) {
370 AliMpConnection* connection = (AliMpConnection*)value;
371 if (connection->GetGassiNum()==gassiNum) return AliMpExMap::GetPair(key);
372 }
373#endif
374
375 return AliMpIntPair::Invalid();
376}
377
378//______________________________________________________________________________
379AliMpIntPair AliMpMotifType::FindLocalIndicesByKaptonNum(Int_t kaptonNum) const
380{
381 /// Give the connection related to the given kapton number
382
383#ifdef WITH_STL
384 for(ConnectionMapCIterator i = fConnections.begin();
385 i!=fConnections.end();++i)
386 if (i->second->GetKaptonNum()==kaptonNum) return i->first;
387#endif
388
389#ifdef WITH_ROOT
390 TExMapIter i = fConnections.GetIterator();
391 Long_t key, value;
392 while ( i.Next(key, value) ) {
393 AliMpConnection* connection = (AliMpConnection*)value;
394 if (connection->GetKaptonNum()==kaptonNum) return AliMpExMap::GetPair(key);
395 }
396#endif
397
398 return AliMpIntPair::Invalid();
399}
400
401//______________________________________________________________________________
402AliMpIntPair AliMpMotifType::FindLocalIndicesByBergNum(Int_t bergNum) const
403{
404 /// Retrieve the connection from a Berg connector number
405
406#ifdef WITH_STL
407 for(ConnectionMapCIterator i = fConnections.begin();
408 i!=fConnections.end();++i)
409 if (i->second->GetBergNum()==bergNum) return i->first;
410#endif
411
412#ifdef WITH_ROOT
413 TExMapIter i = fConnections.GetIterator();
414 Long_t key, value;
415 while ( i.Next(key, value) ) {
416 AliMpConnection* connection = (AliMpConnection*)value;
417 if (connection->GetBergNum()==bergNum) return AliMpExMap::GetPair(key);
418 }
419#endif
420
421 return AliMpIntPair::Invalid();
422}
423
424//______________________________________________________________________________
425Int_t AliMpMotifType::GetNofPads() const
426{
427/// Return the number of pads
428
429#ifdef WITH_STL
430 return fConnections.size();
431#endif
432
433#ifdef WITH_ROOT
434 return fConnections.GetSize();
435#endif
436}
437
438//______________________________________________________________________________
439Bool_t AliMpMotifType::HasPad(const AliMpIntPair& localIndices) const
440{
441 /// Return true if the pad indexed by \a localIndices has a connection
442
443 if (!localIndices.IsValid()) return false;
444
445#ifdef WITH_STL
446 return fConnections.find(localIndices)!=fConnections.end();
447#endif
448
449#ifdef WITH_ROOT
450 TObject* value = fConnections.GetValue(localIndices);
451 return value!=0;
452#endif
453}
454
455//______________________________________________________________________________
456void AliMpMotifType::Print(Option_t *option) const
457{
458 /// Print the map of the motif. In each cell, the value
459 /// printed depends of option, as the following:
460 /// - option="N" the "name" of the pad is written
461 /// - option="K" the Kapton connect. number attached to the pad is written
462 /// - option="B" the Berg connect. number attached to the pad is written
463 /// - option="G" the Gassiplex channel number attached to the pad is written
464 /// otherwise the number of the pad is written
465 ///
466 /// NOTE : this method is really not optimized, in case 'N' or '',
467 /// but the Print() this should not be very important in a Print() method
468
469 switch (option[0]){
470 case 'N':cout<<"Name mapping";
471 break;
472 case 'K':cout<<"Kapton mapping";
473 break;
474 case 'B':cout<<"Berg mapping";
475 break;
476 case 'G':cout<<"Gassiplex number mapping";
477 break;
478 default:cout<<"Pad mapping";
479 }
480 cout<<" in the motif "<<fID<<endl;
481 cout<<"-----------------------------------"<<endl;
482
483 for (Int_t j=fNofPadsY-1;j>=0;j--){
484 for (Int_t i=0;i<fNofPadsX;i++){
485 AliMpConnection *connexion = FindConnectionByLocalIndices(AliMpIntPair(i,j));
486 TString str;
487 if (connexion){
488 AliDebug(1,Form("i,j=%2d,%2d connexion=%p",i,j,connexion));
489
490 switch (option[0]){
491 case 'N':str=PadName(connexion->GetPadNum());
492 break;
493 case 'K':str=Form("%d",connexion->GetKaptonNum());
494 break;
495 case 'B':str=Form("%d",connexion->GetBergNum());
496 break;
497 case 'G':str=Form("%d",connexion->GetGassiNum());
498 break;
499 default:str= Form("%d",connexion->GetPadNum());
500 }
501 cout<<setw(2)<<str;
502 } else cout<<setw(2)<<"--";
503 cout<<" ";
504 }
505 cout<<endl;
506 }
507}
508
509//_____________________________________________________________________________
510Bool_t
511AliMpMotifType::Save() const
512{
513/// Save this motif type
514
515 return Save(fID.Data());
516}
517
518//_____________________________________________________________________________
519Bool_t
520AliMpMotifType::Save(const char* motifName) const
521{
522 /// Generate the 2 files needed to describe the motif
523
524 TString padPosFileName(AliMpFiles::PadPosFileName(motifName));
525
526 TString motifTypeFileName(AliMpFiles::MotifFileName(motifName));
527
528 // first a protection : do not allow overwriting existing files...
529 Bool_t test = gSystem->AccessPathName(padPosFileName.Data());
530 if (test==kFALSE) // AccessPathName has a strange return value convention...
531 {
532 AliError("Cannot overwrite existing padPos file");
533 return kFALSE;
534 }
535 test = gSystem->AccessPathName(motifTypeFileName.Data());
536 if (test==kFALSE)
537 {
538 AliError("Cannot overwrite existing motifType file");
539 return kFALSE;
540 }
541
542 ofstream padPosFile(padPosFileName.Data());
543 ofstream motifFile(motifTypeFileName.Data());
544
545 motifFile << "# Motif " << motifName << endl
546 << "#" << endl
547 << "#connecteur_berg kapton padname not_used" << endl
548 << "#for slats there's no kapton connector, so it's always 1"
549 << " (zero make the reader" << endl
550 << "#abort, so it's not a valid value here)." << endl
551 << "#" << endl;
552
553 for ( Int_t ix = 0; ix < GetNofPadsX(); ++ix )
554 {
555 for ( Int_t iy = 0; iy < GetNofPadsY(); ++iy )
556 {
557 AliMpConnection* con = FindConnectionByLocalIndices(AliMpIntPair(ix,iy));
558 if (con)
559 {
560 motifFile << con->GetBergNum() << "\t1\t" << con->GetPadNum() << "\t-" << endl;
561 padPosFile << con->GetPadNum() << "\t" << ix << "\t" << iy << endl;
562 }
563 }
564 }
565
566 padPosFile.close();
567 motifFile.close();
568
569 return kTRUE;
570}
571
572
573