Macros | Functions
DUNE_FelixAvxReorder_t.cc File Reference
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include "dune-raw-data/Overlays/FelixFragment.hh"
#include "dune-raw-data/Overlays/FelixReordererFacility.hh"
#include "cetlib/quiet_unit_test.hpp"

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE(MilliSlice_t)
 

Functions

 BOOST_AUTO_TEST_CASE (BaselineTest)
 

Macro Definition Documentation

#define BOOST_TEST_MODULE (   MilliSlice_t)

Definition at line 12 of file DUNE_FelixAvxReorder_t.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( BaselineTest  )

Definition at line 17 of file DUNE_FelixAvxReorder_t.cc.

17  {
18  // // Get all files.
19  // std::vector<int> event_nums = {7258, 7263, 7264, 7269, 7276, 7283, 7284, 7287, 7294, 7296};
20  // MC event numbers
21  //std::vector<int> event_nums = {3059515, 3059537, 3059542, 3059574, 3059575,
22  // 3059577, 3059599, 3059603, 3059620, 3059622};
23  std::vector<std::string> filenames;
24  // for (auto event : event_nums) {
25  // for (unsigned p = 0; p < 3; ++p) {
26  // for (unsigned f = 1; f < 10; ++f) {
27  // filenames.push_back(
28  // "/dune/app/users/milov/kevlar/run/uBdat/Run_8700-SubRun_145-Event_" +
29  // std::to_string(event) + "-Plane_" + std::to_string(p) + "-Frame_" +
30  // std::to_string(f) + ".dat");
31  // }
32  // if (p == 2) {
33  // for (unsigned f = 10; f < 14; ++f) {
34  // filenames.push_back(
35  // "/dune/app/users/milov/kevlar/run/uBdat/"
36  // "Run_8700-SubRun_145-Event_" +
37  // std::to_string(event) + "-Plane_" + std::to_string(p) +
38  // "-Frame_" + std::to_string(f) + ".dat");
39  // }
40  // }
41  // }
42  // }
43  filenames.push_back("/nfs/home/np04daq/milo/frametests/channelid/felix-data-milo.dat");
44 
45  for (auto filename : filenames) {
46  // Create a regular fragment from file.
47  std::ifstream in(filename, std::ios::binary);
48  if (!in.is_open()) {
49  std::cout << "Could not open file " << filename << ".\n";
50  continue;
51  }
52  std::string contents((std::istreambuf_iterator<char>(in)),
53  (std::istreambuf_iterator<char>()));
54  // WARNING: inserting buffer of 32 bytes to correspond with raw data files.
55  std::string bufferstring = "abcdefghijklmnopqrstuvwxyzabcdef";
56  contents.insert(0, bufferstring);
57 
59  std::unique_ptr<artdaq::Fragment> frag_ptr(artdaq::Fragment::FragmentBytes(
60  contents.size(), 1, 1, dune::toFragmentType("FELIX"), meta));
61  frag_ptr->resizeBytes(contents.size()-bufferstring.size());
62  memcpy(frag_ptr->dataBeginBytes(), contents.c_str(), contents.size()-bufferstring.size());
63  in.close();
64 
65  dune::FelixFragment flxfrg(*frag_ptr);
66  const size_t frames = flxfrg.total_frames();
67 
68  // Test whether FelixFragment and FelixFragmentReordered correspond.
69  std::cout << "### MEOW -> Reordered FELIX Fragment test.\n";
70 
71  dune::ReorderFacility my_reorderer(false/* dune::ReordererType::TypeMILO */);
72  artdaq::Fragment reordfrg;
73  reordfrg.resizeBytes(frames * dune::FelixReorder::m_num_bytes_per_reord_frame);
74  my_reorderer.do_reorder(reordfrg.dataBeginBytes(), frag_ptr->dataBeginBytes() + bufferstring.size(), frames);
75  dune::FelixFragment reordflxfrg(reordfrg);
76 
77  std::cout << " -> Total words: " << reordflxfrg.total_words() << '\n';
78  std::cout << " -> Total frames: " << reordflxfrg.total_frames() << '\n';
79  std::cout << " -> Total adc values: " << reordflxfrg.total_adc_values()
80  << "\n\n";
81 
82  std::cout << "### WOOF -> Reordered WIB frame test.\n";
83  std::cout << " -> SOF: " << unsigned(reordflxfrg.sof(0)) << "\n";
84  std::cout << " -> Version: " << unsigned(reordflxfrg.version(0)) << "\n";
85  std::cout << " -> FiberNo: " << unsigned(reordflxfrg.fiber_no(0)) << "\n";
86  std::cout << " -> SlotNo: " << unsigned(reordflxfrg.slot_no(0)) << "\n";
87  std::cout << " -> CrateNo: " << unsigned(reordflxfrg.crate_no(0)) << "\n";
88  std::cout << " -> Timestamp: " << std::hex << reordflxfrg.timestamp(0)
89  << std::dec;
90  std::cout << "\n\n";
91 
92  std::cout << "### MEOW -> Comparing " << frames << " frames.\n";
93  auto compare_begin = std::chrono::high_resolution_clock::now();
94  for (unsigned i = 0; i < frames; ++i) {
95  BOOST_REQUIRE_EQUAL(flxfrg.sof(i), reordflxfrg.sof(i));
96  BOOST_REQUIRE_EQUAL(flxfrg.version(i), reordflxfrg.version(i));
97  BOOST_REQUIRE_EQUAL(flxfrg.fiber_no(i), reordflxfrg.fiber_no(i));
98  BOOST_REQUIRE_EQUAL(flxfrg.slot_no(i), reordflxfrg.slot_no(i));
99  BOOST_REQUIRE_EQUAL(flxfrg.crate_no(i), reordflxfrg.crate_no(i));
100  BOOST_REQUIRE_EQUAL(flxfrg.timestamp(i), reordflxfrg.timestamp(i));
101  // BOOST_REQUIRE_EQUAL(flxfrg.CRC(i), reordflxfrg.CRC(i));
102  for (unsigned j = 0; j < 4; ++j) {
103  BOOST_REQUIRE_EQUAL(flxfrg.s1_error(i, j), reordflxfrg.s1_error(i, j));
104  BOOST_REQUIRE_EQUAL(flxfrg.s2_error(i, j), reordflxfrg.s2_error(i, j));
105  BOOST_REQUIRE_EQUAL(flxfrg.checksum_a(i, j),
106  reordflxfrg.checksum_a(i, j));
107  BOOST_REQUIRE_EQUAL(flxfrg.checksum_b(i, j),
108  reordflxfrg.checksum_b(i, j));
109  BOOST_REQUIRE_EQUAL(flxfrg.coldata_convert_count(i, j),
110  reordflxfrg.coldata_convert_count(i, j));
111  BOOST_REQUIRE_EQUAL(flxfrg.error_register(i, j),
112  reordflxfrg.error_register(i, j));
113  for (unsigned h = 0; h < 8; ++h) {
114  BOOST_REQUIRE_EQUAL(flxfrg.hdr(i, j, h), reordflxfrg.hdr(i, j, h));
115  }
116  }
117  for (unsigned ch = 0; ch < 256; ++ch) {
118  BOOST_REQUIRE_EQUAL(flxfrg.get_ADC(i, ch), reordflxfrg.get_ADC(i, ch));
119  }
120  }
121  auto compare_end = std::chrono::high_resolution_clock::now();
122  std::cout << "### MEOW -> Tests successful.\n";
123  std::cout << "Took "
124  << std::chrono::duration_cast<std::chrono::milliseconds>(
125  compare_end - compare_begin)
126  .count()
127  << " ms.\n";
128 
129  // // Write reordered fragment to file for compression testing.
130  // std::string outname = filename;
131  // outname.insert(outname.size() - 4, "_reordered_prev-subtracted");
132  // std::ofstream ofile(outname);
133  // ofile.write(reinterpret_cast<char const*>(reordflxfrg.dataBeginBytes()),
134  // reordflxfrg.dataSizeBytes());
135  // ofile.close();
136  } // Loop over files.
137 }
std::string string
Definition: nybbler.cc:12
QTextStream & hex(QTextStream &s)
string filename
Definition: train.py:213
UWORD32 in[16]
Definition: md5.h:44
QTextStream & dec(QTextStream &s)
FragmentType toFragmentType(std::string t_string)
Definition: FragmentType.cc:10
millisecond milliseconds
Alias for common language habits.
Definition: spacetime.h:105
static constexpr size_t m_num_bytes_per_reord_frame
Definition: FelixReorder.hh:69