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