From: ivana Date: Thu, 29 Mar 2007 11:14:26 +0000 (+0000) Subject: New storage class and its iterator (Laurent) X-Git-Url: http://git.uio.no/git/?p=u%2Fmrichter%2FAliRoot.git;a=commitdiff_plain;h=83c386fbfa0d13bf72fb6dc7b2d6ac03c02b38ac New storage class and its iterator (Laurent) --- diff --git a/MUON/AliMUON1DMap.cxx b/MUON/AliMUON1DMap.cxx new file mode 100644 index 00000000000..90ce7c75244 --- /dev/null +++ b/MUON/AliMUON1DMap.cxx @@ -0,0 +1,134 @@ +/************************************************************************** +* 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$ + +#include "AliMUON1DMap.h" + +#include "AliLog.h" +#include "AliMpExMap.h" +#include "AliMUON1DMapIterator.h" + +/// +/// \class AliMUON1DMap +/// This class is simply a wrapper to an AliMpExMap, offering in addition a +/// control over the replacement policy when you add +/// something to it. +/// +/// \author Laurent Aphecetche + +/// \cond CLASSIMP +ClassImp(AliMUON1DMap) +/// \endcond + +//_____________________________________________________________________________ +AliMUON1DMap::AliMUON1DMap(Int_t theSize) +: AliMUONV1DStore(), + fMap(new AliMpExMap(true)) +{ +/// Default ctor + + if ( theSize ) + { + fMap->SetSize(theSize); + } + fMap->SetOwner(kTRUE); +} + +//_____________________________________________________________________________ +AliMUON1DMap::AliMUON1DMap(const AliMUON1DMap& other) +: AliMUONV1DStore(), + fMap(0x0) +{ +/// Copy constructor + + other.CopyTo(*this); +} + +//_____________________________________________________________________________ +AliMUON1DMap& +AliMUON1DMap::operator=(const AliMUON1DMap& other) +{ +/// Assignment operator + + other.CopyTo(*this); + return *this; +} + +//_____________________________________________________________________________ +AliMUON1DMap::~AliMUON1DMap() +{ +/// dtor, we're the owner of our internal map. + + delete fMap; +} + +//_____________________________________________________________________________ +void +AliMUON1DMap::CopyTo(AliMUON1DMap& dest) const +{ +/// Make a deep copy + + delete dest.fMap; + dest.fMap = fMap; +} + +//_____________________________________________________________________________ +TObject* +AliMUON1DMap::Get(Int_t i) const +{ +/// Get the object located at index i, if it exists, and if i is correct. + + return fMap->GetValue(i); +} + +//_____________________________________________________________________________ +AliMUONVDataIterator* +AliMUON1DMap::Iterator() const +{ + // Create and return an iterator on this map + // Returned iterator must be deleted by user. + if ( fMap ) + { + return new AliMUON1DMapIterator(*fMap); + } + return 0x0; +} + + +//_____________________________________________________________________________ +Bool_t +AliMUON1DMap::Set(Int_t i, TObject* object, Bool_t replace) +{ +/// Set the object located at i +/// 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); + if ( o && !replace ) + { + AliError(Form("Object %p is already there for i=%d",o,i)); + return kFALSE; + } + if ( replace ) + { + delete o; + } + fMap->Add(i,object); + return kTRUE; +} + + + diff --git a/MUON/AliMUON1DMap.h b/MUON/AliMUON1DMap.h new file mode 100644 index 00000000000..339fa2121f4 --- /dev/null +++ b/MUON/AliMUON1DMap.h @@ -0,0 +1,53 @@ +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * +* See cxx source for full Copyright notice */ + +// $Id$ + +/// \ingroup base +/// \class AliMUON1DMap +/// \brief Implementation of AliMUONV1DStore +/// +// Author Laurent Aphecetche + +#ifndef ALIMUON1DMAP_H +#define ALIMUON1DMAP_H + +#ifndef ALIMUONV1DSTORE_H +# include "AliMUONV1DStore.h" +#endif + +class AliMpExMap; + +class AliMUON1DMap : public AliMUONV1DStore +{ +public: + AliMUON1DMap(Int_t theSize=0); + AliMUON1DMap(const AliMUON1DMap& other); + AliMUON1DMap& operator=(const AliMUON1DMap& other); + + virtual ~AliMUON1DMap(); + + /// Return the object stored at i. + virtual TObject* Get(Int_t i) const; + + virtual AliMUONVDataIterator* Iterator() 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); + + /// Whether or not this container is the owner of its contents. + virtual Bool_t IsOwner() const { return kTRUE; } + +private: + void CopyTo(AliMUON1DMap& to) const; + +private: + + AliMpExMap* fMap; ///< Internal array (map) + + ClassDef(AliMUON1DMap,1) // Implementation of AliMUONV1DStore +}; + +#endif diff --git a/MUON/AliMUON1DMapIterator.cxx b/MUON/AliMUON1DMapIterator.cxx new file mode 100644 index 00000000000..b74bd59e9a6 --- /dev/null +++ b/MUON/AliMUON1DMapIterator.cxx @@ -0,0 +1,84 @@ +/************************************************************************** +* 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$ + +#include "AliMUON1DMapIterator.h" +#include "AliMpExMap.h" +#include "AliLog.h" +#include "AliMpIntPair.h" +#include "AliMUONObjectPair.h" +#include "AliMpExMap.h" + +/// \class AliMUON1DMapIterator +/// Implementation of AliMUONVDataIterator for 1Dmaps +/// +/// A simple implementation of VDataIterator for 1Dmaps. +/// +/// \author Laurent Aphecetche + +/// \cond CLASSIMP +ClassImp(AliMUON1DMapIterator) +/// \endcond + +//_____________________________________________________________________________ +AliMUON1DMapIterator::AliMUON1DMapIterator(AliMpExMap& theMap) +: AliMUONVDataIterator(), +fIter(theMap.GetIterator()), +fCurrentI(-1) +{ + /// default ctor + Reset(); +} + +//_____________________________________________________________________________ +AliMUON1DMapIterator::~AliMUON1DMapIterator() +{ + /// dtor +} + +//_____________________________________________________________________________ +TObject* +AliMUON1DMapIterator::Next() +{ + /// + + Long_t key, value; + Bool_t ok = fIter.Next(key,value); + if (!ok) return 0x0; + Int_t i = (Int_t)(key & 0xFFFF); + TObject* o = reinterpret_cast(value); + + return new AliMUONObjectPair(new AliMpIntPair(i,0),o, + kTRUE, /* owner of intpair */ + kFALSE /* but not of o */); +} + +//_____________________________________________________________________________ +void +AliMUON1DMapIterator::Reset() +{ + /// rewind the iterator + fIter.Reset(); +} + +//_____________________________________________________________________________ +Bool_t +AliMUON1DMapIterator::Remove() +{ + /// to be implemented if needed + AliInfo("Not supported yet"); + return kFALSE; +} diff --git a/MUON/AliMUON1DMapIterator.h b/MUON/AliMUON1DMapIterator.h new file mode 100644 index 00000000000..dab95d25e22 --- /dev/null +++ b/MUON/AliMUON1DMapIterator.h @@ -0,0 +1,60 @@ +#ifndef ALIMUON1DMAPITERATOR_H +#define ALIMUON1DMAPITERATOR_H + +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * +* See cxx source for full Copyright notice */ + +// $Id$ + +/// \ingroup base +/// \class AliMUON1DMapIterator +/// \brief Implementation of AliMUONVDataIterator for 1D maps +/// +// Author Laurent Aphecetche + +#ifndef ROOT_TObject +# include "TObject.h" +#endif +#ifndef ROOT_TExMap +# include "TExMap.h" +#endif +#ifndef ALIMUONVDATAITERATOR_H +# include "AliMUONVDataIterator.h" +#endif + +class AliMpExMap; + +//_____________________________________________________________________________ +class AliMUON1DMapIterator : public AliMUONVDataIterator +{ +public: + AliMUON1DMapIterator(AliMpExMap& theMap); + + virtual ~AliMUON1DMapIterator(); + + /** The object returned by this iterator is an AliMUONObjectPair(TObject* key,TObject* value) + where key is an AliMpIntPair (i,0), and value is + an AliMUONVCalibParam. + The returned object must be deleted by the user. + */ + virtual TObject* Next(); + + virtual void Reset(); + + virtual Bool_t Remove(); + +private: + /// copy ctor will not implemented + AliMUON1DMapIterator(const AliMUON1DMapIterator&); + /// assignement operator will not implemented + AliMUON1DMapIterator& operator=(const AliMUON1DMapIterator&); + +private: + TExMapIter fIter; //!< iterator + Int_t fCurrentI; //!< current index in direction i + + ClassDef(AliMUON1DMapIterator,0) // VDataIterator for 1D maps +}; + + +#endif diff --git a/MUON/MUONbaseLinkDef.h b/MUON/MUONbaseLinkDef.h index 7f52989d7d5..71fcb707e3e 100644 --- a/MUON/MUONbaseLinkDef.h +++ b/MUON/MUONbaseLinkDef.h @@ -46,6 +46,8 @@ #pragma link C++ class AliMUON2DMap+; #pragma link C++ class AliMUON2DMapIterator+; #pragma link C++ class AliMUON1DArray+; +#pragma link C++ class AliMUON1DMap+; +#pragma link C++ class AliMUON1DMapIterator+; #pragma link C++ class AliMUONVCalibParam+; #pragma link C++ class AliMUONCalibParam1I+; #pragma link C++ class AliMUONCalibParam2F+; diff --git a/MUON/libMUONbase.pkg b/MUON/libMUONbase.pkg index ee0382b7ee5..4fc82f61510 100644 --- a/MUON/libMUONbase.pkg +++ b/MUON/libMUONbase.pkg @@ -31,6 +31,8 @@ SRCS:= AliMUON.cxx AliMUONv1.cxx \ AliMUON2DMap.cxx \ AliMUON2DMapIterator.cxx \ AliMUON1DArray.cxx \ + AliMUON1DMap.cxx \ + AliMUON1DMapIterator.cxx \ AliMUONVCalibParam.cxx \ AliMUONCalibParam1I.cxx \ AliMUONCalibParam2F.cxx \ @@ -45,7 +47,7 @@ SRCS:= AliMUON.cxx AliMUONv1.cxx \ AliMUON2DStoreValidator.cxx \ AliMUONCheckItem.cxx \ AliMUONCheckItemIterator.cxx - + HDRS:= $(SRCS:.cxx=.h) DHDR:= MUONbaseLinkDef.h