X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=MUON%2FAliMUON2DMap.cxx;h=ff96bec001c8a37fa4fff8296c6e316ed1278515;hb=31a3bbb0b4e08dee50d9e75a69bac1a8acfca13c;hp=85c99f61d42dbabe7fea6e3f879bd9737fccc30b;hpb=be0c6f1f22bb1f37d8756ff26d665a2ce04084b9;p=u%2Fmrichter%2FAliRoot.git diff --git a/MUON/AliMUON2DMap.cxx b/MUON/AliMUON2DMap.cxx index 85c99f61d42..ff96bec001c 100644 --- a/MUON/AliMUON2DMap.cxx +++ b/MUON/AliMUON2DMap.cxx @@ -18,53 +18,56 @@ #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 +#include "AliMpExMapIterator.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 /// /// \author Laurent Aphecetche +//----------------------------------------------------------------------------- /// \cond CLASSIMP ClassImp(AliMUON2DMap) /// \endcond +const Int_t AliMUON2DMap::fgkOptimalSizeForDEManu = 228; + +//_____________________________________________________________________________ +AliMUON2DMap::AliMUON2DMap(TRootIOCtor*) +: AliMUONVStore(), +fMap(0x0), +fOptimizeForDEManu(kFALSE) +{ + /// Root I/O constructor. +} + //_____________________________________________________________________________ AliMUON2DMap::AliMUON2DMap(Bool_t optimizeForDEManu) -: AliMUONV2DStore(), - fMap(new AliMpExMap(true)), +: AliMUONVStore(), + fMap(new AliMpExMap), 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. + // 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) -: AliMUONV2DStore(), -fMap(0x0), -fOptimizeForDEManu(kFALSE) +: AliMUONVStore(), + fMap(new AliMpExMap(*other.fMap)), + fOptimizeForDEManu(other.fOptimizeForDEManu) { /// Copy constructor. - - other.CopyTo(*this); } //_____________________________________________________________________________ @@ -72,8 +75,8 @@ AliMUON2DMap& AliMUON2DMap::operator=(const AliMUON2DMap& other) { /// Assignment operator - - other.CopyTo(*this); + *fMap = *other.fMap; + fOptimizeForDEManu = other.fOptimizeForDEManu; return *this; } @@ -82,84 +85,102 @@ AliMUON2DMap::~AliMUON2DMap() { /// Destructor. /// We delete the map, which will delete the objects, as we're owner. - delete fMap; } //_____________________________________________________________________________ -AliMUONV2DStore* -AliMUON2DMap::CloneEmpty() const +AliMUONVStore* +AliMUON2DMap::Create() const { /// Create a void copy of *this. return new AliMUON2DMap(fOptimizeForDEManu); } //_____________________________________________________________________________ -void -AliMUON2DMap::CopyTo(AliMUON2DMap& dest) const +Bool_t +AliMUON2DMap::Add(TObject* object) { - /// Copy this into dest. + /// 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); +} - delete dest.fMap; - dest.fMap = new AliMpExMap(*fMap); - dest.fOptimizeForDEManu = fOptimizeForDEManu; +//_____________________________________________________________________________ +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::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). + AliMpExMap* m = static_cast(fMap->GetValue(i)); + return m ? m->GetValue(j) : 0x0; +} - TObject* o = fMap->GetValue(i); - if ( o ) - { - AliMpExMap* m = dynamic_cast(o); - if (!m) AliFatal(Form("fMap[%d] not of the expected type",i)); - 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. + return new AliMUON2DMapIterator(*fMap); } //_____________________________________________________________________________ -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 0x0; + return new AliMUON2DMapIteratorByI(*fMap,firstI,lastI); } //_____________________________________________________________________________ -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. + /// Clear memory + fMap->Clear(); +} - AliMUONV2DStore* store = new AliMUON2DMap(true); - - TList* list = AliMpManuList::ManuList(); - - AliMpIntPair* pair; - - TIter next(list); +//_____________________________________________________________________________ +Int_t +AliMUON2DMap::GetSize() const +{ + /// Return the number of objects we hold + TIter next(fMap->CreateIterator()); + Int_t theSize(0); + AliMpExMap* m; - while ( ( pair = static_cast(next()) ) ) + while ( ( m = static_cast(next()) ) ) { - Int_t detElemId = pair->GetFirst(); - Int_t manuId = pair->GetSecond(); - store->Set(detElemId,manuId,object.Clone(),kFALSE); + TIter next2(m->CreateIterator()); + while ( next2() ) + { + ++theSize; + } } - - delete list; - - return store; + return theSize; +} + +//_____________________________________________________________________________ +Int_t +AliMUON2DMap::GetSize(Int_t i) const +{ + /// Return the number of objects we hold + AliMpExMap* m = static_cast(fMap->GetValue(i)); + return m ? m->GetSize() : 0; } //_____________________________________________________________________________ @@ -174,43 +195,36 @@ 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 ) { - 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); - } + m->SetSize(451); // same remark as for the SetSize in ctor... } fMap->Add(i,m); o = fMap->GetValue(i); } - AliMpExMap* m = dynamic_cast(o); - if (!m) AliFatal(Form("fMap[%d] not of the expected type",i)); + AliMpExMap* m = static_cast(o); + 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; } - - - -