Line data Source code
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"
30 : #include "AliMpMotifTypePadIterator.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;
47 : /// \cond CLASSIMP
48 18 : ClassImp(AliMpMotifType)
49 : /// \endcond
50 :
51 : const Int_t AliMpMotifType::fgkPadNumForA = 65;
52 :
53 : //______________________________________________________________________________
54 : AliMpMotifType::AliMpMotifType(const TString &id)
55 639 : : TObject(),
56 639 : fID(id),
57 639 : fNofPadsX(0),
58 639 : fNofPadsY(0),
59 639 : fNofPads(0),
60 639 : fMaxNofPads(AliMpConstants::ManuNofChannels()),
61 639 : fConnectionsByLocalIndices(fMaxNofPads*fMaxNofPads),
62 639 : fConnectionsByManuChannel(fMaxNofPads)
63 3195 : {
64 : /// Standard constructor \n
65 : /// Please note that id should be of the form %s for station 1,2,
66 : // %s-%e-%e for station345 and %sx%e for stationTrigger
67 :
68 639 : fConnectionsByLocalIndices.SetOwner(kTRUE);
69 639 : fConnectionsByManuChannel.SetOwner(kFALSE);
70 3195 : AliDebug(1,Form("this=%p id=%s",this,id.Data()));
71 1278 : }
72 :
73 : //______________________________________________________________________________
74 : AliMpMotifType::AliMpMotifType(TRootIOCtor*)
75 0 : : TObject(),
76 0 : fID(""),
77 0 : fNofPadsX(0),
78 0 : fNofPadsY(0),
79 0 : fNofPads(0),
80 0 : fMaxNofPads(0),
81 0 : fConnectionsByLocalIndices(),
82 0 : fConnectionsByManuChannel()
83 0 : {
84 : /// Default constructor
85 0 : AliDebug(1,Form("this=%p",this));
86 0 : }
87 :
88 : //______________________________________________________________________________
89 : AliMpMotifType::AliMpMotifType(const AliMpMotifType& rhs)
90 0 : : TObject(),
91 0 : fID(""),
92 0 : fNofPadsX(0),
93 0 : fNofPadsY(0),
94 0 : fNofPads(0),
95 0 : fMaxNofPads(0),
96 0 : fConnectionsByLocalIndices(),
97 0 : fConnectionsByManuChannel()
98 0 : {
99 : /// Copy constructor
100 0 : AliDebug(1,Form("this=%p (copy ctor)",this));
101 0 : rhs.Copy(*this);
102 0 : }
103 :
104 : //______________________________________________________________________________
105 : AliMpMotifType&
106 : AliMpMotifType::operator=(const AliMpMotifType& rhs)
107 : {
108 : /// Assignment operator
109 :
110 0 : TObject::operator=(rhs);
111 0 : rhs.Copy(*this);
112 0 : return *this;
113 : }
114 :
115 : //______________________________________________________________________________
116 : TObject*
117 : AliMpMotifType::Clone(const char* /*newname*/) const
118 : {
119 : /// Returns a full copy of this object
120 0 : return new AliMpMotifType(*this);
121 0 : }
122 :
123 : //______________________________________________________________________________
124 : void
125 : AliMpMotifType::Copy(TObject& object) const
126 : {
127 : /// Copy object
128 :
129 0 : TObject::Copy(object);
130 0 : AliMpMotifType& mt = static_cast<AliMpMotifType&>(object);
131 0 : mt.fID = fID;
132 0 : mt.fNofPadsX = fNofPadsX;
133 0 : mt.fNofPadsY = fNofPadsY;
134 0 : mt.fNofPads = fNofPads;
135 0 : mt.fMaxNofPads = fMaxNofPads;
136 0 : mt.fConnectionsByLocalIndices = fConnectionsByLocalIndices;
137 0 : mt.fConnectionsByManuChannel = fConnectionsByManuChannel;
138 0 : }
139 :
140 : //______________________________________________________________________________
141 : AliMpMotifType::~AliMpMotifType()
142 2556 : {
143 : /// Destructor
144 :
145 2130 : AliDebug(1,Form("this=%p",this));
146 1278 : }
147 :
148 : //______________________________________________________________________________
149 : AliMpVPadIterator* AliMpMotifType::CreateIterator() const
150 : {
151 : /// Create new motif type iterator
152 :
153 0 : return new AliMpMotifTypePadIterator(this);
154 0 : }
155 :
156 : //______________________________________________________________________________
157 : void AliMpMotifType::SetNofPads(Int_t nofPadsX, Int_t nofPadsY)
158 : {
159 : /// Change the number of pads in this motif
160 :
161 1278 : fNofPadsX = nofPadsX;
162 639 : fNofPadsY = nofPadsY;
163 639 : }
164 :
165 :
166 : //______________________________________________________________________________
167 : Int_t AliMpMotifType::PadNum(const TString &padName) const
168 : {
169 : /// Transform a pad name into the equivalent pad number
170 :
171 77736 : if ( (padName[0]>='A') && (padName[0]<='Z') )
172 144 : return fgkPadNumForA+padName[0]-'A';
173 : else
174 38652 : return atoi(padName.Data());
175 38796 : }
176 :
177 : //______________________________________________________________________________
178 : TString AliMpMotifType::PadName(Int_t padNum) const
179 : {
180 : /// Transform a pad number into its equivalent pad name
181 :
182 0 : if (padNum<fgkPadNumForA)
183 0 : return Form("%d",padNum);
184 : else
185 0 : return char('A'+padNum-fgkPadNumForA);
186 0 : }
187 :
188 : //______________________________________________________________________________
189 : Bool_t
190 : AliMpMotifType::AddConnection(AliMpConnection* connection)
191 : {
192 : /// Add the connection to the map
193 :
194 77592 : if (!connection) return kFALSE;
195 :
196 38796 : Int_t ix = connection->GetLocalIx();
197 38796 : Int_t iy = connection->GetLocalIy();
198 :
199 38796 : Int_t manuChannel = connection->GetManuChannel();
200 :
201 155184 : if ( ix >=0 && ix < fMaxNofPads &&
202 116388 : iy >=0 && iy < fMaxNofPads &&
203 77592 : manuChannel >= 0 && manuChannel < AliMpConstants::ManuNofChannels())
204 : {
205 :
206 38796 : Int_t index = ix + iy*AliMpConstants::ManuNofChannels();
207 :
208 38796 : AliMpConnection* c = FindConnectionByLocalIndices(
209 38796 : connection->GetLocalIndices());
210 :
211 38796 : if (c)
212 : {
213 0 : AliError(Form("Connection already exists for ix=%d iy=%d",ix,iy));
214 0 : return kFALSE;
215 : }
216 :
217 38796 : ++fNofPads;
218 :
219 38796 : fConnectionsByLocalIndices[index] = connection;
220 38796 : fConnectionsByManuChannel[manuChannel] = connection;
221 :
222 38796 : connection->SetOwner(this);
223 :
224 38796 : return kTRUE;
225 :
226 : }
227 0 : return kFALSE;
228 38796 : }
229 :
230 : //______________________________________________________________________________
231 : AliMpConnection*
232 : AliMpMotifType::FindConnectionByPadNum(Int_t padNum) const
233 : {
234 : /// Retrieve the AliMpConnection pointer from its pad num
235 : /// This method is quite inefficient as we're looping over all connections
236 :
237 0 : TIter next(&fConnectionsByManuChannel);
238 : AliMpConnection* connection;
239 :
240 0 : while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
241 : {
242 0 : if (connection->GetPadNum()==padNum) return connection;
243 : }
244 0 : return 0x0;
245 0 : }
246 :
247 : //______________________________________________________________________________
248 : AliMpConnection*
249 : AliMpMotifType::FindConnectionByLocalIndices(MpPair_t localIndices) const
250 : {
251 : /// Retrieve the AliMpConnection pointer from its position (in pad unit)
252 :
253 21768222 : return FindConnectionByLocalIndices(AliMp::PairFirst(localIndices),
254 7256074 : AliMp::PairSecond(localIndices));
255 : }
256 :
257 : //______________________________________________________________________________
258 : AliMpConnection*
259 : AliMpMotifType::FindConnectionByLocalIndices(Int_t ix, Int_t iy) const
260 : {
261 : /// Retrieve the AliMpConnection pointer from its position (in pad unit)
262 :
263 26584324 : if ( ix < fNofPadsX && iy < fNofPadsY && ix >= 0 && iy >= 0 )
264 : {
265 8834916 : Int_t index = ix + iy*fMaxNofPads;
266 :
267 8834916 : return static_cast<AliMpConnection*>(fConnectionsByLocalIndices.UncheckedAt(index));
268 : }
269 : else
270 : {
271 39683 : return 0x0;
272 : }
273 8874599 : }
274 :
275 : //______________________________________________________________________________
276 : AliMpConnection*
277 : AliMpMotifType::FindConnectionByGassiNum(Int_t gassiNum) const
278 : {
279 : /// Return the connection for the given gassiplex number
280 :
281 13074444 : if ( gassiNum >=0 && gassiNum < fMaxNofPads )
282 : {
283 4357124 : return static_cast<AliMpConnection*>(fConnectionsByManuChannel.UncheckedAt(gassiNum));
284 : }
285 :
286 1536 : return 0x0;
287 4358660 : }
288 :
289 : //______________________________________________________________________________
290 : AliMpConnection*
291 : AliMpMotifType::FindConnectionByKaptonNum(Int_t kaptonNum) const
292 : {
293 : /// Give the connection related to the given kapton number
294 : /// Inefficient method as we loop over connections to find the right one
295 :
296 0 : TIter next(&fConnectionsByManuChannel);
297 : AliMpConnection* connection;
298 :
299 0 : while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
300 : {
301 0 : if ( connection && connection->GetKaptonNum()==kaptonNum) return connection;
302 : }
303 0 : return 0x0;
304 0 : }
305 :
306 : //______________________________________________________________________________
307 : AliMpConnection*
308 : AliMpMotifType::FindConnectionByBergNum(Int_t bergNum) const
309 : {
310 : /// Retrieve the connection from a Berg connector number
311 : /// Inefficient method as we loop over connections to find the right one
312 :
313 0 : TIter next(&fConnectionsByManuChannel);
314 : AliMpConnection* connection;
315 :
316 0 : while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
317 : {
318 0 : if ( connection && connection->GetBergNum()==bergNum) return connection;
319 : }
320 0 : return 0x0;
321 0 : }
322 :
323 :
324 : //______________________________________________________________________________
325 : MpPair_t AliMpMotifType::FindLocalIndicesByConnection(const AliMpConnection* connection) const
326 : {
327 : /// Reurn the pad position from the connection pointer.
328 :
329 0 : return connection->GetLocalIndices();
330 : }
331 :
332 : //______________________________________________________________________________
333 : MpPair_t AliMpMotifType::FindLocalIndicesByPadNum(Int_t padNum) const
334 : {
335 : /// Retrieve the AliMpConnection pointer from its pad num
336 :
337 0 : AliMpConnection* connection = FindConnectionByPadNum(padNum);
338 :
339 0 : if ( ! connection) return -1;
340 :
341 0 : return connection->GetLocalIndices();
342 0 : }
343 :
344 : //______________________________________________________________________________
345 : MpPair_t AliMpMotifType::FindLocalIndicesByGassiNum(Int_t gassiNum) const
346 : {
347 : /// Return the connection for the given gassiplex number
348 :
349 7847560 : AliMpConnection* connection = FindConnectionByGassiNum(gassiNum);
350 :
351 3981932 : if ( ! connection) return -1;
352 :
353 3865628 : return connection->GetLocalIndices();
354 3923780 : }
355 :
356 : //______________________________________________________________________________
357 : MpPair_t AliMpMotifType::FindLocalIndicesByKaptonNum(Int_t kaptonNum) const
358 : {
359 : /// Give the connection related to the given kapton number
360 :
361 0 : AliMpConnection* connection = FindConnectionByKaptonNum(kaptonNum);
362 :
363 0 : if ( ! connection) return -1;
364 :
365 0 : return connection->GetLocalIndices();
366 0 : }
367 :
368 : //______________________________________________________________________________
369 : MpPair_t AliMpMotifType::FindLocalIndicesByBergNum(Int_t bergNum) const
370 : {
371 : /// Retrieve the connection from a Berg connector number
372 :
373 0 : AliMpConnection* connection = FindConnectionByBergNum(bergNum);
374 :
375 0 : if ( ! connection) return -1;
376 :
377 0 : return connection->GetLocalIndices();
378 0 : }
379 :
380 : //______________________________________________________________________________
381 : Bool_t
382 : AliMpMotifType::HasPadByLocalIndices(MpPair_t localIndices) const
383 : {
384 : /// Return true if the pad indexed by \a localIndices has a connection
385 :
386 11017614 : return ( FindConnectionByLocalIndices(localIndices) != 0x0 );
387 : }
388 :
389 : //______________________________________________________________________________
390 : Bool_t
391 : AliMpMotifType::HasPadByLocalIndices(Int_t localIx, Int_t localIy) const
392 : {
393 : /// Return true if the pad indexed by \a localIndices has a connection
394 :
395 3227038 : return ( FindConnectionByLocalIndices(localIx, localIy) != 0x0 );
396 : }
397 :
398 : //______________________________________________________________________________
399 : Bool_t
400 : AliMpMotifType::HasPadByManuChannel(Int_t manuChannel) const
401 : {
402 : /// Return true if the pad indexed by \a localIndices has a connection
403 :
404 : // if ( manuChannel >= fNofPads ) return kFALSE;
405 :
406 869760 : return ( FindConnectionByGassiNum(manuChannel) != 0x0 );
407 : }
408 :
409 : //______________________________________________________________________________
410 : void AliMpMotifType::Print(Option_t *option) const
411 : {
412 : /// Print the map of the motif. In each cell, the value
413 : /// printed depends of option, as the following:
414 : /// - option="N" the "name" of the pad is written
415 : /// - option="K" the Kapton connect. number attached to the pad is written
416 : /// - option="B" the Berg connect. number attached to the pad is written
417 : /// - option="G" the Gassiplex channel number attached to the pad is written
418 : /// otherwise the number of the pad is written
419 : ///
420 : /// NOTE : this method is really not optimized, in case 'N' or '',
421 : /// but the Print() this should not be very important in a Print() method
422 :
423 0 : switch (option[0]){
424 0 : case 'N':cout<<"Name mapping";
425 0 : break;
426 0 : case 'K':cout<<"Kapton mapping";
427 0 : break;
428 0 : case 'B':cout<<"Berg mapping";
429 0 : break;
430 0 : case 'G':cout<<"Gassiplex number mapping";
431 0 : break;
432 0 : default:cout<<"Pad mapping";
433 0 : }
434 0 : cout<<" in the motif "<<fID<<endl;
435 0 : cout<<"-----------------------------------"<<endl;
436 :
437 0 : for (Int_t j=fNofPadsY-1;j>=0;j--){
438 0 : for (Int_t i=0;i<fNofPadsX;i++){
439 0 : AliMpConnection *connexion = FindConnectionByLocalIndices(i,j);
440 0 : TString str;
441 0 : if (connexion){
442 0 : AliDebug(1,Form("i,j=%2d,%2d connexion=%p",i,j,connexion));
443 :
444 0 : switch (option[0]){
445 0 : case 'N':str=PadName(connexion->GetPadNum());
446 0 : break;
447 0 : case 'K':str=Form("%d",connexion->GetKaptonNum());
448 : break;
449 0 : case 'B':str=Form("%d",connexion->GetBergNum());
450 : break;
451 0 : case 'G':str=Form("%d",connexion->GetManuChannel());
452 : break;
453 0 : default:str= Form("%d",connexion->GetPadNum());
454 : }
455 0 : cout<<setw(2)<<str;
456 0 : } else cout<<setw(2)<<"--";
457 0 : cout<<" ";
458 0 : }
459 0 : cout<<endl;
460 : }
461 0 : }
462 :
463 : //_____________________________________________________________________________
464 : Bool_t
465 : AliMpMotifType::Save() const
466 : {
467 : /// Save this motif type
468 :
469 0 : return Save(fID.Data());
470 : }
471 :
472 : //_____________________________________________________________________________
473 : Bool_t
474 : AliMpMotifType::Save(const char* motifName) const
475 : {
476 : /// Generate the 2 files needed to describe the motif
477 :
478 0 : TString padPosFileName(AliMpFiles::PadPosFileName(motifName));
479 :
480 0 : TString motifTypeFileName(AliMpFiles::MotifFileName(motifName));
481 :
482 : // first a protection : do not allow overwriting existing files...
483 0 : Bool_t test = gSystem->AccessPathName(padPosFileName.Data());
484 0 : if (test==kFALSE) // AccessPathName has a strange return value convention...
485 : {
486 0 : AliError("Cannot overwrite existing padPos file");
487 0 : return kFALSE;
488 : }
489 0 : test = gSystem->AccessPathName(motifTypeFileName.Data());
490 0 : if (test==kFALSE)
491 : {
492 0 : AliError("Cannot overwrite existing motifType file");
493 0 : return kFALSE;
494 : }
495 :
496 0 : ofstream padPosFile(padPosFileName.Data());
497 0 : ofstream motifFile(motifTypeFileName.Data());
498 :
499 0 : motifFile << "# Motif " << motifName << endl
500 0 : << "#" << endl
501 0 : << "#connecteur_berg kapton padname not_used" << endl
502 0 : << "#for slats there's no kapton connector, so it's always 1"
503 0 : << " (zero make the reader" << endl
504 0 : << "#exit, so it's not a valid value here)." << endl
505 0 : << "#" << endl;
506 :
507 0 : for ( Int_t ix = 0; ix < GetNofPadsX(); ++ix )
508 : {
509 0 : for ( Int_t iy = 0; iy < GetNofPadsY(); ++iy )
510 : {
511 0 : AliMpConnection* con = FindConnectionByLocalIndices(ix,iy);
512 0 : if (con)
513 : {
514 0 : motifFile << con->GetBergNum() << "\t1\t" << con->GetPadNum() << "\t-" << endl;
515 0 : padPosFile << con->GetPadNum() << "\t" << ix << "\t" << iy << endl;
516 : }
517 : }
518 : }
519 :
520 0 : padPosFile.close();
521 0 : motifFile.close();
522 :
523 : return kTRUE;
524 0 : }
525 :
526 :
527 :
|