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