]>
Commit | Line | Data |
---|---|---|
f246123b | 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 "AliMUON2DMapIterator.h" | |
19 | #include "AliMpExMap.h" | |
20 | #include "TMap.h" | |
21 | #include "AliLog.h" | |
22 | #include "AliMpIntPair.h" | |
fb9b1607 | 23 | #include "AliMUONObjectPair.h" |
f246123b | 24 | |
25 | /// \class AliMUON2DMapIterator | |
26 | /// \brief Implementation of AliMUONVDataIterator for 2Dmaps | |
27 | /// | |
28 | /// A simple implementation of VDataIterator for 2Dmaps. | |
29 | /// | |
30 | /// \author Laurent Aphecetche | |
31 | ||
32 | /// \cond CLASSIMP | |
33 | ClassImp(AliMUON2DMapIterator) | |
34 | /// \endcond | |
35 | ||
36 | //_____________________________________________________________________________ | |
37 | AliMUON2DMapIterator::AliMUON2DMapIterator(AliMpExMap& theMap) | |
38 | : AliMUONVDataIterator(), | |
39 | fIter(theMap.GetIterator()), | |
40 | fIter2(0x0), | |
41 | fCurrentI(-1), | |
42 | fCurrentJ(-1) | |
43 | { | |
44 | // default ctor | |
45 | Reset(); | |
46 | } | |
47 | ||
48 | //_____________________________________________________________________________ | |
49 | AliMUON2DMapIterator::~AliMUON2DMapIterator() | |
50 | { | |
51 | // dtor | |
52 | delete fIter2; | |
53 | } | |
54 | ||
55 | //_____________________________________________________________________________ | |
56 | TObject* | |
57 | AliMUON2DMapIterator::GetValue(TExMapIter& iter, Int_t& theKey) const | |
58 | { | |
59 | // return the value corresponding to theKey in iterator iter | |
60 | theKey = -1; | |
61 | Long_t key, value; | |
62 | Bool_t ok = iter.Next(key,value); | |
63 | if (!ok) return 0x0; | |
64 | theKey = (Int_t)(key & 0xFFFF); | |
65 | return reinterpret_cast<TObject*>(value); | |
66 | } | |
67 | ||
68 | //_____________________________________________________________________________ | |
69 | AliMpExMap* | |
70 | AliMUON2DMapIterator::GetMap(TExMapIter& iter, Int_t& key) | |
71 | { | |
72 | // get the map corresponding to key | |
73 | AliMpExMap* rv(0x0); | |
74 | TObject* o = GetValue(iter,key); | |
75 | if (o) | |
76 | { | |
77 | rv = dynamic_cast<AliMpExMap*>(o); | |
78 | if (!rv) | |
79 | { | |
80 | AliFatal("boom"); | |
81 | } | |
82 | } | |
83 | return rv; | |
84 | } | |
85 | ||
86 | //_____________________________________________________________________________ | |
87 | TObject* | |
88 | AliMUON2DMapIterator::Next() | |
89 | { | |
90 | // logic : | |
91 | // get TObject* from fIter2 | |
92 | // if null, increment fIter2 by getting next on fIter | |
93 | ||
94 | if (!fIter2) return 0x0; | |
95 | ||
96 | TObject* o = GetValue(*fIter2,fCurrentJ); | |
97 | if (!o) | |
98 | { | |
99 | // fIter2 exhausted, try to get the next one | |
100 | AliMpExMap* m = GetMap(fIter,fCurrentI); | |
101 | if (!m) | |
102 | { | |
103 | // nothing left, we are done. | |
104 | return 0x0; | |
105 | } | |
106 | delete fIter2; | |
107 | fIter2 = new TExMapIter(m->GetIterator()); | |
108 | o = GetValue(*fIter2,fCurrentJ); | |
fb9b1607 | 109 | } |
110 | return new AliMUONObjectPair(new AliMpIntPair(fCurrentI,fCurrentJ),o, | |
111 | kTRUE, /* owner of intpair */ | |
112 | kFALSE /* but not of o */); | |
f246123b | 113 | } |
114 | ||
115 | //_____________________________________________________________________________ | |
116 | void | |
117 | AliMUON2DMapIterator::Reset() | |
118 | { | |
119 | // rewind the iterator | |
120 | delete fIter2; | |
121 | fIter.Reset(); | |
122 | AliMpExMap* m = GetMap(fIter,fCurrentI); | |
123 | if (m) | |
124 | { | |
125 | fIter2 = new TExMapIter(m->GetIterator()); | |
126 | } | |
127 | } | |
128 | ||
129 | //_____________________________________________________________________________ | |
130 | Bool_t | |
131 | AliMUON2DMapIterator::Remove() | |
132 | { | |
133 | // to be implemented if needed | |
134 | AliInfo("Not supported yet"); | |
135 | return kFALSE; | |
136 | } |