SISCone  2.0.5
reference.cpp
1 
2 // File: reference.cpp //
3 // Description: source file for checkxor management (Creference class) //
4 // This file is part of the SISCone project. //
5 // For more details, see http://projects.hepforge.org/siscone //
6 // //
7 // Copyright (c) 2006 Gavin Salam and Gregory Soyez //
8 // //
9 // This program is free software; you can redistribute it and/or modify //
10 // it under the terms of the GNU General Public License as published by //
11 // the Free Software Foundation; either version 2 of the License, or //
12 // (at your option) any later version. //
13 // //
14 // This program is distributed in the hope that it will be useful, //
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
17 // GNU General Public License for more details. //
18 // //
19 // You should have received a copy of the GNU General Public License //
20 // along with this program; if not, write to the Free Software //
21 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA //
22 // //
23 // $Revision:: 311 $//
24 // $Date:: 2011-10-05 23:27:09 +0200 (Wed, 05 Oct 2011) $//
26 
27 #include "reference.h"
28 #include "ranlux.h"
29 #include <stdlib.h>
30 
31 namespace siscone{
32 
33 /*******************************************************
34  * Creference implementation *
35  * references used for checksums. *
36  * *
37  * This class implements some reference variable *
38  * that can be used for checksums. Those checksums *
39  * are useful to disentengle between contents of two *
40  * cones without looking into their explicit particle *
41  * contents. *
42  *******************************************************/
43 
44 // default constructor
47  ref[0] = ref[1] = ref[2] = 0;
48 }
49 
50  //static unsigned int reference_bit = 1;
51 
52 // create a random reference
53 //---------------------------
55 // ref[0] = reference_bit;
56 // ref[1] = 0;
57 // ref[2] = 0;
58 // reference_bit <<= 1;
59 
60  unsigned int r1 = ranlux_get();
61  unsigned int r2 = ranlux_get();
62  unsigned int r3 = ranlux_get();
63  unsigned int r4 = ranlux_get();
64  // since ranlux only produces 24 bits, take r4 and add 8 bits
65  // from it to each of r1,r2, r3 to get 3*32 bits.
66  ref[0] = r1+((r4 & 0x00ff0000) << 8);
67  ref[1] = r2+((r4 & 0x0000ff00) << 16);
68  ref[2] = r3+((r4 & 0x000000ff) << 24);
69 
70  if (is_empty()) randomize();
71 }
72 
73 // test emptyness
74 //----------------
76  return (ref[0]==0) && (ref[1]==0) && (ref[2]==0);
77 }
78 
79 // test non-emptyness
80 //--------------------
82  return (ref[0]!=0) || (ref[1]!=0) || (ref[2]!=0);
83 }
84 
85 // assignment of reference
86 //-------------------------
88  ref[0] = r.ref[0];
89  ref[1] = r.ref[1];
90  ref[2] = r.ref[2];
91  return *this;
92 }
93 
94 // addition of reference
95 //-----------------------
97  Creference tmp = *this;
98  return tmp+=r;
99 }
100 
101 // incrementation of reference
102 //-----------------------------
104  ref[0] ^= r.ref[0];
105  ref[1] ^= r.ref[1];
106  ref[2] ^= r.ref[2];
107  return *this;
108 }
109 
110 // decrementation of reference
111 //-----------------------------
113  ref[0] ^= r.ref[0];
114  ref[1] ^= r.ref[1];
115  ref[2] ^= r.ref[2];
116  return *this;
117 }
118 
119 }
120 
The SISCone project has been developed by Gavin Salam and Gregory Soyez
Documentation generated on Wed May 30 2012 06:46:25 for SISCone by  Doxygen 1.8.1