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