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