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 //
12 
13 // system include files
14 
15 // user include files
18 
19 //
20 // constructors and destructor
21 //
23 #ifdef SCRIVI
24  LogDebug("ForwardSim") << "Creating TotemNumberMerger";
25 #endif
26 }
27 
29 #ifdef SCRIVI
30  LogDebug("ForwardSim") << "Destruction of TotemNumberMerger";
31 #endif
32 }
33 
34 //
35 // member functions
36 //
37 
38 unsigned long TotemNumberMerger :: Merge(unsigned long value1,
39  unsigned long value2) const {
40 
41  unsigned long c(value1+value2);
42  unsigned long result(((c*(c+1))>>1)+value1);
43 
44 #ifdef SCRIVI
45  LogDebug("ForwardSim") << "Merge(value1=" << value1
46  << ", value2=" << value2 << ")=" << result;
47 
48  unsigned long invValue1, invValue2;
49  Split(result, invValue1, invValue2);
50 
51  assert(invValue1==value1);
52  assert(invValue2==value2);
53 #endif
54 
55  return result;
56 }
57 
58 unsigned long TotemNumberMerger :: Merge(unsigned long value1,
59  unsigned long value2,
60  unsigned long value3) const {
61  return Merge(Merge(value1, value2), value3);
62 }
63 
64 unsigned long TotemNumberMerger :: Merge(unsigned long value1,
65  unsigned long value2,
66  unsigned long value3,
67  unsigned long value4) const {
68  return Merge(Merge(value1, value2), Merge(value3, value4));
69 }
70 
71 void TotemNumberMerger :: Split(unsigned long source, unsigned long &value1,
72  unsigned long &value2) const {
73  unsigned long c(static_cast<unsigned long>(floor(sqrt(1.+8.*static_cast<float>(source))*0.5-0.5)));
74 
75  value1 = source-((c*(c+1))>>1);
76  value2 = c - value1;
77 
78 #ifdef SCRIVI
79  LogDebug("ForwardSim") << "source=" << source << ", c=" << c
80  << ", value1=" << value1 << ", value2=" << value2;
81 #endif
82 }
83 
84 void TotemNumberMerger :: Split(unsigned long source, unsigned long &value1,
85  unsigned long &value2,
86  unsigned long &value3) const {
87  unsigned long mix12;
88 
89  Split(source, mix12, value3);
90  Split(mix12, value1, value2);
91 }
92 
93 void TotemNumberMerger :: Split(unsigned long source, unsigned long &value1,
94  unsigned long &value2, unsigned long &value3,
95  unsigned long &value4) const {
96  unsigned long mix12, mix34;
97 
98  Split(source, mix12, mix34);
99  Split(mix12, value1, value2);
100  Split(mix34, value3, value4);
101 }
#define LogDebug(id)
assert(m_qm.get())
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:18
tuple result
Definition: query.py:137
static std::string const source
Definition: EdmProvDump.cc:43