LDMX Software
SingleSubsystemUnpacker.cxx
1
2#include "Packing/SingleSubsystemUnpacker.h"
3
4#include "Packing/LDMXRoRHeader.h"
5#include "Packing/RogueFrameHeader.h"
6
7namespace packing {
8
10 reader_.open(ps.get<std::string>("dat_file"));
11 auto subsystem_name{ps.get<std::string>("subsystem_name")};
12 if (subsystem_name.empty()) {
13 subsystem_ = ps.get<int>("subsystem");
14 contributor_ = ps.get<int>("contributor");
15 } else {
16 auto [subsys, contrib] = packing::LDMXRoRHeader::subsystem(subsystem_name);
17 if (subsystem_ == -1) {
18 EXCEPTION_RAISE("BadName",
19 "Subsystem name '" + subsystem_name +
20 "' not 'ts', 'tdaq', 'tracker', 'ecal', 'hcal'.");
21 }
22 subsystem_ = subsys;
23 contributor_ = contrib;
24 }
25 frame_offset_ = ps.get<int>("frame_offset");
26 output_name_ = ps.get<std::string>("output_name");
27 frame_count_ = 0;
28}
29
31 static packing::RogueFrameHeader frame_header;
32 static packing::LDMXRoRHeader ror_header;
33
34 while (reader_ and not reader_.eof()) {
35 reader_ >> frame_header;
36
37 // store location of end-of-frame for skipping this frame
38 // if we fail any of the filter checks
39 const auto frame_end = reader_.tell() + frame_header.size();
40
41 if (frame_header.channel() != 0 or frame_header.probablyYaml()) {
42 // non-data channel in StreamWriter, skip
43 reader_.seek(frame_end);
44 continue;
45 }
46
47 // data channel, read RoR header
48 reader_ >> ror_header;
49 if (ror_header.subsystem() != subsystem_) {
50 // wrong subsystem ID number
51 reader_.seek(frame_end);
52 continue;
53 }
54
55 if (contributor_ >= 0 and contributor_ != ror_header.contributor()) {
56 // wrong contributor ID number
57 reader_.seek(frame_end);
58 continue;
59 }
60
61 // correct subsystem and contributor channel
64 // skip the first frame_offset_ frames that correspond to the selected
65 // subsystem
66 reader_.seek(frame_end);
67 continue;
68 }
69
70 // load data into memory, add to event, and leave
71 std::vector<uint8_t> buff;
72 if (not reader_.read(buff,
73 frame_header.size() - packing::LDMXRoRHeader::SIZE)) {
74 EXCEPTION_RAISE(
75 "MalForm", "Raw file provided was unable to read entire data frame.");
76 }
77
78 // buff has subsystem data without RoR header
79 event.add(output_name_, buff);
80 // ror_header has global RoR information
81 event.getEventHeader().setIntParameter("RoR Timestamp",
82 ror_header.timestamp());
83 // successfully unpacked an event, return from produce
84 return;
85 }
86
88 abortEvent();
89}
90
91} // namespace packing
92
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
void abortEvent()
Abort the event immediately.
Implements an event buffer system for storing event data.
Definition Event.h:42
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
the header that the LDMX DAQ Firmware block includes in the output data stream at the beginning of ea...
uint8_t subsystem() const
ID number for subsystem originating data (compiled into firmware)
static const unsigned int SIZE
size of this header in bytes
the header that the Rogue StreamWriter puts includes at the beginning of each frame.
This producer unpacks the data from the a single subsystem into a single buffer for a downstream proc...
utility::Reader reader_
raw data file we are reading
int subsystem_
subsystem ID to filter for
int frame_offset_
number of frames to skip before sending data
std::string output_name_
destination object name
void produce(framework::Event &event) override
Actually do the unpacking/decoding.
int contributor_
contributor ID to filter for
void configure(framework::config::Parameters &ps) override
Configure the unpacker and open the raw data file for IO.
int frame_count_
frame count from beginning of file for frame_offset_
void open(const std::string &file_name)
Open a file with this reader.
Definition Reader.h:36
bool eof()
check if file is done
Definition Reader.h:217
int tell()
Tell us where the reader is.
Definition Reader.h:88
Reader & read(WordType *w, std::size_t count)
Read the next 'count' words into the input handle.
Definition Reader.h:114
void seek(int off, std::ios_base::seekdir dir=std::ios::beg)
Go ("seek") a specific position in the file.
Definition Reader.h:62