]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpSlatSegmentation.cxx
Fixing a backward compatibility issue
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSlatSegmentation.cxx
index abb3f4dc0b37c385597d4c4882874e3131e250bc..f7220fedb7c951e1e0cd8b0d9046d5ca1d0f9f85 100644 (file)
 **************************************************************************/
 
 // $Id$
-// $MpId: AliMpSlatSegmentation.cxx,v 1.10 2006/03/17 16:42:33 ivana Exp $
+// $MpId: AliMpSlatSegmentation.cxx,v 1.12 2006/05/24 13:58:50 ivana Exp $
 
+//-----------------------------------------------------------------------------
 // Caution !!
 // Implementation note.
 // The position(s) used in the interface are supposed to be relative
 // to the slat center (AliMpSlat::Position()), whereas internally
 // the x,y are relative to bottom-left corner.
+//-----------------------------------------------------------------------------
 
 #include "AliMpSlatSegmentation.h"
 
 #include "AliLog.h"
 #include "AliMpArea.h"
 #include "AliMpConnection.h"
+#include "AliMpConstants.h"
+#include "AliLog.h"
 #include "AliMpMotif.h"
 #include "AliMpMotifPosition.h"
 #include "AliMpMotifType.h"
-#include "AliMpPCB.h"
 #include "AliMpSlat.h"
 #include "AliMpSlatPadIterator.h"
+#include "AliMpEncodePair.h"
 
+/// \cond CLASSIMP
 ClassImp(AliMpSlatSegmentation)
+/// \endcond
 
 //_____________________________________________________________________________
 AliMpSlatSegmentation::AliMpSlatSegmentation() 
 : AliMpVSegmentation(),
-fkSlat(0)
+  fkSlat(0),
+  fIsOwner(false)
 {
-  //
-  // Default ctor. Not to be used really.
-  //
+  ///
+  /// Default ctor. Not to be used really.
+  ///
   AliDebug(1,Form("this=%p Empty ctor",this));
 }
 
 //_____________________________________________________________________________
