]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpExMap.cxx
Adding new libraries
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpExMap.cxx
index 8d8f98637787e4fe8277d38763cd66b54571f24a..294944dd96b6820c0b6d9907bcfb9a9aa64f430d 100644 (file)
@@ -14,7 +14,7 @@
  **************************************************************************/
 
 // $Id$
-// $MpId: AliMpExMap.cxx,v 1.2 2006/03/02 16:28:23 ivana Exp $
+// $MpId: AliMpExMap.cxx,v 1.5 2006/05/24 13:58:29 ivana Exp $
 // Category: basic
 // ------------------------
 // Class AliMpExMap
 // Author:Ivana Hrivnacova; IPN Orsay
 
 #include "AliMpExMap.h"
+#include "AliMpIntPair.h"
 
-#include <stdlib.h>
+#include "AliLog.h"
 
 #include <TClass.h>
-#include <Riostream.h>
 #include <TString.h>
-#include <TError.h>
+#include <Riostream.h>
 
-//#include "AliMpConstants.h"
-#include "AliMpIntPair.h"
-#include "AliLog.h"
+#include <stdlib.h>
+
+/// \cond CLASSIMP
+ClassImp(AliMpExMap)
+/// \endcond
 
 //
 // static members
@@ -48,8 +50,6 @@ const Int_t AliMpExMap::fgkSeparator2 = 100;
 const TString  AliMpExMap::fgkCharacterMap 
   = " 1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.";
 
-ClassImp(AliMpExMap)
-
 //
 // static methods
 //
@@ -60,9 +60,7 @@ Long_t  AliMpExMap::GetIndex(const AliMpIntPair& pair)
 /// Convert the pair of integers to integer.
 
   if (pair.GetFirst() >= fgkSeparator1 || pair.GetSecond() >= fgkSeparator1) {
-    // to do - use AliLog, is it possible for static function
-    // AliFatal("Index out of limit.");
-    cerr << "AliMpExMap::GetIndex(const AliMpIntPair&): Index out of limit." << endl;
+    AliFatalClass("Index out of limit.");
     exit(1); 
   }  
       
@@ -75,9 +73,7 @@ Long_t  AliMpExMap::GetIndex(const TString& s)
 /// Convert the TString to integer.
 
   if (s.Length() > 5) {
-    // to do - use AliLog, is it possible for static function
-    // AliFatal("String too long.");
-    cerr << "AliMpExMap::GetIndex(const TString&): String too long." << endl;
+    AliFatalClass("String too long.");
     return 0;
   }  
 
@@ -136,6 +132,58 @@ AliMpExMap::AliMpExMap()
 /// Default constructor
 }
 
+
+//_____________________________________________________________________________
+AliMpExMap::AliMpExMap(const AliMpExMap& rhs)
+  : TObject(),
+    fMap(),
+    fObjects(),
+    fKeys()
+
+{
+  /// Copy ctor
+  rhs.Copy(*this);
+}
+
+//_____________________________________________________________________________
+AliMpExMap&
+AliMpExMap::operator=(const AliMpExMap& rhs)
+{
+  /// Assignment operator
+  AliMpExMap tmp(rhs);
+  tmp.Copy(*this);
+  return *this;
+}
+
+//_____________________________________________________________________________
+void
+AliMpExMap::Copy(TObject& dest) const
+{
+  /// Copy this to dest
+  /// Copy implies that dest will become owner of its objects, whatever
+  /// the ownership of (*this) is.
+  
+  AliDebug(1,"");
+  
+  TObject::Copy(dest);
+  AliMpExMap& m = static_cast<AliMpExMap&>(dest);
+  m.fKeys = fKeys;
+  m.fMap.Delete();
+  m.fObjects.Delete();
+  
+  for ( Int_t i = 0; i <= fObjects.GetLast(); ++i ) 
+  {
+    TObject* o = fObjects.At(i)->Clone();
+    if (!o)
+    {
+      AliError("Object was not cloned properly ! Please investigate...");
+    }
+    m.fObjects.AddLast(o);
+  }
+  m.FillMap();
+  m.fObjects.SetOwner(kTRUE);
+}
+
 //_____________________________________________________________________________
 AliMpExMap::~AliMpExMap() 
 {
@@ -163,7 +211,7 @@ void AliMpExMap::AddKey(Long_t key)
   // Resize array if needed
   if (fObjects.GetEntriesFast() == fKeys.GetSize()) {
    fKeys.Set(2*fKeys.GetSize());
-   cout << "AliMpExMap::AddKey: resized Key array " << endl;
+   AliWarningStream() << "AliMpExMap::AddKey: resized Key array " << endl;
   } 
    
   fKeys.AddAt(key, fObjects.GetEntriesFast());      
@@ -224,7 +272,7 @@ void AliMpExMap::SetOwner(Bool_t owner)
 //_____________________________________________________________________________
 Int_t AliMpExMap::GetSize() const
 {
-/// Return TExMap iterator set to the beginning of the map
+/// Return the map size
 
   return fObjects.GetEntriesFast();
 }
@@ -237,6 +285,20 @@ TExMapIter AliMpExMap::GetIterator() const
   return TExMapIter(&fMap);
 }
 
+//_____________________________________________________________________________
+TObject* AliMpExMap::GetObject(Int_t index) const
+{
+/// Return the object via its index in the array
+/// (This function makes possible looping over map as over an array)
+
+  if ( index < 0 || index >= fObjects.GetEntriesFast() ) {
+    AliErrorStream() << "Index outside limits" << endl;
+    return 0;
+  }
+  
+  return fObjects.At(index);
+}      
+
 //_____________________________________________________________________________
 TObject* AliMpExMap::GetValue(const AliMpIntPair& key) const
 {
@@ -267,8 +329,8 @@ TObject*  AliMpExMap::GetValue(Int_t key) const
 //_____________________________________________________________________________
 void AliMpExMap::Streamer(TBuffer &R__b)
 {
-/// Customized streamer                                                     \n
-/// After the arrays are read, fill the transient map
+// Customized streamer                                                     \n
+// After the arrays are read, fill the transient map
 
   if (R__b.IsReading()) {
     AliMpExMap::Class()->ReadBuffer(R__b, this);