]>
Commit | Line | Data |
---|---|---|
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 | // $MpId: AliMpIntPair.cxx,v 1.7 2006/05/24 13:58:29 ivana Exp $ | |
18 | // Category: basic | |
19 | ||
20 | //----------------------------------------------------------------------------- | |
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 | // | |
27 | // Included in AliRoot: 2003/05/02 | |
28 | // Authors: David Guez, Ivana Hrivnacova; IPN Orsay | |
29 | //----------------------------------------------------------------------------- | |
30 | ||
31 | #include "AliMpIntPair.h" | |
32 | ||
33 | #include "AliLog.h" | |
34 | ||
35 | #include <Riostream.h> | |
36 | ||
37 | /// \cond CLASSIMP | |
38 | ClassImp(AliMpIntPair) | |
39 | /// \endcond | |
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), | |
57 | fValidity(true) | |
58 | { | |
59 | /// Standard constructor | |
60 | } | |
61 | ||
62 | //_____________________________________________________________________________ | |
63 | AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy, Bool_t validity) | |
64 | : TObject(), | |
65 | fFirst(ix), | |
66 | fSecond(iy), | |
67 | fValidity(validity) | |
68 | { | |
69 | /// Standard constructor with validity argument | |
70 | } | |
71 | ||
72 | //_____________________________________________________________________________ | |
73 | AliMpIntPair::AliMpIntPair() | |
74 | : TObject(), | |
75 | //fFirst(9999), | |
76 | //fSecond(9999), | |
77 | fFirst(0), | |
78 | fSecond(0), | |
79 | fValidity(false) | |
80 | { | |
81 | /// Default constructor | |
82 | } | |
83 | ||
84 | //_____________________________________________________________________________ | |
85 | AliMpIntPair::AliMpIntPair(const AliMpIntPair& src): | |
86 | TObject(src), | |
87 | fFirst(src.fFirst), | |
88 | fSecond(src.fSecond), | |
89 | fValidity(src.fValidity) | |
90 | { | |
91 | /// Copy constructor | |
92 | } | |
93 | ||
94 | //_____________________________________________________________________________ | |
95 | AliMpIntPair::~AliMpIntPair() | |
96 | { | |
97 | /// Destructor | |
98 | } | |
99 | ||
100 | //_____________________________________________________________________________ | |
101 | Bool_t AliMpIntPair::operator< (const AliMpIntPair& pos2) const | |
102 | { | |
103 | /// Less operator | |
104 | ||
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 | { | |
115 | /// Equality operator | |
116 | ||
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 | { | |
132 | /// Non-equality operator | |
133 | ||
134 | // are this and pos2 equals? | |
135 | return !(*this == pos2); | |
136 | } | |
137 | ||
138 | //_____________________________________________________________________________ | |
139 | AliMpIntPair& AliMpIntPair::operator=(const AliMpIntPair& src) | |
140 | { | |
141 | /// Assignment operator | |
142 | ||
143 | // check assignment to self | |
144 | if (this == &src) return *this; | |
145 | ||
146 | // base class assignment | |
147 | TObject::operator=(src); | |
148 | ||
149 | // assignment operator | |
150 | fFirst = src.fFirst; | |
151 | fSecond = src.fSecond; | |
152 | fValidity = src.fValidity; | |
153 | ||
154 | return *this; | |
155 | } | |
156 | //_____________________________________________________________________________ | |
157 | Int_t AliMpIntPair::Compare(const TObject* obj) const | |
158 | { | |
159 | /// Compare using operator < | |
160 | ||
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 | } | |
169 | //_____________________________________________________________________________ | |
170 | void AliMpIntPair::operator += (const AliMpIntPair& op) | |
171 | { | |
172 | /// Incrementation operator | |
173 | ||
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 | { | |
183 | /// Decrementation operator | |
184 | ||
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 | { | |
195 | /// Substraction operator | |
196 | ||
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 | { | |
204 | /// Addition operator | |
205 | ||
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 | { | |
213 | /// Multiplication operator | |
214 | ||
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 | { | |
222 | /// Output streaming | |
223 | ||
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 |