LDMX Software
WRRawDecoder.cxx
1
2#include <bitset>
3#include <iomanip>
4#include <optional>
5
7#include "Packing/Utility/Mask.h"
8#include "Packing/Utility/Reader.h"
9
10// un comment for WRRawDecoder-specific debug printouts to std::cout
11// #define DEBUG
12
13namespace packing {
14
16 int run_number_;
17 int wr_counter_;
18 int channel_;
19 int seq_id_;
20 int sec_;
21 int coarse_;
22 int frac_;
24 return r >> run_number_ >> wr_counter_ >> channel_ >> seq_id_ >> sec_ >>
25 coarse_ >> frac_;
26 }
27 void add(framework::Event& event, const std::string& name) {
28 event.add(name + "RunNumber", run_number_);
29 event.add(name + "Counter", wr_counter_);
30 event.add(name + "Channel", channel_);
31 event.add(name + "SeqId", seq_id_);
32 event.add(name + "Sec", sec_);
33 event.add(name + "Coarse", coarse_);
34 event.add(name + "Frac", frac_);
35 }
36};
37
38std::ostream& operator<<(std::ostream& os, const WRBinaryPacket& p) {
39 return (os << "WR Packet {" << "run: " << p.run_number_
40 << ", counter: " << p.wr_counter_ << ", channel: " << p.channel_
41 << ", seq_id: " << p.seq_id_ << ", sec: " << p.sec_
42 << ", coarse: " << p.coarse_ << ", frac: " << p.frac_ << "}");
43}
44
49 public:
50 WRRawDecoder(const std::string& name, framework::Process& process)
52 virtual ~WRRawDecoder() = default;
53 virtual void configure(framework::config::Parameters&) final override;
54 virtual void onProcessStart() final override;
55 virtual void produce(framework::Event& event) final override;
56
57 private:
59 std::string input_file_;
61 std::string output_name_;
64
65 private:
71 TTree* tree_;
72};
73
75 input_file_ = ps.get<std::string>("input_file");
76 output_name_ = ps.get<std::string>("output_name");
77 ntuplize_ = ps.get<bool>("ntuplize");
78
80}
81
83 if (ntuplize_) {
85 tree_ = new TTree("wrraw", "Flattened and decoded raw WR data");
86 tree_->Branch("run", &p_.run_number_);
87 tree_->Branch("counter", &p_.wr_counter_);
88 tree_->Branch("channel", &p_.channel_);
89 tree_->Branch("seq_id", &p_.seq_id_);
90 tree_->Branch("sec", &p_.sec_);
91 tree_->Branch("coarse", &p_.coarse_);
92 tree_->Branch("frac", &p_.frac_);
93 }
94}
95
97 // only add and fill when file able to readout packet
98 if (file_reader_ >> p_) {
99 p_.add(event, output_name_);
100 tree_->Fill();
101#ifdef DEBUG
102 std::cout << p << std::endl;
103#endif
104 }
105#ifdef DEBUG
106 else {
107 std::cout << "no more events" << std::endl;
108 }
109#endif
110 return;
111} // produce
112
113} // namespace packing
114
Base classes for all user event processing components to extend.
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
TDirectory * getHistoDirectory()
Access/create a directory in the histogram file for this event processor to create histograms and ana...
Implements an event buffer system for storing event data.
Definition Event.h:42
Class which represents the process under execution.
Definition Process.h:36
Base class for a module which produces a data product.
virtual void process(Event &event) final
Processing an event for a Producer is calling produce.
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
std::string output_name_
output object to put onto event bus
packing::utility::Reader file_reader_
the file reader (if we are doing that)
TTree * tree_
ntuple tree
bool ntuplize_
should we ntuplize?
virtual void onProcessStart() final override
Callback for the EventProcessor to take any necessary action when the processing of events starts,...
virtual void produce(framework::Event &event) final override
Process the event and put new data products into it.
std::string input_file_
input file
virtual void configure(framework::config::Parameters &) final override
Callback for the EventProcessor to configure itself from the given set of parameters.
WRBinaryPacket p_
packet being used for decoding
Reading a raw data file.
Definition Reader.h:19
void open(const std::string &file_name)
Open a file with this reader.
Definition Reader.h:35