AliRoot Core  3dc7879 (3dc7879)
AliMUON1DArray.cxx
Go to the documentation of this file.
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"
21 #include <TClass.h>
22 #include <TObjArray.h>
23 #include <Riostream.h>
24 
25 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
33 
35 ClassImp(AliMUON1DArray)
37 
38 //_____________________________________________________________________________
40 : AliMUONVStore(),
41  fArray(0x0)
42 {
44 
45  if (theSize<=0) theSize=16;
46 
47  fArray = new TObjArray(theSize);
48  fArray->SetOwner(kTRUE);
49 }
50 
51 //_____________________________________________________________________________
53 : AliMUONVStore(),
54  fArray(0x0)
55 {
57 
58  AliDebug(1,Form("this=%p copy ctor",this));
59  other.CopyTo(*this);
60 }
61 
62 //_____________________________________________________________________________
65 {
67 
68  other.CopyTo(*this);
69  return *this;
70 }
71 
72 //_____________________________________________________________________________
74 {
76 
77  AliDebug(1,Form("this=%p",this));
78  delete fArray;
79 }
80 
81 //_____________________________________________________________________________
82 Bool_t
83 AliMUON1DArray::Add(TObject* object)
84 {
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 //_____________________________________________________________________________
100 void
101 AliMUON1DArray::Clear(Option_t* opt)
102 {
104  fArray->Clear(opt);
105 }
106 
107 //_____________________________________________________________________________
108 void
110 {
112 
113  delete dest.fArray;
114  dest.fArray = 0;
115  dest.fArray = new TObjArray(fArray->GetSize());
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 //_____________________________________________________________________________
126 {
128  return new AliMUON1DArray(fArray->GetSize());
129 }
130 
131 //_____________________________________________________________________________
132 TObject*
134 {
136 
137  if ( (Int_t)(i) < fArray->GetSize() )
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 //_____________________________________________________________________________
146 TIterator*
148 {
150  return fArray->MakeIterator();
151 }
152 
153 //_____________________________________________________________________________
154 Bool_t
155 AliMUON1DArray::Set(Int_t i, TObject* object, Bool_t replace)
156 {
160 
161  if ( i >= 0 && i < fArray->GetSize() )
162  {
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);
171  if ( o && !replace )
172  {
173  AliError(Form("Object %p is already there for i=%d",o,i));
174  return kFALSE;
175  }
176  if ( o && replace )
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 
187 //_____________________________________________________________________________
188 Int_t
190 {
192  return fArray->GetEntries();
193 }
AliMUON1DArray & operator=(const AliMUON1DArray &other)
virtual TIterator * CreateIterator() const
Return an iterator to loop over the whole store.
virtual Bool_t Add(TObject *object)
#define TObjArray
virtual void Clear(Option_t *opt="")
Clear ourselves (i.e. Reset)
AliMUON1DArray(Int_t theSize=0)
Bool_t Set(Int_t i, TObject *object, Bool_t replace)
virtual Int_t GetSize() const
The number of objects stored.
TObjArray * fArray
Internal array.
virtual AliMUON1DArray * Create() const
Create an empty copy of this.
virtual ~AliMUON1DArray()
virtual TObject * FindObject(UInt_t identifier) const
Return the object stored with id.
Implementation of AliMUONVStore.
#define AliDebug(logLevel, message)
Definition: AliLog.h:300
#define AliError(message)
Definition: AliLog.h:591
void CopyTo(AliMUON1DArray &to) const
Base class for MUON data stores.
Definition: AliMUONVStore.h:22