]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpPad.cxx
- Reordering includes and/or
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpPad.cxx
index 81cf2fb2b0cb919626a90f39db4778dfea73ac12..dde083f79e9b6306707d6aa67b39612a9105a396 100755 (executable)
@@ -1,15 +1,35 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
 // $Id$
+// $MpId: AliMpPad.cxx,v 1.6 2005/08/26 15:43:36 ivana Exp $
 // Category: basic
 //
 // Class AliMpPad
 // ---------------
 // Class which encapsuate all informations about a pad
-//
+// Included in AliRoot: 2003/05/02
 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+// root [0] .x testSectorAreaIterator.C
+// Real time 0:00:56, CP time 36.270
 
 #include <Riostream.h>
+#include <TClonesArray.h>
 
 #include "AliMpPad.h"
+#include "AliLog.h"
 
 ClassImp(AliMpPad)
 
@@ -19,6 +39,8 @@ ClassImp(AliMpPad)
 //
 //////////////////////////////////////////////////////////
 
+const Int_t  AliMpPad::fgkMaxNofLocations = 6;
+
 //
 // foreign operators
 //
@@ -37,127 +59,283 @@ ostream& operator<<(ostream& out,const TVector2& v)
   return out; 
 }
 
+
 //_____________________________________________________________________________
 AliMpPad::AliMpPad(const AliMpIntPair& location,const AliMpIntPair& indices,
                    const TVector2& position,const TVector2& dimensions,
                    Bool_t validity)
  : TObject(),
+   fLocations(0),
    fLocation(location),
    fIndices(indices),
    fPosition(position),
    fDimensions(dimensions),
    fValidity(validity)
 {
-// Be carefull : this constructor doesn't check the validity of
-// the correspondance between location and indices.
-// By default, validity is set true.
-// It is aimed to be used by MSegmentation methods, and never from outside....
+/// Standard constructor                                                   \n
+/// Be carefull : this constructor doesn't check the validity of
+/// the correspondance between location and indices.
+/// By default, validity is set true.
+/// It is aimed to be used by MSegmentation methods, and never from outside....
 }
 
 
 //_____________________________________________________________________________
 AliMpPad::AliMpPad()
   : TObject(),
+    fLocations(0),
     fLocation(AliMpIntPair::Invalid()),
     fIndices(AliMpIntPair::Invalid()),
     fPosition(-1.,-1.),
     fDimensions(0.,0.),
     fValidity(false) 
 {
-// Default constructor - creates pad in invalid state
+/// Default constructor - creates pad in invalid state
 }
 
 
 //_____________________________________________________________________________
-AliMpPad::AliMpPad(const AliMpPad& src)
-  : TObject(src)
+AliMpPad::AliMpPad(const AliMpPad& rhs)
+  : TObject(rhs)
 {
- *this = src;
+/// Copy constructor
+
+ *this = rhs;
 }
 
 //_____________________________________________________________________________
