AliRoot Core  d69033e (d69033e)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMpEncodePair.cxx
Go to the documentation of this file.
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 
18 // AliMp::Pair functions:
19 // The functions for encoding the pair of integers to another integer,
20 // defined withing a namespace AliMp.
21 // The encoded pairs can be added and subtracted.
22 // Author Laurent Aphecetche
23 
24 #include "AliMpEncodePair.h"
25 
26 #include <Riostream.h>
27 
28 //_______________________________________________________________________
29 MpPair_t AliMp::Pair(Int_t first, Int_t second)
30 {
33 
34  return (( first << 16 ) | second);
35 }
36 
37 //_______________________________________________________________________
39 {
42 
43  return ( pair & 0xFFFF0000 ) >> 16;
44 }
45 
46 //_______________________________________________________________________
48 {
51 
52  return pair & 0xFFFF;
53 }
54 
55 //_______________________________________________________________________
56 ostream& AliMp::PairPut(ostream& stream, MpPair_t pair)
57 {
59 
60  if ( pair >= 0 ) {
61  stream << '(' << AliMp::PairFirst(pair)
62  << ',' << AliMp::PairSecond(pair) << ')';
63  return stream;
64  }
65  else {
66  stream << "AliMpIntPair::Invalid";
67  return stream;
68  }
69 }
MpPair_t Pair(Int_t first, Int_t second)
Encode the pair of integers to another integer.
Int_t MpPair_t
Int_t PairFirst(MpPair_t pair)
Decode the first integer from encoded pair.
Int_t PairSecond(MpPair_t pair)
Decode the second integer from encoded pair.
ostream & PairPut(ostream &s, MpPair_t pair)
A special printing for encoded pair.