]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUON2DMap.cxx
Coverity fixes
[u/mrichter/AliRoot.git] / MUON / AliMUON2DMap.cxx
index bfb129c2cb0face84273948b944a84e553413184..19551381f41f880c1b3bfe816b13fa520cf72dd5 100644 (file)
@@ -21,6 +21,7 @@
 #include "AliMUON2DMapIterator.h"
 #include "AliMUON2DMapIteratorByI.h"
 #include "AliMpExMap.h"
+#include "AliMpExMapIterator.h"
 
 //-----------------------------------------------------------------------------
 /// \class AliMUON2DMap
 ClassImp(AliMUON2DMap)
 /// \endcond
 
-namespace
+const Int_t AliMUON2DMap::fgkOptimalSizeForDEManu = 228;
+
+//_____________________________________________________________________________
+AliMUON2DMap::AliMUON2DMap(TRootIOCtor*)
+: AliMUONVStore(), 
+fMap(0x0),
+fOptimizeForDEManu(kFALSE)
 {
-  //___________________________________________________________________________
-  TObject* GetValue(TExMapIter& iter, Int_t& theKey) 
-  {
-    /// return the next value corresponding to theKey in iterator iter
-    theKey = -1;
-    Long_t key, value;
-    Bool_t ok = iter.Next(key,value);
-    if (!ok) return 0x0;
-    theKey = (Int_t)(key & 0xFFFF);
-    return reinterpret_cast<TObject*>(value);
-  }
+  /// Root I/O constructor.
 }
 
 //_____________________________________________________________________________
 AliMUON2DMap::AliMUON2DMap(Bool_t optimizeForDEManu) 
 : AliMUONVStore(), 
-  fMap(0x0),
+  fMap(new AliMpExMap),
   fOptimizeForDEManu(optimizeForDEManu)
 {
   /// Default constructor.
-    Clear();
+  // hard-coded constant in order not to depend on mapping
+  // if this number ever change, it will not break the code, simply the
+  // automatic resizing will give a warning...
+    
+  if ( fOptimizeForDEManu ) fMap->SetSize(fgkOptimalSizeForDEManu); 
 }
 
 //_____________________________________________________________________________
 AliMUON2DMap::AliMUON2DMap(const AliMUON2DMap& other)
 : AliMUONVStore(),
-fMap(0x0),
-fOptimizeForDEManu(kFALSE)
+  fMap(new AliMpExMap(*other.fMap)),
+  fOptimizeForDEManu(other.fOptimizeForDEManu)
 {
  /// Copy constructor.
-
- other.CopyTo(*this);
 }
 
 //_____________________________________________________________________________
@@ -76,8 +75,11 @@ AliMUON2DMap&
 AliMUON2DMap::operator=(const AliMUON2DMap& other)
 {
 /// Assignment operator
-
-  other.CopyTo(*this);
+  if ( this != &other )
+  {
+    *fMap = *other.fMap;
+    fOptimizeForDEManu = other.fOptimizeForDEManu;
+  }
   return *this;
 }
 
@@ -86,7 +88,6 @@ AliMUON2DMap::~AliMUON2DMap()
 {
 /// Destructor. 
 /// We delete the map, which will delete the objects, as we're owner.
-
   delete fMap;
 }
 
@@ -98,37 +99,36 @@ AliMUON2DMap::Create() const
   return new AliMUON2DMap(fOptimizeForDEManu);
 }
 
-//_____________________________________________________________________________
-void
-AliMUON2DMap::CopyTo(AliMUON2DMap& dest) const
-{
-  /// Copy this into dest.
-
-  delete dest.fMap;
-  dest.fMap = new AliMpExMap(*fMap);
-  dest.fOptimizeForDEManu = fOptimizeForDEManu;
-}
-
 //_____________________________________________________________________________
 Bool_t
 AliMUON2DMap::Add(TObject* object)
 {
   /// Add object, using the decoding of uniqueID into two ints as the key
+  if (!object) return kFALSE;
   UInt_t uniqueID = object->GetUniqueID();
   Int_t j = ( uniqueID & 0xFFFF0000 ) >> 16;
   Int_t i = ( uniqueID & 0xFFFF);
   return Set(i,j,object,kFALSE);
 }
 
