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 /// \class AliMUON1DArray
26 /// This class is simply a wrapper to a TObjArray, offering in addition a
27 /// control over the replacement policy when you add
30 /// \author Laurent Aphecetche
33 ClassImp(AliMUON1DArray)
36 //_____________________________________________________________________________
37 AliMUON1DArray::AliMUON1DArray(Int_t theSize)
43 if (theSize<=0) theSize=16;
45 fArray = new TObjArray(theSize);
46 fArray->SetOwner(kTRUE);
49 //_____________________________________________________________________________
50 AliMUON1DArray::AliMUON1DArray(const AliMUON1DArray& other)
56 AliDebug(1,Form("this=%p copy ctor",this));
60 //_____________________________________________________________________________
62 AliMUON1DArray::operator=(const AliMUON1DArray& other)
64 /// Assignment operator
70 //_____________________________________________________________________________
71 AliMUON1DArray::~AliMUON1DArray()
73 /// dtor, we're the owner of our internal array.
75 AliDebug(1,Form("this=%p",this));
79 //_____________________________________________________________________________
81 AliMUON1DArray::Add(TObject* object)
83 /// Add an object to this, if its uniqueID is below maxsize
84 if (!object) return kFALSE;
86 Int_t i = (Int_t)object->GetUniqueID();
87 if ( i >= fArray->GetSize() )
89 AliError(Form("Index out of bounds %u (max is %u)",i,fArray->GetSize()));
93 Set(object->GetUniqueID(),object,kFALSE);
97 //_____________________________________________________________________________
99 AliMUON1DArray::Clear(Option_t* opt)
105 //_____________________________________________________________________________
107 AliMUON1DArray::CopyTo(AliMUON1DArray& dest) const
113 dest.fArray = new TObjArray(fArray->GetSize());
114 dest.fArray->SetOwner(kTRUE);
115 for ( Int_t i = 0; i < fArray->GetLast(); ++i )
117 dest.fArray->AddAt(fArray->At(i)->Clone(),i);
121 //_____________________________________________________________________________
123 AliMUON1DArray::Create() const
125 /// Create an empty clone of this
126 return new AliMUON1DArray(fArray->GetSize());
129 //_____________________________________________________________________________
131 AliMUON1DArray::FindObject(UInt_t i) const
133 /// Get the object located at index i, if it exists, and if i is correct.
135 if ( (Int_t)(i) < fArray->GetSize() )
137 return fArray->At(i);
139 AliError(Form("Index %d out of bounds (max %d)",i,fArray->GetSize()));
143 //_____________________________________________________________________________
145 AliMUON1DArray::CreateIterator() const
147 /// Return an iterator on this
148 return fArray->MakeIterator();
151 //_____________________________________________________________________________
153 AliMUON1DArray::Set(Int_t i, TObject* object, Bool_t replace)
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
159 if ( i >= 0 && i < fArray->GetSize() )
161 if (((Int_t)(object->GetUniqueID()))!=i)
163 AliError(Form("object's UniqueID is %d, which is different from the expected %d",
164 object->GetUniqueID(),i));
168 TObject* o = FindObject(i);
171 AliError(Form("Object %p is already there for i=%d",o,i));
178 fArray->AddAt(object,i);
181 AliError(Form("Index %d out of bounds (max %d)",i,fArray->GetSize()));
185 //_____________________________________________________________________________
187 AliMUON1DArray::GetSize() const
189 /// Return the number of object we hold
190 return fArray->GetEntries();