1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpIntPair.cxx,v 1.7 2006/05/24 13:58:29 ivana Exp $
20 //-----------------------------------------------------------------------------
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.
27 // Included in AliRoot: 2003/05/02
28 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
29 //-----------------------------------------------------------------------------
31 #include "AliMpIntPair.h"
35 #include <Riostream.h>
39 ClassImp(AliMpIntPair)
43 ///////////////////////////////////////////////////
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)
50 ///////////////////////////////////////////////////
53 //_____________________________________________________________________________
54 AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy)
60 /// Standard constructor
63 //_____________________________________________________________________________
64 AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy, Bool_t validity)
70 /// Standard constructor with validity argument
73 //_____________________________________________________________________________
74 AliMpIntPair::AliMpIntPair()
82 /// Default constructor
85 //_____________________________________________________________________________
86 AliMpIntPair::AliMpIntPair(const AliMpIntPair& src):
90 fValidity(src.fValidity)
95 //_____________________________________________________________________________
96 AliMpIntPair::~AliMpIntPair()
101 //_____________________________________________________________________________
102 Bool_t AliMpIntPair::operator< (const AliMpIntPair& pos2) const
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;
113 //_____________________________________________________________________________
114 Bool_t AliMpIntPair::operator== (const AliMpIntPair& pos2) const
116 /// Equality operator
118 // are this and pos2 equals?
120 // one valid, one invalid
121 if (fValidity != pos2.fValidity) return false;
124 if (!fValidity) return true;
127 return (fFirst==pos2.fFirst) && (fSecond==pos2.fSecond);
130 //_____________________________________________________________________________
131 Bool_t AliMpIntPair::operator!= (const AliMpIntPair& pos2) const
133 /// Non-equality operator
135 // are this and pos2 equals?
136 return !(*this == pos2);
139 //_____________________________________________________________________________
140 AliMpIntPair& AliMpIntPair::operator=(const AliMpIntPair& src)
142 /// Assignment operator
144 // check assignment to self
145 if (this == &src) return *this;
147 // base class assignment
148 TObject::operator=(src);
150 // assignment operator
152 fSecond = src.fSecond;
153 fValidity = src.fValidity;
157 //_____________________________________________________________________________
158 Int_t AliMpIntPair::Compare(const TObject* obj) const
160 /// Compare using operator <
162 const AliMpIntPair* pair = dynamic_cast<const AliMpIntPair*>(obj);
164 AliErrorStream() << "Wrong object type." << endl;
168 return ( *this < *pair ) ? -1 : 1;
170 //_____________________________________________________________________________
171 void AliMpIntPair::operator += (const AliMpIntPair& op)
173 /// Incrementation operator
176 fSecond += op.fSecond;
178 // operation only on valid pairs
179 fValidity = fValidity && op.fValidity;
181 //_____________________________________________________________________________
182 void AliMpIntPair::operator -= (const AliMpIntPair& op)
184 /// Decrementation operator
187 fSecond -= op.fSecond;
189 // operation only on valid pairs
190 fValidity = fValidity && op.fValidity;
193 //_____________________________________________________________________________
194 AliMpIntPair operator-(const AliMpIntPair& op1,const AliMpIntPair& op2)
196 /// Substraction operator
198 return AliMpIntPair(op1.GetFirst()-op2.GetFirst(),
199 op1.GetSecond()-op2.GetSecond(),
200 op1.IsValid() && op2.IsValid());
202 //_____________________________________________________________________________
203 AliMpIntPair operator+(const AliMpIntPair& op1,const AliMpIntPair& op2)
205 /// Addition operator
207 return AliMpIntPair(op1.GetFirst()+op2.GetFirst(),
208 op1.GetSecond()+op2.GetSecond(),
209 op1.IsValid() && op2.IsValid());
211 //_____________________________________________________________________________
212 AliMpIntPair operator*(const AliMpIntPair& op1,const AliMpIntPair& op2)
214 /// Multiplication operator
216 return AliMpIntPair(op1.GetFirst()*op2.GetFirst(),
217 op1.GetSecond()*op2.GetSecond(),
218 op1.IsValid() && op2.IsValid());
220 //_____________________________________________________________________________
221 ostream& operator<< (ostream &stream,const AliMpIntPair& op)
227 stream << op.GetFirst()<<','<<op.GetSecond()<<')';
231 stream << "AliMpIntPair::Invalid";