X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=MUON%2Fmapping%2FAliMpExMap.cxx;h=7b67a01be9ba1fc33a4b23ff08dc0f33afd29ab6;hb=e95d49427b8bf389628e6b4ccfa42a4aa1cb7167;hp=8d8f98637787e4fe8277d38763cd66b54571f24a;hpb=f700644396f8f13da9feaa50efcd1ee24e97685b;p=u%2Fmrichter%2FAliRoot.git diff --git a/MUON/mapping/AliMpExMap.cxx b/MUON/mapping/AliMpExMap.cxx index 8d8f9863778..7b67a01be9b 100644 --- a/MUON/mapping/AliMpExMap.cxx +++ b/MUON/mapping/AliMpExMap.cxx @@ -14,26 +14,32 @@ **************************************************************************/ // $Id$ -// $MpId: AliMpExMap.cxx,v 1.2 2006/03/02 16:28:23 ivana Exp $ +// $MpId: AliMpExMap.cxx,v 1.5 2006/05/24 13:58:29 ivana Exp $ // Category: basic -// ------------------------ + +//----------------------------------------------------------------------------- // Class AliMpExMap // ------------------------ // Helper class making Root persistent TExMap // Author:Ivana Hrivnacova; IPN Orsay +//----------------------------------------------------------------------------- #include "AliMpExMap.h" +#include "AliMpExMapIterator.h" -#include +#include "AliLog.h" #include -#include #include -#include +#include -//#include "AliMpConstants.h" -#include "AliMpIntPair.h" -#include "AliLog.h" +#include + +using std::cout; +using std::endl; +/// \cond CLASSIMP +ClassImp(AliMpExMap) +/// \endcond // // static members @@ -45,29 +51,18 @@ const Bool_t AliMpExMap::fgkDefaultOwnership = true; const Int_t AliMpExMap::fgkSeparator1 = 10000; const Int_t AliMpExMap::fgkSeparator2 = 100; -const TString AliMpExMap::fgkCharacterMap - = " 1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ."; - -ClassImp(AliMpExMap) - // // static methods // -//______________________________________________________________________________ -Long_t AliMpExMap::GetIndex(const AliMpIntPair& pair) +//_____________________________________________________________________________ +const TString& AliMpExMap::GetCharacterMap() { -/// Convert the pair of integers to integer. - - if (pair.GetFirst() >= fgkSeparator1 || pair.GetSecond() >= fgkSeparator1) { - // to do - use AliLog, is it possible for static function - // AliFatal("Index out of limit."); - cerr << "AliMpExMap::GetIndex(const AliMpIntPair&): Index out of limit." << endl; - exit(1); - } - - return pair.GetFirst()*fgkSeparator1 + pair.GetSecond() + 1; -} + /// Return the string mapping characters to integers + static const TString kCharacterMap + = " 1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-"; + return kCharacterMap; +} //_____________________________________________________________________________ Long_t AliMpExMap::GetIndex(const TString& s) @@ -75,27 +70,17 @@ Long_t AliMpExMap::GetIndex(const TString& s) /// Convert the TString to integer. if (s.Length() > 5) { - // to do - use AliLog, is it possible for static function - // AliFatal("String too long."); - cerr << "AliMpExMap::GetIndex(const TString&): String too long." << endl; - return 0; + AliErrorClass("String too long."); + return -1; } Long_t index = 0; for (Int_t i=s.Length()-1; i>=0; --i) - index = index*fgkSeparator2 + fgkCharacterMap.First(s(i)); + index = index*fgkSeparator2 + GetCharacterMap().First(s(i)); return index; } -//______________________________________________________________________________ -AliMpIntPair AliMpExMap::GetPair(Long_t index) -{ -/// Convert the integer index to the pair of integers. - - return AliMpIntPair((index-1)/fgkSeparator1,(index-1)%fgkSeparator1); -} - //_____________________________________________________________________________ TString AliMpExMap::GetString(Long_t index) { @@ -103,7 +88,7 @@ TString AliMpExMap::GetString(Long_t index) TString s; while (index >0) { - Char_t c = fgkCharacterMap(index%fgkSeparator2); + Char_t c = GetCharacterMap()(index%fgkSeparator2); s += c; index = index/fgkSeparator2; } @@ -115,25 +100,51 @@ TString AliMpExMap::GetString(Long_t index) // //_____________________________________________________________________________ -AliMpExMap::AliMpExMap(Bool_t /*standardConstructor*/) +AliMpExMap::AliMpExMap() : TObject(), fMap(fgkDefaultSize), fObjects(fgkDefaultSize), fKeys(fgkDefaultSize) { -/// Standard constructor + /// Default constructor fObjects.SetOwner(fgkDefaultOwnership); } //_____________________________________________________________________________ -AliMpExMap::AliMpExMap() +AliMpExMap::AliMpExMap(TRootIOCtor*) + : TObject(), + fMap(), + fObjects(), + fKeys() +{ + /// "Root - I/O" constructor +} + + +//_____________________________________________________________________________ +AliMpExMap::AliMpExMap(const AliMpExMap& rhs) : TObject(), fMap(), fObjects(), fKeys() + +{ + /// Copy ctor + rhs.Copy(*this); +} + +//_____________________________________________________________________________ +AliMpExMap& +AliMpExMap::operator=(const AliMpExMap& rhs) { -/// Default constructor + /// Assignment operator + + // check assignment to self + if (this == &rhs) return *this; + + rhs.Copy(*this); + return *this; } //_____________________________________________________________________________ @@ -142,6 +153,47 @@ AliMpExMap::~AliMpExMap() /// Destructor } +// +// private static methods +// + +//______________________________________________________________________________ +Long_t AliMpExMap::GetIndex(Int_t first, Int_t second) +{ +/// Convert the pair of integers to integer. + + if ( first >= 0xFFFF || second >= 0xFFFF ) + { + AliFatalClass("Index out of limit"); + return 0; + } + + return 1 + ( first | ( second << 16 ) ); + +// if (pair.GetFirst() >= fgkSeparator1 || pair.GetSecond() >= fgkSeparator1) { +// AliFatalClass("Index out of limit."); +// exit(1); +// } +// +// return pair.GetFirst()*fgkSeparator1 + pair.GetSecond() + 1; +} + +//______________________________________________________________________________ +Int_t AliMpExMap::GetPairFirst(Long_t index) +{ +/// Return first integer from index (encoded pair) + + return (index-1) & 0xFFFF ; +} + +//______________________________________________________________________________ +Int_t AliMpExMap::GetPairSecond(Long_t index) +{ +/// Return second integer from index (encoded pair) + + return ( (index-1) & 0xFFFF0000 ) >> 16 ; +} + // // private methods // @@ -163,23 +215,85 @@ void AliMpExMap::AddKey(Long_t key) // Resize array if needed if (fObjects.GetEntriesFast() == fKeys.GetSize()) { fKeys.Set(2*fKeys.GetSize()); - cout << "AliMpExMap::AddKey: resized Key array " << endl; + AliDebugStream(1) << "AliMpExMap::AddKey: resized Key array " << endl; } fKeys.AddAt(key, fObjects.GetEntriesFast()); } +//_____________________________________________________________________________ +void +AliMpExMap::Copy(TObject& dest) const +{ + /// Copy this to dest + /// Copy implies that dest will become owner of its objects, whatever + /// the ownership of (*this) is. + + AliDebug(1,""); + + TObject::Copy(dest); + AliMpExMap& m = static_cast(dest); + m.fKeys = fKeys; + m.fMap.Delete(); + m.fObjects.Clear(); + + for ( Int_t i = 0; i <= fObjects.GetLast(); ++i ) + { + TObject* o = fObjects.At(i)->Clone(); + if (!o) + { + AliError("Object was not cloned properly ! Please investigate..."); + } + m.fObjects.AddLast(o); + } + m.FillMap(); + m.fObjects.SetOwner(kTRUE); +} + // // public methods // //_____________________________________________________________________________ -void AliMpExMap::Add(const AliMpIntPair& key, TObject* object) +void AliMpExMap::Clear(Option_t* option) +{ +/// Clear memory + + fMap.Delete(); + fObjects.Clear(option); + fKeys.Reset(); +} + +//_____________________________________________________________________________ +void AliMpExMap::Print(Option_t* opt) const +{ +/// Print out + + cout << Form("fMap size/capacity %d/%d",fMap.GetSize(),fMap.Capacity()) + << Form(" fObjects.GetSize/Entries %d/%d",fObjects.GetSize(),fObjects.GetEntries()) + << Form(" fKeys.GetSize %d",fKeys.GetSize()) << endl; + + TString sopt(opt); + sopt.ToUpper(); + + if ( sopt.Contains("FULL") ) + { + TIter next(CreateIterator()); + TObject* o; + while ( ( o = next() ) ) + { + o->Print(); + } + } +} + +//_____________________________________________________________________________ +void AliMpExMap::Add(Int_t keyFirst, Int_t keySecond, TObject* object) { /// Add object with its key to the map and arrays - fMap.Add(GetIndex(key), (Long_t)object); - AddKey(GetIndex(key)); + fMap.Add(GetIndex(keyFirst, keySecond), (Long_t)object); + AddKey(GetIndex(keyFirst, keySecond)); fObjects.Add(object); } @@ -224,26 +338,35 @@ void AliMpExMap::SetOwner(Bool_t owner) //_____________________________________________________________________________ Int_t AliMpExMap::GetSize() const { -/// Return TExMap iterator set to the beginning of the map +/// Return the map size return fObjects.GetEntriesFast(); } //_____________________________________________________________________________ -TExMapIter AliMpExMap::GetIterator() const +Int_t AliMpExMap::GetCapacity() const { -/// Return TExMap iterator set to the beginning of the map + /// Return the map capacity + + return fObjects.GetSize(); +} - return TExMapIter(&fMap); +//_____________________________________________________________________________ +AliMpExMapIterator* +AliMpExMap::CreateIterator() const +{ +/// Return iterator set to the beginning of the map + + return new AliMpExMapIterator(*this); } //_____________________________________________________________________________ -TObject* AliMpExMap::GetValue(const AliMpIntPair& key) const +TObject* AliMpExMap::GetValue(Int_t keyFirst, Int_t keySecond) const { /// Return the object associated with the given key if found, /// otherwise return 0 - return reinterpret_cast(fMap.GetValue(GetIndex(key))); + return reinterpret_cast(fMap.GetValue(GetIndex(keyFirst, keySecond))); } //_____________________________________________________________________________ @@ -267,8 +390,8 @@ TObject* AliMpExMap::GetValue(Int_t key) const //_____________________________________________________________________________ void AliMpExMap::Streamer(TBuffer &R__b) { -/// Customized streamer \n -/// After the arrays are read, fill the transient map +// Customized streamer \n +// After the arrays are read, fill the transient map if (R__b.IsReading()) { AliMpExMap::Class()->ReadBuffer(R__b, this);