]>
Commit | Line | Data |
---|---|---|
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" | |
19 | #include "AliMUON1DMapIterator.h" | |
20 | #include "AliMpExMap.h" | |
21 | ||
22 | #include "AliLog.h" | |
23 | ||
24 | //----------------------------------------------------------------------------- | |
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 | |
31 | //----------------------------------------------------------------------------- | |
32 | ||
33 | /// \cond CLASSIMP | |
34 | ClassImp(AliMUON1DMap) | |
35 | /// \endcond | |
36 | ||
37 | //_____________________________________________________________________________ | |
38 | AliMUON1DMap::AliMUON1DMap(Int_t theSize) | |
39 | : AliMUONVStore(), | |
40 | fMap(new AliMpExMap(kTRUE)) | |
41 | { | |
42 | /// Default ctor | |
43 | ||
44 | if ( theSize ) | |
45 | { | |
46 | fMap->SetSize(theSize); | |
47 | } | |
48 | fMap->SetOwner(kTRUE); | |
49 | } | |
50 | ||
51 | //_____________________________________________________________________________ | |
52 | AliMUON1DMap::AliMUON1DMap(const AliMUON1DMap& other) | |
53 | : AliMUONVStore(), | |
54 | fMap(new AliMpExMap(*other.fMap)) | |
55 | { | |
56 | /// Copy constructor | |
57 | } | |
58 | ||
59 | //_____________________________________________________________________________ | |
60 | AliMUON1DMap& | |
61 | AliMUON1DMap::operator=(const AliMUON1DMap& other) | |
62 | { | |
63 | /// Assignment operator | |
64 | *fMap = *other.fMap; | |
65 | return *this; | |
66 | } | |
67 | ||
68 | //_____________________________________________________________________________ | |
69 | AliMUON1DMap::~AliMUON1DMap() | |
70 | { | |
71 | /// destructor | |
72 | delete fMap; | |
73 | } | |
74 | ||
75 | //_____________________________________________________________________________ | |
76 | Bool_t | |
77 | AliMUON1DMap::Add(TObject* object) | |
78 | { | |
79 | /// Add an object to this, using uniqueID as the key | |
80 | if (!object) return kFALSE; | |
81 | return Set(object->GetUniqueID(),object); | |
82 | } | |
83 | ||
84 | //_____________________________________________________________________________ | |
85 | void | |
86 | AliMUON1DMap::Clear(Option_t*) | |
87 | { | |
88 | /// Reset | |
89 | fMap->Clear(); | |
90 | } | |
91 | ||
92 | //_____________________________________________________________________________ | |
93 | AliMUON1DMap* | |
94 | AliMUON1DMap::Create() const | |
95 | { | |
96 | /// Create an empty clone of this | |
97 | return new AliMUON1DMap(fMap->GetSize()); | |
98 | } | |
99 | ||
100 | //_____________________________________________________________________________ | |
101 | TObject* | |
102 | AliMUON1DMap::FindObject(UInt_t i) const | |
103 | { | |
104 | /// Get the object located at index i, if it exists, and if i is correct. | |
105 | return fMap->GetValue(i); | |
106 | } | |
107 | ||
108 | //_____________________________________________________________________________ | |
109 | TObject* | |
110 | AliMUON1DMap::FindObject(Int_t i, Int_t j) const | |
111 | { | |
112 | /// Get the object located at index (i,j), if it exists, and if i,j is correct. | |
113 | ||
114 | UInt_t uid = ( ( ( j & 0xFFFF ) << 16 ) | ( i & 0xFFFF ) ); | |
115 | ||
116 | return fMap->GetValue(uid); | |
117 | } | |
118 | ||
119 | //_____________________________________________________________________________ | |
120 | TIterator* | |
121 | AliMUON1DMap::CreateIterator() const | |
122 | { | |
123 | /// Create and return an iterator on this map | |
124 | /// Returned iterator must be deleted by user. | |
125 | return new AliMUON1DMapIterator(*fMap); | |
126 | } | |
127 | ||
128 | //_____________________________________________________________________________ | |
129 | Int_t | |
130 | AliMUON1DMap::GetSize() const | |
131 | { | |
132 | /// Return the number of objects we hold | |
133 | return fMap->GetSize(); | |
134 | } | |
135 | ||
136 | //_____________________________________________________________________________ | |
137 | Bool_t | |
138 | AliMUON1DMap::Set(Int_t i, TObject* object) | |
139 | { | |
140 | /// Set the object located at i | |
141 | /// If there's already an object at location i, | |
142 | /// this method fails and returns kFALSE, otherwise it returns kTRUE | |
143 | ||
144 | TObject* o = FindObject(i); | |
145 | if ( o ) | |
146 | { | |
147 | AliError(Form("Object %p is already there for i=%d",o,i)); | |
148 | return kFALSE; | |
149 | } | |
150 | fMap->Add(i,object); | |
151 | return kTRUE; | |
152 | } | |
153 |