CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TotemNumberMerger.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Forward
4 // Class : TotemNumberMerger
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: R. Capra
10 // Created: Tue May 16 10:14:34 CEST 2006
11 // $Id: TotemNumberMerger.cc,v 1.1 2006/05/17 16:18:58 sunanda Exp $
12 //
13 
14 // system include files
15 
16 // user include files
19 
20 //
21 // constructors and destructor
22 //
24 #ifdef SCRIVI
25  LogDebug("ForwardSim") << "Creating TotemNumberMerger";
26 #endif
27 }
28 
30 #ifdef SCRIVI
31  LogDebug("ForwardSim") << "Destruction of TotemNumberMerger";
32 #endif
33 }
34 
35 //
36 // member functions
37 //
38 
39 unsigned long TotemNumberMerger :: Merge(unsigned long value1,
40  unsigned long value2) const {
41 
42  unsigned long c(value1+value2);
43  unsigned long result(((c*(c+1))>>1)+value1);
44 
45 #ifdef SCRIVI
46  LogDebug("ForwardSim") << "Merge(value1=" << value1
47  << ", value2=" << value2 << ")=" << result;
48 
49  unsigned long invValue1, invValue2;
50  Split(result, invValue1, invValue2);
51 
52  assert(invValue1==value1);
53  assert(invValue2==value2);
54 #endif
55 
56  return result;
57 }
58 
59 unsigned long TotemNumberMerger :: Merge(unsigned long value1,
60  unsigned long value2,
61  unsigned long value3) const {
62  return Merge(Merge(value1, value2), value3);
63 }
64 
65 unsigned long TotemNumberMerger :: Merge(unsigned long value1,
66  unsigned long value2,
67  unsigned long value3,
68  unsigned long value4) const {
69  return Merge(Merge(value1, value2), Merge(value3, value4));
70 }
71 
72 void TotemNumberMerger :: Split(unsigned long source, unsigned long &value1,
73  unsigned long &value2) const {
74  unsigned long c(static_cast<unsigned long>(floor(sqrt(1.+8.*static_cast<float>(source))*0.5-0.5)));
75 
76  value1 = source-((c*(c+1))>>1);
77  value2 = c - value1;
78 
79 #ifdef SCRIVI
80  LogDebug("ForwardSim") << "source=" << source << ", c=" << c
81  << ", value1=" << value1 << ", value2=" << value2;
82 #endif
83 }
84 
85 void TotemNumberMerger :: Split(unsigned long source, unsigned long &value1,
86  unsigned long &value2,
87  unsigned long &value3) const {
88  unsigned long mix12;
89 
90  Split(source, mix12, value3);
91  Split(mix12, value1, value2);
92 }
93 
94 void TotemNumberMerger :: Split(unsigned long source, unsigned long &value1,
95  unsigned long &value2, unsigned long &value3,
96  unsigned long &value4) const {
97  unsigned long mix12, mix34;
98 
99  Split(source, mix12, mix34);
100  Split(mix12, value1, value2);
101  Split(mix34, value3, value4);
102 }
#define LogDebug(id)
unsigned long Merge(unsigned long value1, unsigned long value2) const
void Split(unsigned long source, unsigned long &value1, unsigned long &value2) const
T sqrt(T t)
Definition: SSEVec.h:46
tuple result
Definition: query.py:137