]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONVDigit.cxx
Attempt to fix Coverity defect 14695
[u/mrichter/AliRoot.git] / MUON / AliMUONVDigit.cxx
CommitLineData
d6c3334d 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
3d1463c8 18//-----------------------------------------------------------------------------
d6c3334d 19/// \class AliMUONVDigit
20///
21/// This is the base class of a MUON digit that most client code should deal with.
22/// There should be no reason to have to use a concrete class in most cases.
23///
24/// All digits have basic features, like :
25///
26/// - a way to identify it : detection element, electronics card and
27/// channel, cathode. Note that some static methods exists to compact
28/// those 4 informations into a single 4 bytes integer (stored in the
29/// fUniqueID data member present in all TObjects).
30///
31/// - its charge
32///
33/// - a set of boolean methods to indicate whether the digit has been calibrated, etc...
34///
35/// In addition, if HasMCInformation is true, the digit store also the list
36/// of MC tracks that contributed to its charge
37///
38/// Also, if HasGeometryInformation is true, the digit knows the position and
39/// the (half) dimensions (in cm) of the pad it corresponds to.
40///
41/// \author Laurent Aphecetche, Subatech
3d1463c8 42//-----------------------------------------------------------------------------
d6c3334d 43
44#include "AliMUONVDigit.h"
45
46#include <Riostream.h>
47#include <TClass.h>
48
49/// \cond CLASSIMP
50ClassImp(AliMUONVDigit)
51/// \endcond
52
53//_____________________________________________________________________________
54AliMUONVDigit::AliMUONVDigit(Int_t detElemId, Int_t eCardId,
55 Int_t eCardChannel, Int_t cathode)
56: TObject()
57{
58 /// Normal constructor for trigger digits
59 SetUniqueID(BuildUniqueID(detElemId,eCardId,eCardChannel,cathode));
60}
61
62//_____________________________________________________________________________
63AliMUONVDigit::AliMUONVDigit()
7332f213 64: TObject()
d6c3334d 65{
66 /// Default ctor
67}
68
69//_____________________________________________________________________________
70AliMUONVDigit::~AliMUONVDigit()
71{
72 /// dtor
73}
74
36a01415 75//_____________________________________________________________________________
76Bool_t
77AliMUONVDigit::IsEqual(const TObject* object) const
78{
22dce0e3 79 /// Whether we're equal to object.
80 /// WARNING : only based on our identifiers (de,manu,channel,cathode), not our
81 /// content (i.e. charge, status...)
82
36a01415 83 const AliMUONVDigit* d = static_cast<const AliMUONVDigit*>(object);
84
85 return ( DetElemId() == d->DetElemId() &&
86 Cathode() == d->Cathode() &&
87 ManuId() == d->ManuId() &&
88 ManuChannel() == d->ManuChannel() );
89}
90
91//_____________________________________________________________________________
92Int_t
93AliMUONVDigit::Compare(const TObject* object) const
94{
22dce0e3 95 /// Compare two digits, trying to get as complete an order as possible.
96 /// We sort by DE, then by charge, then by manu, etc...
97 ///
36a01415 98 const AliMUONVDigit* d = static_cast<const AliMUONVDigit*>(object);
99
100 if ( DetElemId() > d->DetElemId() )
101 {
102 return 1;
103 }
104 else if ( DetElemId() < d->DetElemId() )
105 {
106 return -1;
107 }
108 else
109 {
110 if ( Charge() > d->Charge() )
111 {
112 return 1;
113 }
114 else if ( Charge() < d->Charge() )
115 {
116 return -1;
117 }
118 else
119 {
be296517 120 if ( ManuId() > d->ManuId() )
36a01415 121 {
122 return 1;
123 }
be296517 124 else if ( ManuId() < d->ManuId() )
36a01415 125 {
126 return -1;
127 }
128 else
129 {
be296517 130 if ( ManuChannel() > d->ManuChannel() )
131 {
132 return 1;
133 }
134 else if ( ManuChannel() < d->ManuChannel() )
135 {
136 return -1;
137 }
36a01415 138 }
139 }
140 }
141 return 0;
142}
143
d6c3334d 144//_____________________________________________________________________________
145UInt_t
146AliMUONVDigit::BuildUniqueID(Int_t detElemId, Int_t manuId,
147 Int_t manuChannel, Int_t cathode)
148{
149 /// Build a single integer with id information
150 return ( ( detElemId ) | ( manuId << 12 ) | ( manuChannel << 24 )
151 | ( cathode << 30 ) );
152}
153
154//_____________________________________________________________________________
155Int_t
156AliMUONVDigit::DetElemId(UInt_t uniqueID)
157{
158 /// Return detection element id part of the uniqueID
159 return uniqueID & 0xFFF;
160}
161
162//_____________________________________________________________________________
163Int_t
164AliMUONVDigit::ManuChannel(UInt_t uniqueID)
165{
166 /// Return manuChannel part of the uniqueID
167 return ( uniqueID & 0x3F000000 ) >> 24;
168}
169
170//_____________________________________________________________________________
171Int_t
172AliMUONVDigit::ManuId(UInt_t uniqueID)
173{
174 /// Return manuId part of the uniqueID
175 return ( uniqueID & 0xFFF000 ) >> 12;
176}
177
178//_____________________________________________________________________________
179Int_t
180AliMUONVDigit::Cathode(UInt_t uniqueID)
181{
182 /// Return the cathode part of the uniqueID
183 return ( uniqueID & 0x40000000 ) >> 30;
184}
185
186//_____________________________________________________________________________
187void
188AliMUONVDigit::DecodeUniqueID(UInt_t uniqueID,
189 Int_t& detElemId, Int_t& manuId,
190 Int_t& manuChannel, Int_t& cathode)
191{
192 /// Unpack uniqueID into 4 elements
193 detElemId = DetElemId(uniqueID);
194 manuId = ManuId(uniqueID);
195 manuChannel = ManuChannel(uniqueID);
196 cathode = Cathode(uniqueID);
197}
198
199//_____________________________________________________________________________
200const char*
201AliMUONVDigit::GetName() const
202{
203 /// Return the name of this digit, composed of its id parts.
204 return Form("DE%04d-%04d-%02d-%d",
205 DetElemId(),ManuId(),ManuChannel(),Cathode());
206}
207
208//_____________________________________________________________________________
209void
210AliMUONVDigit::Print(Option_t* opt) const
211{
212 /// Dump to screen.
213 /// If opt=="tracks", info on tracks are printed too.
214
215 cout << Form("<%s>: ID %12u DE %4d Cath %d (Ix,Iy)=(%3d,%3d) (Manu,Channel)=(%4d,%2d)"
216 ", Charge=%7.2f",
217 ClassName(),GetUniqueID(),
218 DetElemId(),Cathode(),PadX(),PadY(),ManuId(),ManuChannel(),Charge());
219 if ( IsSaturated() )
220 {
221 cout << "(S)";
222 }
223 else
224 {
225 cout << " ";
226 }
227
228 if ( IsCalibrated() )
229 {
230 cout << "(C)";
231 }
232 else
233 {
234 cout << " ";
235 }
236
237 if ( IsUsed() )
238 {
239 cout << "(U)";
240 }
241 else
242 {
243 cout << " ";
244 }
245
246 cout << Form(" ADC=%4d StatusMap=%04x",ADC(),StatusMap());
247
248 TString options(opt);
249 options.ToLower();
250 if ( options.Contains("tracks") && HasMCInformation() )
251 {
252 cout << " Hit " << setw(3) << Hit();
253 Int_t ntracks = Ntracks();
254 if (ntracks)
255 {
256 cout << " Tracks : " << setw(2) << ntracks;
257 for ( Int_t i = 0; i < ntracks; ++i )
258 {
259 cout << " Track(" << i << ")=" << setw(3) << Track(i)
260 << " Charge(" << i << ")=" << setw(5) << TrackCharge(i);
261 }
262 }
263 else
264 {
265 cout << " no track info.";
266 }
267 }
268 cout << endl;
269}