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 runNumber;
17 int WRCounter;
18 int channel;
19 int seq_id;
20 int sec;
21 int coarse;
22 int frac;
24 return r >> runNumber >> WRCounter >> channel >> seq_id >> sec >> coarse >>
25 frac;
26 }
27 void add(framework::Event& event, const std::string& name) {
28 event.add(name + "RunNumber", runNumber);
29 event.add(name + "Counter", WRCounter);
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 {"
40 << "run: " << p.runNumber << ", counter: " << p.WRCounter
41 << ", channel: " << p.channel << ", seq_id: " << p.seq_id
42 << ", sec: " << p.sec << ", coarse: " << p.coarse
43 << ", frac: " << p.frac << "}");
44}
45
50 public:
51 WRRawDecoder(const std::string& name, framework::Process& process)
52 : framework::Producer(name, process) {}
53 virtual ~WRRawDecoder() = default;
54 virtual void configure(framework::config::Parameters&) final override;
55 virtual void onProcessStart() final override;
56 virtual void produce(framework::Event& event) final override;
57
58 private:
60 std::string input_file_;
62 std::string output_name_;
65
66 private:
72 TTree* tree_;
73};
74
76 input_file_ = ps.getParameter<std::string>("input_file");
77 output_name_ = ps.getParameter<std::string>("output_name");
78 ntuplize_ = ps.getParameter<bool>("ntuplize");
79
81}
82
84 if (ntuplize_) {
86 tree_ = new TTree("wrraw", "Flattened and decoded raw WR data");
87 tree_->Branch("run", &p.runNumber);
88 tree_->Branch("counter", &p.WRCounter);
89 tree_->Branch("channel", &p.channel);
90 tree_->Branch("seq_id", &p.seq_id);
91 tree_->Branch("sec", &p.sec);
92 tree_->Branch("coarse", &p.coarse);
93 tree_->Branch("frac", &p.frac);
94 }
95}
96
98 // only add and fill when file able to readout packet
99 if (file_reader_ >> p) {
100 p.add(event, output_name_);
101 tree_->Fill();
102#ifdef DEBUG
103 std::cout << p << std::endl;
104#endif
105 }
106#ifdef DEBUG
107 else {
108 std::cout << "no more events" << std::endl;
109 }
110#endif
111 return;
112} // produce
113
114} // namespace packing
115
116DECLARE_PRODUCER_NS(packing, WRRawDecoder);
Base classes for all user event processing components to extend.
#define DECLARE_PRODUCER_NS(NS, 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:41
Class which represents the process under execution.
Definition Process.h:36
Base class for a module which produces a data product.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
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
WRBinaryPacket p
packet being used for decoding
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.
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