CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/SimG4CMS/Forward/src/TotemNumberMerger.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Forward
00004 // Class  :     TotemNumberMerger
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  R. Capra
00010 //         Created:  Tue May 16 10:14:34 CEST 2006
00011 // $Id: TotemNumberMerger.cc,v 1.1 2006/05/17 16:18:58 sunanda Exp $
00012 //
00013 
00014 // system include files
00015 
00016 // user include files
00017 #include "SimG4CMS/Forward/interface/TotemNumberMerger.h"
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019 
00020 //
00021 // constructors and destructor
00022 //
00023 TotemNumberMerger :: TotemNumberMerger() {
00024 #ifdef SCRIVI
00025   LogDebug("ForwardSim") << "Creating TotemNumberMerger";
00026 #endif
00027 }
00028 
00029 TotemNumberMerger :: ~TotemNumberMerger() {
00030 #ifdef SCRIVI
00031   LogDebug("ForwardSim") << "Destruction of TotemNumberMerger";
00032 #endif
00033 }
00034 
00035 //
00036 // member functions
00037 //
00038 
00039 unsigned long TotemNumberMerger :: Merge(unsigned long value1, 
00040                                          unsigned long value2) const {
00041 
00042   unsigned long c(value1+value2);
00043   unsigned long result(((c*(c+1))>>1)+value1);
00044 
00045 #ifdef SCRIVI
00046   LogDebug("ForwardSim") << "Merge(value1=" << value1
00047                          << ", value2=" << value2 << ")=" << result;
00048   
00049   unsigned long invValue1, invValue2;
00050   Split(result, invValue1, invValue2);
00051   
00052   assert(invValue1==value1);
00053   assert(invValue2==value2);                                  
00054 #endif
00055 
00056   return result;
00057 }
00058 
00059 unsigned long TotemNumberMerger :: Merge(unsigned long value1, 
00060                                          unsigned long value2, 
00061                                          unsigned long value3) const {
00062   return Merge(Merge(value1, value2), value3);
00063 }
00064 
00065 unsigned long TotemNumberMerger :: Merge(unsigned long value1, 
00066                                          unsigned long value2, 
00067                                          unsigned long value3, 
00068                                          unsigned long value4) const {
00069   return Merge(Merge(value1, value2), Merge(value3, value4));
00070 }
00071 
00072 void TotemNumberMerger :: Split(unsigned long source, unsigned long &value1, 
00073                                 unsigned long &value2) const {
00074   unsigned long c(static_cast<unsigned long>(floor(sqrt(1.+8.*static_cast<float>(source))*0.5-0.5)));
00075  
00076   value1 = source-((c*(c+1))>>1);
00077   value2 = c - value1;
00078  
00079 #ifdef SCRIVI
00080   LogDebug("ForwardSim") << "source=" << source << ", c=" << c
00081                          << ", value1=" << value1 << ", value2=" << value2;
00082 #endif
00083 }
00084 
00085 void TotemNumberMerger :: Split(unsigned long source, unsigned long &value1, 
00086                                 unsigned long &value2,
00087                                 unsigned long &value3) const {
00088   unsigned long mix12;
00089  
00090   Split(source, mix12, value3);
00091   Split(mix12, value1, value2);
00092 }
00093 
00094 void TotemNumberMerger :: Split(unsigned long source,  unsigned long &value1, 
00095                                 unsigned long &value2, unsigned long &value3,
00096                                 unsigned long &value4) const {
00097   unsigned long mix12, mix34;
00098  
00099   Split(source, mix12, mix34);
00100   Split(mix12, value1, value2);
00101   Split(mix34, value3, value4);
00102 }