From 5fc43f28de119714c889b6153ffc0c06c734aa97 Mon Sep 17 00:00:00 2001 From: hristov Date: Sun, 17 Jun 2007 20:27:43 +0000 Subject: [PATCH] New TIterator implementation for AliMUON2DMap, by range (Laurent) --- MUON/AliMUON2DMapIteratorByI.cxx | 181 +++++++++++++++++++++++++++++++ MUON/AliMUON2DMapIteratorByI.h | 59 ++++++++++ 2 files changed, 240 insertions(+) create mode 100644 MUON/AliMUON2DMapIteratorByI.cxx create mode 100644 MUON/AliMUON2DMapIteratorByI.h diff --git a/MUON/AliMUON2DMapIteratorByI.cxx b/MUON/AliMUON2DMapIteratorByI.cxx new file mode 100644 index 00000000000..155224592f8 --- /dev/null +++ b/MUON/AliMUON2DMapIteratorByI.cxx @@ -0,0 +1,181 @@ +/************************************************************************** +* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * +* * +* Author: The ALICE Off-line Project. * +* Contributors are mentioned in the code where appropriate. * +* * +* Permission to use, copy, modify and distribute this software and its * +* documentation strictly for non-commercial purposes is hereby granted * +* without fee, provided that the above copyright notice appears in all * +* copies and that both the copyright notice and this permission notice * +* appear in the supporting documentation. The authors make no claims * +* about the suitability of this software for any purpose. It is * +* provided "as is" without express or implied warranty. * +**************************************************************************/ + +// $Id$ + +/// \class AliMUON2DMapIteratorByI +/// +/// Implementation of TIterator for 2D maps +/// +/// An implementation of TIterator for 2D maps, which can iterate +/// on a range of i values (i being the first element of the couple +/// (i,j) used to index values in the map). +/// +/// \author Laurent Aphecetche + +#include "AliMUON2DMapIteratorByI.h" + +#include "AliMpExMap.h" + +/// \cond CLASSIMP +ClassImp(AliMUON2DMapIteratorByI) +/// \endcond + +//_____________________________________________________________________________ +AliMUON2DMapIteratorByI::AliMUON2DMapIteratorByI(const AliMpExMap& theMap, + Int_t firstI, + Int_t lastI) +: TIterator(), +fMap(&theMap), +fIter2(0x0), +fCurrentI(-1), +fCurrentJ(-1), +fFirstI(firstI), +fLastI(lastI) +{ + /// default ctor + Reset(); +} + +//_____________________________________________________________________________ +AliMUON2DMapIteratorByI::AliMUON2DMapIteratorByI(const AliMUON2DMapIteratorByI& rhs) +:TIterator(rhs), +fMap(rhs.fMap), +fIter2(0x0), +fCurrentI(rhs.fCurrentI), +fCurrentJ(rhs.fCurrentJ), +fFirstI(rhs.fFirstI), +fLastI(rhs.fLastI) +{ + /// copy ctor + if ( rhs.fIter2 ) fIter2 = new TExMapIter(*(rhs.fIter2)); +} + +//_____________________________________________________________________________ +AliMUON2DMapIteratorByI& +AliMUON2DMapIteratorByI::operator=(const AliMUON2DMapIteratorByI& rhs) +{ + /// assignment operator + if ( this != &rhs ) + { + fMap = rhs.fMap; + fIter2 = 0x0; + if ( rhs.fIter2 ) fIter2 = new TExMapIter(*(rhs.fIter2)); + fCurrentI = rhs.fCurrentI; + fCurrentJ = rhs.fCurrentJ; + fFirstI = rhs.fFirstI; + fLastI = rhs.fLastI; + } + return *this; +} + +//_____________________________________________________________________________ +TIterator& +AliMUON2DMapIteratorByI::operator=(const TIterator& rhs) +{ + /// overriden assigment operator (imposed by Root's declaration of TIterator ?) + if ( this != &rhs ) + { + const AliMUON2DMapIteratorByI& rhs1 = static_cast(rhs); + fMap = rhs1.fMap; + fIter2 = 0x0; + if ( rhs1.fIter2 ) fIter2 = new TExMapIter(*(rhs1.fIter2)); + fCurrentI = rhs1.fCurrentI; + fCurrentJ = rhs1.fCurrentJ; + fFirstI = rhs1.fFirstI; + fLastI = rhs1.fLastI; + } + return *this; +} + +//_____________________________________________________________________________ +AliMUON2DMapIteratorByI::~AliMUON2DMapIteratorByI() +{ + /// dtor + delete fIter2; +} + +//_____________________________________________________________________________ +const TCollection* +AliMUON2DMapIteratorByI::GetCollection() const +{ + /// Not implemented + return 0x0; +} + +//_____________________________________________________________________________ +TObject* +AliMUON2DMapIteratorByI::GetValue(TExMapIter& iter, Int_t& theKey) const +{ + /// return the 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(value); +} + +//_____________________________________________________________________________ +TObject* +AliMUON2DMapIteratorByI::Next() +{ + /// logic : + /// get TObject* from fIter2 + /// if null, increment fIter2 by getting next map from fMap + + if (!fIter2) return 0x0; + + TObject* o = GetValue(*fIter2,fCurrentJ); + if (!o) + { + // fIter2 exhausted, try to get the next one + delete fIter2; + fIter2 = 0x0; + AliMpExMap* m(0x0); + while ( !m && fCurrentI < fLastI ) + { + ++fCurrentI; + m = static_cast(fMap->GetValue(fCurrentI)); + } + if (!m) return 0x0; // we are done + fIter2 = new TExMapIter(m->GetIterator()); + o = GetValue(*fIter2,fCurrentJ); + } + + return o; +} + +//_____________________________________________________________________________ +void +AliMUON2DMapIteratorByI::Reset() +{ + /// rewind the iterator + delete fIter2; + fIter2 = 0x0; + fCurrentI = fFirstI; + AliMpExMap* m; + + while ( !( m = static_cast(fMap->GetValue(fCurrentI) ) ) && + fCurrentI < fLastI ) + { + ++fCurrentI; + } + + if ( m ) + { + fIter2 = new TExMapIter(m->GetIterator()); + } +} diff --git a/MUON/AliMUON2DMapIteratorByI.h b/MUON/AliMUON2DMapIteratorByI.h new file mode 100644 index 00000000000..7c8b61bb9ae --- /dev/null +++ b/MUON/AliMUON2DMapIteratorByI.h @@ -0,0 +1,59 @@ +#ifndef ALIMUON2DMAPITERATORBYI_H +#define ALIMUON2DMAPITERATORBYI_H + +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * +* See cxx source for full Copyright notice */ + +// $Id$ + +/// \ingroup calib +/// \class AliMUON2DMapIteratorByIByI +/// \brief Implementation of TIterator for 2D maps +/// +// Author Laurent Aphecetche + +#ifndef ROOT_TExMap +# include "TExMap.h" +#endif +#ifndef ROOT_TIterator +# include "TIterator.h" +#endif + +class AliMpExMap; + +//_____________________________________________________________________________ +class AliMUON2DMapIteratorByI : public TIterator +{ +public: + AliMUON2DMapIteratorByI(const AliMpExMap& theMap, + Int_t firstI, Int_t lastI); + AliMUON2DMapIteratorByI(const AliMUON2DMapIteratorByI& rhs); + TIterator& operator=(const TIterator& rhs); + AliMUON2DMapIteratorByI& operator=(const AliMUON2DMapIteratorByI& rhs); + + virtual ~AliMUON2DMapIteratorByI(); + + ///The returned object must not be deleted by the user. + virtual TObject* Next(); + + virtual void Reset(); + + virtual const TCollection* GetCollection() const; + +private: + + TObject* GetValue(TExMapIter& iter, Int_t& key) const; + +private: + const AliMpExMap* fMap; //!< map to iterate upon + TExMapIter* fIter2; //!< second iterator + Int_t fCurrentI; //!< current index in direction i + Int_t fCurrentJ; //!< current index in direction j + Int_t fFirstI; //!< first I to iterate upon + Int_t fLastI; //!< last I to iterate upon + + ClassDef(AliMUON2DMapIteratorByI,0) // VDataIterator for 2D maps +}; + + +#endif -- 2.39.3