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 $
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.
26 // Included in AliRoot: 2003/05/02
27 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
29 #include "AliMpIntPair.h"
33 #include <Riostream.h>
36 ClassImp(AliMpIntPair)
40 ///////////////////////////////////////////////////
42 // This class is a replacement for the standard STL
43 // pair<int,int> class, which can not be handed
44 // by the normal ROOT automatic streamer
45 // (at least in the ROOT version 3.03/03)
47 ///////////////////////////////////////////////////
50 //_____________________________________________________________________________
51 AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy)
57 /// Standard constructor
60 //_____________________________________________________________________________
61 AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy, Bool_t validity)
67 /// Standard constructor with validity argument
70 //_____________________________________________________________________________
71 AliMpIntPair::AliMpIntPair()
79 /// Default constructor
82 //_____________________________________________________________________________
83 AliMpIntPair::AliMpIntPair(const AliMpIntPair& src):
87 fValidity(src.fValidity)
92 //_____________________________________________________________________________
93 AliMpIntPair::~AliMpIntPair()
98 //_____________________________________________________________________________
99 Bool_t AliMpIntPair::operator< (const AliMpIntPair& pos2) const
103 // fFirst prior to fSecond
104 if (fFirst<pos2.fFirst) return kTRUE;
105 if (fFirst>pos2.fFirst) return kFALSE;
106 if (fSecond<pos2.fSecond) return kTRUE;
110 //_____________________________________________________________________________
111 Bool_t AliMpIntPair::operator== (const AliMpIntPair& pos2) const
113 /// Equality operator
115 // are this and pos2 equals?
117 // one valid, one invalid
118 if (fValidity != pos2.fValidity) return false;
121 if (!fValidity) return true;
124 return (fFirst==pos2.fFirst) && (fSecond==pos2.fSecond);
127 //_____________________________________________________________________________
128 Bool_t AliMpIntPair::operator!= (const AliMpIntPair& pos2) const
130 /// Non-equality operator
132 // are this and pos2 equals?
133 return !(*this == pos2);
136 //_____________________________________________________________________________
137 AliMpIntPair& AliMpIntPair::operator=(const AliMpIntPair& src)
139 /// Assignment operator
141 // check assignment to self
142 if (this == &src) return *this;
144 // base class assignment
145 TObject::operator=(src);
147 // assignment operator
149 fSecond = src.fSecond;
150 fValidity = src.fValidity;
154 //_____________________________________________________________________________
155 Int_t AliMpIntPair::Compare(const TObject* obj) const
157 /// Compare using operator <
159 const AliMpIntPair* pair = dynamic_cast<const AliMpIntPair*>(obj);
161 AliErrorStream() << "Wrong object type." << endl;
165 return ( *this < *pair ) ? -1 : 1;
167 //_____________________________________________________________________________
168 void AliMpIntPair::operator += (const AliMpIntPair& op)
170 /// Incrementation operator
173 fSecond += op.fSecond;
175 // operation only on valid pairs
176 fValidity = fValidity && op.fValidity;
178 //_____________________________________________________________________________
179 void AliMpIntPair::operator -= (const AliMpIntPair& op)
181 /// Decrementation operator
184 fSecond -= op.fSecond;
186 // operation only on valid pairs
187 fValidity = fValidity && op.fValidity;
190 //_____________________________________________________________________________
191 AliMpIntPair operator-(const AliMpIntPair& op1,const AliMpIntPair& op2)
193 /// Substraction operator
195 return AliMpIntPair(op1.GetFirst()-op2.GetFirst(),
196 op1.GetSecond()-op2.GetSecond(),
197 op1.IsValid() && op2.IsValid());
199 //_____________________________________________________________________________
200 AliMpIntPair operator+(const AliMpIntPair& op1,const AliMpIntPair& op2)
202 /// Addition operator
204 return AliMpIntPair(op1.GetFirst()+op2.GetFirst(),
205 op1.GetSecond()+op2.GetSecond(),
206 op1.IsValid() && op2.IsValid());
208 //_____________________________________________________________________________
209 AliMpIntPair operator*(const AliMpIntPair& op1,const AliMpIntPair& op2)
211 /// Multiplication operator
213 return AliMpIntPair(op1.GetFirst()*op2.GetFirst(),
214 op1.GetSecond()*op2.GetSecond(),
215 op1.IsValid() && op2.IsValid());
217 //_____________________________________________________________________________
218 ostream& operator<< (ostream &stream,const AliMpIntPair& op)
224 stream << op.GetFirst()<<','<<op.GetSecond()<<')';
228 stream << "AliMpIntPair::Invalid";