00001 00002 // File: reference.cpp // 00003 // Description: source file for checkxor management (Creference class) // 00004 // This file is part of the SISCone project. // 00005 // For more details, see http://projects.hepforge.org/siscone // 00006 // // 00007 // Copyright (c) 2006 Gavin Salam and Gregory Soyez // 00008 // // 00009 // This program is free software; you can redistribute it and/or modify // 00010 // it under the terms of the GNU General Public License as published by // 00011 // the Free Software Foundation; either version 2 of the License, or // 00012 // (at your option) any later version. // 00013 // // 00014 // This program is distributed in the hope that it will be useful, // 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 00017 // GNU General Public License for more details. // 00018 // // 00019 // You should have received a copy of the GNU General Public License // 00020 // along with this program; if not, write to the Free Software // 00021 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA // 00022 // // 00023 // $Revision:: 123 $// 00024 // $Date:: 2007-02-28 20:52:16 -0500 (Wed, 28 Feb 2007) $// 00026 00027 #include "reference.h" 00028 #include "ranlux.h" 00029 #include <stdlib.h> 00030 00031 namespace siscone{ 00032 00033 /******************************************************* 00034 * Creference implementation * 00035 * references used for checksums. * 00036 * * 00037 * This class implements some reference variable * 00038 * that can be used for checksums. Those checksums * 00039 * are useful to disentengle between contents of two * 00040 * cones without looking into their explicit particle * 00041 * contents. * 00042 *******************************************************/ 00043 00044 // default constructor 00046 Creference::Creference(){ 00047 ref[0] = ref[1] = ref[2] = 0; 00048 } 00049 00050 //static unsigned int reference_bit = 1; 00051 00052 // create a random reference 00053 //--------------------------- 00054 void Creference::randomize(){ 00055 // ref[0] = reference_bit; 00056 // ref[1] = 0; 00057 // ref[2] = 0; 00058 // reference_bit <<= 1; 00059 00060 unsigned int r1 = ranlux_get(); 00061 unsigned int r2 = ranlux_get(); 00062 unsigned int r3 = ranlux_get(); 00063 unsigned int r4 = ranlux_get(); 00064 // since ranlux only produces 24 bits, take r4 and add 8 bits 00065 // from it to each of r1,r2, r3 to get 3*32 bits. 00066 ref[0] = r1+((r4 & 0x00ff0000) << 8); 00067 ref[1] = r2+((r4 & 0x0000ff00) << 16); 00068 ref[2] = r3+((r4 & 0x000000ff) << 24); 00069 00070 if (is_empty()) randomize(); 00071 } 00072 00073 // test emptyness 00074 //---------------- 00075 bool Creference::is_empty(){ 00076 return (ref[0]==0) && (ref[1]==0) && (ref[2]==0); 00077 } 00078 00079 // test non-emptyness 00080 //-------------------- 00081 bool Creference::not_empty(){ 00082 return (ref[0]!=0) || (ref[1]!=0) || (ref[2]!=0); 00083 } 00084 00085 // assignment of reference 00086 //------------------------- 00087 Creference& Creference::operator = (const Creference &r){ 00088 ref[0] = r.ref[0]; 00089 ref[1] = r.ref[1]; 00090 ref[2] = r.ref[2]; 00091 return *this; 00092 } 00093 00094 // addition of reference 00095 //----------------------- 00096 Creference Creference::operator + (const Creference &r){ 00097 Creference tmp = *this; 00098 return tmp+=r; 00099 } 00100 00101 // incrementation of reference 00102 //----------------------------- 00103 Creference& Creference::operator += (const Creference &r){ 00104 ref[0] ^= r.ref[0]; 00105 ref[1] ^= r.ref[1]; 00106 ref[2] ^= r.ref[2]; 00107 return *this; 00108 } 00109 00110 // decrementation of reference 00111 //----------------------------- 00112 Creference& Creference::operator -= (const Creference &r){ 00113 ref[0] ^= r.ref[0]; 00114 ref[1] ^= r.ref[1]; 00115 ref[2] ^= r.ref[2]; 00116 return *this; 00117 } 00118 00119 // addition with 2 references 00120 //---------------------------- 00121 Creference operator + (Creference &r1, Creference &r2){ 00122 Creference tmp = r1; 00123 return r1+=r2; 00124 } 00125 00126 } 00127