]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUON1DArray.cxx
Updates (N. Bastid)
[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"
21#include "TObjArray.h"
22
23///
5398f946 24/// \class AliMUON1DArray
70b4a8d6 25/// This class is simply a wrapper to a TObjArray, offering in addition a
26/// control over the replacement policy when you add
27/// something to it.
28///
5398f946 29/// \author Laurent Aphecetche
70b4a8d6 30
5398f946 31/// \cond CLASSIMP
70b4a8d6 32ClassImp(AliMUON1DArray)
5398f946 33/// \endcond
70b4a8d6 34
35//_____________________________________________________________________________
36AliMUON1DArray::AliMUON1DArray(Int_t theSize)
37: AliMUONV1DStore(),
38 fArray(0x0)
39{
5398f946 40/// Default ctor
41
70b4a8d6 42 if ( theSize )
43 {
44 fArray = new TObjArray(theSize);
45 }
46}
47
48//_____________________________________________________________________________
49AliMUON1DArray::AliMUON1DArray(const AliMUON1DArray& other)
50: AliMUONV1DStore(),
51 fArray(0x0)
52{
5398f946 53/// Copy constructor
54
70b4a8d6 55 other.CopyTo(*this);
56}
57
58//_____________________________________________________________________________
59AliMUON1DArray&
60AliMUON1DArray::operator=(const AliMUON1DArray& other)
61{
5398f946 62/// Assignment operator
63
70b4a8d6 64 other.CopyTo(*this);
65 return *this;
66}
67
68//_____________________________________________________________________________
69AliMUON1DArray::~AliMUON1DArray()
70{
5398f946 71/// dtor, we're the owner of our internal array.
72
70b4a8d6 73 delete fArray;
74}
75
76//_____________________________________________________________________________
77void
78AliMUON1DArray::CopyTo(AliMUON1DArray& dest) const
79{
5398f946 80/// Make a deep copy
81
70b4a8d6 82 delete dest.fArray;
83 dest.fArray = new TObjArray;
84 dest.fArray->SetOwner(kTRUE);
85 for ( Int_t i = 0; i < fArray->GetLast(); ++i )
86 {
87 dest.fArray->AddAt(fArray->At(i)->Clone(),i);
88 }
89}
90
91//_____________________________________________________________________________
92TObject*
93AliMUON1DArray::Get(Int_t i) const
94{
5398f946 95/// Get the object located at index i, if it exists, and if i is correct.
96
70b4a8d6 97 if ( i >= 0 && i < fArray->GetSize() )
98 {
99 return fArray->At(i);
100 }
101 AliError(Form("Index %d out of bounds (max %d)",i,fArray->GetSize()));
102 return 0x0;
103}
104
105//_____________________________________________________________________________
106Bool_t
107AliMUON1DArray::Set(Int_t i, TObject* object, Bool_t replace)
108{
5398f946 109/// Set the object located at i
110/// If replace=kFALSE and there's already an object at location i,
111/// this method fails and returns kFALSE, otherwise it returns kTRUE
112
70b4a8d6 113 if ( i >= 0 && i < fArray->GetSize() )
114 {
115 TObject* o = Get(i);
116 if ( o && !replace )
117 {
118 AliError(Form("Object %p is already there for i=%d",o,i));
119 return kFALSE;
120 }
121 if ( replace )
122 {
123 delete o;
124 }
125 fArray->AddAt(object,i);
126 return kTRUE;
127 }
128 AliError(Form("Index %d out of bounds (max %d)",i,fArray->GetSize()));
129 return kFALSE;
130}
131
132
133