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(),
86 /// Ctor. We adopt vseg.
88 AliCodeTimerAuto(vseg->ClassName());
92 AliError("Will get a hard time working with a NULL vseg !");
96 fPosition = vseg->Position();
100 vseg->GetAllElectronicCardIDs(manus);
102 for ( Int_t i = 0; i < manus.GetSize(); ++i )
104 Int_t manuId = manus[i];
106 AliMpMotifPosition* mp = vseg->MotifPosition(manuId);
108 // Should never happen
110 AliFatal("AliMpMotifPosition not found.");
113 Int_t index = 1 + fMotifPositions.GetLast();
115 fMotifPositions.AddLast(mp);
117 fManuId.Add(Encode2(manuId),1+index);
119 for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
121 if ( vseg->HasPadByLocation(manuId,manuChannel) )
123 AliMpPad pad = vseg->PadByLocation(manuId,manuChannel);
125 fIxIy.Add(Encode(pad.GetIx(),pad.GetIy()),1+index);
131 //_____________________________________________________________________________
132 AliMpFastSegmentation::~AliMpFastSegmentation()
138 //_____________________________________________________________________________
140 AliMpFastSegmentation::CreateIterator(const AliMpArea& area) const
142 /// Forward to our helper
143 return fHelper->CreateIterator(area);
146 //_____________________________________________________________________________
148 AliMpFastSegmentation::CreateIterator() const
150 /// Forward to our helper
151 return fHelper->CreateIterator();
154 //_____________________________________________________________________________
156 AliMpFastSegmentation::GetNeighbours(const AliMpPad& pad, TObjArray& neighbours,
158 Bool_t includeVoid) const
160 /// Use default implementation
161 return AliMpVSegmentation::GetNeighbours(pad,neighbours,includeSelf,includeVoid);
164 //_____________________________________________________________________________
166 AliMpFastSegmentation::PadByLocation(Int_t manuId, Int_t manuChannel,
167 Bool_t warning) const
169 /// Get the pad by location, using the manuid map.
171 Int_t index = fManuId.GetValue(Encode2(manuId));
177 AliWarning(Form("Manu ID %d not found",manuId));
180 return AliMpPad::Invalid();
183 AliMpMotifPosition* motifPos = InternalMotifPosition(index);
187 AliError(Form("InternalMotifPosition(%d) failed",index));
189 return AliMpPad::Invalid();
192 AliMpVMotif* motif = motifPos->GetMotif();
193 MpPair_t localIndices
194 = motif->GetMotifType()->FindLocalIndicesByGassiNum(manuChannel);
196 if ( localIndices < 0 )
200 AliWarning(Form("The pad number %d doesn't exists", manuChannel));
203 return AliMpPad::Invalid();
207 AliMpPad pad1 = AliMpPad(manuId, manuChannel,
208 motifPos->GlobalIndices(localIndices),
210 + motif->PadPositionLocal(localIndices)
212 motif->GetPadDimensionsByIndices(localIndices));
213 AliMpPad pad2 = fHelper->PadByLocation(manuId, manuChannel,warning);
223 return AliMpPad(manuId, manuChannel,
224 motifPos->GlobalIndices(localIndices),
226 + motif->PadPositionLocal(localIndices)
228 motif->GetPadDimensionsByIndices(localIndices));
231 //_____________________________________________________________________________
233 AliMpFastSegmentation::InternalMotifPosition(Int_t index) const
235 /// Get the internal manu from the index
236 return static_cast<AliMpMotifPosition*>(fMotifPositions.UncheckedAt(index-1));
239 //_____________________________________________________________________________
241 AliMpFastSegmentation::PadByIndices (Int_t ix, Int_t iy, Bool_t warning) const
243 /// Get pad by indices
245 Int_t index = fIxIy.GetValue(Encode(ix, iy));
251 AliWarning(Form("ManuID not found for pad indices (%d,%d)", ix, iy));
254 return AliMpPad::Invalid();
257 AliMpMotifPosition* motifPos = InternalMotifPosition(index);
261 AliError(Form("InternalMotifPosition(%d) failed",index));
263 return AliMpPad::Invalid();
266 AliMpVMotif* motif = motifPos->GetMotif();
267 AliMpMotifType* motifType = motif->GetMotifType();
268 MpPair_t localIndices(AliMp::Pair(ix, iy) - motifPos->GetLowIndicesLimit());
269 AliMpConnection* connection = motifType->FindConnectionByLocalIndices(localIndices);
275 AliWarning(Form("No connection for pad indices (%d,%d)", ix, iy));
277 return AliMpPad::Invalid();
281 AliMpPad pad2 = fHelper->PadByIndices(ix, iy, warning);
282 AliMpPad pad1 = AliMpPad(motifPos->GetID(),connection->GetManuChannel(),
285 + motif->PadPositionLocal(localIndices)
287 motif->GetPadDimensionsByIndices(localIndices));
294 return AliMpPad(motifPos->GetID(),connection->GetManuChannel(),
297 + motif->PadPositionLocal(localIndices)
299 motif->GetPadDimensionsByIndices(localIndices));
303 //_____________________________________________________________________________
305 AliMpFastSegmentation::PadByPosition(const TVector2& position, Bool_t warning ) const
307 /// Forward to our helper
308 return fHelper->PadByPosition(position,warning);
311 //_____________________________________________________________________________
313 AliMpFastSegmentation::MaxPadIndexX() const
315 /// Forward to our helper
316 return fHelper->MaxPadIndexX();
319 //_____________________________________________________________________________
321 AliMpFastSegmentation::MaxPadIndexY() const
323 /// Forward to our helper
324 return fHelper->MaxPadIndexY();
327 //_____________________________________________________________________________
329 AliMpFastSegmentation::NofPads() const
331 /// Forward to our helper
332 return fHelper->NofPads();
335 //_____________________________________________________________________________
337 AliMpFastSegmentation::GetNofElectronicCards() const
339 /// Forward to our helper
340 return fHelper->GetNofElectronicCards();
343 //_____________________________________________________________________________
345 AliMpFastSegmentation::GetAllElectronicCardIDs(TArrayI& ecn) const
347 /// Forward to our helper
348 fHelper->GetAllElectronicCardIDs(ecn);
351 //_____________________________________________________________________________
353 AliMpFastSegmentation::HasPadByIndices(Int_t ix, Int_t iy) const
355 /// Whether there is a pad at the given indices
356 Int_t index = fIxIy.GetValue(Encode(ix, iy));
358 if ( !index ) return kFALSE;
360 AliMpMotifPosition* mp = InternalMotifPosition(index);
362 Bool_t r1 = mp->HasPadByIndices(AliMp::Pair(ix, iy));
364 Bool_t r2 = fHelper->HasPadByIndices(ix, iy);
371 //_____________________________________________________________________________
373 AliMpFastSegmentation::HasPadByLocation(Int_t manuId, Int_t manuChannel) const
375 /// Whether there is a pad at the given location (de,manuid)
377 Int_t index = fManuId.GetValue(Encode2(manuId));
379 if (!index) return kFALSE;
381 AliMpMotifPosition* mp = InternalMotifPosition(index);
383 Bool_t r1 = mp->HasPadByManuChannel(manuChannel);
385 Bool_t r2 = fHelper->HasPadByLocation(manuId, manuChannel);
392 //_____________________________________________________________________________
394 AliMpFastSegmentation::Print(Option_t* opt) const
396 /// Forward to our helper
400 //_____________________________________________________________________________
402 AliMpFastSegmentation::PlaneType() const
404 /// Forward to our helper
405 return fHelper->PlaneType();
408 //_____________________________________________________________________________
410 AliMpFastSegmentation::Dimensions() const
412 /// Forward to our helper
413 return fHelper->Dimensions();
416 //_____________________________________________________________________________
418 AliMpFastSegmentation::Position() const
420 /// Forward to our helper
421 return fHelper->Position();
424 //_____________________________________________________________________________
426 AliMpFastSegmentation::HasMotifPosition(Int_t manuId) const
428 /// Whether or not we have a given manu
429 return ( fManuId.GetValue(Encode2(manuId)) != 0);
432 //_____________________________________________________________________________
434 AliMpFastSegmentation::MotifPosition(Int_t manuId) const
436 /// Get the motifPosition object of a given manu
437 Int_t index = fManuId.GetValue(Encode2(manuId));
441 AliMpVPadIterator* it = CreateIterator();
443 AliMpPad pad = it->CurrentItem();
445 AliWarning(Form("DE %04d Manu ID %04d not found",pad.GetManuId(),manuId));
449 return InternalMotifPosition(index);