+//_____________________________________________________________________________
+TObject* 
+AliMUON2DMap::FindObject(UInt_t uid) const
+{
+  /// Return the value at position uid
+  
+  Int_t j = ( uid & 0xFFFF0000 ) >> 16;
+  Int_t i = ( uid & 0xFFFF);
+  return FindObject(i,j);
+}
+
 //_____________________________________________________________________________
 TObject* 
 AliMUON2DMap::FindObject(Int_t i, Int_t j) const
 {
   /// Return the value at position (i,j).
-
   AliMpExMap* m = static_cast<AliMpExMap*>(fMap->GetValue(i));
-  if (m) return m->GetValue(j);
-  return 0x0;
+  return m ? m->GetValue(j) : 0x0;
 }
 
 //_____________________________________________________________________________
@@ -137,11 +137,7 @@ AliMUON2DMap::CreateIterator() const
 {
   // Create and return an iterator on this map
   // Returned iterator must be deleted by user.
-  if ( fMap ) 
-  {
-    return new AliMUON2DMapIterator(fMap);
-  }
-  return 0x0;
+  return new AliMUON2DMapIterator(*fMap);
 }
 
 //_____________________________________________________________________________
@@ -150,28 +146,15 @@ AliMUON2DMap::CreateIterator(Int_t firstI, Int_t lastI) const
 {
   // Create and return an iterator on this map
   // Returned iterator must be deleted by user.
-  if ( fMap ) 
-  {
-    return new AliMUON2DMapIteratorByI(*fMap,firstI,lastI);
-  }
-  return 0x0;
+  return new AliMUON2DMapIteratorByI(*fMap,firstI,lastI);
 }
 
 //_____________________________________________________________________________
 void 
 AliMUON2DMap::Clear(Option_t*)
 {
-  /// Reset
-  delete fMap;
-
-  fMap = new AliMpExMap(kTRUE);
-
-  if ( fOptimizeForDEManu )
-  {
-    fMap->SetSize(228); // hard-coded constant in order not to depend on mapping
-    // if this number ever change, it will not break the code, simply the
-    // automatic resizing will give a warning...
-  }
+  /// Clear memory
+  fMap->Clear();
 }  
 
 //_____________________________________________________________________________
@@ -179,13 +162,17 @@ Int_t
 AliMUON2DMap::GetSize() const
 {
   /// Return the number of objects we hold
-  TExMapIter iter(fMap->GetIterator());
-  Int_t i;
+  TIter next(fMap->CreateIterator());
   Int_t theSize(0);
+  AliMpExMap* m;
   
-  while ( GetValue(iter,i) ) 
+  while ( ( m = static_cast<AliMpExMap*>(next()) ) )
   {
-    theSize += GetSize(i);
+    TIter next2(m->CreateIterator());
+    while ( next2() ) 
+    {
+      ++theSize;
+    }
   }
   return theSize;
 }
@@ -196,11 +183,7 @@ AliMUON2DMap::GetSize(Int_t i) const
 {
   /// Return the number of objects we hold
   AliMpExMap* m = static_cast<AliMpExMap*>(fMap->GetValue(i));
-  if (m)
-  {
-    return m->GetSize();
-  }
-  return 0;
+  return m ? m->GetSize() : 0;
 }
 
 //_____________________________________________________________________________
@@ -215,7 +198,7 @@ AliMUON2DMap::Set(Int_t i, Int_t j, TObject* object, Bool_t replace)
   TObject* o = fMap->GetValue(i);
   if ( !o )
   {
-    AliMpExMap* m = new AliMpExMap(true);
+    AliMpExMap* m = new AliMpExMap;
     if ( fOptimizeForDEManu ) 
     {
       m->SetSize(451); // same remark as for the SetSize in ctor...
@@ -248,7 +231,3 @@ AliMUON2DMap::Set(Int_t i, Int_t j, TObject* object, Bool_t replace)
   return kTRUE;
 }
 
-
-
-
-