]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliESDMuonCluster.cxx
Fixes for Coverity defects
[u/mrichter/AliRoot.git] / STEER / 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 "AliESDMuonCluster.h"
27 #include "AliESDMuonPad.h"
28
29 #include "AliLog.h"
30
31 #include <TClonesArray.h>
32 #include <Riostream.h>
33
34 /// \cond CLASSIMP
35 ClassImp(AliESDMuonCluster)
36 /// \endcond
37
38 //_____________________________________________________________________________
39 AliESDMuonCluster::AliESDMuonCluster()
40 : TObject(),
41   fCharge(0.),
42   fChi2(0.),
43   fPads(0x0),
44   fLabel(-1)
45 {
46   /// default constructor
47   fXYZ[0] = fXYZ[1] = fXYZ[2] = 0.;
48   fErrXY[0] = fErrXY[1] = 0.;
49 }
50
51 //_____________________________________________________________________________
52 AliESDMuonCluster::AliESDMuonCluster (const AliESDMuonCluster& cluster)
53 : TObject(cluster),
54   fCharge(cluster.fCharge),
55   fChi2(cluster.fChi2),
56   fPads(0x0),
57   fLabel(cluster.fLabel)
58 {
59   /// Copy constructor
60   fXYZ[0] = cluster.fXYZ[0];
61   fXYZ[1] = cluster.fXYZ[1];
62   fXYZ[2] = cluster.fXYZ[2];
63   fErrXY[0] = cluster.fErrXY[0];
64   fErrXY[1] = cluster.fErrXY[1];
65   
66   if (cluster.fPads) {
67     fPads = new TClonesArray("AliESDMuonPad",cluster.fPads->GetEntriesFast());
68     AliESDMuonPad *pad = (AliESDMuonPad*) cluster.fPads->First();
69     while (pad) {
70       new ((*fPads)[fPads->GetEntriesFast()]) AliESDMuonPad(*pad);
71       pad = (AliESDMuonPad*) cluster.fPads->After(pad);
72     }
73   }
74 }
75
76 //_____________________________________________________________________________
77 AliESDMuonCluster& AliESDMuonCluster::operator=(const AliESDMuonCluster& cluster)
78 {
79   /// Equal operator
80   if (this == &cluster) return *this;
81   
82   TObject::operator=(cluster); // don't forget to invoke the base class' assignment operator
83   
84   fXYZ[0] = cluster.fXYZ[0];
85   fXYZ[1] = cluster.fXYZ[1];
86   fXYZ[2] = cluster.fXYZ[2];
87   fErrXY[0] = cluster.fErrXY[0];
88   fErrXY[1] = cluster.fErrXY[1];
89   
90   fCharge = cluster.fCharge;
91   fChi2 = cluster.fChi2;
92   fLabel = cluster.fLabel;
93   
94   delete fPads;
95   if (cluster.fPads) {
96     fPads = new TClonesArray("AliESDMuonPad",cluster.fPads->GetEntriesFast());
97     AliESDMuonPad *pad = (AliESDMuonPad*) cluster.fPads->First();
98     while (pad) {
99       new ((*fPads)[fPads->GetEntriesFast()]) AliESDMuonPad(*pad);
100       pad = (AliESDMuonPad*) cluster.fPads->After(pad);
101     }
102   } else fPads = 0x0;
103   
104   return *this;
105 }
106
107 //__________________________________________________________________________
108 AliESDMuonCluster::~AliESDMuonCluster()
109 {
110   /// Destructor
111   delete fPads;
112 }
113
114 //__________________________________________________________________________
115 void AliESDMuonCluster::Clear(Option_t* /*opt*/)
116 {
117   /// Clear arrays
118   delete fPads;
119   fPads = 0x0;
120 }
121
122 //_____________________________________________________________________________
123 Int_t AliESDMuonCluster::GetNPads() const
124 {
125   // return the number of pads associated to the cluster
126   if (!fPads) return 0;
127   
128   return fPads->GetEntriesFast();
129 }
130
131 //_____________________________________________________________________________
132 TClonesArray& AliESDMuonCluster::GetPads() const
133 {
134   // return the array of pads associated to the cluster
135   if (!fPads) fPads = new TClonesArray("AliESDMuonPad",10);
136   
137   return *fPads;
138 }
139
140 //_____________________________________________________________________________
141 void AliESDMuonCluster::AddPad(const AliESDMuonPad &pad)
142 {
143   // add a pad to the TClonesArray of pads associated to the cluster
144   if (!fPads) fPads = new TClonesArray("AliESDMuonPad",10);
145   
146   new ((*fPads)[fPads->GetEntriesFast()]) AliESDMuonPad(pad);
147 }
148
149 //_____________________________________________________________________________
150 Bool_t AliESDMuonCluster::PadsStored() const
151 {
152   // return kTRUE if the pads associated to the cluster are registered
153   if (GetNPads() == 0) return kFALSE;
154   
155   return kTRUE;
156 }
157
158 //_____________________________________________________________________________
159 void AliESDMuonCluster::Print(Option_t */*option*/) const
160 {
161   /// print cluster content
162   UInt_t cId = GetUniqueID();
163   
164   cout<<Form("clusterID=%u (ch=%d, det=%d, index=%d)",
165              cId,GetChamberId(),GetDetElemId(),GetClusterIndex())<<endl;
166   
167   cout<<Form("  position=(%5.2f, %5.2f, %5.2f), sigma=(%5.2f, %5.2f, 0.0)",
168              GetX(),GetY(),GetZ(),GetErrX(),GetErrY())<<endl;
169   
170   cout<<Form("  charge=%5.2f, chi2=%5.2f, MClabel=%d", GetCharge(), GetChi2(), GetLabel())<<endl;
171   
172   if (PadsStored()) {
173     cout<<"  pad infos:"<<endl;
174     for (Int_t iPad=0; iPad<GetNPads(); iPad++) {
175       cout<<"  ";
176       ( (AliESDMuonPad*) fPads->UncheckedAt(iPad) )->Print();
177     }
178   }
179 }
180