]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpIntPair.cxx
Introduced new DE names unique to each det element;
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpIntPair.cxx
CommitLineData
dee1d5f1 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
5f91c9e8 16// $Id$
13985652 17// $MpId: AliMpIntPair.cxx,v 1.7 2006/05/24 13:58:29 ivana Exp $
5f91c9e8 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//
dbe945cc 26// Included in AliRoot: 2003/05/02
5f91c9e8 27// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
28
5f91c9e8 29#include "AliMpIntPair.h"
30
ef053765 31#include "AliLog.h"
32
2c605e66 33#include <Riostream.h>
34
13985652 35/// \cond CLASSIMP
5f91c9e8 36ClassImp(AliMpIntPair)
13985652 37/// \endcond
5f91c9e8 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//_____________________________________________________________________________
51AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy)
52 : TObject(),
53 fFirst(ix),
54 fSecond(iy),
dee1d5f1 55 fValidity(true)
56{
57/// Standard constructor
5f91c9e8 58}
59
60//_____________________________________________________________________________
61AliMpIntPair::AliMpIntPair(Int_t ix,Int_t iy, Bool_t validity)
62 : TObject(),
63 fFirst(ix),
64 fSecond(iy),
dee1d5f1 65 fValidity(validity)
66{
67/// Standard constructor with validity argument
5f91c9e8 68}
69
70//_____________________________________________________________________________
71AliMpIntPair::AliMpIntPair()
72 : TObject(),
73 //fFirst(9999),
74 //fSecond(9999),
75 fFirst(0),
76 fSecond(0),
dee1d5f1 77 fValidity(false)
78{
79/// Default constructor
5f91c9e8 80}
dee1d5f1 81
5f91c9e8 82//_____________________________________________________________________________
83AliMpIntPair::AliMpIntPair(const AliMpIntPair& src):
84 TObject(src),
85 fFirst(src.fFirst),
86 fSecond(src.fSecond),
87 fValidity(src.fValidity)
88{
dee1d5f1 89/// Copy constructor
5f91c9e8 90}
91
92//_____________________________________________________________________________
dee1d5f1 93AliMpIntPair::~AliMpIntPair()
94{
95/// Destructor
5f91c9e8 96}
97
98//_____________________________________________________________________________
99Bool_t AliMpIntPair::operator< (const AliMpIntPair& pos2) const
100{
dee1d5f1 101/// Less operator
102
5f91c9e8 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//_____________________________________________________________________________
111Bool_t AliMpIntPair::operator== (const AliMpIntPair& pos2) const
112{
dee1d5f1 113/// Equality operator
114
5f91c9e8 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//_____________________________________________________________________________
128Bool_t AliMpIntPair::operator!= (const AliMpIntPair& pos2) const
129{
dee1d5f1 130/// Non-equality operator
131
5f91c9e8 132 // are this and pos2 equals?
133 return !(*this == pos2);
134}
135
136//_____________________________________________________________________________
137AliMpIntPair& AliMpIntPair::operator=(const AliMpIntPair& src)
138{
dee1d5f1 139/// Assignment operator
140
141 // check assignment to self
5f91c9e8 142 if (this == &src) return *this;
143
dee1d5f1 144 // base class assignment
5f91c9e8 145 TObject::operator=(src);
146
dee1d5f1 147 // assignment operator
5f91c9e8 148 fFirst = src.fFirst;
149 fSecond = src.fSecond;
150 fValidity = src.fValidity;
151
152 return *this;
153}
ef053765 154//_____________________________________________________________________________
155Int_t AliMpIntPair::Compare(const TObject* obj) const
156{
157/// Compare using operator <
5f91c9e8 158
ef053765 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}
5f91c9e8 167//_____________________________________________________________________________
168void AliMpIntPair::operator += (const AliMpIntPair& op)
169{
dee1d5f1 170/// Incrementation operator
171
5f91c9e8 172 fFirst += op.fFirst;
173 fSecond += op.fSecond;
174
175 // operation only on valid pairs
176 fValidity = fValidity && op.fValidity;
177}
178//_____________________________________________________________________________
179void AliMpIntPair::operator -= (const AliMpIntPair& op)
180{
dee1d5f1 181/// Decrementation operator
182
5f91c9e8 183 fFirst -= op.fFirst;
184 fSecond -= op.fSecond;
185
186 // operation only on valid pairs
187 fValidity = fValidity && op.fValidity;
188}
189
190//_____________________________________________________________________________
191AliMpIntPair operator-(const AliMpIntPair& op1,const AliMpIntPair& op2)
192{
dee1d5f1 193/// Substraction operator
194
5f91c9e8 195 return AliMpIntPair(op1.GetFirst()-op2.GetFirst(),
196 op1.GetSecond()-op2.GetSecond(),
197 op1.IsValid() && op2.IsValid());
198}
199//_____________________________________________________________________________
200AliMpIntPair operator+(const AliMpIntPair& op1,const AliMpIntPair& op2)
201{
dee1d5f1 202/// Addition operator
203
5f91c9e8 204 return AliMpIntPair(op1.GetFirst()+op2.GetFirst(),
205 op1.GetSecond()+op2.GetSecond(),
206 op1.IsValid() && op2.IsValid());
207}
208//_____________________________________________________________________________
209AliMpIntPair operator*(const AliMpIntPair& op1,const AliMpIntPair& op2)
210{
dee1d5f1 211/// Multiplication operator
212
5f91c9e8 213 return AliMpIntPair(op1.GetFirst()*op2.GetFirst(),
214 op1.GetSecond()*op2.GetSecond(),
215 op1.IsValid() && op2.IsValid());
216}
217//_____________________________________________________________________________
218ostream& operator<< (ostream &stream,const AliMpIntPair& op)
219{
dee1d5f1 220/// Output streaming
221
5f91c9e8 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