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