]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/ESD/AliESDMuonCluster.cxx
Changes for #90436: Misuse of TClonesArray containing AliESDMuonCluster
[u/mrichter/AliRoot.git] / STEER / ESD / AliESDMuonCluster.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 //-----------------------------------------------------------------------------
19 /// \class AliESDMuonCluster
20 ///
21 /// Class to describe the MUON clusters in the Event Summary Data
22 ///
23 /// \author Philippe Pillot, Subatech
24 //-----------------------------------------------------------------------------
25
26 #include "AliESDEvent.h"
27 #include "AliESDMuonCluster.h"
28 #include "AliESDMuonPad.h"
29
30 #include "AliLog.h"
31
32 #include <TClonesArray.h>
33 #include <Riostream.h>
34
35 /// \cond CLASSIMP
36 ClassImp(AliESDMuonCluster)
37 /// \endcond
38
39 //_____________________________________________________________________________
40 AliESDMuonCluster::AliESDMuonCluster()
41 : TObject(),
42   fCharge(0.),
43   fChi2(0.),
44   fPads(0x0),
45   fNPads(0),
46   fPadsId(0x0),
47   fLabel(-1)
48 {
49   /// default constructor
50   fXYZ[0] = fXYZ[1] = fXYZ[2] = 0.;
51   fErrXY[0] = fErrXY[1] = 0.;
52 }
53
54 //_____________________________________________________________________________
55 AliESDMuonCluster::AliESDMuonCluster (const AliESDMuonCluster& cluster)
56 : TObject(cluster),
57   fCharge(cluster.fCharge),
58   fChi2(cluster.fChi2),
59   fPads(0x0),
60   fNPads(cluster.fNPads),
61   fPadsId(0x0),
62   fLabel(cluster.fLabel)
63 {
64   /// Copy constructor
65   fXYZ[0] = cluster.fXYZ[0];
66   fXYZ[1] = cluster.fXYZ[1];
67   fXYZ[2] = cluster.fXYZ[2];
68   fErrXY[0] = cluster.fErrXY[0];
69   fErrXY[1] = cluster.fErrXY[1];
70   
71   if (cluster.fPads) {
72     fPads = new TClonesArray("AliESDMuonPad",cluster.fPads->GetEntriesFast());
73     AliESDMuonPad *pad = (AliESDMuonPad*) cluster.fPads->First();
74     while (pad) {
75       new ((*fPads)[fPads->GetEntriesFast()]) AliESDMuonPad(*pad);
76       pad = (AliESDMuonPad*) cluster.fPads->After(pad);
77     }
78   }
79   
80   if (cluster.fPadsId) fPadsId = new TArrayI(*(cluster.fPadsId));
81 }
82
83 //_____________________________________________________________________________
84 AliESDMuonCluster& AliESDMuonCluster::operator=(const AliESDMuonCluster& cluster)
85 {
86   /// Equal operator
87   if (this == &cluster) return *this;
88   
89   TObject::operator=(cluster); // don't forget to invoke the base class' assignment operator
90   
91   fXYZ[0] = cluster.fXYZ[0];
92   fXYZ[1] = cluster.fXYZ[1];
93   fXYZ[2] = cluster.fXYZ[2];
94   fErrXY[0] = cluster.fErrXY[0];
95   fErrXY[1] = cluster.fErrXY[1];
96   
97   fCharge = cluster.fCharge;
98   fChi2 = cluster.fChi2;
99   fLabel = cluster.fLabel;
100   
101   delete fPads;
102   if (cluster.fPads) {
103     fPads = new TClonesArray("AliESDMuonPad",cluster.fPads->GetEntriesFast());
104     AliESDMuonPad *pad = (AliESDMuonPad*) cluster.fPads->First();
105     while (pad) {
106       new ((*fPads)[fPads->GetEntriesFast()]) AliESDMuonPad(*pad);
107       pad = (AliESDMuonPad*) cluster.fPads->After(pad);
108     }
109   } else fPads = 0x0;
110   
111   SetPadsId(cluster.fNPads, cluster.GetPadsId());
112   
113   return *this;
114 }
115
116 //__________________________________________________________________________
117 AliESDMuonCluster::~AliESDMuonCluster()
118 {
119   /// Destructor
120   delete fPads;
121   delete fPadsId;
122 }
123
124 //__________________________________________________________________________
125 void AliESDMuonCluster::Clear(Option_t* opt)
126 {
127   /// Clear arrays
128   if (opt && opt[0] == 'C') {
129     if (fPads) fPads->Clear("C");
130   } else {
131     delete fPads; fPads = 0x0;
132   }
133   delete fPadsId; fPadsId = 0x0;
134   fNPads = 0;
135 }
136
137 //_____________________________________________________________________________
138 void AliESDMuonCluster::AddPadId(UInt_t padId)
139 {
140   /// Add the given pad Id to the list associated to the cluster
141   if (!fPadsId) fPadsId = new TArrayI(10);
142   if (fPadsId->GetSize() <= fNPads) fPadsId->Set(fNPads+10);
143   fPadsId->AddAt(static_cast<Int_t>(padId), fNPads++);
144 }
145
146 //_____________________________________________________________________________
147 void AliESDMuonCluster::SetPadsId(Int_t nPads, const UInt_t *padsId)
148 {
149   /// Fill the list pads'Id associated to the cluster with the given list
150   
151   if (nPads <= 0 || !padsId) {
152     delete fPadsId;
153     fPadsId = 0x0;
154     fNPads = 0;
155     return;
156   }
157   
158   if (!fPadsId) fPadsId = new TArrayI(nPads, reinterpret_cast<const Int_t*>(padsId));
159   else fPadsId->Set(nPads, reinterpret_cast<const Int_t*>(padsId));
160   fNPads = nPads;
161   
162 }
163
164 //_____________________________________________________________________________
165 void AliESDMuonCluster::MovePadsToESD(AliESDEvent &esd)
166 {
167   /// move the pads to the new ESD structure
168   if (!fPads) return;
169   for (Int_t i = 0; i < fPads->GetEntriesFast(); i++) {
170     AliESDMuonPad *pad = static_cast<AliESDMuonPad*>(fPads->UncheckedAt(i));
171     AliESDMuonPad *newPad = esd.NewMuonPad();
172     *newPad = *pad;
173     AddPadId(newPad->GetUniqueID());
174   }
175   delete fPads;
176   fPads = 0x0;
177 }
178
179 //_____________________________________________________________________________
180 void AliESDMuonCluster::Print(Option_t */*option*/) const
181 {
182   /// print cluster content
183   UInt_t cId = GetUniqueID();
184   
185   cout<<Form("clusterID=%u (ch=%d, det=%d, index=%d)",
186              cId,GetChamberId(),GetDetElemId(),GetClusterIndex())<<endl;
187   
188   cout<<Form("  position=(%5.2f, %5.2f, %5.2f), sigma=(%5.2f, %5.2f, 0.0)",
189              GetX(),GetY(),GetZ(),GetErrX(),GetErrY())<<endl;
190   
191   cout<<Form("  charge=%5.2f, chi2=%5.2f, MClabel=%d", GetCharge(), GetChi2(), GetLabel())<<endl;
192   
193   if (PadsStored()) {
194     cout<<"  pad infos:"<<endl;
195     for (Int_t iPad=0; iPad<GetNPads(); iPad++) cout<<"  "<<GetPadId(iPad)<<endl;
196   }
197 }
198