CbmRoot
CbmMcbm2018UnpackerUtilRich.cxx
Go to the documentation of this file.
2 
3 #include <iostream>
4 
5 std::string mRichSupport::GetBinaryRepresentation(size_t const size,
6  uint8_t const* const ptr) {
7  std::string outString;
8 
9  unsigned char* b = (unsigned char*) ptr;
10  unsigned char byte;
11 
12  char cStr[2];
13  cStr[1] = '\0';
14 
15  for (int i = size - 1; i >= 0; i--) {
16  for (int j = 7; j >= 0; j--) {
17  byte = (b[i] >> j) & 1;
18  sprintf(cStr, "%u", byte);
19  outString.append(cStr);
20  }
21  }
22 
23  return outString;
24 }
25 
29 std::string mRichSupport::GetHexRepresentation(size_t const size,
30  uint8_t const* const ptr) {
31  std::string outString;
32 
33  unsigned char* b = (unsigned char*) ptr;
34  unsigned char byte;
35 
36  char cStr[3];
37  cStr[2] = '\0';
38 
39  for (int i = size - 1; i >= 0; i--) {
40  byte = b[i] & 0xff;
41  sprintf(cStr, "%02x", byte);
42  outString.append(cStr);
43  }
44 
45  return outString;
46 }
47 
48 std::string mRichSupport::GetWordHexRepr(uint8_t const* const ptr) {
49  std::string outString;
50 
51  unsigned char* b = (unsigned char*) ptr;
52  unsigned char byte[4];
53  byte[0] = b[3] & 0xff;
54  byte[1] = b[2] & 0xff;
55  byte[2] = b[1] & 0xff;
56  byte[3] = b[0] & 0xff;
57 
58  char cStr[10];
59  cStr[9] = '\0';
60 
61  sprintf(cStr, "%02x%02x %02x%02x", byte[0], byte[1], byte[2], byte[3]);
62 
63  outString.append(cStr);
64 
65  return outString;
66 }
67 
68 std::string mRichSupport::GetWordHexReprInv(uint8_t const* const ptr) {
69  std::string outString;
70 
71  unsigned char* b = (unsigned char*) ptr;
72  unsigned char byte[4];
73  byte[0] = b[0] & 0xff;
74  byte[1] = b[1] & 0xff;
75  byte[2] = b[2] & 0xff;
76  byte[3] = b[3] & 0xff;
77 
78  char cStr[10];
79  cStr[9] = '\0';
80 
81  sprintf(cStr, "%02x%02x %02x%02x", byte[0], byte[1], byte[2], byte[3]);
82 
83  outString.append(cStr);
84 
85  return outString;
86 }
87 
88 void mRichSupport::SwapBytes(size_t const /*size*/, uint8_t const* ptr) {
89  unsigned char* b = (unsigned char*) ptr;
90  unsigned char byte[4];
91  byte[0] = b[3] & 0xff;
92  byte[1] = b[2] & 0xff;
93  byte[2] = b[1] & 0xff;
94  byte[3] = b[0] & 0xff;
95 
96  b[0] = byte[0];
97  b[1] = byte[1];
98  b[2] = byte[2];
99  b[3] = byte[3];
100 }
101 
102 void mRichSupport::PrintRaw(size_t const size, uint8_t const* const ptr) {
103  size_t nWords = size / 4;
104  // size_t nRestBytes = size%4;
105 
106  for (size_t iWord = 0; iWord < nWords; iWord++) {
107  //std::cout << GetHexRepresentation(4, ptr+iWord*4) << " ";
108 
109  std::cout << GetWordHexReprInv(ptr + iWord * 4) << " ";
110  }
111  /*if (nRestBytes > 0) {
112  std::cout << GetHexRepresentation(nRestBytes, ptr+nWords*4) << " " << std::endl;
113  } else {
114  std::cout << std::endl;
115  }*/
116  std::cout << std::endl;
117 }
mRichSupport::GetBinaryRepresentation
std::string GetBinaryRepresentation(size_t const size, uint8_t const *const ptr)
Definition: CbmMcbm2018UnpackerUtilRich.cxx:5
mRichSupport::GetWordHexRepr
std::string GetWordHexRepr(uint8_t const *const ptr)
Definition: CbmMcbm2018UnpackerUtilRich.cxx:48
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
mRichSupport::PrintRaw
void PrintRaw(size_t const size, uint8_t const *const ptr)
Definition: CbmMcbm2018UnpackerUtilRich.cxx:102
mRichSupport::SwapBytes
void SwapBytes(size_t const size, uint8_t const *ptr)
Definition: CbmMcbm2018UnpackerUtilRich.cxx:88
mRichSupport::GetWordHexReprInv
std::string GetWordHexReprInv(uint8_t const *const ptr)
Definition: CbmMcbm2018UnpackerUtilRich.cxx:68
mRichSupport::GetHexRepresentation
std::string GetHexRepresentation(size_t const size, uint8_t const *const ptr)
Definition: CbmMcbm2018UnpackerUtilRich.cxx:29
CbmMcbm2018UnpackerUtilRich.h