#include "AliMUON1DArray.h"
#include "AliLog.h"
-#include "TObjArray.h"
-
+#include <TClass.h>
+#include <TObjArray.h>
+#include <Riostream.h>
///
/// \class AliMUON1DArray
/// This class is simply a wrapper to a TObjArray, offering in addition a
//_____________________________________________________________________________
AliMUON1DArray::AliMUON1DArray(Int_t theSize)
-: AliMUONV1DStore(),
+: AliMUONVStore(),
fArray(0x0)
{
-/// Default ctor
+ /// Default ctor
- if ( theSize )
- {
- fArray = new TObjArray(theSize);
- }
+ if (theSize<=0) theSize=16;
+
+ fArray = new TObjArray(theSize);
+ fArray->SetOwner(kTRUE);
}
//_____________________________________________________________________________
AliMUON1DArray::AliMUON1DArray(const AliMUON1DArray& other)
-: AliMUONV1DStore(),
+: AliMUONVStore(),
fArray(0x0)
{
/// Copy constructor
+ AliDebug(1,Form("this=%p copy ctor",this));
other.CopyTo(*this);
}
//_____________________________________________________________________________
AliMUON1DArray::~AliMUON1DArray()
{
-/// dtor, we're the owner of our internal array.
+ /// dtor, we're the owner of our internal array.
+ AliDebug(1,Form("this=%p",this));
delete fArray;
}
+//_____________________________________________________________________________
+Bool_t
+AliMUON1DArray::Add(TObject* object)
+{
+ /// Add an object to this, if its uniqueID is below maxsize
+ if (!object) return kFALSE;
+
+ Int_t i = (Int_t)object->GetUniqueID();
+ if ( i >= fArray->GetSize() )
+ {
+ AliError(Form("Index out of bounds %u (max is %u)",i,fArray->GetSize()));
+ return kFALSE;
+ }
+
+ Set(object->GetUniqueID(),object,kFALSE);
+ return kTRUE;
+}
+
+//_____________________________________________________________________________
+void
+AliMUON1DArray::Clear(Option_t* opt)
+{
+ /// Reset
+ fArray->Clear(opt);
+}
+
//_____________________________________________________________________________
void
AliMUON1DArray::CopyTo(AliMUON1DArray& dest) const
/// Make a deep copy
delete dest.fArray;
- dest.fArray = new TObjArray;
+ dest.fArray = 0;
+ dest.fArray = new TObjArray(fArray->GetSize());
dest.fArray->SetOwner(kTRUE);
for ( Int_t i = 0; i < fArray->GetLast(); ++i )
{
}
}
+//_____________________________________________________________________________
+AliMUON1DArray*
+AliMUON1DArray::Create() const
+{
+ /// Create an empty clone of this
+ return new AliMUON1DArray(fArray->GetSize());
+}
+
//_____________________________________________________________________________
TObject*
-AliMUON1DArray::Get(Int_t i) const
+AliMUON1DArray::FindObject(UInt_t i) const
{
-/// Get the object located at index i, if it exists, and if i is correct.
+ /// Get the object located at index i, if it exists, and if i is correct.
- if ( i >= 0 && i < fArray->GetSize() )
+ if ( (Int_t)(i) < fArray->GetSize() )
{
return fArray->At(i);
}
return 0x0;
}
+//_____________________________________________________________________________
+TIterator*
+AliMUON1DArray::CreateIterator() const
+{
+ /// Return an iterator on this
+ return fArray->MakeIterator();
+}
+
//_____________________________________________________________________________
Bool_t
AliMUON1DArray::Set(Int_t i, TObject* object, Bool_t replace)
if ( i >= 0 && i < fArray->GetSize() )
{
- TObject* o = Get(i);
+ if (((Int_t)(object->GetUniqueID()))!=i)
+ {
+ AliError(Form("object's UniqueID is %d, which is different from the expected %d",
+ object->GetUniqueID(),i));
+ return kFALSE;
+ }
+
+ TObject* o = FindObject(i);
if ( o && !replace )
{
AliError(Form("Object %p is already there for i=%d",o,i));
return kFALSE;
}
- if ( replace )
+ if ( o && replace )
{
delete o;
}
return kFALSE;
}
-
-
+//_____________________________________________________________________________
+Int_t
+AliMUON1DArray::GetSize() const
+{
+ /// Return the number of object we hold
+ return fArray->GetEntries();
+}
/// \ingroup calib
/// \class AliMUON1DArray
-/// \brief Implementation of AliMUONV1DStore
+/// \brief Implementation of AliMUONVStore
///
// Author Laurent Aphecetche
#ifndef ALIMUON1DARRAY_H
#define ALIMUON1DARRAY_H
-#ifndef ALIMUONV1DSTORE_H
-# include "AliMUONV1DStore.h"
+#ifndef ALIMUONVSTORE_H
+# include "AliMUONVStore.h"
#endif
class TObjArray;
-class AliMUON1DArray : public AliMUONV1DStore
+class AliMUON1DArray : public AliMUONVStore
{
public:
AliMUON1DArray(Int_t theSize=0);
virtual ~AliMUON1DArray();
- /// Return the object stored at i.
- virtual TObject* Get(Int_t i) const;
+ virtual AliMUON1DArray* Create() const;
- /** Set the object stored at i.
- if replace=false and there's already an object there, returns kFALSE
- */
- virtual Bool_t Set(Int_t i, TObject* object, Bool_t replace);
+ /// Add an object. Object must have a valid UniqueID, which is
+ /// used as the index of the array.
+ virtual Bool_t Add(TObject* object);
+
+ virtual Bool_t CanConnect() const { return kFALSE; }
+
+ virtual void Clear(Option_t* opt="");
+
+ virtual TIterator* CreateIterator() const;
+
+ using AliMUONVStore::FindObject;
+
+ /// Return the object stored with id.
+ virtual TObject* FindObject(UInt_t identifier) const;
+
+ using AliMUONVStore::GetSize;
- /// Whether or not this container is the owner of its contents.
- virtual Bool_t IsOwner() const { return kTRUE; }
+ virtual Int_t GetSize() const;
private:
void CopyTo(AliMUON1DArray& to) const;
+ Bool_t Set(Int_t i, TObject* object, Bool_t replace);
private:
TObjArray* fArray; ///< Internal array
- ClassDef(AliMUON1DArray,1) // Implementation of AliMUONV1DStore
+ ClassDef(AliMUON1DArray,1) // Implementation of AliMUONVStore
};
#endif
//_____________________________________________________________________________
AliMUON1DMap::AliMUON1DMap(Int_t theSize)
-: AliMUONV1DStore(),
+: AliMUONVStore(),
fMap(new AliMpExMap(true))
{
/// Default ctor
//_____________________________________________________________________________
AliMUON1DMap::AliMUON1DMap(const AliMUON1DMap& other)
-: AliMUONV1DStore(),
+: AliMUONVStore(),
fMap(0x0)
{
/// Copy constructor
delete fMap;
}
+//_____________________________________________________________________________
+Bool_t
+AliMUON1DMap::Add(TObject* object)
+{
+ /// Add an object to this, using uniqueID as the key
+ if (!object) return kFALSE;
+ Set(object->GetUniqueID(),object,kFALSE);
+ return kTRUE;
+}
+
+//_____________________________________________________________________________
+void
+AliMUON1DMap::Clear(Option_t*)
+{
+ /// Reset
+ delete fMap;
+ fMap = 0x0;
+}
+
//_____________________________________________________________________________
void
AliMUON1DMap::CopyTo(AliMUON1DMap& dest) const
dest.fMap = fMap;
}
+//_____________________________________________________________________________
+AliMUON1DMap*
+AliMUON1DMap::Create() const
+{
+ /// Create an empty clone of this
+ return new AliMUON1DMap(fMap->GetSize());
+}
+
//_____________________________________________________________________________
TObject*
-AliMUON1DMap::Get(Int_t i) const
+AliMUON1DMap::FindObject(UInt_t i) const
{
/// Get the object located at index i, if it exists, and if i is correct.
}
//_____________________________________________________________________________
-AliMUONVDataIterator*
-AliMUON1DMap::Iterator() const
+TIterator*
+AliMUON1DMap::CreateIterator() const
{
// Create and return an iterator on this map
// Returned iterator must be deleted by user.
return 0x0;
}
+//_____________________________________________________________________________
+Int_t
+AliMUON1DMap::GetSize() const
+{
+ /// Return the number of objects we hold
+ return fMap->GetSize();
+}
//_____________________________________________________________________________
Bool_t
/// If replace=kFALSE and there's already an object at location i,
/// this method fails and returns kFALSE, otherwise it returns kTRUE
- TObject* o = Get(i);
+ TObject* o = FindObject(i);
if ( o && !replace )
{
AliError(Form("Object %p is already there for i=%d",o,i));
/// \ingroup calib
/// \class AliMUON1DMap
-/// \brief Implementation of AliMUONV1DStore
+/// \brief Implementation of AliMUONVStore
///
// Author Laurent Aphecetche
#define ALIMUON1DMAP_H
#ifndef ALIMUONV1DSTORE_H
-# include "AliMUONV1DStore.h"
+# include "AliMUONVStore.h"
#endif
class AliMpExMap;
-class AliMUON1DMap : public AliMUONV1DStore
+class AliMUON1DMap : public AliMUONVStore
{
public:
AliMUON1DMap(Int_t theSize=0);
AliMUON1DMap(const AliMUON1DMap& other);
AliMUON1DMap& operator=(const AliMUON1DMap& other);
-
virtual ~AliMUON1DMap();
+
+ virtual Bool_t Add(TObject* object);
+
+ virtual Bool_t CanConnect() const { return kFALSE; }
- /// Return the object stored at i.
- virtual TObject* Get(Int_t i) const;
+ virtual void Clear(Option_t* opt="");
+
+ virtual AliMUON1DMap* Create() const;
- virtual AliMUONVDataIterator* Iterator() const;
+ using AliMUONVStore::FindObject;
- /** Set the object stored at i.
- if replace=false and there's already an object there, returns kFALSE
- */
- virtual Bool_t Set(Int_t i, TObject* object, Bool_t replace);
+ virtual TObject* FindObject(UInt_t i) const;
+
+ virtual TIterator* CreateIterator() const;
- /// Whether or not this container is the owner of its contents.
- virtual Bool_t IsOwner() const { return kTRUE; }
+ using AliMUONVStore::GetSize;
+
+ virtual Int_t GetSize() const;
private:
void CopyTo(AliMUON1DMap& to) const;
+ /** Set the object stored at i.
+ if replace=false and there's already an object there, returns kFALSE
+ */
+ virtual Bool_t Set(Int_t i, TObject* object, Bool_t replace);
private:
AliMpExMap* fMap; ///< Internal array (map)
- ClassDef(AliMUON1DMap,1) // Implementation of AliMUONV1DStore
+ ClassDef(AliMUON1DMap,1) // Implementation of AliMUONVStore
};
#endif
#include "AliMUON2DMap.h"
#include "AliLog.h"
-#include "AliMUONVDataIterator.h"
#include "AliMUON2DMapIterator.h"
+#include "AliMUON2DMapIteratorByI.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
+/// Basic implementation of AliMUONVStore container using
/// AliMpExMap internally.
/// What we store is a "double" map : an AliMpExMap of AliMpExMaps
///
ClassImp(AliMUON2DMap)
/// \endcond
+namespace
+{
+ //___________________________________________________________________________
+ 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);
+ }
+}
+
//_____________________________________________________________________________
AliMUON2DMap::AliMUON2DMap(Bool_t optimizeForDEManu)
-: AliMUONV2DStore(),
- fMap(new AliMpExMap(true)),
+: AliMUONVStore(),
+ fMap(0x0),
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);
- }
+ /// Default constructor.
+ Clear();
}
//_____________________________________________________________________________
AliMUON2DMap::AliMUON2DMap(const AliMUON2DMap& other)
-: AliMUONV2DStore(),
+: AliMUONVStore(),
fMap(0x0),
fOptimizeForDEManu(kFALSE)
{
}
//_____________________________________________________________________________
-AliMUONV2DStore*
-AliMUON2DMap::CloneEmpty() const
+AliMUONVStore*
+AliMUON2DMap::Create() const
{
/// Create a void copy of *this.
return new AliMUON2DMap(fOptimizeForDEManu);
dest.fOptimizeForDEManu = fOptimizeForDEManu;
}
+//_____________________________________________________________________________
+Bool_t
+AliMUON2DMap::Add(TObject* object)
+{
+ /// Add object, using the decoding of uniqueID into two ints as the key
+ UInt_t uniqueID = object->GetUniqueID();
+ Int_t j = ( uniqueID & 0xFFFF0000 ) >> 16;
+ Int_t i = ( uniqueID & 0xFFFF);
+ return Set(i,j,object,kFALSE);
+}
+
//_____________________________________________________________________________
TObject*
-AliMUON2DMap::Get(Int_t i, Int_t j) const
+AliMUON2DMap::FindObject(Int_t i, Int_t j) const
{
-/// Return the value at position (i,j).
+ /// Return the value at position (i,j).
- TObject* o = fMap->GetValue(i);
- if ( o )
+ AliMpExMap* m = static_cast<AliMpExMap*>(fMap->GetValue(i));
+ if (m) return m->GetValue(j);
+ return 0x0;
+}
+
+//_____________________________________________________________________________
+TIterator*
+AliMUON2DMap::CreateIterator() const
+{
+ // Create and return an iterator on this map
+ // Returned iterator must be deleted by user.
+ if ( fMap )
{
- AliMpExMap* m = dynamic_cast<AliMpExMap*>(o);
- if (!m) AliFatal(Form("fMap[%d] not of the expected type",i));
- return m->GetValue(j);
+ return new AliMUON2DMapIterator(*fMap);
}
return 0x0;
}
//_____________________________________________________________________________
-AliMUONVDataIterator*
-AliMUON2DMap::Iterator() const
+TIterator*
+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 AliMUON2DMapIterator(*fMap);
+ return new AliMUON2DMapIteratorByI(*fMap,firstI,lastI);
}
return 0x0;
}
//_____________________________________________________________________________
-AliMUONV2DStore*
-AliMUON2DMap::Generate(const TObject& object)
+void
+AliMUON2DMap::Clear(Option_t*)
{
- /// 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.
+ /// Reset
+ delete fMap;
- AliMUONV2DStore* store = new AliMUON2DMap(true);
-
- TList* list = AliMpManuList::ManuList();
-
- AliMpIntPair* pair;
-
- TIter next(list);
-
- while ( ( pair = static_cast<AliMpIntPair*>(next()) ) )
+ fMap = new AliMpExMap(kTRUE);
+
+ if ( fOptimizeForDEManu )
{
- Int_t detElemId = pair->GetFirst();
- Int_t manuId = pair->GetSecond();
- store->Set(detElemId,manuId,object.Clone(),kFALSE);
+ Int_t nDEs(0);
+ for ( Int_t i = 0; i < AliMpConstants::NofChambers(); ++i )
+ {
+ nDEs += AliMpDEManager::GetNofDEInChamber(i);
+ }
+ fMap->SetSize(nDEs);
}
+}
+
+//_____________________________________________________________________________
+Int_t
+AliMUON2DMap::GetSize() const
+{
+ /// Return the number of objects we hold
+ TExMapIter iter(fMap->GetIterator());
+ Int_t i;
+ Int_t theSize(0);
- delete list;
-
- return store;
+ while ( GetValue(iter,i) )
+ {
+ theSize += GetSize(i);
+ }
+ return theSize;
+}
+
+//_____________________________________________________________________________
+Int_t
+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;
}
//_____________________________________________________________________________
fMap->Add(i,m);
o = fMap->GetValue(i);
}
- AliMpExMap* m = dynamic_cast<AliMpExMap*>(o);
- if (!m) AliFatal(Form("fMap[%d] not of the expected type",i));
+ AliMpExMap* m = static_cast<AliMpExMap*>(o);
+// AliMpExMap* m = dynamic_cast<AliMpExMap*>(o);
+// if (!m) AliFatal(Form("fMap[%d] not of the expected type",i));
+
o = m->GetValue(j);
- if ( !o || ( o && replace ) )
+
+ if ( !o )
{
- if ( IsOwner() )
- {
- delete o;
- }
m->Add(j,object);
}
- else if ( o && !replace )
+ else
{
- AliError(Form("Object %p is already there for (i,j)=(%d,%d)",o,i,j));
- return kFALSE;
+ if ( replace )
+ {
+ delete o;
+ m->Add(j,object);
+ }
+ else
+ {
+ AliError(Form("Object %p is already there for (i,j)=(%d,%d)",o,i,j));
+ return kFALSE;
+ }
}
+
return kTRUE;
}
/// \ingroup calib
/// \class AliMUON2DMap
-/// \brief Basic implementation of AliMUONV2DStore container using
+/// \brief Basic implementation of AliMUONVStore container using
/// AliMpExMap internally.
///
// Author Laurent Aphecetche
#ifndef AliMUON2DMAP_H
#define AliMUON2DMAP_H
-#include "AliMUONV2DStore.h"
+#include "AliMUONVStore.h"
class AliMpExMap;
-class AliMUON2DMap : public AliMUONV2DStore
+class AliMUON2DMap : public AliMUONVStore
{
public:
AliMUON2DMap(Bool_t optimizeForDEManu=kFALSE);
+ AliMUON2DMap(const AliMUON2DMap& other);
+ AliMUON2DMap& operator = (const AliMUON2DMap& other);
virtual ~AliMUON2DMap();
- AliMUONV2DStore* CloneEmpty() const;
+ virtual Bool_t Add(TObject* object);
+
+ /// Mandatory methods from TCollection
+ virtual void Clear(Option_t* opt="");
+
+ /// Whether the Connect(TTree&) method is implemented
+ virtual Bool_t CanConnect() const { return kFALSE; }
+
+ virtual AliMUONVStore* Create() const;
/// The returned iterator is owned by the client.
- AliMUONVDataIterator* Iterator() const;
+ virtual TIterator* CreateIterator() const;
+
+ /// Iterate on part of the store (only for (i,j) where firstI<=i<=lastI
+ TIterator* CreateIterator(Int_t firstI, Int_t lastI) const;
+
+ using AliMUONVStore::FindObject;
- virtual TObject* Get(Int_t i, Int_t j) const;
- virtual Bool_t Set(Int_t i, Int_t j, TObject* object, Bool_t replace);
- /// Whether or not this container is the owner of its contents.
- virtual Bool_t IsOwner() const { return kTRUE; }
+ virtual TObject* FindObject(Int_t i, Int_t j) const;
- AliMUON2DMap(const AliMUON2DMap& other);
- AliMUON2DMap& operator = (const AliMUON2DMap& other);
+ /// Whether our internal storage is optimize to store (detection element id, manu id)
+ Bool_t IsOptimizedForDEManu() const { return fOptimizeForDEManu; }
+
+ virtual Int_t GetSize() const;
+
+ virtual Int_t GetSize(Int_t i) const;
- /// 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.
- static AliMUONV2DStore* Generate(const TObject& object);
-
private:
void CopyTo(AliMUON2DMap& destination) const;
+ Bool_t Set(Int_t i, Int_t j, TObject* object, Bool_t replace);
private:
AliMpExMap* fMap; ///< Our internal map (an AliMpExMap of AliMpExMaps)