DUNE_FelixDecode_t.cc
Go to the documentation of this file.
1  #include <stdint.h>
2 #include <fstream>
3 #include <iostream>
4 #include <string>
5 #include <vector>
7 #include "artdaq-core/Data/Fragment.hh"
12 #include "gallery/Event.h"
13 
14 #pragma GCC diagnostic push
15 #pragma GCC diagnostic ignored "-Wsign-compare"
16 
17 #define BOOST_TEST_MODULE(MilliSlice_t)
19 
20 BOOST_AUTO_TEST_SUITE(FelixDecode_test)
21 
22 BOOST_AUTO_TEST_CASE(BaselineTest) {
23  // // Generate frames to put into a file.
24  // std::ofstream framefile("frames.dat");
25  // dune::FelixFrame frame[6000];
26  // for(unsigned i = 0; i < 6000; ++i) {
27  // // WIB header fields.
28  // frame[i].set_version(1);
29  // frame[i].set_fiber_no(1);
30  // frame[i].set_slot_no(3);
31  // frame[i].set_crate_no(6);
32  // frame[i].set_mm(0);
33  // frame[i].set_oos(0);
34  // frame[i].set_wib_errors(0);
35  // frame[i].set_timestamp(i*25);
36  // frame[i].set_z(0);
37 
38  // // COLDATA header fields.
39  // for(unsigned b = 0; b < 4; ++b) {
40  // frame[i].set_s1_error(b, 0);
41  // frame[i].set_s2_error(b, 0);
42  // frame[i].set_checksum_a(b, 0xabab);
43  // frame[i].set_checksum_b(b, 0xcdcd);
44  // frame[i].set_coldata_convert_count(b, i);
45  // frame[i].set_error_register(b, 0);
46  // for(unsigned h = 0; h < 8; ++h) {
47  // frame[i].set_hdr(b, h, h);
48  // }
49  // }
50 
51  // // Channel values. Set to be a counter
52  // for(unsigned c = 0; c < 256; ++c) {
53  // frame[i].set_channel(c, c);
54  // }
55  // }
56  // framefile.write(reinterpret_cast<char const*>(&frame[0]), 6000*464);
57  // framefile.close();
58 
59  // Uncompressed (no metadata)
60  // std::string filename = "/pnfs/dune/tape_backed/dunepro/protodune/np04/beam/detector/None/raw/04/99/61/01/np04_raw_run004155_0096_dl2.root";
61  // Compressed ({1, 0, 0} metadata)
62  // std::string filename = "/pnfs/dune/tape_backed/dunepro/protodune/np04/beam/detector/None/raw/04/99/35/53/np04_raw_run004149_0024_dl4.root";
63  // std::string outputDestination = "noise_records/test";
65  "/pnfs/dune/tape_backed/dunepro/protodune/np04/beam/detector/None/raw/05/"
66  "16/24/57/np04_raw_run004424_0001_dl5.root";
67 
68  // Initialise a decoder object from the file.
69  dune::FelixDecoder flxdec(filename);
70 
71  for(unsigned i = 0; i < flxdec.total_fragments(); ++i) {
72  // Load fragments into overlay.
73  artdaq::Fragment frag = flxdec.Fragment(i);
74  dune::FelixFragment flxfrag(frag);
75  if(frag.timestamp() - flxfrag.timestamp() >= 12525 || frag.timestamp() - flxfrag.timestamp() < 12500) {
76  std::cout << "\nFragment " << i << "\tCrate " << (unsigned)flxfrag.crate_no() << '\t';
77  std::cout << "Slot " << (unsigned)flxfrag.slot_no() << '\t';
78  std::cout << "Fiber " << (unsigned)flxfrag.fiber_no() << '\n';
79 
81  *frag.metadata<dune::FelixFragment::Metadata>();
82  std::cout << "Metadata: " << (unsigned)meta.num_frames << " " << (unsigned)meta.reordered << " " << (unsigned)meta.compressed << " " << (unsigned)meta.offset_frames << " " << (unsigned)meta.window_frames << '\n';
83 
84  std::cout << "Timestamp difference: " << frag.timestamp() - flxfrag.timestamp() << '\n';
85  }
86 
87  std::cout << "Timestamp difference: " << frag.timestamp() - flxfrag.timestamp() << '\n';
88 
89 
90  // std::ofstream ofile("frag.dat");
91  // ofile.write((char*)flxfrag.dataBeginBytes(), flxfrag.dataSizeBytes());
92  // ofile.close();
93 
94  // std::ofstream offile("fragment.dat");
95  // ofile.write((char*)uncompflxfrag.dataBeginBytes(), uncompflxfrag.dataSizeBytes());
96  // ofile.close();
97 
98  // Print out relevant information.
99  // dune::FelixFragment::Metadata meta = *(frag.metadata<dune::FelixFragment::Metadata>());
100  // std::cout << "Metadata information:\n";
101  // std::cout << "Number of frames: " << meta.num_frames << '\n';
102  // std::cout << "Reordered: " << (unsigned)meta.reordered << '\n';
103  // std::cout << "Compressed: " << (unsigned)meta.compressed << '\n';
104  // std::cout << "Number of frames considered: " << flxfrag.total_frames() << '\n';
105  // std::cout << "Fragment data size: " << frag.dataSizeBytes() << '\n';
106 
107  // for(unsigned fr = 0; fr < flxfrag.total_frames(); ++fr) {
108  // for(unsigned b = 0; b < 4; ++b) {
109  // std::cout << b << '\t' << flxfrag.coldata_convert_count(fr, b) << '\t';
110  // }
111  // std::cout << '\n';
112  // }
113  // std::cout << "\n\n";
114 
115  // // Save fragment to file.
116  // std::string frag_number = std::to_string(i);
117  // frag_number = std::string(4 - frag_number.size(), '0') + frag_number;
118 
119  // std::string filename = "run/run003311_0001_" + frag_number + ".dat";
120  // // std::cout << "Writing to " << filename << ".\n";
121  // std::ofstream ofile(filename);
122  // artdaq::Fragment frag = flxdec.Fragment(i);
123  // ofile.write(reinterpret_cast<char const*>(frag.dataBeginBytes())+8*4, frag.dataSizeBytes()-8*4);
124  // ofile.close();
125 
126  // dune::FelixFragment flxfrag(frag);
127  // artdaq::Fragment reordfrag = dune::FelixReorder(frag.dataBeginBytes()+8*4,
128  // (frag.dataSizeBytes()-8*4) / 464);
129 
130  // std::string reordfilename = filename.insert(filename.size()-4, "-reordered");
131  // // std::cout << "Writing to " << reordfilename << ".\n";
132  // std::ofstream reordfile(reordfilename);
133  // reordfile.write(reinterpret_cast<char const*>(reordfrag.dataBeginBytes()),
134  // reordfrag.dataSizeBytes());
135  // reordfile.close();
136 
137  // std::cout << i << '\t' << (unsigned)flxfrag.crate_no() << '\n';
138  }
139  // std::cout << "Starting checks.\n";
140  // flxdec.check_all_timestamps();
141  // flxdec.check_all_CCCs();
142  // flxdec.check_all_IDs();
143 
144  // artdaq::Fragment frag = flxdec.Fragment(0);
145  // dune::FelixFragment flxfrag(frag);
146  // std::cout << (unsigned)flxfrag.crate_no() << " " << (unsigned)flxfrag.slot_no() << " "
147  // << (unsigned)flxfrag.fiber_no() << '\n';
148 
149  // Print RMS values to file.
150  // flxdec.calculateNoiseRMS("RMSnoise.dat");
151 
152  // // Print frames 4,5,6 of the 8th fragment.
153  // flxdec.printFrames(3, 5, 7);
154 }
155 
156 BOOST_AUTO_TEST_SUITE_END()
157 
158 #pragma GCC diagnostic pop
uint8_t slot_no(const unsigned &frame_ID=0) const
std::string string
Definition: nybbler.cc:12
uint8_t crate_no(const unsigned &frame_ID=0) const
artdaq::Fragment Fragment(const size_t &frag_num) const
Definition: FelixDecode.hh:243
string filename
Definition: train.py:213
size_t total_fragments() const
Definition: FelixDecode.hh:59
uint8_t fiber_no(const unsigned &frame_ID=0) const
BOOST_AUTO_TEST_CASE(BaselineTest)
uint64_t timestamp(const unsigned &frame_ID=0) const