]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUON1DArray.cxx
No more misaligned_geometry
[u/mrichter/AliRoot.git] / MUON / AliMUON1DArray.cxx
CommitLineData
70b4a8d6 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 "AliMUON1DArray.h"
19
20#include "AliLog.h"
4178b5c7 21#include <TClass.h>
22#include <TObjArray.h>
23#include <Riostream.h>
70b4a8d6 24///
5398f946 25/// \class AliMUON1DArray
70b4a8d6 26/// This class is simply a wrapper to a TObjArray, offering in addition a
27/// control over the replacement policy when you add
28/// something to it.
29///
5398f946 30/// \author Laurent Aphecetche
70b4a8d6 31
5398f946 32/// \cond CLASSIMP
70b4a8d6 33ClassImp(AliMUON1DArray)
5398f946 34/// \endcond
70b4a8d6 35
36//_____________________________________________________________________________
37AliMUON1DArray::AliMUON1DArray(Int_t theSize)
4178b5c7 38: AliMUONVStore(),
70b4a8d6 39 fArray(0x0)
40{
4178b5c7 41 /// Default ctor
5398f946 42
4178b5c7 43 if (theSize<=0) theSize=16;
44
45 fArray = new TObjArray(theSize);
46 fArray->SetOwner(kTRUE);
70b4a8d6 47}
48
49//_____________________________________________________________________________
50AliMUON1DArray::AliMUON1DArray(const AliMUON1DArray& other)
4178b5c7 51: AliMUONVStore(),
70b4a8d6 52 fArray(0x0)
53{
5398f946 54/// Copy constructor
55
4178b5c7 56 AliDebug(1,Form("this=%p copy ctor",this));
70b4a8d6 57 other.CopyTo(*this);
58}
59
60//_____________________________________________________________________________
61AliMUON1DArray&
62AliMUON1DArray::operator=(const AliMUON1DArray& other)
63{
5398f946 64/// Assignment operator
65
70b4a8d6 66 other.CopyTo(*this);
67 return *this;
68}
69
70//_____________________________________________________________________________
71AliMUON1DArray::~AliMUON1DArray()
72{
4178b5c7 73 /// dtor, we're the owner of our internal array.
5398f946 74
4178b5c7 75 AliDebug(1,Form("this=%p",this));
70b4a8d6 76 delete fArray;
77}
78
4178b5c7 79//_____________________________________________________________________________
80Bool_t
81AliMUON1DArray::Add(TObject* object)
82{
83 /// Add an object to this, if its uniqueID is below maxsize
84 if (!object) return kFALSE;
85
86 Int_t i = (Int_t)object->GetUniqueID();
87 if ( i >= fArray->GetSize() )
88 {
89 AliError(Form("Index out of bounds %u (max is %u)",i,fArray->GetSize()));
90 return kFALSE;
91 }
92
93 Set(object->GetUniqueID(),object,kFALSE);
94 return kTRUE;
95}
96
97//_____________________________________________________________________________
98void
99AliMUON1DArray::Clear(Option_t* opt)
100{
101 /// Reset
102 fArray->Clear(opt);
103}
104
70b4a8d6 105//_____________________________________________________________________________
106void
107AliMUON1DArray::CopyTo(AliMUON1DArray& dest) const
108{
5398f946 109/// Make a deep copy
110
70b4a8d6 111 delete dest.fArray;
4178b5c7 112 dest.fArray = 0;
113 dest.fArray = new TObjArray(fArray->GetSize());
70b4a8d6 114 dest.fArray->SetOwner(kTRUE);
115 for ( Int_t i = 0; i < fArray->GetLast(); ++i )
116 {
117 dest.fArray->AddAt(fArray->At(i)->Clone(),i);
118 }
119}
120
4178b5c7 121//_____________________________________________________________________________
122AliMUON1DArray*
123AliMUON1DArray::Create() const
124{
125 /// Create an empty clone of this
126 return new AliMUON1DArray(fArray->GetSize());
127}
128
70b4a8d6 129//_____________________________________________________________________________
130TObject*
4178b5c7 131AliMUON1DArray::FindObject(UInt_t i) const
70b4a8d6 132{
4178b5c7 133 /// Get the object located at index i, if it exists, and if i is correct.
5398f946 134
4178b5c7 135 if ( (Int_t)(i) < fArray->GetSize() )
70b4a8d6 136 {
137 return fArray->At(i);
138 }
139 AliError(Form("Index %d out of bounds (max %d)",i,fArray->GetSize()));
140 return 0x0;
141}
142
4178b5c7 143//_____________________________________________________________________________
144TIterator*
145AliMUON1DArray::CreateIterator() const
146{
147 /// Return an iterator on this
148 return fArray->MakeIterator();
149}
150
70b4a8d6 151//_____________________________________________________________________________
152Bool_t
153AliMUON1DArray::Set(Int_t i, TObject* object, Bool_t replace)
154{
5398f946 155/// Set the object located at i
156/// If replace=kFALSE and there's already an object at location i,
157/// this method fails and returns kFALSE, otherwise it returns kTRUE
158
70b4a8d6 159 if ( i >= 0 && i < fArray->GetSize() )
160 {
4178b5c7 161 if (((Int_t)(object->GetUniqueID()))!=i)
162 {
163 AliError(Form("object's UniqueID is %d, which is different from the expected %d",
164 object->GetUniqueID(),i));
165 return kFALSE;
166 }
167
168 TObject* o = FindObject(i);
70b4a8d6 169 if ( o && !replace )
170 {
171 AliError(Form("Object %p is already there for i=%d",o,i));
172 return kFALSE;
173 }
4178b5c7 174 if ( o && replace )
70b4a8d6 175 {
176 delete o;
177 }
178 fArray->AddAt(object,i);
179 return kTRUE;
180 }
181 AliError(Form("Index %d out of bounds (max %d)",i,fArray->GetSize()));
182 return kFALSE;
183}
184
4178b5c7 185//_____________________________________________________________________________
186Int_t
187AliMUON1DArray::GetSize() const
188{
189 /// Return the number of object we hold
190 return fArray->GetEntries();
191}