-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_decode.cpp
More file actions
102 lines (93 loc) · 4.17 KB
/
Copy pathrun_decode.cpp
File metadata and controls
102 lines (93 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <array>
#include <iostream>
#include <string>
#include "src/process_events.h"
// #include <pybind11/embed.h>
int main(int argc, char *argv[]) {
// Usage: run_raw_decoder <data_file.dat> [num_events]
// num_events defaults to 3 if not supplied.
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " <data_file.dat> [num_events]\n"
<< "Example: " << argv[0]
<< " /home/pgrams/data_for_yinrui/pGRAMS_bin_441_0.dat 100\n";
return 1;
}
const std::string filename = argv[1];
const size_t num_events = (argc >= 3)
? static_cast<size_t>(std::stoul(argv[2]))
: 3;
// Make sure the python interpreter is initialized
// py::scoped_interpreter guard;
const uint16_t light_slot = 16;
const bool use_charge_roi = false;
const std::vector<uint16_t> channel_threshold(64, 0);
const bool skip_beam_roi = false;
ProcessEvents events(light_slot, use_charge_roi, channel_threshold, skip_beam_roi);
// Slot numbers every event is expected to contain. The 3 Q-FEM
// slots come from the run configuration (matched against the first
// FEM header of pGRAMS_bin_441_0.dat); update for other runs.
events.SetExpectedSlots({13, 14, 15, light_slot});
events.SetLightEventNumberOffset(-1);
events.SetCompareQFemsOnly(false);
events.OpenFile(filename);
// Sweep the requested number of events, count how many trip each error
// bit, and print a per-bit summary at the end. Also dump details for
// the first few failing events so we can see what is mismatching.
const char* kBitNames[32] = {
"missing_fem", "wrong_slot", "bad_header_tag",
"qfem_event_num_mismatch", "lfem_event_num_mismatch",
"qfem_frame_num_mismatch", "lfem_frame_num_mismatch",
"qfem_trigger_num_mismatch", "lfem_trigger_num_mismatch",
"qfem_sample_num_mismatch", "lfem_sample_num_mismatch",
"fem_status_warning", nullptr, nullptr, nullptr, nullptr,
"qfem_adc_count_mismatch", "lfem_adc_count_mismatch",
"qfem_checksum_mismatch", "lfem_checksum_mismatch",
"qfem_missing_channels", "lfem_wrong_channels",
"qfem_untypical_adc_count", "lfem_untypical_adc_count",
"lfem_roi_inconsistent", "qfem_stuck_channel",
nullptr, nullptr, nullptr, nullptr, nullptr,
"event_number_gap"
};
std::array<size_t, 32> bit_counts{};
size_t n_processed = 0;
size_t n_with_errors = 0;
size_t n_dumped = 0;
constexpr size_t max_dump = 5;
for (size_t evt = 0; evt < num_events; evt++) {
if (!events.GetEvent()) break;
n_processed++;
const uint32_t err = events.getErrorBitword();
if (err == 0) continue;
n_with_errors++;
for (uint32_t bit = 0; bit < 32; bit++) {
if (err & (1u << bit)) bit_counts[bit]++;
}
if (n_dumped < max_dump) {
auto &es = events.GetEventStruct();
std::cout << "--- evt " << evt
<< " err_bitword=0x" << std::hex << err << std::dec << " ---\n";
std::cout << " slot : ";
for (auto v : es.slot_number) std::cout << v << " ";
std::cout << "\n event_number : ";
for (auto v : es.event_number) std::cout << v << " ";
std::cout << "\n event_frame# : ";
for (auto v : es.event_frame_number) std::cout << v << " ";
std::cout << "\n trig_frame# : ";
for (auto v : es.trigger_frame_number) std::cout << v << " ";
std::cout << "\n trig_sample : ";
for (auto v : es.trigger_sample) std::cout << v << " ";
std::cout << std::endl;
n_dumped++;
}
}
std::cout << "Processed " << n_processed << " events, "
<< n_with_errors << " had errors.\n";
std::cout << "Per-bit counts (bit -> count):\n";
for (uint32_t bit = 0; bit < 32; bit++) {
if (bit_counts[bit] == 0) continue;
std::cout << " bit " << (bit + 1);
if (kBitNames[bit]) std::cout << "-" << kBitNames[bit];
std::cout << " : " << bit_counts[bit] << "\n";
}
return 0;
}