ATLAS Offline Software
FibrePackerBase.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
5 
6 #include <iostream>
7 #include <cstdlib>
8 #include <cmath>
9 #include <map>
10 
11 FibrePackerBase::myDataWord FibrePackerBase::crc9full(const std::vector<myDataWord>& inwords, size_t num_bits ) const
12 {
21  size_t num_words = inwords.size();
22  if ( (num_bits+31)/32 > num_words )
23  {
24  std::cout << "ERROR: not enough words (" << num_words << ") for " << num_bits << "-bit CRC calculation." << std::endl;
25  return 0;
26  }
27  long int val = 0x1ff;
28  for ( size_t i = 0 ; i < num_bits ; ++i )
29  {
30  if ( (inwords.at(i/32)>>(i%32)) & 1 )
31  val ^= 1;
32  if ( val&1 )
33  val ^= 0x37d; // 1101111101 = polynomial reversed
34  val >>= 1;
35  }
36  return val;
37 }
38 
39 
40 FibrePackerBase::myDataWord FibrePackerBase::crc9d32(const std::vector<FibrePackerBase::myDataWord>& inwords, size_t num_words, bool bit_reverse = true) const{
48  long int mask = 0x00000001;
49  long int crc_word = 0x000;
50 
51 
52  //d_in_s is a '23-bit input word'
53 
54  std::vector<long int> d_in(32,0);
55  std::vector<long int> crc_s(9,1);
56  std::vector<long int> crc_r(9,1);
57 
58  for(size_t k=0; k != num_words; k++){
59 
60  // 32-bit word crc calculation
61 
62  if (bit_reverse){
63  for(int i=0; i!= 32; i++){
64  d_in [31-i] = inwords.at(k) & (mask << i);
65  d_in[31-i] = d_in[31-i] >> i;
66  }
67  } else {
68  for(int i=0; i!= 32; i++){
69  d_in [i] = inwords.at(k) & (mask << i);
70  d_in[i] = d_in[i] >> i;
71  }
72  }
73 
74  // in the first iteration CRC_S must be set to all 1's: note CRC_R is set to 1's above
75  // then CRC_S must equal the previous CRC_R
76 
77  for(int j=0; j!= 9; j++)
78  crc_s[j] = crc_r[j];
79 
80 
81  crc_r[0]= crc_s[0] ^ crc_s[2] ^ crc_s[3] ^ crc_s[6] ^ crc_s[8] ^ d_in[0] ^ d_in[2] ^ d_in[3] ^ d_in[5] ^ d_in[6] ^ d_in[7] ^ d_in[8] ^ d_in[9] ^ d_in[10] ^ d_in[11] ^ d_in[15] ^ d_in[18] ^ d_in[19] ^ d_in[20] ^ d_in[21] ^ d_in[22] ^ d_in[23] ^ d_in[25] ^ d_in[26] ^ d_in[29] ^ d_in[31];
82  crc_r[1]= crc_s[1] ^ crc_s[2] ^ crc_s[4] ^ crc_s[6] ^ crc_s[7] ^ crc_s[8] ^ d_in[0] ^ d_in[1] ^ d_in[2] ^ d_in[4] ^ d_in[5] ^ d_in[12] ^ d_in[15] ^ d_in[16] ^ d_in[18] ^ d_in[24] ^ d_in[25] ^ d_in[27] ^ d_in[29] ^ d_in[30] ^ d_in[31];
83  crc_r[2]= crc_s[2] ^ crc_s[3] ^ crc_s[5] ^ crc_s[7] ^ crc_s[8] ^ d_in[1] ^ d_in[2] ^ d_in[3] ^ d_in[5] ^ d_in[6] ^ d_in[13] ^ d_in[16] ^ d_in[17] ^ d_in[19] ^ d_in[25] ^ d_in[26] ^ d_in[28] ^ d_in[30] ^ d_in[31];
84  crc_r[3]= crc_s[0] ^ crc_s[2] ^ crc_s[4] ^ d_in[0] ^ d_in[4] ^ d_in[5] ^ d_in[8] ^ d_in[9] ^ d_in[10] ^ d_in[11] ^ d_in[14] ^ d_in[15] ^ d_in[17] ^ d_in[19] ^ d_in[21] ^ d_in[22] ^ d_in[23] ^ d_in[25] ^ d_in[27];
85  crc_r[4]= crc_s[1] ^ crc_s[2] ^ crc_s[5] ^ crc_s[6] ^ crc_s[8] ^ d_in[0] ^ d_in[1] ^ d_in[2] ^ d_in[3] ^ d_in[7] ^ d_in[8] ^ d_in[12] ^ d_in[16] ^ d_in[19] ^ d_in[21] ^ d_in[24] ^ d_in[25] ^ d_in[28] ^ d_in[29] ^ d_in[31];
86  crc_r[5]= crc_s[0] ^ crc_s[7] ^ crc_s[8] ^ d_in[0] ^ d_in[1] ^ d_in[4] ^ d_in[5] ^ d_in[6] ^ d_in[7] ^ d_in[10] ^ d_in[11] ^ d_in[13] ^ d_in[15] ^ d_in[17] ^ d_in[18] ^ d_in[19] ^ d_in[21] ^ d_in[23] ^ d_in[30] ^ d_in[31];
87  crc_r[6]= crc_s[0] ^ crc_s[1] ^ crc_s[2] ^ crc_s[3] ^ crc_s[6] ^ d_in[0] ^ d_in[1] ^ d_in[3] ^ d_in[9] ^ d_in[10] ^ d_in[12] ^ d_in[14] ^ d_in[15] ^ d_in[16] ^ d_in[21] ^ d_in[23] ^ d_in[24] ^ d_in[25] ^ d_in[26] ^ d_in[29];
88  crc_r[7]= crc_s[0] ^ crc_s[1] ^ crc_s[4] ^ crc_s[6] ^ crc_s[7] ^ crc_s[8] ^ d_in[0] ^ d_in[1] ^ d_in[3] ^ d_in[4] ^ d_in[5] ^ d_in[6] ^ d_in[7] ^ d_in[8] ^ d_in[9] ^ d_in[13] ^ d_in[16] ^ d_in[17] ^ d_in[18] ^ d_in[19] ^ d_in[20] ^ d_in[21] ^ d_in[23] ^ d_in[24] ^ d_in[27] ^ d_in[29] ^ d_in[30] ^ d_in[31];
89  crc_r[8]= crc_s[1] ^ crc_s[2] ^ crc_s[5] ^ crc_s[7] ^ crc_s[8] ^ d_in[1] ^ d_in[2] ^ d_in[4] ^ d_in[5] ^ d_in[6] ^ d_in[7] ^ d_in[8] ^ d_in[9] ^ d_in[10] ^ d_in[14] ^ d_in[17] ^ d_in[18] ^ d_in[19] ^ d_in[20] ^ d_in[21] ^ d_in[22] ^ d_in[24] ^ d_in[25] ^ d_in[28] ^ d_in[30] ^ d_in[31];
90 
91  crc_word = 0x000;
92 
93  if (bit_reverse){
94 
95  for(int i=0; i!= 9; i++)
96  crc_word = crc_word | (crc_r[8-i] << i);
97 
98  } else {
99 
100  for(int i=0; i!= 9; i++)
101  crc_word = crc_word | (crc_r[i] << i);
102 
103  }
104 
105  }
106 
107  return (crc_word);
108 
109 }
110 
112 
121  long int mask = 0x00000001;
122  long int crc_word = 0x000;
123 
124 
125  //d_in_s is a '23-bit input word'
126 
127  std::vector<long int> d_in_s(23,0);
128  std::vector<long int> crc_in_s(9,0);
129  std::vector<long int> crc_r(9,0);
130 
131  // crc calculation
132 
133  if (bit_reverse){
134 
135  for(int i=0; i!= 23; i++){
136  d_in_s[22-i] = inword & (mask << i);
137  d_in_s[22-i] = d_in_s[22-i] >> i;
138  }
139 
140  for(int i=0; i!= 9; i++){
141  crc_in_s[8-i] = in_crc & (mask << i);
142  crc_in_s[8-i] = crc_in_s[8-i] >> i;
143  }
144 
145  } else {
146 
147  for(int i=0; i!= 23; i++){
148  d_in_s[i] = inword & (mask << i);
149  d_in_s[i] = d_in_s[i] >> i;
150  }
151 
152  for(int i=0; i!= 9; i++){
153  crc_in_s[i] = in_crc & (mask << i);
154  crc_in_s[i] = crc_in_s[i] >> i;
155  }
156  }
157 
158  crc_r[0] = crc_in_s[1] ^ crc_in_s[4] ^ crc_in_s[5] ^ crc_in_s[6] ^ crc_in_s[7] ^ crc_in_s[8] ^ d_in_s[0] ^ d_in_s[2] ^ d_in_s[3] ^ d_in_s[5] ^ d_in_s[6] ^ d_in_s[7] ^ d_in_s[8] ^ d_in_s[9] ^ d_in_s[10] ^ d_in_s[11] ^ d_in_s[15] ^ d_in_s[18] ^ d_in_s[19] ^ d_in_s[20] ^ d_in_s[21] ^ d_in_s[22];
159  crc_r[1] = crc_in_s[1] ^ crc_in_s[2] ^ crc_in_s[4] ^ d_in_s[0] ^ d_in_s[1] ^ d_in_s[2] ^ d_in_s[4] ^ d_in_s[5] ^ d_in_s[12] ^ d_in_s[15] ^ d_in_s[16] ^ d_in_s[18];
160  crc_r[2] = crc_in_s[2] ^ crc_in_s[3] ^ crc_in_s[5] ^ d_in_s[1] ^ d_in_s[2] ^ d_in_s[3] ^ d_in_s[5] ^ d_in_s[6] ^ d_in_s[13] ^ d_in_s[16] ^ d_in_s[17] ^ d_in_s[19];
161  crc_r[3] = crc_in_s[0] ^ crc_in_s[1] ^ crc_in_s[3] ^ crc_in_s[5] ^ crc_in_s[7] ^ crc_in_s[8] ^ d_in_s[0] ^ d_in_s[4] ^ d_in_s[5] ^ d_in_s[8] ^ d_in_s[9] ^ d_in_s[10] ^ d_in_s[11] ^ d_in_s[14] ^ d_in_s[15] ^ d_in_s[17] ^ d_in_s[19] ^ d_in_s[21] ^ d_in_s[22];
162  crc_r[4] = crc_in_s[2] ^ crc_in_s[5] ^ crc_in_s[7] ^ d_in_s[0] ^ d_in_s[1] ^ d_in_s[2] ^ d_in_s[3] ^ d_in_s[7] ^ d_in_s[8] ^ d_in_s[12] ^ d_in_s[16] ^ d_in_s[19] ^ d_in_s[21];
163  crc_r[5] = crc_in_s[1] ^ crc_in_s[3] ^ crc_in_s[4] ^ crc_in_s[5] ^ crc_in_s[7] ^ d_in_s[0] ^ d_in_s[1] ^ d_in_s[4] ^ d_in_s[5] ^ d_in_s[6] ^ d_in_s[7] ^ d_in_s[10] ^ d_in_s[11] ^ d_in_s[13] ^ d_in_s[15] ^ d_in_s[17] ^ d_in_s[18] ^ d_in_s[19] ^ d_in_s[21];
164  crc_r[6] = crc_in_s[0] ^ crc_in_s[1] ^ crc_in_s[2] ^ crc_in_s[7] ^ d_in_s[0] ^ d_in_s[1] ^ d_in_s[3] ^ d_in_s[9] ^ d_in_s[10] ^ d_in_s[12] ^ d_in_s[14] ^ d_in_s[15] ^ d_in_s[16] ^ d_in_s[21];
165  crc_r[7] = crc_in_s[2] ^ crc_in_s[3] ^ crc_in_s[4] ^ crc_in_s[5] ^ crc_in_s[6] ^ crc_in_s[7] ^ d_in_s[0] ^ d_in_s[1] ^ d_in_s[3] ^ d_in_s[4] ^ d_in_s[5] ^ d_in_s[6] ^ d_in_s[7] ^ d_in_s[8] ^ d_in_s[9] ^ d_in_s[13] ^ d_in_s[16] ^ d_in_s[17] ^ d_in_s[18] ^ d_in_s[19] ^ d_in_s[20] ^ d_in_s[21];
166  crc_r[8] = crc_in_s[0] ^ crc_in_s[3] ^ crc_in_s[4] ^ crc_in_s[5] ^ crc_in_s[6] ^ crc_in_s[7] ^ crc_in_s[8] ^ d_in_s[1] ^ d_in_s[2] ^ d_in_s[4] ^ d_in_s[5] ^ d_in_s[6] ^ d_in_s[7] ^ d_in_s[8] ^ d_in_s[9] ^ d_in_s[10] ^ d_in_s[14] ^ d_in_s[17] ^ d_in_s[18] ^ d_in_s[19] ^ d_in_s[20] ^ d_in_s[21] ^ d_in_s[22];
167 
168 
169  if (bit_reverse){
170  for(int i=0; i!= 9; i++)
171  crc_word = crc_word | (crc_r[8-i] << i);
172  } else{
173  for(int i=0; i!= 9; i++)
174  crc_word = crc_word | (crc_r[i] << i);
175  }
176 
177  return (crc_word);
178 
179 }
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:459
FibrePackerBase::crc9full
virtual myDataWord crc9full(const std::vector< myDataWord > &inwords, size_t num_bits) const
Functions calculating CRC over input data.
Definition: FibrePackerBase.cxx:11
lumiFormat.i
int i
Definition: lumiFormat.py:85
FibrePackerBase::crc9d32
virtual myDataWord crc9d32(const std::vector< myDataWord > &inwords, size_t num_words, bool bit_reverse) const
Definition: FibrePackerBase.cxx:40
FibrePackerBase.h
FibrePackerBase::myDataWord
uint32_t myDataWord
Definition: FibrePackerBase.h:25
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
FibrePackerBase::crc9d23
virtual myDataWord crc9d23(myDataWord inword, myDataWord in_crc, bool bit_reverse) const
Definition: FibrePackerBase.cxx:111
fitman.k
k
Definition: fitman.py:528