]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpArrayI.cxx
including task to produce final histograms on isolated photon analysis
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpArrayI.cxx
index fe12196e8b9ca44354231a7ba6f0ab999c5e6ca1..52b85e75ac1245bc3437a1bb0afc95b1c84796e2 100644 (file)
 // $Id$
 // $MpId: AliMpArrayI.cxx,v 1.5 2006/05/24 13:58:29 ivana Exp $
 // Category: basic
-// ------------------------
+
+//-----------------------------------------------------------------------------
 // Class AliMpArrayI
 // ------------------------
 // Helper class for sorted integer array
 // Author:Ivana Hrivnacova; IPN Orsay
+//-----------------------------------------------------------------------------
 
 #include "AliMpArrayI.h"
-#include "AliMpIntPair.h"
 
 #include "AliLog.h"
 
@@ -32,7 +33,9 @@
 #include <Riostream.h>
 
 #include <stdlib.h>
+#include <limits.h>
 
+using std::endl;
 /// \cond CLASSIMP
 ClassImp(AliMpArrayI)
 /// \endcond
@@ -40,10 +43,13 @@ ClassImp(AliMpArrayI)
 const Int_t AliMpArrayI::fgkDefaultSize = 100;
 
 //_____________________________________________________________________________
-AliMpArrayI::AliMpArrayI() 
+AliMpArrayI::AliMpArrayI(Bool_t sort
   : TObject(),
+    fSort(sort),
     fNofValues(0),
-    fValues(fgkDefaultSize)
+    fValues(fgkDefaultSize),
+    fMinValue(INT_MAX),
+    fMaxValue(INT_MIN)
 {
 /// Standard & default constructor
 
@@ -52,8 +58,11 @@ AliMpArrayI::AliMpArrayI()
 //_____________________________________________________________________________
 AliMpArrayI::AliMpArrayI(TRootIOCtor* /*ioCtor*/) 
   : TObject(),
+    fSort(),
     fNofValues(),
-    fValues()
+    fValues(),
+    fMinValue(),
+    fMaxValue()
 {
 /// IO constructor
 }
@@ -85,34 +94,47 @@ Int_t  AliMpArrayI::GetPosition(Int_t value) const
 //
 
 //_____________________________________________________________________________
-Bool_t AliMpArrayI::Add(Int_t value)
+Bool_t AliMpArrayI::Add(Int_t value, Bool_t warn)
 {
 /// Add object with its key to the map and arrays
   
   // Resize array if needed
-  if ( fValues.GetSize() == fNofValues ) {
-   fValues.Set(2*fValues.GetSize());
-   AliWarningStream() << "Resized array." << endl;
+  if ( fValues.GetSize() == fNofValues ) 
+  {
+    fValues.Set(2*fValues.GetSize());
+    if ( warn ) 
+    {
+      AliWarningStream() << "Resized array." << endl;
+    }
   }
   
-  // Find the position for the new value  
-  Int_t pos = GetPosition(value); 
-   
-  // Move elements 
-  for ( Int_t i=fNofValues; i>=pos; i-- )
-    fValues.AddAt(fValues.At(i), i+1);
-    
+  // The position for the new value  
+  Int_t pos;
+  if ( fSort ) {
+    pos = GetPosition(value);
+
+    // Move elements 
+    for ( Int_t i=fNofValues; i>=pos; i-- )
+      fValues.AddAt(fValues.At(i), i+1);
+  }  
+  else
+    pos = fNofValues;     
+     
   // Add the new value in freed space
   fValues.AddAt(value, pos);  
   ++fNofValues;
   
+  // Update linits
+  if ( value < fMinValue )  fMinValue = value;
+  if ( value > fMaxValue )  fMaxValue = value;;
+  
   return true;
 }
 
 //_____________________________________________________________________________
 Bool_t AliMpArrayI::Remove(Int_t value)
 {
-/// Add object with its key to the map and arrays
+/// Remove value from the array
   
   // Find the position for the new value  
   Int_t pos = GetPosition(value); 
@@ -130,6 +152,41 @@ Bool_t AliMpArrayI::Remove(Int_t value)
   return true;
 }
 
+//_____________________________________________________________________________
+Bool_t  AliMpArrayI::Revert()
+{
+/// Revert the order of elements
+
+  if ( fSort ) {
+    AliErrorStream() << "Cannot revert sorted array." << endl;
+    return false;
+  }  
+
+  Int_t size = GetSize();
+  TArrayI newArray(size);
+  Int_t idx = 0 ;
+  for ( Int_t i = size-1 ; i >= 0 ; i--) {
+    Int_t value = GetValue(i);
+    newArray.AddAt(value,idx++);
+  }
+
+  for (Int_t i = 0; i < size ; i++) {
+    fValues[i]=newArray.At(i);
+  }
+  return true;
+}  
+
+//_____________________________________________________________________________
+void AliMpArrayI::Reset()
+{
+/// Reset the array
+
+  fValues.Set(fgkDefaultSize);
+  fNofValues = 0;
+  fMinValue = INT_MAX;
+  fMaxValue = INT_MIN;
+} 
+
 //_____________________________________________________________________________
 void AliMpArrayI::SetSize(Int_t size)
 {
@@ -166,7 +223,7 @@ Bool_t AliMpArrayI::HasValue(Int_t value) const
 
   if ( ! fNofValues ) return false;
 
-  if ( fValues.At(0) > value || fValues.At(fNofValues-1) < value ) 
+  if ( value < fMinValue || value > fMaxValue ) 
     return false;
 
   for ( Int_t i=0; i<fNofValues; i++ )