]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/MUONcore/AliMpIntPair.cxx
TENDER becomes Tender, removing .so
[u/mrichter/AliRoot.git] / MUON / MUONcore / AliMpIntPair.cxx
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;
38 /// \cond CLASSIMP
39 ClassImp(AliMpIntPair)
40 /// \endcond
41
42
43 ///////////////////////////////////////////////////
44 //
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 //
50 ///////////////////////////////////////////////////
51
52
53 //_____________________________________________________________________________
54 AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy)
55   : TObject(),
56     fFirst(ix),
57     fSecond(iy),
58     fValidity(true) 
59 {
60 /// Standard constructor
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 {
70 /// Standard constructor with validity argument
71 }
72
73 //_____________________________________________________________________________
74 AliMpIntPair::AliMpIntPair()
75   : TObject(),
76     //fFirst(9999),
77     //fSecond(9999),
78     fFirst(0),
79     fSecond(0),
80     fValidity(false) 
81 {
82 /// Default constructor
83 }
84
85 //_____________________________________________________________________________
86 AliMpIntPair::AliMpIntPair(const AliMpIntPair& src):
87   TObject(src),
88   fFirst(src.fFirst),
89   fSecond(src.fSecond),
90   fValidity(src.fValidity)
91 {
92 /// Copy constructor
93 }
94
95 //_____________________________________________________________________________
96 AliMpIntPair::~AliMpIntPair() 
97 {
98 /// Destructor
99 }
100
101 //_____________________________________________________________________________
102 Bool_t AliMpIntPair::operator< (const AliMpIntPair& pos2) const
103 {
104 /// Less operator
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 {
116 /// Equality operator
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 {
133 /// Non-equality operator
134
135   // are this and pos2 equals?
136   return !(*this == pos2);
137 }
138
139 //_____________________________________________________________________________
140 AliMpIntPair& AliMpIntPair::operator=(const AliMpIntPair& src) 
141 {
142 /// Assignment operator
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 {
160 /// Compare using operator <
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 //_____________________________________________________________________________
171 void AliMpIntPair::operator += (const AliMpIntPair& op)
172 {
173 /// Incrementation operator
174
175   fFirst += op.fFirst;
176   fSecond += op.fSecond;
177   
178   // operation only on valid pairs
179   fValidity = fValidity && op.fValidity;
180 }
181 //_____________________________________________________________________________
182 void AliMpIntPair::operator -= (const AliMpIntPair& op)
183 {
184 /// Decrementation operator
185
186   fFirst -= op.fFirst;
187   fSecond -= op.fSecond;
188
189   // operation only on valid pairs
190   fValidity = fValidity && op.fValidity;
191 }
192
193 //_____________________________________________________________________________
194 AliMpIntPair operator-(const AliMpIntPair& op1,const AliMpIntPair& op2)
195 {
196 /// Substraction operator
197
198   return AliMpIntPair(op1.GetFirst()-op2.GetFirst(),
199                   op1.GetSecond()-op2.GetSecond(),
200                   op1.IsValid() && op2.IsValid());
201 }
202 //_____________________________________________________________________________
203 AliMpIntPair operator+(const AliMpIntPair& op1,const AliMpIntPair& op2)
204 {
205 /// Addition operator
206
207   return AliMpIntPair(op1.GetFirst()+op2.GetFirst(),
208                   op1.GetSecond()+op2.GetSecond(),
209                   op1.IsValid() && op2.IsValid());
210 }
211 //_____________________________________________________________________________
212 AliMpIntPair operator*(const AliMpIntPair& op1,const AliMpIntPair& op2)
213 {
214 /// Multiplication operator
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 {
223 /// Output streaming
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