Skip to content

Commit 4834a33

Browse files
draft support for rogue-written file in econd-decoder
not functional, but step in the right direction
1 parent 9d8487a commit 4834a33

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

app/econd_decoder.cxx

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
#include <iostream>
6+
#include <optional>
67

78
#include "pflib/logging/Logging.h"
89
#include "pflib/packing/FileReader.h"
@@ -13,7 +14,7 @@
1314
static void usage() {
1415
std::cout << "\n"
1516
" USAGE:\n"
16-
" econd-decoder [options] NLINKS input_file.raw\n"
17+
" econd-decoder [options] NLINKS input_file.{raw,data}\n"
1718
"\n"
1819
" OPTIONS:\n"
1920
" -h,--help : print this help and exit\n"
@@ -23,6 +24,8 @@ static void usage() {
2324
"all events possible)\n"
2425
" -l,--log : logging level to printout (-1: trace up to 4: "
2526
"fatal)\n"
27+
" --is[-not]-rogue : set if the input file was written by Rogue or "
28+
"not (default is to check extension)"
2629
<< std::endl;
2730
}
2831

@@ -41,6 +44,7 @@ int main(int argc, char* argv[]) {
4144
}
4245

4346
bool trigger{false};
47+
std::optional<bool> is_rogue;
4448

4549
int n_links{-1};
4650
int nevents{-1};
@@ -94,6 +98,10 @@ int main(int argc, char* argv[]) {
9498
<< "' is not an integer.";
9599
return 1;
96100
}
101+
} else if (arg == "--is-rogue") {
102+
is_rogue = true;
103+
} else if (arg == "--is-not-rogue") {
104+
is_rogue = false;
97105
} else {
98106
pflib_log(fatal) << "Unrecognized option " << arg;
99107
return 1;
@@ -125,6 +133,22 @@ int main(int argc, char* argv[]) {
125133
return 1;
126134
}
127135

136+
if (not is_rogue.has_value()) {
137+
pflib_log(debug) << "neither --is-rogue nor --is-not-rogue provided"
138+
<< " on command line, checking extension";
139+
auto ext = in_file.substr(in_file.find_last_of("."));
140+
if (ext == ".raw") {
141+
is_rogue = false;
142+
} else if (ext == ".dat") {
143+
is_rogue = true;
144+
} else {
145+
pflib_log(warn) << "unrecognized extension '" << ext
146+
<< "' from input file '" << in_file
147+
<< "'. Guessing NOT rogue.";
148+
is_rogue = false;
149+
}
150+
}
151+
128152
if (out_file.empty()) {
129153
out_file = in_file.substr(0, in_file.find_last_of(".")) + ".csv";
130154
}
@@ -152,9 +176,47 @@ int main(int argc, char* argv[]) {
152176
// the output CSV if desired
153177
int count{0};
154178

179+
uint32_t size, flags_err_ch, header;
180+
std::vector<uint32_t> frame;
155181
while (r) {
156182
pflib_log(info) << "popping " << count << " event from stream";
157-
r >> ep;
183+
if (is_rogue.value()) {
184+
using pflib::packing::mask;
185+
if(!r >> size >> flags_err_ch) {
186+
pflib_log(error) << "failure to readout header Rogue File Frame header";
187+
return 1;
188+
}
189+
long unsigned int ch{flags_err_ch & mask<8>};
190+
if (ch != 0) {
191+
pflib_log(debug) << "skipping frame not corresponding to data (channel = " << ch << ")";
192+
r.seek(size);
193+
continue;
194+
}
195+
// Rogue channel=0 (data), peak at next word to see if its the correct subsystem
196+
if (!(r >> header)) {
197+
pflib_log(error) << "partial frame transmitted, failure to readout LDMX RoR Header";
198+
return 1;
199+
}
200+
printf("%08x\n", header);
201+
long unsigned int subsys{((header >> 16) & mask<8>)};
202+
if (subsys != 5) {
203+
pflib_log(debug) << "skipping frame not corresponding to calorimeter subsystem (subsys = " << subsys << ")";
204+
r.seek(size - 4);
205+
continue;
206+
}
207+
frame.clear();
208+
frame.push_back(header);
209+
std::size_t n_words{(size - 4)/4}, offset{1};
210+
if(!r.Reader::read(frame, n_words, offset)) {
211+
pflib_log(error) << "partial frame transmitted, failure to read frame";
212+
return 1;
213+
}
214+
ep.from(frame, true);
215+
} else {
216+
// the non-rogue writer within pflib contains nothing
217+
// except a sequence of ECOND event packets
218+
r >> ep;
219+
}
158220
pflib_log(debug) << "r.eof(): " << std::boolalpha << r.eof()
159221
<< " and bool(r): " << bool(r);
160222
ep.to_csv(o);

0 commit comments

Comments
 (0)