-AliMpSlatSegmentation::AliMpSlatSegmentation(const AliMpSlat* slat) 
+AliMpSlatSegmentation::AliMpSlatSegmentation(const AliMpSlat* slat, Bool_t own
 : AliMpVSegmentation(), 
-fkSlat(slat)
+  fkSlat(slat),
+  fIsOwner(own)
 {
-  //
-  // Normal ctor.
-  //
+  ///
+  /// Normal ctor.
+  ///
   AliDebug(1,Form("this=%p Normal ctor slat=%p",this,slat));
 }
 
-//______________________________________________________________________________
-AliMpSlatSegmentation::AliMpSlatSegmentation(const AliMpSlatSegmentation& right) 
-  : AliMpVSegmentation(right) 
-{  
-/// Protected copy constructor (not implemented)
-
-  AliFatal("Copy constructor not provided.");
-}
-
 //_____________________________________________________________________________
 AliMpSlatSegmentation::~AliMpSlatSegmentation()
 {
-  //
-  // Dtor (empty).
-  //
+  ///
+  /// Dtor (empty).
+  ///
+  if ( fIsOwner ) delete fkSlat;
   // Int_t i(0);//just to be able to put a breakpoint in gdb
   AliDebug(1,Form("this=%p",this));                    
 }
 
-//______________________________________________________________________________
-AliMpSlatSegmentation& 
-AliMpSlatSegmentation::operator=(const AliMpSlatSegmentation& right)
-{
-/// Protected assignement operator (not implemented)
-
-  // check assignement to self
-  if (this == &right) return *this;
-
-  AliFatal("Assignement operator not provided.");
-    
-  return *this;  
-}    
-
 //_____________________________________________________________________________
 AliMpVPadIterator*
 AliMpSlatSegmentation::CreateIterator(const AliMpArea& area) const
 {
-  //
-  // Returns an iterator to loop over the pad contained within given area.
-  //
-  AliMpArea a(area.Position()+fkSlat->Position(),area.Dimensions());
+  ///
+  /// Returns an iterator to loop over the pad contained within given area.
+  ///
+  AliMpArea a(area.GetPositionX()+fkSlat->GetPositionX(),
+              area.GetPositionY()+fkSlat->GetPositionY(),
+              area.GetDimensionX(), 
+              area.GetDimensionY());
   AliDebug(3,Form("Converted input area wrt to slat center : "
                   "%7.2f,%7.2f->%7.2f,%7.2f to wrt slat lower-left : "
                   "%7.2f,%7.2f->%7.2f,%7.2f ",
@@ -111,16 +102,52 @@ AliMpSlatSegmentation::CreateIterator(const AliMpArea& area) const
 }
 
 //_____________________________________________________________________________
-TVector2
-AliMpSlatSegmentation::Dimensions() const
+AliMpVPadIterator*
+AliMpSlatSegmentation::CreateIterator() const
 {
-  return Slat()->Dimensions();
+  /// Returns an iterator to loop over all pads of that segmentation
+  ///
+  /// FIXME: we currently just forward this to the other CreateIterator,
+  /// with the proper region. Might be more efficient to write a dedicated
+  /// iterator ? Test that idea.
+  
+  AliMpArea area(0.0,0.0,fkSlat->DX(),fkSlat->DY());
+  return CreateIterator(area);
+}
+
+//_____________________________________________________________________________
+Int_t 
+AliMpSlatSegmentation::GetNeighbours(const AliMpPad& pad, 
+                                     TObjArray& neighbours,
+                                     Bool_t includeSelf,
+                                     Bool_t includeVoid) const
+{
+  /// Uses default implementation
+  return AliMpVSegmentation::GetNeighbours(pad,neighbours,includeSelf,includeVoid);
+}
+
+//_____________________________________________________________________________
+Double_t  
+AliMpSlatSegmentation::GetDimensionX() const
+{
+/// Return slat x dimensions
+  return Slat()->DX();
+}
+
+//_____________________________________________________________________________
+Double_t  
+AliMpSlatSegmentation::GetDimensionY() const
+{
+/// Return slat y dimensions
+  return Slat()->DY();
 }
 
 //_____________________________________________________________________________
 void 
 AliMpSlatSegmentation::GetAllElectronicCardIDs(TArrayI& ecn) const
 {
+  /// Fill the array ecn with all manuIds
+
   Slat()->GetAllMotifPositionsIDs(ecn);
 }
 
@@ -128,6 +155,8 @@ AliMpSlatSegmentation::GetAllElectronicCardIDs(TArrayI& ecn) const
 const char*
 AliMpSlatSegmentation::GetName() const
 {
+  /// The name of this segmentation is "SlatSegmentation"+slatName
+
   TString name("SlatSegmentation");
   if ( fkSlat) 
   {
@@ -137,25 +166,13 @@ AliMpSlatSegmentation::GetName() const
   return name.Data();
 }
 
-//_____________________________________________________________________________
-Bool_t
-AliMpSlatSegmentation::HasPad(const AliMpIntPair& indices) const
-{
-  //
-  // Test if this slat has a pad located at the position referenced
-  // by the integer indices.
-  //
-  
-  return PadByIndices(indices,kFALSE) != AliMpPad::Invalid();
-}
-
 //_____________________________________________________________________________
 Int_t 
 AliMpSlatSegmentation::MaxPadIndexX() const
 {
-  //
-  // Returns the value of the largest pad index in x-direction.
-  //
+  ///
+  /// Returns the value of the largest pad index in x-direction.
+  ///
   
   return fkSlat->GetMaxPadIndexX();
 }
@@ -164,9 +181,9 @@ AliMpSlatSegmentation::MaxPadIndexX() const
 Int_t 
 AliMpSlatSegmentation::MaxPadIndexY() const
 {
-  //
-  // Returns the value of the largest pad index in y-direction.
-  //
+  ///
+  /// Returns the value of the largest pad index in y-direction.
+  ///
   
   return fkSlat->GetMaxNofPadsY()-1;
 }
@@ -182,162 +199,177 @@ AliMpSlatSegmentation::NofPads() const
 
 //_____________________________________________________________________________
 AliMpPad
-AliMpSlatSegmentation::PadByLocation(const AliMpIntPair& location
+AliMpSlatSegmentation::PadByLocation(Int_t manuId, Int_t manuChannel
                                      Bool_t warning) const
 {
-  //
-  // Returns the pad specified by its location, where location is the 
-  // pair (ManuID,ManuChannel).
-  // If warning=kTRUE and the pad does not exist, a warning message is 
-  // printed.
-  //
-  // AliMpPad::Invalid() is returned if there's no pad at the given location.
-  //
-  Int_t manuID = location.GetFirst();
-       
-  AliMpMotifPosition* motifPos = fkSlat->FindMotifPosition(manuID);
+  ///
+  /// Returns the pad specified by its location, where location is the 
+  /// pair (ManuID,ManuChannel).
+  /// If warning=kTRUE and the pad does not exist, a warning message is 
+  /// printed.
+  ///
+  /// AliMpPad::Invalid() is returned if there's no pad at the given location.
+  ///
+  AliMpMotifPosition* motifPos = fkSlat->FindMotifPosition(manuId);
        
   if (!motifPos)
-       {
-               if (warning)
-               {
-                       AliWarning(Form("Manu ID %d not found in slat %s",
-                                        manuID, fkSlat->GetID()));
+  {
+    if (warning)
+    {
+      AliWarning(Form("Manu ID %d not found in slat %s",
+                       manuId, fkSlat->GetID()));
     }
     return AliMpPad::Invalid();
-       }
+  }
   AliMpVMotif* motif = motifPos->GetMotif();
-  AliMpIntPair localIndices = 
-    motif->GetMotifType()->FindLocalIndicesByGassiNum(location.GetSecond());
+  MpPair_t localIndices = 
+    motif->GetMotifType()->FindLocalIndicesByGassiNum(manuChannel);
        
-  if (!localIndices.IsValid()) 
-       {
-               if (warning) 
-               {
-                       AliWarning(Form("The pad number %d doesn't exists",
-                                       location.GetSecond()));
-               }
-               return AliMpPad::Invalid();
-       }
+  if ( localIndices < 0 ) 
+  {
+    if (warning) 
+    {
+      AliWarning(Form("The pad number %d doesn't exists",
+                 manuChannel));
+    }
+    return AliMpPad::Invalid();
+  }
+
+  Double_t posx, posy;
+  motif->PadPositionLocal(localIndices, posx, posy);
+  posx += motifPos->GetPositionX() - fkSlat->GetPositionX();
+  posy += motifPos->GetPositionY() - fkSlat->GetPositionY();
+
+  Double_t dx, dy;
+  motif->GetPadDimensionsByIndices(localIndices, dx, dy);
        
-  return AliMpPad(location,
+  return AliMpPad(manuId, manuChannel,
                   motifPos->GlobalIndices(localIndices),
-                  motifPos->Position() 
-                  + motif->PadPositionLocal(localIndices) 
-                  - fkSlat->Position(),
-                  motif->GetPadDimensions(localIndices));  
+                  posx, posy, dx, dy);
 }
 
 //_____________________________________________________________________________
 AliMpPad
-AliMpSlatSegmentation::PadByIndices(const AliMpIntPair& indices
+AliMpSlatSegmentation::PadByIndices(Int_t ix, Int_t iy
                                     Bool_t warning) const
 {
-  //
-  // Returns the pad specified by its integer indices.
-  // If warning=kTRUE and the pad does not exist, a warning message is 
-  // printed.
-  //
-  // AliMpPad::Invalid() is returned if there's no pad at the given location.
-  //
-  //  
-  // FIXME: except for the FindMotifPosition below, this method
-  // is exactly as the one in AliMpSectorSegmentation.
-  // See if we can merge them somehow.
+  ///
+  /// Returns the pad specified by its integer indices.
+  /// If warning=kTRUE and the pad does not exist, a warning message is 
+  /// printed.
+  ///
+  /// AliMpPad::Invalid() is returned if there's no pad at the given location.
+  ///
+  ///  
+  /// FIXME: except for the FindMotifPosition below, this method
+  /// is exactly as the one in AliMpSectorSegmentation.
+  /// See if we can merge them somehow.
        
-  AliMpMotifPosition* motifPos = fkSlat->FindMotifPosition(indices.GetFirst(),
-                                                                                                                                                                                                        indices.GetSecond());
+  AliMpMotifPosition* motifPos = fkSlat->FindMotifPosition(ix,iy);
+  
   if (!motifPos)
-       {
-               if ( warning ) 
-               {
-                       AliWarning(Form("No motif found containing pad location (%d,%d)",
-                                        indices.GetFirst(),indices.GetSecond()));        
-               }
-               return AliMpPad::Invalid();
-       }
+  {
+    if ( warning ) 
+    {
+      AliWarning(Form("No motif found containing pad location (%d,%d)",ix,iy));          
+    }
+    return AliMpPad::Invalid();
+  }
        
   AliMpVMotif* motif = motifPos->GetMotif();
   AliMpMotifType* motifType = motif->GetMotifType();
-  AliMpIntPair localIndices(indices-motifPos->GetLowIndicesLimit());
-  AliMpConnection* connection = motifType->FindConnectionByLocalIndices(localIndices);
+  MpPair_t localIndices = AliMp::Pair(ix,iy) - motifPos->GetLowIndicesLimit();
+  AliMpConnection* connection 
+    = motifType->FindConnectionByLocalIndices(localIndices);
   
   if (!connection)
-       {
-               if ( warning )
-               {
-                       AliWarning(Form("No connection for pad location (%d,%d)",
-                                       indices.GetFirst(),indices.GetSecond()));
+  {
+    if ( warning )
+    {
+      AliWarning(Form("No connection for pad location (%d,%d)",ix,iy));
     }
     return AliMpPad::Invalid();
-       }
-       
-  return AliMpPad(AliMpIntPair(motifPos->GetID(),connection->GetGassiNum()),
-                  indices,
-                  motifPos->Position()
-                  + motif->PadPositionLocal(localIndices)
-                  - fkSlat->Position(),
-                  motif->GetPadDimensions(localIndices));
+  }
+
+  Double_t posx, posy;
+  motif->PadPositionLocal(localIndices, posx, posy);
+  posx += motifPos->GetPositionX() - fkSlat->GetPositionX();
+  posy += motifPos->GetPositionY() - fkSlat->GetPositionY();
+
+  Double_t dx, dy;
+  motif->GetPadDimensionsByIndices(localIndices, dx, dy);
+
+  return AliMpPad(motifPos->GetID(),connection->GetManuChannel(),
+                  ix, iy, posx, posy, dx, dy);
 }
 
 //_____________________________________________________________________________
 AliMpPad
-AliMpSlatSegmentation::PadByPosition(const TVector2& position
+AliMpSlatSegmentation::PadByPosition(Double_t x, Double_t y
                                      Bool_t warning) const
 {
-  //
-  // Returns the pad specified by its (floating point) position.
-  // If warning=kTRUE and the pad does not exist, a warning message is 
-  // printed.
-  //
-  // AliMpPad::Invalid() is returned if there's no pad at the given location.
-  //
+  ///
+  /// Returns the pad specified by its (floating point) position.
+  /// If warning=kTRUE and the pad does not exist, a warning message is 
+  /// printed.
+  ///
+  /// AliMpPad::Invalid() is returned if there's no pad at the given location.
+  ///
+  
+  Double_t blPosX(x);
+  Double_t blPosY(y);
   
-  TVector2 blPos(position+fkSlat->Position()); // position relative to 
-  // bottom-left of the slat.
+  blPosX += fkSlat->GetPositionX();
+  blPosY += fkSlat->GetPositionY(); // position relative to bottom-left of the slat.
   
-  AliMpMotifPosition* motifPos = fkSlat->FindMotifPosition(blPos.X(),blPos.Y());
+  AliMpMotifPosition* motifPos = fkSlat->FindMotifPosition(blPosX,blPosY);
        
   if (!motifPos)
-       {
-               if (warning) 
-               {
-                       AliWarning(Form("Slat %s Position (%e,%e)/center (%e,%e)/bottom-left cm "
-                      " outside limits",fkSlat->GetID(),
-                      position.X(),position.Y(),
-                      blPos.X(),blPos.Y()));
-               }
-               return AliMpPad::Invalid();
-       }
+  {
+    if (warning) 
+    {
+      AliWarning(Form("Slat %s Position (%e,%e)/center (%e,%e)/bottom-left cm "
+                      " outside limits",fkSlat->GetID(),x,y,
+                      blPosX,blPosY));
+    }
+    return AliMpPad::Invalid();
+  }
        
   AliMpVMotif* motif =  motifPos->GetMotif();  
-  AliMpIntPair localIndices 
-    = motif->PadIndicesLocal(blPos-motifPos->Position());
+
+  blPosX -= motifPos->GetPositionX();
+  blPosY -= motifPos->GetPositionY();
+  MpPair_t localIndices = motif->PadIndicesLocal(blPosX, blPosY);
        
   AliMpConnection* connect = 
     motif->GetMotifType()->FindConnectionByLocalIndices(localIndices);
        
   if (!connect)
-       {
-               if (warning) 
-               {
-                       AliWarning(Form("Slat %s localIndices (%d,%d) outside motif %s limits",
-                      fkSlat->GetID(),localIndices.GetFirst(),
-                      localIndices.GetSecond(),motif->GetID().Data()));
-               }
-               return AliMpPad::Invalid();
-       }
-  
-  return AliMpPad(AliMpIntPair(motifPos->GetID(),connect->GetGassiNum()),
+  {
+    if (warning) 
+    {
+      AliWarning(Form("Slat %s localIndices (%d,%d) outside motif %s limits",
+                      fkSlat->GetID(),AliMp::PairFirst(localIndices),
+                      AliMp::PairSecond(localIndices),motif->GetID().Data()));
+    }
+    return AliMpPad::Invalid();
+  }
+
+  Double_t posx, posy;
+  motif->PadPositionLocal(localIndices, posx, posy);
+  posx += motifPos->GetPositionX() - fkSlat->GetPositionX();
+  posy += motifPos->GetPositionY() - fkSlat->GetPositionY();
+
+  Double_t dx, dy;
+  motif->GetPadDimensionsByIndices(localIndices, dx, dy);
+    
+  return AliMpPad(motifPos->GetID(),connect->GetManuChannel(),
                   motifPos->GlobalIndices(localIndices),
-                  motifPos->Position()
-                  + motif->PadPositionLocal(localIndices)
-                  - fkSlat->Position(),
-                  motif->GetPadDimensions(localIndices));  
+                  posx, posy, dx, dy);
 }
 
 //_____________________________________________________________________________
-AliMpPlaneType
+AliMp::PlaneType
 AliMpSlatSegmentation::PlaneType() const
 {
   return Slat()->PlaneType();
@@ -347,6 +379,8 @@ AliMpSlatSegmentation::PlaneType() const
 void
 AliMpSlatSegmentation::Print(Option_t* opt) const
 {
+/// Printing
+
   fkSlat->Print(opt);
 }
 
@@ -354,9 +388,79 @@ AliMpSlatSegmentation::Print(Option_t* opt) const
 const AliMpSlat* 
 AliMpSlatSegmentation::Slat() const
 {
-  //
-  // Returns the pointer to the referenced slat.
-  //
+  ///
+  /// Returns the pointer to the referenced slat.
+  ///
   
   return fkSlat;
 }
+
+//_____________________________________________________________________________
+Bool_t 
+AliMpSlatSegmentation::HasPadByIndices(Int_t ix, Int_t iy) const
+{
+  /// Tell whether we have a pad at indices=(ix,iy)
+  
+  AliMpMotifPosition* motifPos = Slat()->FindMotifPosition(ix, iy);
+  
+  if (motifPos) return motifPos->HasPadByIndices(AliMp::Pair(ix, iy));
+  
+  return kFALSE;
+}
+
+//_____________________________________________________________________________
+Bool_t 
+AliMpSlatSegmentation::HasPadByLocation(Int_t manuId, Int_t manuChannel) const
+{
+  /// Tell whether we have a pad at location=(manuId,manuChannel)
+  
+  AliMpMotifPosition* motifPos = Slat()->FindMotifPosition(manuId);
+  
+  if ( motifPos ) return motifPos->HasPadByManuChannel(manuChannel);
+  
+  return kFALSE;  
+}
+
+
+//_____________________________________________________________________________
+Int_t 
+AliMpSlatSegmentation::GetNofElectronicCards() const
+{
+  /// Get the number of manus of this slat
+  return Slat()->GetNofElectronicCards();
+
+}
+
+//_____________________________________________________________________________
+Double_t  
+AliMpSlatSegmentation::GetPositionX() const
+{
+/// Return x position of slat origin
+  return Slat()->GetPositionX();
+}
+
+//_____________________________________________________________________________
+Double_t  
+AliMpSlatSegmentation::GetPositionY() const
+{
+/// Return y position of slat origin
+
+  return Slat()->GetPositionY();
+}
+
+//_____________________________________________________________________________
+Bool_t 
+AliMpSlatSegmentation::HasMotifPosition(Int_t manuId) const
+{
+  /// Use default implementation
+  return AliMpVSegmentation::HasMotifPosition(manuId);
+}
+
+//_____________________________________________________________________________
+AliMpMotifPosition* 
+AliMpSlatSegmentation::MotifPosition(Int_t manuId) const
+{
+  /// Get back a given manu
+  return Slat()->FindMotifPosition(manuId);
+}
+