]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUON2DMap.cxx
Updated list of MUON libraries
[u/mrichter/AliRoot.git] / MUON / AliMUON2DMap.cxx
index 6c5cce64cbd1e50c7321a0bda7288d47d59ad0b6..85c99f61d42dbabe7fea6e3f879bd9737fccc30b 100644 (file)
 #include "AliMUON2DMap.h"
 
 #include "AliLog.h"
+#include "AliMUONVDataIterator.h"
+#include "AliMUON2DMapIterator.h"
 #include "AliMpExMap.h"
+#include "AliMpIntPair.h"
+#include "AliMpManuList.h"
+#include "AliMpDEManager.h"
+#include "AliMpConstants.h"
+#include <TList.h>
+
+/// \class AliMUON2DMap
+/// Basic implementation of AliMUONV2DStore container using
+/// AliMpExMap internally.
+/// What we store is a "double" map : an AliMpExMap of AliMpExMaps
+///
+/// \author Laurent Aphecetche
+
+/// \cond CLASSIMP
+ClassImp(AliMUON2DMap)
+/// \endcond
 
-#include <cassert>
+//_____________________________________________________________________________
+AliMUON2DMap::AliMUON2DMap(Bool_t optimizeForDEManu) 
+: AliMUONV2DStore(), 
+  fMap(new AliMpExMap(true)), 
+  fOptimizeForDEManu(optimizeForDEManu)
+{
+/// Default constructor.
+    if ( fOptimizeForDEManu )
+    {
+      Int_t nDEs(0);
+      for ( Int_t i = 0; i < AliMpConstants::NofTrackingChambers(); ++i )
+      {
+        nDEs += AliMpDEManager::GetNofDEInChamber(i);
+      }
+      fMap->SetSize(nDEs);
+    }
+}
 
-ClassImp(AliMUON2DMap)
+//_____________________________________________________________________________
+AliMUON2DMap::AliMUON2DMap(const AliMUON2DMap& other)
+: AliMUONV2DStore(),
+fMap(0x0),
+fOptimizeForDEManu(kFALSE)
+{
+ /// Copy constructor.
+
+ other.CopyTo(*this);
+}
 
 //_____________________________________________________________________________
-AliMUON2DMap::AliMUON2DMap() : AliMUONV2DStore(), fMap(new AliMpExMap(true))
+AliMUON2DMap&
+AliMUON2DMap::operator=(const AliMUON2DMap& other)
 {
+/// Assignment operator
+
+  other.CopyTo(*this);
+  return *this;
 }
 
 //_____________________________________________________________________________
 AliMUON2DMap::~AliMUON2DMap()
 {
+/// Destructor. 
+/// We delete the map, which will delete the objects, as we're owner.
+
   delete fMap;
 }
 
+//_____________________________________________________________________________
+AliMUONV2DStore*
+AliMUON2DMap::CloneEmpty() const
+{
+  /// Create a void copy of *this. 
+  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;
+}
+
 //_____________________________________________________________________________
 TObject* 
 AliMUON2DMap::Get(Int_t i, Int_t j) const
 {
+/// Return the value at position (i,j).
+
   TObject* o = fMap->GetValue(i);
   if ( o )
   {
@@ -50,30 +122,74 @@ AliMUON2DMap::Get(Int_t i, Int_t j) const
 }
 
 //_____________________________________________________________________________
-Bool_t 
-AliMUON2DMap::IsOwner() const
+AliMUONVDataIterator*
+AliMUON2DMap::Iterator() const
 {
-  return kTRUE;
+  // Create and return an iterator on this map
+  // Returned iterator must be deleted by user.
+  if ( fMap ) 
+  {
+    return new AliMUON2DMapIterator(*fMap);
+  }
+  return 0x0;
 }
 
 //_____________________________________________________________________________
-void
-AliMUON2DMap::Print(Option_t*) const
+AliMUONV2DStore* 
+AliMUON2DMap::Generate(const TObject& object)
 {
+  /// Build a complete (i.e. all detElemId,manuId couple will be there) store
+  /// but with identical values, given by object 
+  /// The returned store will be obviously optimized for DEManu.
+
+  AliMUONV2DStore* store = new AliMUON2DMap(true);
   
+  TList* list = AliMpManuList::ManuList();
+  
+  AliMpIntPair* pair;
+  
+  TIter next(list);
+  
+  while ( ( pair = static_cast<AliMpIntPair*>(next()) ) ) 
+  {
+    Int_t detElemId = pair->GetFirst();
+    Int_t manuId = pair->GetSecond();
+    store->Set(detElemId,manuId,object.Clone(),kFALSE);
+  }
+  
+  delete list;
+  
+  return store;
 }
 
 //_____________________________________________________________________________
 Bool_t 
 AliMUON2DMap::Set(Int_t i, Int_t j, TObject* object, Bool_t replace)
 {
+/// Set the object at position (i,j).
+/// If replace==kTRUE, we don't care if there's an object there already,
+/// otherwise we might refuse to set if the (i,j) location is already
+/// filled (in which case we return kFALSE).
+  
   TObject* o = fMap->GetValue(i);
   if ( !o )
   {
     AliMpExMap* m = new AliMpExMap(true);
+    if ( fOptimizeForDEManu ) 
+    {
+      Int_t n(AliMpManuList::NumberOfManus(i));
+      if (!n)
+      {
+        AliError(Form("This does not look right : i = %d is supposed to "
+                      "be a DetElemId with n = %d manus!",i,n));
+      }
+      else
+      {
+        m->SetSize(n);
+      }
+    }
     fMap->Add(i,m);
     o = fMap->GetValue(i);
-    assert(m==o);
   }
   AliMpExMap* m = dynamic_cast<AliMpExMap*>(o);
   if (!m) AliFatal(Form("fMap[%d] not of the expected type",i));