-AliMpPad::~AliMpPad() {
-//
+AliMpPad::~AliMpPad() 
+{
+/// Destructor
+
+#ifdef WITH_ROOT
+  if (fLocations) fLocations->Delete();
+#endif
+
+  delete fLocations;
 }
 
 //_____________________________________________________________________________
-AliMpPad& AliMpPad::operator = (const AliMpPad& src
+AliMpPad& AliMpPad::operator = (const AliMpPad& rhs
 {
-  // check assignement to self
-  if (this == &src) return *this;
+/// Assignment operator
+  // check assignment to self
+  if (this == &rhs) return *this;
+
+  // base class assignment
+  TObject::operator=(rhs);
+
+  // assignment operator
+  fLocation   = rhs.fLocation;
+  fIndices    = rhs.fIndices;
+  fPosition.Set(rhs.fPosition);
+  fDimensions.Set(rhs.fDimensions);
+  fValidity = rhs.fValidity;
+  
+  fLocations = 0;
 
-  // base class assignement
-  TObject::operator=(src);
+#ifdef WITH_STL
+  if ( rhs.GetNofLocations() ) {
+    fLocations = new IntPairVector(rhs.GetNofLocations());
+    
+    for (Int_t i=0; i<rhs.GetNofLocations(); i++)
+      (*fLocations)[i] = rhs.GetLocation(i);
+  }                    
+#endif
 
-  // assignement operator
-  fLocation   = src.fLocation;
-  fIndices    = src.fIndices;
-  fPosition.Set(src.fPosition);
-  fDimensions.Set(src.fDimensions);
-  fValidity = src.fValidity;
+#ifdef WITH_ROOT
+  if ( rhs.GetNofLocations() ) {
+    fLocations = new TClonesArray("AliMpIntPair", rhs.GetNofLocations());
+    
+    for (Int_t i=0; i<rhs.GetNofLocations(); i++)
+      new((*fLocations)[i]) AliMpIntPair(rhs.GetLocation(i));
+  }                    
+#endif
 
   return *this;
 }
 
 //_____________________________________________________________________________
-Bool_t AliMpPad::operator == (const AliMpPad& pos2) const
+Bool_t AliMpPad::operator == (const AliMpPad& rhs) const
 {
-  // are this and pos2 equals?
+/// Equality operator
+
+  // are this and rhs equals?
 
   // one valid, one invalid
-  if (fValidity != pos2.fValidity) return false;
+  if (fValidity != rhs.fValidity) return false;
   
   // both invalid
   if (!fValidity) return true;
   
   // both valid
-  return    (fLocation==pos2.fLocation) && (fIndices   ==pos2.fIndices   )
-         && (fPosition==pos2.fPosition) && (fDimensions==pos2.fDimensions);
+  Bool_t sameLocations = true;
+  
+  if (rhs.GetNofLocations()) {
+    for (Int_t i=0; i<rhs.GetNofLocations(); i++) 
+      if ( GetLocation(i) != rhs.GetLocation(i) )
+        sameLocations = false;
+  }
+  
+  return    (fLocation   == rhs.fLocation) 
+         && (fIndices    == rhs.fIndices)
+         && (fPosition   == rhs.fPosition) 
+        && (fDimensions == rhs.fDimensions)
+        && sameLocations;
 }
 //_____________________________________________________________________________
-Bool_t AliMpPad::operator!= (const AliMpPad& pos2) const
+Bool_t AliMpPad::operator != (const AliMpPad& rhs) const
 {
-  // are this and pos2 equals?
-  return !(*this==pos2);
+/// Non-equality operator
+
+  // are this and rhs equals?
+  return !(*this==rhs);
 }
 
 //_____________________________________________________________________________
-ostream& operator<< (ostream &out, const AliMpPad& op)
+Bool_t operator < (const AliMpPad& left, const AliMpPad& right)
 {
-  if (op.IsValid()) {
-    out << "Pad: Location " << op.GetLocation() 
-        << "  Indices "     << op.GetIndices() 
-       << "  Position "    << op.Position()
-        << "  Dimensions "  << op.Dimensions();
-    return out;
-  }
-  else {
+/// Less operator
+
+  return left.GetIndices()<right.GetIndices();
+}
+
+//_____________________________________________________________________________
+Bool_t AliMpPad::AddLocation(const AliMpIntPair& location, Bool_t warn)
+{
+/// Add location to the collection if not yet present and
+/// if collection is not yet full                                           \n
+/// Return false and optionally give a warning if location is not 
+/// added. 
+
+  // Check maximum number limit
+  if ( GetNofLocations() == fgkMaxNofLocations ) {
+    if (warn) {
+      AliWarningStream() << "Cannot add location: "
+                         << location
+                        << "  Maximum number has been reached." << endl;
+    }
+    return false;
+  }                     
+
+  // Check if location is present
+  if ( HasLocation(location) ) {
+    if (warn) {
+      AliWarningStream() << "Cannot add location: "
+                         << location
+                        << "  Location is already present." << endl;
+    }
+    return false;
+  } 
+  
+  // Add location
+#ifdef WITH_STL
+  if (! fLocations )  
+    fLocations = new IntPairVector();
+
+  fLocations->push_back(location);
+  return true;
+#endif
+
+#ifdef WITH_ROOT
+  if (! fLocations)
+    fLocations = new TClonesArray("AliMpIntPair", fgkMaxNofLocations);
+    
+  new ((*fLocations)[GetNofLocations()]) AliMpIntPair(location);
+  return true;
+#endif
+}
+
+//_____________________________________________________________________________
+void AliMpPad::PrintOn(ostream& out) const
+{
+/// Prints all pad data.
+
+  if ( !fValidity ) {
     out << "Pad::Invalid";
-    return out;
+    return;
   }  
+
+  out << "Pad: Location " << fLocation 
+      << "  Indices "     << fIndices
+      << "  Position "    << fPosition
+      << "  Dimensions "  << fDimensions;
+
+  if ( GetNofLocations() ) {
+    out << endl;
+    out << "     Other locations: ";
+
+    for (Int_t i=0; i<GetNofLocations(); i++) 
+        out << GetLocation(i) << "  ";
+  }
 }
 
 //_____________________________________________________________________________
-Bool_t operator < (const AliMpPad& left, const AliMpPad& right)
+void AliMpPad::Print(const char* /*option*/) const
 {
-return left.GetIndices()<right.GetIndices();
+/// Prints all pad data.
+
+  PrintOn(cout);
+  cout << endl;
 }
 
 //_____________________________________________________________________________
-void AliMpPad::Print() const
+Int_t  AliMpPad::GetNofLocations() const
+{
+/// Return number of other locations associated with this pad
+
+  if (!fLocations) return 0;
+  
+#ifdef WITH_STL
+  return fLocations->size();
+#endif
+
+#ifdef WITH_ROOT
+  return fLocations->GetEntriesFast();
+#endif
+}  
+  
+
+//_____________________________________________________________________________
+AliMpIntPair AliMpPad::GetLocation(Int_t i) const
+{
+/// Return i-th other location associated with this pad
+
+  if ( !fLocations || i<0 || i>=GetNofLocations() ) 
+    return AliMpIntPair::Invalid();
+
+#ifdef WITH_STL
+  return (*fLocations)[i];
+#endif
+  
+#ifdef WITH_ROOT
+  return *(AliMpIntPair*)fLocations->At(i);
+#endif
+}  
+
+//_____________________________________________________________________________
+Bool_t AliMpPad::HasLocation(const AliMpIntPair& location) const
 {
-// Prints all pad data.
-// ---
+/// Return true if given location is present either as fLocation
+/// or in the collectio
 
-  if (fValidity) {
-    cout << "Indices: " << fIndices << "; "
-         << " Location: " << fLocation << "; "
-         << " Position: " << fPosition.X() << " " << fPosition.Y() << "; "
-         << " Dimensions: " << fDimensions.X() << " " << fDimensions.Y() 
-         << endl;
+  if (fLocation == location) return true;
+
+  for (Int_t i=0; i<GetNofLocations(); i++) {
+    if ( GetLocation(i) == location ) return true;
   }
-  else {        
-    cout << "Pad::Invalid " << endl;
-  }  
+    
+  return false;
+}      
+
+//_____________________________________________________________________________
+ostream& operator<< (ostream &out, const AliMpPad& pad)
+{
+/// Output streaming
+
+  pad.PrintOn(out);
+
+  return out;
 }