1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUON1DArray.h"
22 #include <TObjArray.h>
23 #include <Riostream.h>
25 //-----------------------------------------------------------------------------
26 /// \class AliMUON1DArray
27 /// This class is simply a wrapper to a TObjArray, offering in addition a
28 /// control over the replacement policy when you add
31 /// \author Laurent Aphecetche
32 //-----------------------------------------------------------------------------
35 ClassImp(AliMUON1DArray)
38 //_____________________________________________________________________________
39 AliMUON1DArray::AliMUON1DArray(Int_t theSize)
45 if (theSize<=0) theSize=16;
47 fArray = new TObjArray(theSize);
48 fArray->SetOwner(kTRUE);
51 //_____________________________________________________________________________
52 AliMUON1DArray::AliMUON1DArray(const AliMUON1DArray& other)
58 AliDebug(1,Form("this=%p copy ctor",this));
62 //_____________________________________________________________________________
64 AliMUON1DArray::operator=(const AliMUON1DArray& other)
66 /// Assignment operator
72 //_____________________________________________________________________________
73 AliMUON1DArray::~AliMUON1DArray()
75 /// dtor, we're the owner of our internal array.
77 AliDebug(1,Form("this=%p",this));
81 //_____________________________________________________________________________
83 AliMUON1DArray::Add(TObject* object)
85 /// Add an object to this, if its uniqueID is below maxsize
86 if (!object) return kFALSE;
88 Int_t i = (Int_t)object->GetUniqueID();
89 if ( i >= fArray->GetSize() )
91 AliError(Form("Index out of bounds %u (max is %u)",i,fArray->GetSize()));
95 Set(object->GetUniqueID(),object,kFALSE);
99 //_____________________________________________________________________________
101 AliMUON1DArray::Clear(Option_t* opt)
107 //_____________________________________________________________________________
109 AliMUON1DArray::CopyTo(AliMUON1DArray& dest) const
115 dest.fArray = new TObjArray(fArray->GetSize());
116 dest.fArray->SetOwner(kTRUE);
117 for ( Int_t i = 0; i < fArray->GetLast(); ++i )
119 dest.fArray->AddAt(fArray->At(i)->Clone(),i);
123 //_____________________________________________________________________________
125 AliMUON1DArray::Create() const
127 /// Create an empty clone of this
128 return new AliMUON1DArray(fArray->GetSize());
131 //_____________________________________________________________________________
133 AliMUON1DArray::FindObject(UInt_t i) const
135 /// Get the object located at index i, if it exists, and if i is correct.
137 if ( (Int_t)(i) < fArray->GetSize() )
139 return fArray->At(i);
141 AliError(Form("Index %d out of bounds (max %d)",i,fArray->GetSize()));
145 //_____________________________________________________________________________
147 AliMUON1DArray::CreateIterator() const
149 /// Return an iterator on this
150 return fArray->MakeIterator();
153 //_____________________________________________________________________________
155 AliMUON1DArray::Set(Int_t i, TObject* object, Bool_t replace)
157 /// Set the object located at i
158 /// If replace=kFALSE and there's already an object at location i,
159 /// this method fails and returns kFALSE, otherwise it returns kTRUE
161 if ( i >= 0 && i < fArray->GetSize() )
163 if (((Int_t)(object->GetUniqueID()))!=i)
165 AliError(Form("object's UniqueID is %d, which is different from the expected %d",
166 object->GetUniqueID(),i));
170 TObject* o = FindObject(i);
173 AliError(Form("Object %p is already there for i=%d",o,i));
180 fArray->AddAt(object,i);
183 AliError(Form("Index %d out of bounds (max %d)",i,fArray->GetSize()));
187 //_____________________________________________________________________________
189 AliMUON1DArray::GetSize() const
191 /// Return the number of object we hold
192 return fArray->GetEntries();