]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUON1DMap.cxx
- Removing use of volpath.dat file, now we can use volume symnames
[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 /// \cond CLASSIMP
33 ClassImp(AliMUON1DMap)
34 /// \endcond
35
36 //_____________________________________________________________________________
37 AliMUON1DMap::AliMUON1DMap(Int_t theSize)
38 : AliMUONVStore(),
39   fMap(new AliMpExMap(true))
40 {
41 /// Default ctor
42
43   if ( theSize ) 
44   {
45     fMap->SetSize(theSize);
46   }
47     fMap->SetOwner(kTRUE);
48 }
49
50 //_____________________________________________________________________________
51 AliMUON1DMap::AliMUON1DMap(const AliMUON1DMap& other)
52 : AliMUONVStore(),
53   fMap(0x0)
54 {
55 /// Copy constructor
56
57   other.CopyTo(*this);
58 }
59
60 //_____________________________________________________________________________
61 AliMUON1DMap&
62 AliMUON1DMap::operator=(const AliMUON1DMap& other)
63 {
64 /// Assignment operator
65
66   other.CopyTo(*this);
67   return *this;
68 }
69
70 //_____________________________________________________________________________
71 AliMUON1DMap::~AliMUON1DMap()
72 {
73 /// dtor, we're the owner of our internal map.
74
75   delete fMap;
76 }
77
78 //_____________________________________________________________________________
79 Bool_t 
80 AliMUON1DMap::Add(TObject* object)
81 {
82   /// Add an object to this, using uniqueID as the key
83   if (!object) return kFALSE;
84   Set(object->GetUniqueID(),object,kFALSE);
85   return kTRUE;
86 }
87
88 //_____________________________________________________________________________
89 void 
90 AliMUON1DMap::Clear(Option_t*)
91 {
92   /// Reset
93   delete fMap;
94   fMap = 0x0;
95 }
96
97 //_____________________________________________________________________________
98 void
99 AliMUON1DMap::CopyTo(AliMUON1DMap& dest) const
100 {
101 /// Make a deep copy
102
103   delete dest.fMap;
104   dest.fMap = fMap;
105 }
106
107 //_____________________________________________________________________________
108 AliMUON1DMap* 
109 AliMUON1DMap::Create() const
110 {
111   /// Create an empty clone of this
112   return new AliMUON1DMap(fMap->GetSize());
113 }
114
115 //_____________________________________________________________________________
116 TObject* 
117 AliMUON1DMap::FindObject(UInt_t i) const
118 {
119 /// Get the object located at index i, if it exists, and if i is correct.
120
121   return fMap->GetValue(i);
122 }
123
124 //_____________________________________________________________________________
125 TIterator*
126 AliMUON1DMap::CreateIterator() const
127 {
128   // Create and return an iterator on this map
129   // Returned iterator must be deleted by user.
130   if ( fMap ) 
131   {
132     return new AliMUON1DMapIterator(*fMap);
133   }
134   return 0x0;
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, Bool_t replace)
148 {
149 /// Set the object located at i
150 /// If replace=kFALSE and 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 && !replace )
155   {
156     AliError(Form("Object %p is already there for i=%d",o,i));
157     return kFALSE;
158   }
159   if ( replace ) 
160   {
161     delete o;
162   }
163   fMap->Add(i,object);
164   return kTRUE;
165 }
166
167
168