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>
38 ClassImp(AliMpIntPair)
42 ///////////////////////////////////////////////////
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)
49 ///////////////////////////////////////////////////
52 //_____________________________________________________________________________
53 AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy)
59 /// Standard constructor
62 //_____________________________________________________________________________
63 AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy, Bool_t validity)
69 /// Standard constructor with validity argument
72 //_____________________________________________________________________________
73 AliMpIntPair::AliMpIntPair()
81 /// Default constructor
84 //_____________________________________________________________________________
85 AliMpIntPair::AliMpIntPair(const AliMpIntPair& src):
89 fValidity(src.fValidity)
94 //_____________________________________________________________________________
95 AliMpIntPair::~AliMpIntPair()
100 //_____________________________________________________________________________
101 Bool_t AliMpIntPair::operator< (const AliMpIntPair& pos2) const
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;
112 //_____________________________________________________________________________
113 Bool_t AliMpIntPair::operator== (const AliMpIntPair& pos2) const
115 /// Equality operator
117 // are this and pos2 equals?
119 // one valid, one invalid
120 if (fValidity != pos2.fValidity) return false;
123 if (!fValidity) return true;
126 return (fFirst==pos2.fFirst) && (fSecond==pos2.fSecond);
129 //_____________________________________________________________________________
130 Bool_t AliMpIntPair::operator!= (const AliMpIntPair& pos2) const
132 /// Non-equality operator
134 // are this and pos2 equals?
135 return !(*this == pos2);
138 //_____________________________________________________________________________
139 AliMpIntPair& AliMpIntPair::operator=(const AliMpIntPair& src)
141 /// Assignment operator
143 // check assignment to self
144 if (this == &src) return *this;
146 // base class assignment
147 TObject::operator=(src);
149 // assignment operator
151 fSecond = src.fSecond;
152 fValidity = src.fValidity;
156 //_____________________________________________________________________________
157 Int_t AliMpIntPair::Compare(const TObject* obj) const
159 /// Compare using operator <
161 const AliMpIntPair* pair = dynamic_cast<const AliMpIntPair*>(obj);
163 AliErrorStream() << "Wrong object type." << endl;
167 return ( *this < *pair ) ? -1 : 1;
169 //_____________________________________________________________________________
170 void AliMpIntPair::operator += (const AliMpIntPair& op)
172 /// Incrementation operator
175 fSecond += op.fSecond;
177 // operation only on valid pairs
178 fValidity = fValidity && op.fValidity;
180 //_____________________________________________________________________________
181 void AliMpIntPair::operator -= (const AliMpIntPair& op)
183 /// Decrementation operator
186 fSecond -= op.fSecond;
188 // operation only on valid pairs
189 fValidity = fValidity && op.fValidity;
192 //_____________________________________________________________________________
193 AliMpIntPair operator-(const AliMpIntPair& op1,const AliMpIntPair& op2)
195 /// Substraction operator
197 return AliMpIntPair(op1.GetFirst()-op2.GetFirst(),
198 op1.GetSecond()-op2.GetSecond(),
199 op1.IsValid() && op2.IsValid());
201 //_____________________________________________________________________________
202 AliMpIntPair operator+(const AliMpIntPair& op1,const AliMpIntPair& op2)
204 /// Addition operator
206 return AliMpIntPair(op1.GetFirst()+op2.GetFirst(),
207 op1.GetSecond()+op2.GetSecond(),
208 op1.IsValid() && op2.IsValid());
210 //_____________________________________________________________________________
211 AliMpIntPair operator*(const AliMpIntPair& op1,const AliMpIntPair& op2)
213 /// Multiplication operator
215 return AliMpIntPair(op1.GetFirst()*op2.GetFirst(),
216 op1.GetSecond()*op2.GetSecond(),
217 op1.IsValid() && op2.IsValid());
219 //_____________________________________________________________________________
220 ostream& operator<< (ostream &stream,const AliMpIntPair& op)
226 stream << op.GetFirst()<<','<<op.GetSecond()<<')';
230 stream << "AliMpIntPair::Invalid";