]>
Commit | Line | Data |
---|---|---|
dee1d5f1 | 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 | ||
5f91c9e8 | 16 | // $Id$ |
13985652 | 17 | // $MpId: AliMpIntPair.cxx,v 1.7 2006/05/24 13:58:29 ivana Exp $ |
5f91c9e8 | 18 | // Category: basic |
3d1463c8 | 19 | |
20 | //----------------------------------------------------------------------------- | |
5f91c9e8 | 21 | // Class AliMpIntPair |
22 | // -------------- | |
23 | // Class that defines the pair of integers. | |
24 | // The pair created by the default constructor is in invalide state, | |
25 | // setting one of values changes the state to valid. | |
26 | // | |
dbe945cc | 27 | // Included in AliRoot: 2003/05/02 |
5f91c9e8 | 28 | // Authors: David Guez, Ivana Hrivnacova; IPN Orsay |
3d1463c8 | 29 | //----------------------------------------------------------------------------- |
5f91c9e8 | 30 | |
5f91c9e8 | 31 | #include "AliMpIntPair.h" |
32 | ||
ef053765 | 33 | #include "AliLog.h" |
34 | ||
2c605e66 | 35 | #include <Riostream.h> |
36 | ||
b80faac0 | 37 | using std::endl; |
13985652 | 38 | /// \cond CLASSIMP |
5f91c9e8 | 39 | ClassImp(AliMpIntPair) |
13985652 | 40 | /// \endcond |
5f91c9e8 | 41 | |
42 | ||
43 | /////////////////////////////////////////////////// | |
44 | // | |
45 | // This class is a replacement for the standard STL | |
46 | // pair<int,int> class, which can not be handed | |
47 | // by the normal ROOT automatic streamer | |
48 | // (at least in the ROOT version 3.03/03) | |
49 | // | |
50 | /////////////////////////////////////////////////// | |
51 | ||
52 | ||
53 | //_____________________________________________________________________________ | |
54 | AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy) | |
55 | : TObject(), | |
56 | fFirst(ix), | |
57 | fSecond(iy), | |
dee1d5f1 | 58 | fValidity(true) |
59 | { | |
60 | /// Standard constructor | |
5f91c9e8 | 61 | } |
62 | ||
63 | //_____________________________________________________________________________ | |
64 | AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy, Bool_t validity) | |
65 | : TObject(), | |
66 | fFirst(ix), | |
67 | fSecond(iy), | |
dee1d5f1 | 68 | fValidity(validity) |
69 | { | |
70 | /// Standard constructor with validity argument | |
5f91c9e8 | 71 | } |
72 | ||
73 | //_____________________________________________________________________________ | |
74 | AliMpIntPair::AliMpIntPair() | |
75 | : TObject(), | |
76 | //fFirst(9999), | |
77 | //fSecond(9999), | |
78 | fFirst(0), | |
79 | fSecond(0), | |
dee1d5f1 | 80 | fValidity(false) |
81 | { | |
82 | /// Default constructor | |
5f91c9e8 | 83 | } |
dee1d5f1 | 84 | |
5f91c9e8 | 85 | //_____________________________________________________________________________ |
86 | AliMpIntPair::AliMpIntPair(const AliMpIntPair& src): | |
87 | TObject(src), | |
88 | fFirst(src.fFirst), | |
89 | fSecond(src.fSecond), | |
90 | fValidity(src.fValidity) | |
91 | { | |
dee1d5f1 | 92 | /// Copy constructor |
5f91c9e8 | 93 | } |
94 | ||
95 | //_____________________________________________________________________________ | |
dee1d5f1 | 96 | AliMpIntPair::~AliMpIntPair() |
97 | { | |
98 | /// Destructor | |
5f91c9e8 | 99 | } |
100 | ||
101 | //_____________________________________________________________________________ | |
102 | Bool_t AliMpIntPair::operator< (const AliMpIntPair& pos2) const | |
103 | { | |
dee1d5f1 | 104 | /// Less operator |
105 | ||
5f91c9e8 | 106 | // fFirst prior to fSecond |
107 | if (fFirst<pos2.fFirst) return kTRUE; | |
108 | if (fFirst>pos2.fFirst) return kFALSE; | |
109 | if (fSecond<pos2.fSecond) return kTRUE; | |
110 | return kFALSE; | |
111 | } | |
112 | ||
113 | //_____________________________________________________________________________ | |
114 | Bool_t AliMpIntPair::operator== (const AliMpIntPair& pos2) const | |
115 | { | |
dee1d5f1 | 116 | /// Equality operator |
117 | ||
5f91c9e8 | 118 | // are this and pos2 equals? |
119 | ||
120 | // one valid, one invalid | |
121 | if (fValidity != pos2.fValidity) return false; | |
122 | ||
123 | // both invalid | |
124 | if (!fValidity) return true; | |
125 | ||
126 | // both valid | |
127 | return (fFirst==pos2.fFirst) && (fSecond==pos2.fSecond); | |
128 | } | |
129 | ||
130 | //_____________________________________________________________________________ | |
131 | Bool_t AliMpIntPair::operator!= (const AliMpIntPair& pos2) const | |
132 | { | |
dee1d5f1 | 133 | /// Non-equality operator |
134 | ||
5f91c9e8 | 135 | // are this and pos2 equals? |
136 | return !(*this == pos2); | |
137 | } | |
138 | ||
139 | //_____________________________________________________________________________ | |
140 | AliMpIntPair& AliMpIntPair::operator=(const AliMpIntPair& src) | |
141 | { | |
dee1d5f1 | 142 | /// Assignment operator |
143 | ||
144 | // check assignment to self | |
5f91c9e8 | 145 | if (this == &src) return *this; |
146 | ||
dee1d5f1 | 147 | // base class assignment |
5f91c9e8 | 148 | TObject::operator=(src); |
149 | ||
dee1d5f1 | 150 | // assignment operator |
5f91c9e8 | 151 | fFirst = src.fFirst; |
152 | fSecond = src.fSecond; | |
153 | fValidity = src.fValidity; | |
154 | ||
155 | return *this; | |
156 | } | |
ef053765 | 157 | //_____________________________________________________________________________ |
158 | Int_t AliMpIntPair::Compare(const TObject* obj) const | |
159 | { | |
160 | /// Compare using operator < | |
5f91c9e8 | 161 | |
ef053765 | 162 | const AliMpIntPair* pair = dynamic_cast<const AliMpIntPair*>(obj); |
163 | if ( !pair ) { | |
164 | AliErrorStream() << "Wrong object type." << endl; | |
165 | return -1; | |
166 | } | |
167 | ||
168 | return ( *this < *pair ) ? -1 : 1; | |
169 | } | |
5f91c9e8 | 170 | //_____________________________________________________________________________ |
171 | void AliMpIntPair::operator += (const AliMpIntPair& op) | |
172 | { | |
dee1d5f1 | 173 | /// Incrementation operator |
174 | ||
5f91c9e8 | 175 | fFirst += op.fFirst; |
176 | fSecond += op.fSecond; | |
177 | ||
178 | // operation only on valid pairs | |
179 | fValidity = fValidity && op.fValidity; | |
180 | } | |
181 | //_____________________________________________________________________________ | |
182 | void AliMpIntPair::operator -= (const AliMpIntPair& op) | |
183 | { | |
dee1d5f1 | 184 | /// Decrementation operator |
185 | ||
5f91c9e8 | 186 | fFirst -= op.fFirst; |
187 | fSecond -= op.fSecond; | |
188 | ||
189 | // operation only on valid pairs | |
190 | fValidity = fValidity && op.fValidity; | |
191 | } | |
192 | ||
193 | //_____________________________________________________________________________ | |
194 | AliMpIntPair operator-(const AliMpIntPair& op1,const AliMpIntPair& op2) | |
195 | { | |
dee1d5f1 | 196 | /// Substraction operator |
197 | ||
5f91c9e8 | 198 | return AliMpIntPair(op1.GetFirst()-op2.GetFirst(), |
199 | op1.GetSecond()-op2.GetSecond(), | |
200 | op1.IsValid() && op2.IsValid()); | |
201 | } | |
202 | //_____________________________________________________________________________ | |
203 | AliMpIntPair operator+(const AliMpIntPair& op1,const AliMpIntPair& op2) | |
204 | { | |
dee1d5f1 | 205 | /// Addition operator |
206 | ||
5f91c9e8 | 207 | return AliMpIntPair(op1.GetFirst()+op2.GetFirst(), |
208 | op1.GetSecond()+op2.GetSecond(), | |
209 | op1.IsValid() && op2.IsValid()); | |
210 | } | |
211 | //_____________________________________________________________________________ | |
212 | AliMpIntPair operator*(const AliMpIntPair& op1,const AliMpIntPair& op2) | |
213 | { | |
dee1d5f1 | 214 | /// Multiplication operator |
215 | ||
5f91c9e8 | 216 | return AliMpIntPair(op1.GetFirst()*op2.GetFirst(), |
217 | op1.GetSecond()*op2.GetSecond(), | |
218 | op1.IsValid() && op2.IsValid()); | |
219 | } | |
220 | //_____________________________________________________________________________ | |
221 | ostream& operator<< (ostream &stream,const AliMpIntPair& op) | |
222 | { | |
dee1d5f1 | 223 | /// Output streaming |
224 | ||
5f91c9e8 | 225 | if (op.IsValid()) { |
226 | stream << '('; | |
227 | stream << op.GetFirst()<<','<<op.GetSecond()<<')'; | |
228 | return stream; | |
229 | } | |
230 | else { | |
231 | stream << "AliMpIntPair::Invalid"; | |
232 | return stream; | |
233 | } | |
234 | } | |
235 |