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