Macros | Functions
DUNE_FelixReorder_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_FelixReorder_t.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( BaselineTest  )

Definition at line 17 of file DUNE_FelixReorder_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/newerrun/uBdat/Run_8700-SubRun_145-Event_" +
29  std::to_string(event) + "-Plane_" + std::to_string(p) + "-Frame_0" +
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/newerrun/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  in.close();
55 
57  meta.num_frames = contents.size()/sizeof(dune::FelixFrame);
58  meta.reordered = 0;
59  meta.compressed = 0;
60  std::unique_ptr<artdaq::Fragment> frag_ptr(artdaq::Fragment::FragmentBytes(
61  contents.size(), 1, 1, dune::toFragmentType("FELIX"), meta));
62  frag_ptr->resizeBytes(contents.size());
63  memcpy(frag_ptr->dataBeginBytes(), contents.c_str(), contents.size());
64 
65  dune::FelixFragment flxfrg(*frag_ptr);
66  const size_t frames = flxfrg.total_frames();
67 
68  // // Create a compressed fragment from file.
69  // std::ifstream incomp(filename+".gz", std::ios::binary);
70  // if (!incomp.is_open()) {
71  // std::cout << "Could not open file " << filename+".gz" << ".\n";
72  // continue;
73  // }
74  // std::string compcontents((std::istreambuf_iterator<char>(incomp)),
75  // (std::istreambuf_iterator<char>()));
76  // incomp.close();
77 
78  // dune::FelixFragmentBase::Metadata compmeta;
79  // compmeta.num_frames = 6024;//contents.size() / sizeof(dune::FelixFrame);
80  // compmeta.reordered = 1;
81  // compmeta.compressed = 0;
82  // std::unique_ptr<artdaq::Fragment> compfrag_ptr(artdaq::Fragment::FragmentBytes(
83  // compcontents.size(), 1, 1, dune::toFragmentType("FELIX"), compmeta));
84  // compfrag_ptr->resizeBytes(compcontents.size());
85  // memcpy(compfrag_ptr->dataBeginBytes(), compcontents.c_str(), compcontents.size());
86 
87  // dune::FelixFragment compflxfrg(*compfrag_ptr);
88 
89  // Test whether FelixFragment and FelixFragmentReordered correspond.
90  std::cout << "### MEOW -> Compressed FELIX Fragment test.\n";
91 
92  artdaq::Fragment reordfrg(
93  dune::FelixReorder(frag_ptr->dataBeginBytes(), frames));
94  // reordfrg.metadata<dune::FelixFragmentBase::Metadata>()->num_frames = 6000;
95  // reordfrg.metadata<dune::FelixFragmentBase::Metadata>()->reordered = 1;
96  dune::FelixFragment compflxfrg(reordfrg);
97 
98  std::cout << " -> Total words: " << compflxfrg.total_words() << '\n';
99  std::cout << " -> Total frames: " << compflxfrg.total_frames() << '\n';
100  std::cout << " -> Total adc values: " << compflxfrg.total_adc_values()
101  << "\n\n";
102 
103  std::cout << "### WOOF -> WIB frame test.\n";
104  std::cout << " -> SOF: " << unsigned(flxfrg.sof(0)) << "\n";
105  std::cout << " -> Version: " << unsigned(flxfrg.version(0)) << "\n";
106  std::cout << " -> FiberNo: " << unsigned(flxfrg.fiber_no(0)) << "\n";
107  std::cout << " -> SlotNo: " << unsigned(flxfrg.slot_no(0)) << "\n";
108  std::cout << " -> CrateNo: " << unsigned(flxfrg.crate_no(0)) << "\n";
109  std::cout << " -> Timestamp: " << std::hex << flxfrg.timestamp(0)
110  << std::dec;
111  std::cout << "\n\n";
112 
113  std::cout << "### WOOF -> Reordered WIB frame test.\n";
114  std::cout << " -> SOF: " << unsigned(compflxfrg.sof(0)) << "\n";
115  std::cout << " -> Version: " << unsigned(compflxfrg.version(0)) << "\n";
116  std::cout << " -> FiberNo: " << unsigned(compflxfrg.fiber_no(0)) << "\n";
117  std::cout << " -> SlotNo: " << unsigned(compflxfrg.slot_no(0)) << "\n";
118  std::cout << " -> CrateNo: " << unsigned(compflxfrg.crate_no(0)) << "\n";
119  std::cout << " -> Timestamp: " << std::hex << compflxfrg.timestamp(0)
120  << std::dec;
121  std::cout << "\n\n";
122 
123  std::cout << "### MEOW -> Comparing " << frames << " frames.\n";
124  std::cout << "First compressed frame:\n";
125  compflxfrg.print(0);
126  auto compare_begin = std::chrono::high_resolution_clock::now();
127  for (unsigned i = 0; i < frames; ++i) {
128  // std::cout << i << '\t';
129  BOOST_REQUIRE_EQUAL(flxfrg.sof(i), compflxfrg.sof(i));
130  BOOST_REQUIRE_EQUAL(flxfrg.version(i), compflxfrg.version(i));
131  BOOST_REQUIRE_EQUAL(flxfrg.fiber_no(i), compflxfrg.fiber_no(i));
132  BOOST_REQUIRE_EQUAL(flxfrg.slot_no(i), compflxfrg.slot_no(i));
133  BOOST_REQUIRE_EQUAL(flxfrg.crate_no(i), compflxfrg.crate_no(i));
134  BOOST_REQUIRE_EQUAL(flxfrg.timestamp(i), compflxfrg.timestamp(i));
135  for (unsigned j = 0; j < 4; ++j) {
136  // std::cout << j << std::endl;
137  BOOST_REQUIRE_EQUAL(flxfrg.s1_error(i, j), compflxfrg.s1_error(i, j));
138  BOOST_REQUIRE_EQUAL(flxfrg.s2_error(i, j), compflxfrg.s2_error(i, j));
139  BOOST_REQUIRE_EQUAL(flxfrg.checksum_a(i, j),
140  compflxfrg.checksum_a(i, j));
141  BOOST_REQUIRE_EQUAL(flxfrg.checksum_b(i, j),
142  compflxfrg.checksum_b(i, j));
143  BOOST_REQUIRE_EQUAL(flxfrg.coldata_convert_count(i, j),
144  compflxfrg.coldata_convert_count(i, j));
145  BOOST_REQUIRE_EQUAL(flxfrg.error_register(i, j),
146  compflxfrg.error_register(i, j));
147  for (unsigned h = 0; h < 8; ++h) {
148  BOOST_REQUIRE_EQUAL(flxfrg.hdr(i, j, h), compflxfrg.hdr(i, j, h));
149  }
150  }
151  for (unsigned ch = 0; ch < 256; ++ch) {
152  BOOST_REQUIRE_EQUAL(flxfrg.get_ADC(i, ch), compflxfrg.get_ADC(i, ch));
153  }
154  }
155  auto compare_end = std::chrono::high_resolution_clock::now();
156  std::cout << "### MEOW -> Tests successful.\n";
157  std::cout << "Took "
158  << std::chrono::duration_cast<std::chrono::milliseconds>(
159  compare_end - compare_begin)
160  .count()
161  << " ms.\n";
162 
163  // // Write reordered fragment to file for compression testing.
164  // std::string outname = filename;
165  // outname.insert(outname.size() - 4, "_reordered_prev-subtracted");
166  // std::ofstream ofile(outname);
167  // ofile.write(reinterpret_cast<char const*>(compflxfrg.dataBeginBytes()),
168  // compflxfrg.dataSizeBytes());
169  // ofile.close();
170  } // Loop over files.
171 }
std::string string
Definition: nybbler.cc:12
QTextStream & hex(QTextStream &s)
string filename
Definition: train.py:213
UWORD32 in[16]
Definition: md5.h:44
p
Definition: test.py:223
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
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
Event finding and building.