pflib v3.9.4-7-gb2e7f4f
Pretty Fine HGCROC Interaction Library
Loading...
Searching...
No Matches
daq_run.h
1#pragma once
2
3#include <stdio.h>
4
5#include <fstream>
6#include <functional>
7#include <memory>
8#include <string>
9#include <vector>
10
11#include "pflib/Target.h"
12#include "pflib/logging/Logging.h"
13#include "pflib/packing/MultiSampleECONDEventPacket.h"
14#include "pflib/packing/SingleROCEventPacket.h"
15
20 public:
21 virtual void start_run() {}
22 virtual void end_run() {}
23 virtual void consume(std::vector<uint32_t>& event) = 0;
24 virtual ~DAQRunConsumer() = default;
25};
26
36void daq_run(pflib::Target* tgt, const std::string& cmd,
37 DAQRunConsumer& consumer, int nevents, int rate = 100);
38
43 std::string file_name_;
44 FILE* fp_;
45
46 public:
47 WriteToBinaryFile(const std::string& file_name);
49 virtual void consume(std::vector<uint32_t>& event) final;
50};
51
59template <class EventPacket>
61 public:
66 explicit DecodeAndWrite(int n_links);
67 virtual ~DecodeAndWrite() = default;
72 virtual void consume(std::vector<uint32_t>& event) final;
73
75 virtual void write_event(const EventPacket& ep) = 0;
76
77 protected:
79 mutable ::pflib::logging::logger the_log_;
80
81 private:
83 EventPacket ep_;
84};
85
90template <class EventPacket>
91class DecodeAndWriteToCSV : public DecodeAndWrite<EventPacket> {
95 std::function<void(std::ofstream&, const EventPacket&)> write_event_;
96
97 public:
99 const std::string& file_name,
100 std::function<void(std::ofstream&)> write_header,
101 std::function<void(std::ofstream&, const EventPacket&)> write_event,
102 int n_links);
103 virtual ~DecodeAndWriteToCSV() = default;
105 virtual void write_event(const EventPacket& ep) final;
106};
107
108template <class EventPacket>
109DecodeAndWriteToCSV<EventPacket> all_channels_to_csv(
110 const std::string& file_name);
111
128template <typename EventPacket>
129class DecodeAndBuffer : public DecodeAndWrite<EventPacket> {
130 public:
132 DecodeAndBuffer(std::size_t nevents, int n_links);
133 virtual ~DecodeAndBuffer() = default;
137 void set_buffer_size(std::size_t nevents);
139 virtual void write_event(const EventPacket& ep) override;
141 virtual void start_run() override;
142
143 private:
146};
Abstract base class for consuming event packets.
Definition daq_run.h:19
Consume an event packet, decode it, and save to buffer.
Definition daq_run.h:129
virtual void write_event(const EventPacket &ep) override
Save to buffer.
Definition daq_run.cxx:144
DecodeAndBuffer(std::size_t nevents, int n_links)
define number of events to buffer and number of links enabled
Definition daq_run.cxx:138
const std::vector< EventPacket > & get_buffer() const
get buffer
Definition daq_run.cxx:159
std::vector< EventPacket > ep_buffer_
Buffer for event packets.
Definition daq_run.h:145
void set_buffer_size(std::size_t nevents)
Set the buffer size.
Definition daq_run.cxx:165
virtual void start_run() override
Check that the buffer was read and flushed since last run.
Definition daq_run.cxx:154
specializatin of DecodeAndWrite that holds a std::ofstream for the user with functions for writing th...
Definition daq_run.h:91
virtual void write_event(const EventPacket &ep) final
call write_event with our file handle
Definition daq_run.cxx:121
std::function< void(std::ofstream &, const EventPacket &)> write_event_
function that writes row(s) to csv given an event
Definition daq_run.h:95
std::ofstream file_
output file writing to
Definition daq_run.h:93
Consume an event packet, decode it, and then do something else.
Definition daq_run.h:60
EventPacket ep_
event packet for decoding
Definition daq_run.h:83
DecodeAndWrite(int n_links)
Definition daq_run.cxx:66
mutable::pflib::logging::logger the_log_
logging for warning messages on empty events
Definition daq_run.h:79
virtual void consume(std::vector< uint32_t > &event) final
Decode the input event packet into our pflib::packing::SingleROCEventPacket and then call write_event...
Definition daq_run.cxx:89
virtual void write_event(const EventPacket &ep)=0
pure virtual function for writing out decoded event
just copy input event packets to the output file as binary
Definition daq_run.h:42
encapulating a given setup's access rules
Definition Target.h:24