AliRoot Core  3dc7879 (3dc7879)
AliMpMotifType.cxx
Go to the documentation of this file.
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 //-----------------------------------------------------------------------------
21 // Class AliMpMotifType
22 // --------------------
23 // Class that defines the motif properties.
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
26 //-----------------------------------------------------------------------------
27 
28 #include "AliMpMotifType.h"
29 #include "AliMpExMapIterator.h"
31 #include "AliMpConnection.h"
32 #include "AliMpConstants.h"
33 #include "AliMpFiles.h"
34 #include "AliMpEncodePair.h"
35 
36 #include "AliLog.h"
37 
38 #include <TSystem.h>
39 #include <Riostream.h>
40 
41 #include <cstdlib>
42 
43 using std::cout;
44 using std::endl;
45 using std::ofstream;
46 using std::setw;
48 ClassImp(AliMpMotifType)
50 
51 const Int_t AliMpMotifType::fgkPadNumForA = 65;
52 
53 //______________________________________________________________________________
54 AliMpMotifType::AliMpMotifType(const TString &id)
55 : TObject(),
56 fID(id),
57 fNofPadsX(0),
58 fNofPadsY(0),
59 fNofPads(0),
60 fMaxNofPads(AliMpConstants::ManuNofChannels()),
61 fConnectionsByLocalIndices(fMaxNofPads*fMaxNofPads),
62 fConnectionsByManuChannel(fMaxNofPads)
63 {
66  // %s-%e-%e for station345 and %sx%e for stationTrigger
67 
68  fConnectionsByLocalIndices.SetOwner(kTRUE);
69  fConnectionsByManuChannel.SetOwner(kFALSE);
70  AliDebug(1,Form("this=%p id=%s",this,id.Data()));
71 }
72 
73 //______________________________________________________________________________
75 : TObject(),
76 fID(""),
77 fNofPadsX(0),
78 fNofPadsY(0),
79 fNofPads(0),
80 fMaxNofPads(0),
81 fConnectionsByLocalIndices(),
82 fConnectionsByManuChannel()
83 {
85  AliDebug(1,Form("this=%p",this));
86 }
87 
88 //______________________________________________________________________________
90 : TObject(),
91 fID(""),
92 fNofPadsX(0),
93 fNofPadsY(0),
94 fNofPads(0),
95 fMaxNofPads(0),
98 {
100  AliDebug(1,Form("this=%p (copy ctor)",this));
101  rhs.Copy(*this);
102 }
103 
104 //______________________________________________________________________________
107 {
109 
110  TObject::operator=(rhs);
111  rhs.Copy(*this);
112  return *this;
113 }
114 
115 //______________________________________________________________________________
116 TObject*
117 AliMpMotifType::Clone(const char* newname) const
118 {
120  AliMpMotifType* mt = new AliMpMotifType(*this);
121 
122  if ( strlen(newname) ) {
123  mt->fID = newname;
124  }
125  return mt;
126 }
127 
128 //______________________________________________________________________________
129 void
130 AliMpMotifType::Copy(TObject& object) const
131 {
133 
134  TObject::Copy(object);
135  AliMpMotifType& mt = static_cast<AliMpMotifType&>(object);
136  mt.fID = fID;
137  mt.fNofPadsX = fNofPadsX;
138  mt.fNofPadsY = fNofPadsY;
139  mt.fNofPads = fNofPads;
143 }
144 
145 //______________________________________________________________________________
147 {
149 
150  AliDebug(1,Form("this=%p",this));
151 }
152 
153 //______________________________________________________________________________
155 {
157 
158  return new AliMpMotifTypePadIterator(this);
159 }
160 
161 //______________________________________________________________________________
162 void AliMpMotifType::SetNofPads(Int_t nofPadsX, Int_t nofPadsY)
163 {
165 
166  fNofPadsX = nofPadsX;
167  fNofPadsY = nofPadsY;
168 }
169 
170 
171 //______________________________________________________________________________
172 Int_t AliMpMotifType::PadNum(const TString &padName) const
173 {
175 
176  if ( (padName[0]>='A') && (padName[0]<='Z') )
177  return fgkPadNumForA+padName[0]-'A';
178  else
179  return atoi(padName.Data());
180 }
181 
182 //______________________________________________________________________________
183 TString AliMpMotifType::PadName(Int_t padNum) const
184 {
186 
187  if (padNum<fgkPadNumForA)
188  return Form("%d",padNum);
189  else
190  return char('A'+padNum-fgkPadNumForA);
191 }
192 
193 //______________________________________________________________________________
194 Bool_t
196 {
198 
199  if (!connection) return kFALSE;
200 
201  Int_t ix = connection->GetLocalIx();
202  Int_t iy = connection->GetLocalIy();
203 
204  Int_t manuChannel = connection->GetManuChannel();
205 
206  if ( ix >=0 && ix < fMaxNofPads &&
207  iy >=0 && iy < fMaxNofPads &&
208  manuChannel >= 0 && manuChannel < AliMpConstants::ManuNofChannels())
209  {
210 
211  Int_t index = ix + iy*AliMpConstants::ManuNofChannels();
212 
214  connection->GetLocalIndices());
215 
216  if (c)
217  {
218  AliError(Form("Connection already exists for ix=%d iy=%d",ix,iy));
219  return kFALSE;
220  }
221 
222  ++fNofPads;
223 
224  fConnectionsByLocalIndices[index] = connection;
225  fConnectionsByManuChannel[manuChannel] = connection;
226 
227  connection->SetOwner(this);
228 
229  return kTRUE;
230 
231  }
232  return kFALSE;
233 }
234 
235 //______________________________________________________________________________
238 {
241 
242  TIter next(&fConnectionsByManuChannel);
243  AliMpConnection* connection;
244 
245  while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
246  {
247  if (connection->GetPadNum()==padNum) return connection;
248  }
249  return 0x0;
250 }
251 
252 //______________________________________________________________________________
255 {
257 
258  return FindConnectionByLocalIndices(AliMp::PairFirst(localIndices),
259  AliMp::PairSecond(localIndices));
260 }
261 
262 //______________________________________________________________________________
265 {
267 
268  if ( ix < fNofPadsX && iy < fNofPadsY && ix >= 0 && iy >= 0 )
269  {
270  Int_t index = ix + iy*fMaxNofPads;
271 
272  return static_cast<AliMpConnection*>(fConnectionsByLocalIndices.UncheckedAt(index));
273  }
274  else
275  {
276  return 0x0;
277  }
278 }
279 
280 //______________________________________________________________________________
283 {
285 
286  if ( gassiNum >=0 && gassiNum < fMaxNofPads )
287  {
288  return static_cast<AliMpConnection*>(fConnectionsByManuChannel.UncheckedAt(gassiNum));
289  }
290 
291  return 0x0;
292 }
293 
294 //______________________________________________________________________________
297 {
300 
301  TIter next(&fConnectionsByManuChannel);
302  AliMpConnection* connection;
303 
304  while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
305  {
306  if ( connection && connection->GetKaptonNum()==kaptonNum) return connection;
307  }
308  return 0x0;
309 }
310 
311 //______________________________________________________________________________
314 {
317 
318  TIter next(&fConnectionsByManuChannel);
319  AliMpConnection* connection;
320 
321  while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
322  {
323  if ( connection && connection->GetBergNum()==bergNum) return connection;
324  }
325  return 0x0;
326 }
327 
328 
329 //______________________________________________________________________________
331 {
333 
334  return connection->GetLocalIndices();
335 }
336 
337 //______________________________________________________________________________
339 {
341 
342  AliMpConnection* connection = FindConnectionByPadNum(padNum);
343 
344  if ( ! connection) return -1;
345 
346  return connection->GetLocalIndices();
347 }
348 
349 //______________________________________________________________________________
351 {
353 
354  AliMpConnection* connection = FindConnectionByGassiNum(gassiNum);
355 
356  if ( ! connection) return -1;
357 
358  return connection->GetLocalIndices();
359 }
360 
361 //______________________________________________________________________________
363 {
365 
366  AliMpConnection* connection = FindConnectionByKaptonNum(kaptonNum);
367 
368  if ( ! connection) return -1;
369 
370  return connection->GetLocalIndices();
371 }
372 
373 //______________________________________________________________________________
375 {
377 
378  AliMpConnection* connection = FindConnectionByBergNum(bergNum);
379 
380  if ( ! connection) return -1;
381 
382  return connection->GetLocalIndices();
383 }
384 
385 //______________________________________________________________________________
386 Bool_t
388 {
390 
391  return ( FindConnectionByLocalIndices(localIndices) != 0x0 );
392 }
393 
394 //______________________________________________________________________________
395 Bool_t
396 AliMpMotifType::HasPadByLocalIndices(Int_t localIx, Int_t localIy) const
397 {
399 
400  return ( FindConnectionByLocalIndices(localIx, localIy) != 0x0 );
401 }
402 
403 //______________________________________________________________________________
404 Bool_t
405 AliMpMotifType::HasPadByManuChannel(Int_t manuChannel) const
406 {
408 
409 // if ( manuChannel >= fNofPads ) return kFALSE;
410 
411  return ( FindConnectionByGassiNum(manuChannel) != 0x0 );
412 }
413 
414 //______________________________________________________________________________
415 void AliMpMotifType::Print(Option_t *option) const
416 {
427 
428  switch (option[0]){
429  case 'N':cout<<"Name mapping";
430  break;
431  case 'K':cout<<"Kapton mapping";
432  break;
433  case 'B':cout<<"Berg mapping";
434  break;
435  case 'G':cout<<"Gassiplex number mapping";
436  break;
437  default:cout<<"Pad mapping";
438  }
439  cout<<" in the motif "<<fID<<endl;
440  cout<<"-----------------------------------"<<endl;
441 
442  for (Int_t j=fNofPadsY-1;j>=0;j--){
443  for (Int_t i=0;i<fNofPadsX;i++){
445  TString str;
446  if (connexion){
447  AliDebug(1,Form("i,j=%2d,%2d connexion=%p",i,j,connexion));
448 
449  switch (option[0]){
450  case 'N':str=PadName(connexion->GetPadNum());
451  break;
452  case 'K':str=Form("%d",connexion->GetKaptonNum());
453  break;
454  case 'B':str=Form("%d",connexion->GetBergNum());
455  break;
456  case 'G':str=Form("%d",connexion->GetManuChannel());
457  break;
458  default:str= Form("%d",connexion->GetPadNum());
459  }
460  cout<<setw(2)<<str;
461  } else cout<<setw(2)<<"--";
462  cout<<" ";
463  }
464  cout<<endl;
465  }
466 }
467 
468 //_____________________________________________________________________________
469 Bool_t
471 {
473 
474  return Save(fID.Data());
475 }
476 
477 //_____________________________________________________________________________
478 Bool_t
479 AliMpMotifType::Save(const char* motifName) const
480 {
482 
483  TString padPosFileName(AliMpFiles::PadPosFileName(motifName));
484 
485  TString motifTypeFileName(AliMpFiles::MotifFileName(motifName));
486 
487  // first a protection : do not allow overwriting existing files...
488  Bool_t test = gSystem->AccessPathName(padPosFileName.Data());
489  if (test==kFALSE) // AccessPathName has a strange return value convention...
490  {
491  AliError("Cannot overwrite existing padPos file");
492  return kFALSE;
493  }
494  test = gSystem->AccessPathName(motifTypeFileName.Data());
495  if (test==kFALSE)
496  {
497  AliError("Cannot overwrite existing motifType file");
498  return kFALSE;
499  }
500 
501  ofstream padPosFile(padPosFileName.Data());
502  ofstream motifFile(motifTypeFileName.Data());
503 
504  motifFile << "# Motif " << motifName << endl
505  << "#" << endl
506  << "#connecteur_berg kapton padname not_used" << endl
507  << "#for slats there's no kapton connector, so it's always 1"
508  << " (zero make the reader" << endl
509  << "#exit, so it's not a valid value here)." << endl
510  << "#" << endl;
511 
512  for ( Int_t ix = 0; ix < GetNofPadsX(); ++ix )
513  {
514  for ( Int_t iy = 0; iy < GetNofPadsY(); ++iy )
515  {
517  if (con)
518  {
519  motifFile << con->GetBergNum() << "\t1\t" << con->GetPadNum() << "\t-" << endl;
520  padPosFile << con->GetPadNum() << "\t" << ix << "\t" << iy << endl;
521  }
522  }
523  }
524 
525  padPosFile.close();
526  motifFile.close();
527 
528  return kTRUE;
529 }
530 
531 
532 
Int_t fNofPads
total number of pads (= the number of non-void entries in the arrays below)
Int_t PadNum(const TString &padName) const
A connection properties.
virtual AliMpVPadIterator * CreateIterator() const
AliMpConnection * FindConnectionByGassiNum(Int_t gassiNum) const
An iterator over the pads of a given motif type.
AliMpConnection * FindConnectionByKaptonNum(Int_t kaptonNum) const
Int_t GetLocalIx() const
MpPair_t FindLocalIndicesByPadNum(Int_t padNum) const
Int_t fNofPadsX
number of pads in x direction
virtual ~AliMpMotifType()
AliMpConnection * FindConnectionByLocalIndices(MpPair_t localIndices) const
void Copy(TObject &o) const
Int_t GetBergNum() const
Return Berg connector number.
MpPair_t GetLocalIndices() const
Return encoded local indices.
TString PadName(Int_t padNum) const
MpPair_t FindLocalIndicesByGassiNum(Int_t gassiNum) const
AliMpMotifType & operator=(const AliMpMotifType &rhs)
TObject * Clone(const char *newname="") const
TObjArray fConnectionsByManuChannel
array [manuChannel] -> AliMpConnection*
void SetNofPads(Int_t nofPadsX, Int_t nofPadY)
static const Int_t fgkPadNumForA
the pad number for the pad "A"
static Int_t ManuNofChannels()
Max number of channels per manu.
AliMpMotifType()
Not implemented.
AliMpConnection * FindConnectionByBergNum(Int_t bergNum) const
Int_t GetKaptonNum() const
Return kapton connector number.
Int_t GetNofPadsX() const
Return number of pads in x direction.
Int_t fNofPadsY
number of pads in y direction
Bool_t Save() const
void SetOwner(AliMpMotifType *owner)
Set the motif type which contains this connection.
Int_t GetNofPadsY() const
Return number of pads in y direction.
Bool_t HasPadByLocalIndices(MpPair_t localIndices) const
Bool_t HasPadByManuChannel(Int_t manuChannel) const
An interface for an iterator over pads.
MpPair_t FindLocalIndicesByConnection(const AliMpConnection *connection) const
Int_t fMaxNofPads
max number of pads we can hold
Int_t GetPadNum() const
Return pad number.
Int_t GetLocalIy() const
MpPair_t FindLocalIndicesByBergNum(Int_t bergNum) const
void test()
Definition: interpolTest.C:100
#define AliDebug(logLevel, message)
Definition: AliLog.h:300
virtual void Print(Option_t *option="") const
Int_t MpPair_t
Int_t GetManuChannel() const
Return manu channel number.
Int_t PairFirst(MpPair_t pair)
Decode the first integer from encoded pair.
Bool_t AddConnection(AliMpConnection *connection)
MpPair_t FindLocalIndicesByKaptonNum(Int_t kaptonNum) const
TObjArray fConnectionsByLocalIndices
array [ix + 64*iy ] -> AliMpConnection*
#define AliError(message)
Definition: AliLog.h:591
Globally used constants definition.
Int_t PairSecond(MpPair_t pair)
Decode the second integer from encoded pair.
TString fID
unique motif ID
AliMpConnection * FindConnectionByPadNum(Int_t padNum) const
Class that defines the motif properties.
static TString MotifFileName(const TString &motifTypeID)
Definition: AliMpFiles.cxx:411
static TString PadPosFileName(const TString &motifTypeID)
Definition: AliMpFiles.cxx:431