ATLAS Offline Software
Public Member Functions | List of all members
TestVectorTool Class Reference

#include <TestVectorTool.h>

Inheritance diagram for TestVectorTool:
Collaboration diagram for TestVectorTool:

Public Member Functions

StatusCode initialize () override
 
StatusCode prepareTV (const std::string inputFile, std::vector< uint64_t > &testVector) const
 Prepare test vector in the form of std::vector<uint64_t>, can be either .txt or .bin. More...
 
StatusCode compare (const std::vector< uint64_t > &tv_1, const std::vector< uint64_t > &tv_2) const
 Compare two TV in the form of std::vector<uint64_t> More...
 
StatusCode compare (const EFTrackingFPGAIntegration::TVHolder &tvHolder, const std::vector< uint64_t > &tv_comp) const
 Compare two TV in the form of TVHolder and std::vector<uint64_t> More...
 

Detailed Description

Definition at line 43 of file TestVectorTool.h.

Member Function Documentation

◆ compare() [1/2]

StatusCode TestVectorTool::compare ( const EFTrackingFPGAIntegration::TVHolder tvHolder,
const std::vector< uint64_t > &  tv_comp 
) const

Compare two TV in the form of TVHolder and std::vector<uint64_t>

Parameters
tvHolderThe TVHolder object, the refTV in the TVHolder will be compared to the output
tv_compThe vector to be compared to the refTV

Definition at line 118 of file TestVectorTool.cxx.

119 {
120  ATH_MSG_INFO("Comparing the FPGA output to the reference vector for " << tvHolder.name);
121 
122  std::vector<uint64_t>::size_type size = -1;
123 
124  if (tvHolder.refTV.size() != tv_comp.size())
125  {
126  ATH_MSG_WARNING("The two test vectors have different sizes: " << tvHolder.refTV.size() << " and " << tv_comp.size());
127  // Use the shorter one for comparison
128  size = tvHolder.refTV.size() < tv_comp.size() ? tvHolder.refTV.size() : tv_comp.size();
129  }
130  else
131  {
132  ATH_MSG_DEBUG("The two test vectors have the same size: " << tvHolder.refTV.size());
133  size = tvHolder.refTV.size();
134  }
135 
136  bool pass = true;
137  for (std::vector<uint64_t>::size_type i = 0; i < size; i++)
138  {
139  if (tvHolder.refTV[i] != tv_comp[i])
140  {
141  ATH_MSG_DEBUG("The two test vectors are different at index " << i);
142  pass = false;
143  }
144  }
145 
146  if (pass)
147  {
148  ATH_MSG_INFO(tvHolder.name << " FPGA output matches the reference vector");
149  }
150  else
151  {
152  ATH_MSG_WARNING(tvHolder.name << " FPGA output does not match the reference vector");
153  }
154 
155  return StatusCode::SUCCESS;
156 }

◆ compare() [2/2]

StatusCode TestVectorTool::compare ( const std::vector< uint64_t > &  tv_1,
const std::vector< uint64_t > &  tv_2 
) const

Compare two TV in the form of std::vector<uint64_t>

Definition at line 78 of file TestVectorTool.cxx.

79 {
80  ATH_MSG_DEBUG("Comparing two test vectors");
81 
82  std::vector<uint64_t>::size_type size = -1;
83 
84  if (tv_1.size() != tv_2.size())
85  {
86  ATH_MSG_WARNING("The two test vectors have different sizes: " << tv_1.size() << " and " << tv_2.size());
87  // Use the shorter one for comparison
88  size = tv_1.size() < tv_2.size() ? tv_1.size() : tv_2.size();
89  }
90  else
91  {
92  ATH_MSG_DEBUG("The two test vectors have the same size: " << tv_1.size());
93  size = tv_1.size();
94  }
95 
96  bool pass = true;
97  for (std::vector<uint64_t>::size_type i = 0; i < size; i++)
98  {
99  if (tv_1[i] != tv_2[i])
100  {
101  ATH_MSG_DEBUG("The two test vectors are different at index " << i);
102  pass = false;
103  }
104  }
105 
106  if (pass)
107  {
108  ATH_MSG_INFO("The two test vectors are the same");
109  }
110  else
111  {
112  ATH_MSG_WARNING("The two test vectors are different!");
113  }
114 
115  return StatusCode::SUCCESS;
116 }

◆ initialize()

StatusCode TestVectorTool::initialize ( )
override

Definition at line 14 of file TestVectorTool.cxx.

15 {
16  ATH_MSG_INFO("Initializing TestVectorTool tool");
17 
18  return StatusCode::SUCCESS;
19 }

◆ prepareTV()

StatusCode TestVectorTool::prepareTV ( const std::string  inputFile,
std::vector< uint64_t > &  testVector 
) const

Prepare test vector in the form of std::vector<uint64_t>, can be either .txt or .bin.

Parameters
inputFileThe input file name to be opened
testVectorThe vector of uint64_t to be filled

Definition at line 21 of file TestVectorTool.cxx.

22 {
23  ATH_MSG_DEBUG("Preparing input test vector from " << inputFile);
24 
25  // Check if the input file ends with .txt or .bin
26  if (inputFile.find(".txt") == std::string::npos && inputFile.find(".bin") == std::string::npos)
27  {
28  ATH_MSG_ERROR("Input TV file must be either .txt or .bin");
29  return StatusCode::FAILURE;
30  }
31 
32  // clear the test vector before reading
33  testVector.clear();
34 
35  // if .txt
36  if (inputFile.find(".txt") != std::string::npos)
37  {
38  std::ifstream file(inputFile, std::ios::in);
39  if (!file.is_open())
40  {
41  ATH_MSG_ERROR("Cannot open file " << inputFile);
42  return StatusCode::FAILURE;
43  }
44 
45  uint64_t cache;
46  while (file >> std::hex >> cache)
47  {
48  testVector.push_back(cache);
49  }
50 
51  // close the file
52  file.close();
53  }
54  else
55  {
56  std::ifstream file(inputFile, std::ios::binary);
57  if (!file.is_open())
58  {
59  ATH_MSG_ERROR("Cannot open input TV file " << inputFile);
60  return StatusCode::FAILURE;
61  }
62 
63  uint64_t cache;
64  while (file.read(reinterpret_cast<char *>(&cache), sizeof(uint64_t)))
65  {
66  // Reverse the byte order
67  cache = __builtin_bswap64(cache);
68  testVector.push_back(cache);
69  }
70 
71  // close the file
72  file.close();
73  }
74 
75  return StatusCode::SUCCESS;
76 }

The documentation for this class was generated from the following files:
EFTrackingFPGAIntegration::TVHolder::refTV
std::vector< uint64_t > refTV
Definition: TestVectorTool.h:32
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
EFTrackingFPGAIntegration::TVHolder::name
std::string name
Definition: TestVectorTool.h:30
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CaloCondBlobAlgs_fillNoiseFromASCII.inputFile
string inputFile
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:17
lumiFormat.i
int i
Definition: lumiFormat.py:85
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
file
TFile * file
Definition: tile_monitor.h:29
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32