AliRoot Core  v5-06-30 (35d6c57)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMpIntPair.cxx
Go to the documentation of this file.
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 
16 // $Id$
17 // $MpId: AliMpIntPair.cxx,v 1.7 2006/05/24 13:58:29 ivana Exp $
18 // Category: basic
19 
20 //-----------------------------------------------------------------------------
21 // Class AliMpIntPair
22 // --------------
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.
26 //
27 // Included in AliRoot: 2003/05/02
28 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
29 //-----------------------------------------------------------------------------
30 
31 #include "AliMpIntPair.h"
32 
33 #include "AliLog.h"
34 
35 #include <Riostream.h>
36 
37 using std::endl;
41 
42 
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)
49 //
51 
52 
53 //_____________________________________________________________________________
54 AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy)
55  : TObject(),
56  fFirst(ix),
57  fSecond(iy),
58  fValidity(true)
59 {
61 }
62 
63 //_____________________________________________________________________________
64 AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy, Bool_t validity)
65  : TObject(),
66  fFirst(ix),
67  fSecond(iy),
68  fValidity(validity)
69 {
71 }
72 
73 //_____________________________________________________________________________
75  : TObject(),
76  //fFirst(9999),
77  //fSecond(9999),
78  fFirst(0),
79  fSecond(0),
80  fValidity(false)
81 {
83 }
84 
85 //_____________________________________________________________________________
87  TObject(src),
88  fFirst(src.fFirst),
89  fSecond(src.fSecond),
90  fValidity(src.fValidity)
91 {
93 }
94 
95 //_____________________________________________________________________________
97 {
99 }
100 
101 //_____________________________________________________________________________
102 Bool_t AliMpIntPair::operator< (const AliMpIntPair& pos2) const
103 {
105 
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;
110  return kFALSE;
111 }
112 
113 //_____________________________________________________________________________
114 Bool_t AliMpIntPair::operator== (const AliMpIntPair& pos2) const
115 {
117 
118  // are this and pos2 equals?
119 
120  // one valid, one invalid
121  if (fValidity != pos2.fValidity) return false;
122 
123  // both invalid
124  if (!fValidity) return true;
125 
126  // both valid
127  return (fFirst==pos2.fFirst) && (fSecond==pos2.fSecond);
128 }
129 
130 //_____________________________________________________________________________
131 Bool_t AliMpIntPair::operator!= (const AliMpIntPair& pos2) const
132 {
134 
135  // are this and pos2 equals?
136  return !(*this == pos2);
137 }
138 
139 //_____________________________________________________________________________
141 {
143 
144  // check assignment to self
145  if (this == &src) return *this;
146 
147  // base class assignment
148  TObject::operator=(src);
149 
150  // assignment operator
151  fFirst = src.fFirst;
152  fSecond = src.fSecond;
153  fValidity = src.fValidity;
154 
155  return *this;
156 }
157 //_____________________________________________________________________________
158 Int_t AliMpIntPair::Compare(const TObject* obj) const
159 {
161 
162  const AliMpIntPair* pair = dynamic_cast<const AliMpIntPair*>(obj);
163  if ( !pair ) {
164  AliErrorStream() << "Wrong object type." << endl;
165  return -1;
166  }
167 
168  return ( *this < *pair ) ? -1 : 1;
169 }
170 //_____________________________________________________________________________
172 {
174 
175  fFirst += op.fFirst;
176  fSecond += op.fSecond;
177 
178  // operation only on valid pairs
179  fValidity = fValidity && op.fValidity;
180 }
181 //_____________________________________________________________________________
183 {
185 
186  fFirst -= op.fFirst;
187  fSecond -= op.fSecond;
188 
189  // operation only on valid pairs
190  fValidity = fValidity && op.fValidity;
191 }
192 
193 //_____________________________________________________________________________
195 {
197 
198  return AliMpIntPair(op1.GetFirst()-op2.GetFirst(),
199  op1.GetSecond()-op2.GetSecond(),
200  op1.IsValid() && op2.IsValid());
201 }
202 //_____________________________________________________________________________
204 {
206 
207  return AliMpIntPair(op1.GetFirst()+op2.GetFirst(),
208  op1.GetSecond()+op2.GetSecond(),
209  op1.IsValid() && op2.IsValid());
210 }
211 //_____________________________________________________________________________
213 {
215 
216  return AliMpIntPair(op1.GetFirst()*op2.GetFirst(),
217  op1.GetSecond()*op2.GetSecond(),
218  op1.IsValid() && op2.IsValid());
219 }
220 //_____________________________________________________________________________
221 ostream& operator<< (ostream &stream,const AliMpIntPair& op)
222 {
224 
225  if (op.IsValid()) {
226  stream << '(';
227  stream << op.GetFirst()<<','<<op.GetSecond()<<')';
228  return stream;
229  }
230  else {
231  stream << "AliMpIntPair::Invalid";
232  return stream;
233  }
234 }
235 
AliMpIntPair & operator=(const AliMpIntPair &src)
virtual ~AliMpIntPair()
Int_t GetFirst() const
Return first value.
Definition: AliMpIntPair.h:50
Bool_t operator==(const AliMpIntPair &pos2) const
Bool_t IsValid() const
Return validity.
Definition: AliMpIntPair.h:54
Int_t fFirst
the first value
Definition: AliMpIntPair.h:75
Bool_t fValidity
validity
Definition: AliMpIntPair.h:77
Int_t fSecond
the second value
Definition: AliMpIntPair.h:76
AliMpIntPair operator+(const AliMpIntPair &op1, const AliMpIntPair &op2)
void operator+=(const AliMpIntPair &op)
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
AliMpIntPair operator*(const AliMpIntPair &op1, const AliMpIntPair &op2)
Bool_t operator<(const AliMpIntPair &pos2) const
void operator-=(const AliMpIntPair &op)
Bool_t operator!=(const AliMpIntPair &pos2) const
virtual Int_t Compare(const TObject *obj) const
ostream & operator<<(ostream &stream, const AliMpIntPair &op)
AliMpIntPair operator-(const AliMpIntPair &op1, const AliMpIntPair &op2)
A pair of integers.
Definition: AliMpIntPair.h:23
Int_t GetSecond() const
Return second value.
Definition: AliMpIntPair.h:52