]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpIntPair.cxx
Code for MUON Station1 (I.Hrivnacova)
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpIntPair.cxx
1 // $Id$
2 // Category: basic
3 //
4 // Class AliMpIntPair
5 // --------------
6 // Class that defines the pair of integers.
7 // The pair created by the default constructor is in invalide state,
8 // setting one of values changes the state to valid.
9 //
10 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
11
12 #include <Riostream.h>
13
14 #include "AliMpIntPair.h"
15
16 ClassImp(AliMpIntPair)
17
18
19 ///////////////////////////////////////////////////
20 //
21 // This class is a replacement for the standard STL
22 // pair<int,int> class, which can not be handed
23 // by the normal ROOT automatic streamer
24 // (at least in the ROOT version 3.03/03)
25 //
26 ///////////////////////////////////////////////////
27
28
29 //_____________________________________________________________________________
30 AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy)
31   : TObject(),
32     fFirst(ix),
33     fSecond(iy),
34     fValidity(true) {
35 //
36 }
37
38 //_____________________________________________________________________________
39 AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy, Bool_t validity)
40   : TObject(),
41     fFirst(ix),
42     fSecond(iy),
43     fValidity(validity) {
44 //
45 }
46
47 //_____________________________________________________________________________
48 AliMpIntPair::AliMpIntPair()
49   : TObject(),
50     //fFirst(9999),
51     //fSecond(9999),
52     fFirst(0),
53     fSecond(0),
54     fValidity(false) {
55 //
56 }
57 //_____________________________________________________________________________
58 AliMpIntPair::AliMpIntPair(const AliMpIntPair& src):
59   TObject(src),
60   fFirst(src.fFirst),
61   fSecond(src.fSecond),
62   fValidity(src.fValidity)
63 {
64
65 }
66
67 //_____________________________________________________________________________
68 AliMpIntPair::~AliMpIntPair() {
69 //
70 }
71
72 //_____________________________________________________________________________
73 Bool_t AliMpIntPair::operator< (const AliMpIntPair& pos2) const
74 {
75   // fFirst prior to fSecond
76   if (fFirst<pos2.fFirst) return kTRUE;
77   if (fFirst>pos2.fFirst) return kFALSE;
78   if (fSecond<pos2.fSecond) return kTRUE;
79   return kFALSE;
80 }
81
82 //_____________________________________________________________________________
83 Bool_t AliMpIntPair::operator== (const AliMpIntPair& pos2) const
84 {
85   // are this and pos2 equals?
86   
87   // one valid, one invalid
88   if (fValidity != pos2.fValidity) return false;
89   
90   // both invalid
91   if (!fValidity) return true;
92   
93   // both valid
94   return (fFirst==pos2.fFirst) && (fSecond==pos2.fSecond);
95 }
96
97 //_____________________________________________________________________________
98 Bool_t AliMpIntPair::operator!= (const AliMpIntPair& pos2) const
99 {
100   // are this and pos2 equals?
101   return !(*this == pos2);
102 }
103
104 //_____________________________________________________________________________
105 AliMpIntPair& AliMpIntPair::operator=(const AliMpIntPair& src) 
106 {
107   // check assignement to self
108   if (this == &src) return *this;
109
110   // base class assignement
111   TObject::operator=(src);
112
113   // assignement operator
114   fFirst = src.fFirst;
115   fSecond = src.fSecond;
116   fValidity = src.fValidity;
117   
118   return *this;
119 }
120
121 //_____________________________________________________________________________
122 void AliMpIntPair::operator += (const AliMpIntPair& op)
123 {
124   // incrementation operator
125   fFirst += op.fFirst;
126   fSecond += op.fSecond;
127   
128   // operation only on valid pairs
129   fValidity = fValidity && op.fValidity;
130 }
131 //_____________________________________________________________________________
132 void AliMpIntPair::operator -= (const AliMpIntPair& op)
133 {
134   // decrementation operator
135   fFirst -= op.fFirst;
136   fSecond -= op.fSecond;
137
138   // operation only on valid pairs
139   fValidity = fValidity && op.fValidity;
140 }
141
142 //_____________________________________________________________________________
143 AliMpIntPair operator-(const AliMpIntPair& op1,const AliMpIntPair& op2)
144 {
145   return AliMpIntPair(op1.GetFirst()-op2.GetFirst(),
146                   op1.GetSecond()-op2.GetSecond(),
147                   op1.IsValid() && op2.IsValid());
148 }
149 //_____________________________________________________________________________
150 AliMpIntPair operator+(const AliMpIntPair& op1,const AliMpIntPair& op2)
151 {
152   return AliMpIntPair(op1.GetFirst()+op2.GetFirst(),
153                   op1.GetSecond()+op2.GetSecond(),
154                   op1.IsValid() && op2.IsValid());
155 }
156 //_____________________________________________________________________________
157 AliMpIntPair operator*(const AliMpIntPair& op1,const AliMpIntPair& op2)
158 {
159   return AliMpIntPair(op1.GetFirst()*op2.GetFirst(),
160                   op1.GetSecond()*op2.GetSecond(),
161                   op1.IsValid() && op2.IsValid());
162 }
163 //_____________________________________________________________________________
164 ostream& operator<< (ostream &stream,const AliMpIntPair& op)
165 {
166   if (op.IsValid()) {
167     stream << '(';
168     stream << op.GetFirst()<<','<<op.GetSecond()<<')';
169     return stream;
170   }  
171   else { 
172     stream << "AliMpIntPair::Invalid";
173     return stream;
174   }  
175 }
176