]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUON1DMap.cxx
In AliMUONRawStreamTriggerHP:
[u/mrichter/AliRoot.git] / MUON / AliMUON1DMap.cxx
CommitLineData
83c386fb 1/**************************************************************************
2* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3* *
4* Author: The ALICE Off-line Project. *
5* Contributors are mentioned in the code where appropriate. *
6* *
7* Permission to use, copy, modify and distribute this software and its *
8* documentation strictly for non-commercial purposes is hereby granted *
9* without fee, provided that the above copyright notice appears in all *
10* copies and that both the copyright notice and this permission notice *
11* appear in the supporting documentation. The authors make no claims *
12* about the suitability of this software for any purpose. It is *
13* provided "as is" without express or implied warranty. *
14**************************************************************************/
15
16// $Id$
17
18#include "AliMUON1DMap.h"
7332f213 19#include "AliMpExMap.h"
630711ed 20#include "AliMpExMapIterator.h"
83c386fb 21
22#include "AliLog.h"
83c386fb 23
3d1463c8 24//-----------------------------------------------------------------------------
83c386fb 25/// \class AliMUON1DMap
26/// This class is simply a wrapper to an AliMpExMap, offering in addition a
27/// control over the replacement policy when you add
28/// something to it.
29///
30/// \author Laurent Aphecetche
3d1463c8 31//-----------------------------------------------------------------------------
83c386fb 32
33/// \cond CLASSIMP
34ClassImp(AliMUON1DMap)
35/// \endcond
36
630711ed 37//_____________________________________________________________________________
38AliMUON1DMap::AliMUON1DMap(TRootIOCtor*)
39: AliMUONVStore(),
40fMap(0x0)
41{
42 /// I/O ctor
43
44}
45
83c386fb 46//_____________________________________________________________________________
47AliMUON1DMap::AliMUON1DMap(Int_t theSize)
4178b5c7 48: AliMUONVStore(),
630711ed 49 fMap(new AliMpExMap)
83c386fb 50{
51/// Default ctor
52
630711ed 53 AliInfo("");
54
55 if ( theSize > 0)
83c386fb 56 {
57 fMap->SetSize(theSize);
58 }
630711ed 59 fMap->SetOwner(kTRUE);
83c386fb 60}
61
62//_____________________________________________________________________________
63AliMUON1DMap::AliMUON1DMap(const AliMUON1DMap& other)
4178b5c7 64: AliMUONVStore(),
7332f213 65 fMap(new AliMpExMap(*other.fMap))
83c386fb 66{
67/// Copy constructor
83c386fb 68}
69
70//_____________________________________________________________________________
71AliMUON1DMap&
72AliMUON1DMap::operator=(const AliMUON1DMap& other)
73{
74/// Assignment operator
7332f213 75 *fMap = *other.fMap;
83c386fb 76 return *this;
77}
78
79//_____________________________________________________________________________
80AliMUON1DMap::~AliMUON1DMap()
81{
7332f213 82/// destructor
83c386fb 83 delete fMap;
84}
85
4178b5c7 86//_____________________________________________________________________________
87Bool_t
88AliMUON1DMap::Add(TObject* object)
89{
90 /// Add an object to this, using uniqueID as the key
91 if (!object) return kFALSE;
7332f213 92 return Set(object->GetUniqueID(),object);
4178b5c7 93}
94
95//_____________________________________________________________________________
96void
97AliMUON1DMap::Clear(Option_t*)
98{
99 /// Reset
7332f213 100 fMap->Clear();
83c386fb 101}
102
4178b5c7 103//_____________________________________________________________________________
104AliMUON1DMap*
105AliMUON1DMap::Create() const
106{
107 /// Create an empty clone of this
108 return new AliMUON1DMap(fMap->GetSize());
109}
110
83c386fb 111//_____________________________________________________________________________
112TObject*
4178b5c7 113AliMUON1DMap::FindObject(UInt_t i) const
83c386fb 114{
115/// Get the object located at index i, if it exists, and if i is correct.
83c386fb 116 return fMap->GetValue(i);
117}
118
49419555 119//_____________________________________________________________________________
120TObject*
121AliMUON1DMap::FindObject(Int_t i, Int_t j) const
122{
123 /// Get the object located at index (i,j), if it exists, and if i,j is correct.
124
125 UInt_t uid = ( ( ( j & 0xFFFF ) << 16 ) | ( i & 0xFFFF ) );
126
127 return fMap->GetValue(uid);
128}
129
83c386fb 130//_____________________________________________________________________________
4178b5c7 131TIterator*
132AliMUON1DMap::CreateIterator() const
83c386fb 133{
7332f213 134 /// Create and return an iterator on this map
135 /// Returned iterator must be deleted by user.
630711ed 136 return fMap->CreateIterator();
83c386fb 137}
138
4178b5c7 139//_____________________________________________________________________________
140Int_t
141AliMUON1DMap::GetSize() const
142{
143 /// Return the number of objects we hold
144 return fMap->GetSize();
145}
83c386fb 146
147//_____________________________________________________________________________
148Bool_t
7332f213 149AliMUON1DMap::Set(Int_t i, TObject* object)
83c386fb 150{
151/// Set the object located at i
7332f213 152/// If there's already an object at location i,
83c386fb 153/// this method fails and returns kFALSE, otherwise it returns kTRUE
7332f213 154
4178b5c7 155 TObject* o = FindObject(i);
7332f213 156 if ( o )
83c386fb 157 {
158 AliError(Form("Object %p is already there for i=%d",o,i));
159 return kFALSE;
160 }
83c386fb 161 fMap->Add(i,object);
162 return kTRUE;
163}
164