Line data Source code
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 18 : 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 0 : : TObject(),
56 0 : fFirst(ix),
57 0 : fSecond(iy),
58 0 : fValidity(true)
59 0 : {
60 : /// Standard constructor
61 0 : }
62 :
63 : //_____________________________________________________________________________
64 : AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy, Bool_t validity)
65 50484 : : TObject(),
66 50484 : fFirst(ix),
67 50484 : fSecond(iy),
68 50484 : fValidity(validity)
69 151452 : {
70 : /// Standard constructor with validity argument
71 100968 : }
72 :
73 : //_____________________________________________________________________________
74 : AliMpIntPair::AliMpIntPair()
75 0 : : TObject(),
76 : //fFirst(9999),
77 : //fSecond(9999),
78 0 : fFirst(0),
79 0 : fSecond(0),
80 0 : fValidity(false)
81 0 : {
82 : /// Default constructor
83 0 : }
84 :
85 : //_____________________________________________________________________________
86 : AliMpIntPair::AliMpIntPair(const AliMpIntPair& src):
87 0 : TObject(src),
88 0 : fFirst(src.fFirst),
89 0 : fSecond(src.fSecond),
90 0 : fValidity(src.fValidity)
91 0 : {
92 : /// Copy constructor
93 0 : }
94 :
95 : //_____________________________________________________________________________
96 : AliMpIntPair::~AliMpIntPair()
97 201936 : {
98 : /// Destructor
99 201936 : }
100 :
101 : //_____________________________________________________________________________
102 : Bool_t AliMpIntPair::operator< (const AliMpIntPair& pos2) const
103 : {
104 : /// Less operator
105 :
106 : // fFirst prior to fSecond
107 736710 : if (fFirst<pos2.fFirst) return kTRUE;
108 234600 : if (fFirst>pos2.fFirst) return kFALSE;
109 0 : if (fSecond<pos2.fSecond) return kTRUE;
110 0 : return kFALSE;
111 284670 : }
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 0 : if (fValidity != pos2.fValidity) return false;
122 :
123 : // both invalid
124 0 : if (!fValidity) return true;
125 :
126 : // both valid
127 0 : return (fFirst==pos2.fFirst) && (fSecond==pos2.fSecond);
128 0 : }
129 :
130 : //_____________________________________________________________________________
131 : Bool_t AliMpIntPair::operator!= (const AliMpIntPair& pos2) const
132 : {
133 : /// Non-equality operator
134 :
135 : // are this and pos2 equals?
136 0 : return !(*this == pos2);
137 : }
138 :
139 : //_____________________________________________________________________________
140 : AliMpIntPair& AliMpIntPair::operator=(const AliMpIntPair& src)
141 : {
142 : /// Assignment operator
143 :
144 : // check assignment to self
145 0 : if (this == &src) return *this;
146 :
147 : // base class assignment
148 0 : TObject::operator=(src);
149 :
150 : // assignment operator
151 0 : fFirst = src.fFirst;
152 0 : fSecond = src.fSecond;
153 0 : fValidity = src.fValidity;
154 :
155 0 : return *this;
156 0 : }
157 : //_____________________________________________________________________________
158 : Int_t AliMpIntPair::Compare(const TObject* obj) const
159 : {
160 : /// Compare using operator <
161 :
162 1138680 : const AliMpIntPair* pair = dynamic_cast<const AliMpIntPair*>(obj);
163 284670 : if ( !pair ) {
164 0 : AliErrorStream() << "Wrong object type." << endl;
165 0 : return -1;
166 : }
167 :
168 284670 : return ( *this < *pair ) ? -1 : 1;
169 284670 : }
170 : //_____________________________________________________________________________
171 : void AliMpIntPair::operator += (const AliMpIntPair& op)
172 : {
173 : /// Incrementation operator
174 :
175 0 : fFirst += op.fFirst;
176 0 : fSecond += op.fSecond;
177 :
178 : // operation only on valid pairs
179 0 : fValidity = fValidity && op.fValidity;
180 0 : }
181 : //_____________________________________________________________________________
182 : void AliMpIntPair::operator -= (const AliMpIntPair& op)
183 : {
184 : /// Decrementation operator
185 :
186 0 : fFirst -= op.fFirst;
187 0 : fSecond -= op.fSecond;
188 :
189 : // operation only on valid pairs
190 0 : fValidity = fValidity && op.fValidity;
191 0 : }
192 :
193 : //_____________________________________________________________________________
194 : AliMpIntPair operator-(const AliMpIntPair& op1,const AliMpIntPair& op2)
195 : {
196 : /// Substraction operator
197 :
198 0 : return AliMpIntPair(op1.GetFirst()-op2.GetFirst(),
199 0 : op1.GetSecond()-op2.GetSecond(),
200 0 : op1.IsValid() && op2.IsValid());
201 : }
202 : //_____________________________________________________________________________
203 : AliMpIntPair operator+(const AliMpIntPair& op1,const AliMpIntPair& op2)
204 : {
205 : /// Addition operator
206 :
207 0 : return AliMpIntPair(op1.GetFirst()+op2.GetFirst(),
208 0 : op1.GetSecond()+op2.GetSecond(),
209 0 : op1.IsValid() && op2.IsValid());
210 : }
211 : //_____________________________________________________________________________
212 : AliMpIntPair operator*(const AliMpIntPair& op1,const AliMpIntPair& op2)
213 : {
214 : /// Multiplication operator
215 :
216 0 : return AliMpIntPair(op1.GetFirst()*op2.GetFirst(),
217 0 : op1.GetSecond()*op2.GetSecond(),
218 0 : op1.IsValid() && op2.IsValid());
219 : }
220 : //_____________________________________________________________________________
221 : ostream& operator<< (ostream &stream,const AliMpIntPair& op)
222 : {
223 : /// Output streaming
224 :
225 0 : if (op.IsValid()) {
226 0 : stream << '(';
227 0 : stream << op.GetFirst()<<','<<op.GetSecond()<<')';
228 0 : return stream;
229 : }
230 : else {
231 0 : stream << "AliMpIntPair::Invalid";
232 0 : return stream;
233 : }
234 0 : }
235 :
|