[20] | 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: 1.1 $//
|
---|
| 24 | // $Date: 2008-10-02 15:20:28 $//
|
---|
| 25 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 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
|
---|
| 45 | //////////////////////
|
---|
| 46 | Creference::Creference(){
|
---|
| 47 | ref[0] = ref[1] = ref[2] = 0;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | //static unsigned int reference_bit = 1;
|
---|
| 51 |
|
---|
| 52 | // create a random reference
|
---|
| 53 | //---------------------------
|
---|
| 54 | void Creference::randomize(){
|
---|
| 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 | //----------------
|
---|
| 75 | bool Creference::is_empty(){
|
---|
| 76 | return (ref[0]==0) && (ref[1]==0) && (ref[2]==0);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | // test non-emptyness
|
---|
| 80 | //--------------------
|
---|
| 81 | bool Creference::not_empty(){
|
---|
| 82 | return (ref[0]!=0) || (ref[1]!=0) || (ref[2]!=0);
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | // assignment of reference
|
---|
| 86 | //-------------------------
|
---|
| 87 | Creference& Creference::operator = (const Creference &r){
|
---|
| 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 | //-----------------------
|
---|
| 96 | Creference Creference::operator + (const Creference &r){
|
---|
| 97 | Creference tmp = *this;
|
---|
| 98 | return tmp+=r;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | // incrementation of reference
|
---|
| 102 | //-----------------------------
|
---|
| 103 | Creference& Creference::operator += (const Creference &r){
|
---|
| 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 | //-----------------------------
|
---|
| 112 | Creference& Creference::operator -= (const Creference &r){
|
---|
| 113 | ref[0] ^= r.ref[0];
|
---|
| 114 | ref[1] ^= r.ref[1];
|
---|
| 115 | ref[2] ^= r.ref[2];
|
---|
| 116 | return *this;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | // addition with 2 references
|
---|
| 120 | //----------------------------
|
---|
| 121 | Creference operator + (Creference &r1, Creference &r2){
|
---|
| 122 | Creference tmp = r1;
|
---|
| 123 | return r1+=r2;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | }
|
---|
| 127 |
|
---|