1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 /// \class AliMpFastSegmentation
19 /// An implementation of AliMpVSegmentation, which uses
20 /// some internal maps to speed up the (Has)PadByIndices and PadByLocation
23 /// L. Aphecetche, Subatech
26 #include "AliMpFastSegmentation.h"
28 #include "AliCodeTimer.h"
30 #include "AliMpConnection.h"
31 #include "AliMpConstants.h"
32 #include "AliMpMotifMap.h"
33 #include "AliMpMotifPosition.h"
34 #include "AliMpMotifType.h"
36 #include "AliMpSector.h"
37 #include "AliMpSlat.h"
38 #include "AliMpVPadIterator.h"
39 #include "AliMpEncodePair.h"
44 ClassImp(AliMpFastSegmentation)
56 /// The values in Encode and Encode2 are not exactly random.
57 /// They are the result of a few "try and see" efforts to optimize the
58 /// timing of the TExMap::GetValue (you should note that the TExMap implementation
59 /// speed depends on the "non-uniformity" of the keys).
61 /// So don't change those values w/o at least testing a bit the implications...
62 /// But feel free to experiment though, in order to optimizer further ;-)
64 Int_t Encode(Int_t a, Int_t b)
69 Int_t Encode2(Int_t a)
71 /// Ideally this method should be different for sectors and slats, as we have
72 /// much less manus per DE for slats, and hence the "non-uniformity" is less...
73 return ( a ^ (1<<10) ) << 16 ;
77 //_____________________________________________________________________________
78 AliMpFastSegmentation::AliMpFastSegmentation(AliMpVSegmentation* vseg)
79 : AliMpVSegmentation(),
87 /// Ctor. We adopt vseg.
91 AliError("Will get a hard time working with a NULL vseg !");
95 AliCodeTimerAuto(vseg->ClassName(),0);
97 fPositionX = vseg->GetPositionX();
98 fPositionY = vseg->GetPositionY();
102 vseg->GetAllElectronicCardIDs(manus);
104 for ( Int_t i = 0; i < manus.GetSize(); ++i )
106 Int_t manuId = manus[i];
108 AliMpMotifPosition* mp = vseg->MotifPosition(manuId);
110 // Should never happen
112 AliFatal("AliMpMotifPosition not found.");
115 Int_t index = 1 + fMotifPositions.GetLast();
117 fMotifPositions.AddLast(mp);
119 fManuId.Add(Encode2(manuId),1+index);
121 for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
123 if ( vseg->HasPadByLocation(manuId,manuChannel) )
125 AliMpPad pad = vseg->PadByLocation(manuId,manuChannel);
127 fIxIy.Add(Encode(pad.GetIx(),pad.GetIy()),1+index);
133 //_____________________________________________________________________________
134 AliMpFastSegmentation::~AliMpFastSegmentation()
140 //_____________________________________________________________________________
142 AliMpFastSegmentation::CreateIterator(const AliMpArea& area) const
144 /// Forward to our helper
145 return fHelper->CreateIterator(area);
148 //_____________________________________________________________________________
150 AliMpFastSegmentation::CreateIterator() const
152 /// Forward to our helper
153 return fHelper->CreateIterator();
156 //_____________________________________________________________________________
158 AliMpFastSegmentation::GetNeighbours(const AliMpPad& pad, TObjArray& neighbours,
160 Bool_t includeVoid) const
162 /// Use default implementation
163 return AliMpVSegmentation::GetNeighbours(pad,neighbours,includeSelf,includeVoid);
166 //_____________________________________________________________________________
168 AliMpFastSegmentation::PadByLocation(Int_t manuId, Int_t manuChannel,
169 Bool_t warning) const
171 /// Get the pad by location, using the manuid map.
173 Int_t index = fManuId.GetValue(Encode2(manuId));
179 AliWarning(Form("Manu ID %d not found",manuId));
182 return AliMpPad::Invalid();
185 AliMpMotifPosition* motifPos = InternalMotifPosition(index);
189 AliError(Form("InternalMotifPosition(%d) failed",index));
191 return AliMpPad::Invalid();
194 AliMpVMotif* motif = motifPos->GetMotif();
195 MpPair_t localIndices
196 = motif->GetMotifType()->FindLocalIndicesByGassiNum(manuChannel);
198 if ( localIndices < 0 )
202 AliWarning(Form("The pad number %d doesn't exists", manuChannel));
205 return AliMpPad::Invalid();
210 motif->PadPositionLocal(localIndices, posx, posy);
211 posx += motifPos->GetPositionX() - fPositionX;
212 posy += motifPos->GetPositionY() - fPositionY;
215 motif->GetPadDimensionsByIndices(localIndices, dx, dy);
217 AliMpPad pad1 = AliMpPad(manuId, manuChannel,
218 motifPos->GlobalIndices(localIndices),
221 AliMpPad pad2 = fHelper->PadByLocation(manuId, manuChannel,warning);
231 motif->PadPositionLocal(localIndices, posx, posy);
232 posx += motifPos->GetPositionX() - fPositionX;
233 posy += motifPos->GetPositionY() - fPositionY;
236 motif->GetPadDimensionsByIndices(localIndices, dx, dy);
238 return AliMpPad(manuId, manuChannel,
239 motifPos->GlobalIndices(localIndices),
243 //_____________________________________________________________________________
245 AliMpFastSegmentation::InternalMotifPosition(Int_t index) const
247 /// Get the internal manu from the index
248 return static_cast<AliMpMotifPosition*>(fMotifPositions.UncheckedAt(index-1));
251 //_____________________________________________________________________________
253 AliMpFastSegmentation::PadByIndices (Int_t ix, Int_t iy, Bool_t warning) const
255 /// Get pad by indices
257 Int_t index = fIxIy.GetValue(Encode(ix, iy));
263 AliWarning(Form("ManuID not found for pad indices (%d,%d)", ix, iy));
266 return AliMpPad::Invalid();
269 AliMpMotifPosition* motifPos = InternalMotifPosition(index);
273 AliError(Form("InternalMotifPosition(%d) failed",index));
275 return AliMpPad::Invalid();
278 AliMpVMotif* motif = motifPos->GetMotif();
279 AliMpMotifType* motifType = motif->GetMotifType();
280 MpPair_t localIndices(AliMp::Pair(ix, iy) - motifPos->GetLowIndicesLimit());
281 AliMpConnection* connection = motifType->FindConnectionByLocalIndices(localIndices);
287 AliWarning(Form("No connection for pad indices (%d,%d)", ix, iy));
289 return AliMpPad::Invalid();
293 AliMpPad pad2 = fHelper->PadByIndices(ix, iy, warning);
296 motif->PadPositionLocal(localIndices, posx, posy);
297 posx += motifPos->GetPositionX() - fPositionX;
298 posy += motifPos->GetPositionY() - fPositionY;
301 motif->GetPadDimensionsByIndices(localIndices, dx, dy);
303 AliMpPad pad1 = AliMpPad(motifPos->GetID(),connection->GetManuChannel(),
304 ix, iy, posx, posy, dx, dy);
309 motif->PadPositionLocal(localIndices, posx, posy);
310 posx += motifPos->GetPositionX() - fPositionX;
311 posy += motifPos->GetPositionY() - fPositionY;
314 motif->GetPadDimensionsByIndices(localIndices, dx, dy);
316 return AliMpPad(motifPos->GetID(),connection->GetManuChannel(),
317 ix, iy, posx, posy, dx, dy);
321 //_____________________________________________________________________________
323 AliMpFastSegmentation::PadByPosition(Double_t x, Double_t y, Bool_t warning ) const
325 /// Forward to our helper
326 return fHelper->PadByPosition(x, y, warning);
329 //_____________________________________________________________________________
331 AliMpFastSegmentation::MaxPadIndexX() const
333 /// Forward to our helper
334 return fHelper->MaxPadIndexX();
337 //_____________________________________________________________________________
339 AliMpFastSegmentation::MaxPadIndexY() const
341 /// Forward to our helper
342 return fHelper->MaxPadIndexY();
345 //_____________________________________________________________________________
347 AliMpFastSegmentation::NofPads() const
349 /// Forward to our helper
350 return fHelper->NofPads();
353 //_____________________________________________________________________________
355 AliMpFastSegmentation::GetNofElectronicCards() const
357 /// Forward to our helper
358 return fHelper->GetNofElectronicCards();
361 //_____________________________________________________________________________
363 AliMpFastSegmentation::GetAllElectronicCardIDs(TArrayI& ecn) const
365 /// Forward to our helper
366 fHelper->GetAllElectronicCardIDs(ecn);
369 //_____________________________________________________________________________
371 AliMpFastSegmentation::HasPadByIndices(Int_t ix, Int_t iy) const
373 /// Whether there is a pad at the given indices
374 Int_t index = fIxIy.GetValue(Encode(ix, iy));
376 if ( !index ) return kFALSE;
378 AliMpMotifPosition* mp = InternalMotifPosition(index);
380 Bool_t r1 = mp->HasPadByIndices(AliMp::Pair(ix, iy));
382 Bool_t r2 = fHelper->HasPadByIndices(ix, iy);
389 //_____________________________________________________________________________
391 AliMpFastSegmentation::HasPadByLocation(Int_t manuId, Int_t manuChannel) const
393 /// Whether there is a pad at the given location (de,manuid)
395 Int_t index = fManuId.GetValue(Encode2(manuId));
397 if (!index) return kFALSE;
399 AliMpMotifPosition* mp = InternalMotifPosition(index);
401 Bool_t r1 = mp->HasPadByManuChannel(manuChannel);
403 Bool_t r2 = fHelper->HasPadByLocation(manuId, manuChannel);
410 //_____________________________________________________________________________
412 AliMpFastSegmentation::Print(Option_t* opt) const
414 /// Forward to our helper
418 //_____________________________________________________________________________
420 AliMpFastSegmentation::PlaneType() const
422 /// Forward to our helper
423 return fHelper->PlaneType();
426 //_____________________________________________________________________________
428 AliMpFastSegmentation::GetDimensionX() const
430 /// Forward to our helper
431 return fHelper->GetDimensionX();
434 //_____________________________________________________________________________
436 AliMpFastSegmentation::GetDimensionY() const
438 /// Forward to our helper
439 return fHelper->GetDimensionY();
442 //_____________________________________________________________________________
444 AliMpFastSegmentation::GetPositionX() const
446 /// Forward to our helper
447 return fHelper->GetPositionX();
450 //_____________________________________________________________________________
452 AliMpFastSegmentation::GetPositionY() const
454 /// Forward to our helper
455 return fHelper->GetPositionY();
458 //_____________________________________________________________________________
460 AliMpFastSegmentation::HasMotifPosition(Int_t manuId) const
462 /// Whether or not we have a given manu
463 return ( fManuId.GetValue(Encode2(manuId)) != 0);
466 //_____________________________________________________________________________
468 AliMpFastSegmentation::MotifPosition(Int_t manuId) const
470 /// Get the motifPosition object of a given manu
471 Int_t index = fManuId.GetValue(Encode2(manuId));
475 AliMpVPadIterator* it = CreateIterator();
477 AliMpPad pad = it->CurrentItem();
479 AliWarning(Form("DE %04d Manu ID %04d not found",pad.GetManuId(),manuId));
483 return InternalMotifPosition(index);