]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUON2DMap.cxx
Implemented iterator (Laurent)
[u/mrichter/AliRoot.git] / MUON / AliMUON2DMap.cxx
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 "AliMUON2DMap.h"
19
20 #include "AliLog.h"
21 #include "AliMUONVDataIterator.h"
22 #include "AliMUON2DMapIterator.h"
23 #include "AliMpExMap.h"
24 #include "AliMpIntPair.h"
25
26 /// \class AliMUON2DMap
27 /// \brief Basic implementation of AliMUONV2DStore container using
28 /// AliMpExMap internally.
29 /// What we store is a "double" map : an AliMpExMap of AliMpExMaps
30 ///
31 /// \author Laurent Aphecetche
32
33 /// \cond CLASSIMP
34 ClassImp(AliMUON2DMap)
35 /// \endcond
36
37 //_____________________________________________________________________________
38 AliMUON2DMap::AliMUON2DMap() : AliMUONV2DStore(), fMap(new AliMpExMap(true))
39 {
40 /// Default constructor.
41 }
42
43 //_____________________________________________________________________________
44 AliMUON2DMap::AliMUON2DMap(const AliMUON2DMap& other)
45 : AliMUONV2DStore(),
46 fMap(0x0)
47 {
48  /// Copy constructor.
49
50  other.CopyTo(*this);
51 }
52
53 //_____________________________________________________________________________
54 AliMUON2DMap&
55 AliMUON2DMap::operator=(const AliMUON2DMap& other)
56 {
57 /// Assignment operator
58
59   other.CopyTo(*this);
60   return *this;
61 }
62
63 //_____________________________________________________________________________
64 AliMUON2DMap::~AliMUON2DMap()
65 {
66 /// Destructor. 
67 /// We delete the map, which will delete the objects, as we're owner.
68
69   delete fMap;
70 }
71
72 //_____________________________________________________________________________
73 void
74 AliMUON2DMap::CopyTo(AliMUON2DMap&) const
75 {
76 /// Copy this into dest.
77
78   AliFatal("Implement me if needed");
79 }
80
81 //_____________________________________________________________________________
82 TObject* 
83 AliMUON2DMap::Get(Int_t i, Int_t j) const
84 {
85 /// Return the value at position (i,j).
86
87   TObject* o = fMap->GetValue(i);
88   if ( o )
89   {
90     AliMpExMap* m = dynamic_cast<AliMpExMap*>(o);
91     if (!m) AliFatal(Form("fMap[%d] not of the expected type",i));
92     return m->GetValue(j);
93   }
94   return 0x0;
95 }
96
97 //_____________________________________________________________________________
98 AliMUONVDataIterator*
99 AliMUON2DMap::Iterator() const
100 {
101   // Create and return an iterator on this map
102   // Returned iterator must be deleted by user.
103   if ( fMap ) 
104   {
105     return new AliMUON2DMapIterator(*fMap);
106   }
107   return 0x0;
108 }
109
110 //_____________________________________________________________________________
111 void
112 AliMUON2DMap::Print(Option_t*) const
113 {
114 /// Not implemented (yet?)
115 }
116
117 //_____________________________________________________________________________
118 Bool_t 
119 AliMUON2DMap::Set(Int_t i, Int_t j, TObject* object, Bool_t replace)
120 {
121 /// Set the object at position (i,j).
122 /// If replace==kTRUE, we don't care if there's an object there already,
123 /// otherwise we might refuse to set if the (i,j) location is already
124 /// filled (in which case we return kFALSE).
125   
126   TObject* o = fMap->GetValue(i);
127   if ( !o )
128   {
129     AliMpExMap* m = new AliMpExMap(true);
130     fMap->Add(i,m);
131     o = fMap->GetValue(i);
132   }
133   AliMpExMap* m = dynamic_cast<AliMpExMap*>(o);
134   if (!m) AliFatal(Form("fMap[%d] not of the expected type",i));
135   o = m->GetValue(j);
136   if ( !o || ( o && replace ) )
137   {
138     if ( IsOwner() ) 
139     {
140       delete o;
141     }
142     m->Add(j,object);
143   }
144   else if ( o && !replace )
145   {
146     AliError(Form("Object %p is already there for (i,j)=(%d,%d)",o,i,j));
147     return kFALSE;
148   }
149   return kTRUE;
150 }
151
152
153
154
155