]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUON1DArray.cxx
- The part of JETAN dealing with ESD data has been separated from the one using MC...
[u/mrichter/AliRoot.git] / MUON / AliMUON1DArray.cxx
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 ///
24 /// \class AliMUON1DArray
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 ///
29 /// \author Laurent Aphecetche
30
31 /// \cond CLASSIMP
32 ClassImp(AliMUON1DArray)
33 /// \endcond
34
35 //_____________________________________________________________________________
36 AliMUON1DArray::AliMUON1DArray(Int_t theSize)
37 : AliMUONV1DStore(),
38   fArray(0x0)
39 {
40 /// Default ctor
41
42   if ( theSize ) 
43   {
44     fArray = new TObjArray(theSize);
45   }
46 }
47
48 //_____________________________________________________________________________
49 AliMUON1DArray::AliMUON1DArray(const AliMUON1DArray& other)
50 : AliMUONV1DStore(),
51   fArray(0x0)
52 {
53 /// Copy constructor
54
55   other.CopyTo(*this);
56 }
57
58 //_____________________________________________________________________________
59 AliMUON1DArray&
60 AliMUON1DArray::operator=(const AliMUON1DArray& other)
61 {
62 /// Assignment operator
63
64   other.CopyTo(*this);
65   return *this;
66 }
67
68 //_____________________________________________________________________________
69 AliMUON1DArray::~AliMUON1DArray()
70 {
71 /// dtor, we're the owner of our internal array.
72
73   delete fArray;
74 }
75
76 //_____________________________________________________________________________
77 void
78 AliMUON1DArray::CopyTo(AliMUON1DArray& dest) const
79 {
80 /// Make a deep copy
81
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 //_____________________________________________________________________________
92 TObject* 
93 AliMUON1DArray::Get(Int_t i) const
94 {
95 /// Get the object located at index i, if it exists, and if i is correct.
96
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 //_____________________________________________________________________________
106 Bool_t 
107 AliMUON1DArray::Set(Int_t i, TObject* object, Bool_t replace)
108 {
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
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