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