7#include "Packing/LDMXRoRHeader.h"
8#include "Packing/RogueFrameHeader.h"
9#include "Packing/Utility/Reader.h"
14 " rogue-extract [options] input_file.dat\n"
17 " -h,--help : print this help and exit\n"
18 " -n,--nevent : maximum number of events to unpack\n"
19 " -s,--subsystem : which subsystem\n "
20 "('ecal','hcal','ts','tdaq', 'tracker', or integer)\n"
24int main(
int argc,
char* argv[]) {
33 int subsystem{-1}, contributor{-1};
34 for (
int i_arg{1}; i_arg < argc; i_arg++) {
35 std::string arg{argv[i_arg]};
38 if (arg ==
"-h" or arg ==
"--help") {
41 }
else if (arg ==
"-n" or arg ==
"--nevent") {
42 if (i_arg + 1 == argc or argv[i_arg + 1][0] ==
'-') {
43 std::cerr <<
"The " << arg
44 <<
" parameter requires an argument after it.\n";
49 nevents = std::stoi(argv[i_arg]);
50 }
catch (
const std::invalid_argument& e) {
51 std::cerr <<
"The argument to " << arg <<
" '" << argv[i_arg]
52 <<
"' is not an integer.\n";
55 }
else if (arg ==
"-s" or arg ==
"--subsystem") {
56 if (i_arg + 1 == argc or argv[i_arg + 1][0] ==
'-') {
57 std::cerr <<
"The " << arg
58 <<
" parameter requires an argument after it.\n";
62 std::string subsys_arg{argv[i_arg]};
66 subsystem = std::stoi(subsys_arg.c_str());
67 }
catch (
const std::invalid_argument& e) {
68 std::cerr <<
"The argument to " << arg <<
" '" << subsys_arg
69 <<
"' is not 'ecal', 'hcal', 'ts', 'tdaq', 'tracker'"
70 <<
" or a positive integer.\n";
75 contributor = contrib;
78 std::cerr <<
"Unrecognized option " << arg << std::endl;
82 if (not in_file.empty()) {
83 std::cerr <<
"Can only decode one file at a time.\n";
91 if (in_file.empty()) {
92 std::cerr <<
"Need to provide a file to decode.\n";
99 std::cerr <<
"Unable to open file '" << in_file <<
"'.\n";
105 std::vector<uint8_t> bytes;
112 const int frame_end = r.tell() + frame_header.
size();
113 if (frame_header.channel() != 0) {
119 if (frame_header.probablyYaml()) {
126 if (ror_header.subsystem() != subsystem) {
132 if (contributor >= 0 and ror_header.contributor() != contributor) {
140 printf(
"frame %d\n", frame_count);
141 printf(
" channel = %d, size = %d, trailer = 0x%02x\n",
142 frame_header.channel(), frame_header.size(),
143 frame_header.trailer());
144 printf(
" vers = %d, subsys = %d, contrib = %d\n", ror_header.version(),
145 ror_header.subsystem(), ror_header.contributor());
150 for (std::size_t i_row{0}; i_row < bytes.size() / 16; i_row++) {
151 printf(
"%8lu ", i_row);
152 for (std::size_t i_byte{0}; i_byte < 16; i_byte++) {
153 printf(
"%02x ", bytes[16 * i_row + i_byte]);
159 if (nevents > 0 and event_count >= nevents) {
163 }
catch (
const std::runtime_error& e) {
164 std::cerr << e.what() <<
"\n";