]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpIntPair.cxx
Add the det.element id for each local board
[u/mrichter/AliRoot.git] / MUON / mapping / 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 // Class AliMpIntPair
21 // --------------
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.
25 //
26 // Included in AliRoot: 2003/05/02
27 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
28
29 #include "AliMpIntPair.h"
30
31 #include "AliLog.h"
32
33 #include <Riostream.h>
34
35 /// \cond CLASSIMP
36 ClassImp(AliMpIntPair)
37 /// \endcond
38
39
40 ///////////////////////////////////////////////////
41 //
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)
46 //
47 ///////////////////////////////////////////////////
48
49
50 //_____________________________________________________________________________
51 AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy)
52   : TObject(),
53     fFirst(ix),
54     fSecond(iy),
55     fValidity(true) 
56 {
57 /// Standard constructor
58 }
59
60 //_____________________________________________________________________________
61 AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy, Bool_t validity)
62   : TObject(),
63     fFirst(ix),
64     fSecond(iy),
65     fValidity(validity) 
66 {
67 /// Standard constructor with validity argument
68 }
69
70 //_____________________________________________________________________________
71 AliMpIntPair::AliMpIntPair()
72   : TObject(),
73     //fFirst(9999),
74     //fSecond(9999),
75     fFirst(0),
76     fSecond(0),
77     fValidity(false) 
78 {
79 /// Default constructor
80 }
81
82 //_____________________________________________________________________________
83 AliMpIntPair::AliMpIntPair(const AliMpIntPair& src):
84   TObject(src),
85   fFirst(src.fFirst),
86   fSecond(src.fSecond),
87   fValidity(src.fValidity)
88 {
89 /// Copy constructor
90 }
91
92 //_____________________________________________________________________________
93 AliMpIntPair::~AliMpIntPair() 
94 {
95 /// Destructor
96 }
97
98 //_____________________________________________________________________________
99 Bool_t AliMpIntPair::operator< (const AliMpIntPair& pos2) const
100 {
101 /// Less operator
102
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;
107   return kFALSE;
108 }
109
110 //_____________________________________________________________________________
111 Bool_t AliMpIntPair::operator== (const AliMpIntPair& pos2) const
112 {
113 /// Equality operator
114
115   // are this and pos2 equals?
116   
117   // one valid, one invalid
118   if (fValidity != pos2.fValidity) return false;
119   
120   // both invalid
121   if (!fValidity) return true;
122   
123   // both valid
124   return (fFirst==pos2.fFirst) && (fSecond==pos2.fSecond);
125 }
126
127 //_____________________________________________________________________________
128 Bool_t AliMpIntPair::operator!= (const AliMpIntPair& pos2) const
129 {
130 /// Non-equality operator
131
132   // are this and pos2 equals?
133   return !(*this == pos2);
134 }
135
136 //_____________________________________________________________________________
137 AliMpIntPair& AliMpIntPair::operator=(const AliMpIntPair& src) 
138 {
139 /// Assignment operator
140
141   // check assignment to self
142   if (this == &src) return *this;
143
144   // base class assignment
145   TObject::operator=(src);
146
147   // assignment operator
148   fFirst = src.fFirst;
149   fSecond = src.fSecond;
150   fValidity = src.fValidity;
151   
152   return *this;
153 }
154 //_____________________________________________________________________________
155 Int_t AliMpIntPair::Compare(const TObject* obj) const
156 {
157 /// Compare using operator <
158
159   const AliMpIntPair* pair = dynamic_cast<const AliMpIntPair*>(obj);
160   if ( !pair ) {
161     AliErrorStream() << "Wrong object type." << endl;
162     return -1;
163   }  
164
165   return ( *this < *pair ) ? -1 : 1;
166 }
167 //_____________________________________________________________________________
168 void AliMpIntPair::operator += (const AliMpIntPair& op)
169 {
170 /// Incrementation operator
171
172   fFirst += op.fFirst;
173   fSecond += op.fSecond;
174   
175   // operation only on valid pairs
176   fValidity = fValidity && op.fValidity;
177 }
178 //_____________________________________________________________________________
179 void AliMpIntPair::operator -= (const AliMpIntPair& op)
180 {
181 /// Decrementation operator
182
183   fFirst -= op.fFirst;
184   fSecond -= op.fSecond;
185
186   // operation only on valid pairs
187   fValidity = fValidity && op.fValidity;
188 }
189
190 //_____________________________________________________________________________
191 AliMpIntPair operator-(const AliMpIntPair& op1,const AliMpIntPair& op2)
192 {
193 /// Substraction operator
194
195   return AliMpIntPair(op1.GetFirst()-op2.GetFirst(),
196                   op1.GetSecond()-op2.GetSecond(),
197                   op1.IsValid() && op2.IsValid());
198 }
199 //_____________________________________________________________________________
200 AliMpIntPair operator+(const AliMpIntPair& op1,const AliMpIntPair& op2)
201 {
202 /// Addition operator
203
204   return AliMpIntPair(op1.GetFirst()+op2.GetFirst(),
205                   op1.GetSecond()+op2.GetSecond(),
206                   op1.IsValid() && op2.IsValid());
207 }
208 //_____________________________________________________________________________
209 AliMpIntPair operator*(const AliMpIntPair& op1,const AliMpIntPair& op2)
210 {
211 /// Multiplication operator
212
213   return AliMpIntPair(op1.GetFirst()*op2.GetFirst(),
214                   op1.GetSecond()*op2.GetSecond(),
215                   op1.IsValid() && op2.IsValid());
216 }
217 //_____________________________________________________________________________
218 ostream& operator<< (ostream &stream,const AliMpIntPair& op)
219 {
220 /// Output streaming
221
222   if (op.IsValid()) {
223     stream << '(';
224     stream << op.GetFirst()<<','<<op.GetSecond()<<')';
225     return stream;
226   }  
227   else { 
228     stream << "AliMpIntPair::Invalid";
229     return stream;
230   }  
231 }
232