gdata
Loading...
Searching...
No Matches
gFrameDataCollection.h
Go to the documentation of this file.
1#pragma once
2
30#include "gFrameHeader.h"
31#include "gIntegralPayload.h"
33#include <vector>
34
49{
50public:
64 GFrameDataCollection(GFrameHeader* header, std::shared_ptr<GLogger> logger)
65 : log(logger), gevent_header(header) {
66 log->debug(CONSTRUCTOR, "GFrameDataCollection");
67 integralPayloads = new std::vector<GIntegralPayload*>();
68 }
69
70 // Owns raw pointers freed in the destructor: forbid copy (a shallow copy would double-free)
71 // and move (no current need; re-enable with explicit pointer-nulling move ops if required).
76
92 log->debug(DESTRUCTOR, "GFrameDataCollection");
93 delete gevent_header;
94 for (auto* payload : *integralPayloads) { delete payload; }
95 delete integralPayloads;
96 }
97
98public:
122 void addIntegralPayload(std::vector<int> payload) const {
123 // Decode the fixed packed layout only when the payload size matches the contract.
124 if (payload.size() == 5) {
125 int crate = payload[0];
126 int slot = payload[1];
127 int channel = payload[2];
128 int charge = payload[3];
129 int time = payload[4];
130
131 // Create and store one owned payload object for this frame.
132 auto gpayload = new GIntegralPayload(crate, slot, channel, charge, time, log);
133 integralPayloads->push_back(gpayload);
134 log->debug(NORMAL, " adding integral payload for crate ", crate, " slot ", slot, " channel ", channel,
135 " charge ", charge, " time ", time);
136 }
137 else {
138 // Reject malformed packed payloads and keep the collection unchanged.
139 log->error(ERR_WRONGPAYLOAD, "payload size is not 5 but ", payload.size());
140 }
141 }
142
153 void addEvent(int evn);
154
166 [[nodiscard]] bool shouldWriteFrame() const;
167
177 [[nodiscard]] inline const GFrameHeader* getHeader() const { return gevent_header; }
178
190 [[nodiscard]] inline const std::vector<GIntegralPayload*>* getIntegralPayload() const { return integralPayloads; }
191
200 [[nodiscard]] inline long int getFrameID() const { return gevent_header->getFrameID(); }
201
202private:
203 std::shared_ptr<GLogger> log;
204 GFrameHeader* gevent_header = nullptr;
205 std::vector<GIntegralPayload*>* integralPayloads;
206};
Owns one frame header and the list of payloads accumulated for that frame.
GFrameDataCollection & operator=(const GFrameDataCollection &)=delete
const GFrameHeader * getHeader() const
Returns the owned frame header.
bool shouldWriteFrame() const
Placeholder decision hook indicating whether this frame should be emitted.
void addIntegralPayload(std::vector< int > payload) const
Add one integral payload to this frame.
long int getFrameID() const
Convenience getter for the frame ID.
const std::vector< GIntegralPayload * > * getIntegralPayload() const
Returns the stored payload pointers.
GFrameDataCollection(GFrameDataCollection &&)=delete
GFrameDataCollection(GFrameHeader *header, std::shared_ptr< GLogger > logger)
Construct a frame data collection.
GFrameDataCollection(const GFrameDataCollection &)=delete
GFrameDataCollection & operator=(GFrameDataCollection &&)=delete
void addEvent(int evn)
Placeholder for adding event-level information into the frame.
Stores minimal metadata for one frame-style time window.
long int getFrameID() const
Returns the frame identifier.
void debug(debug_type type, Args &&... args) const
void error(int exit_code, Args &&... args) const
Defines the GFrameHeader class, a minimal header describing a frame.
Defines GIntegralPayload, one integrated electronics payload sample.
Shared constants, schema keys, and error codes for the GData module.
constexpr int ERR_WRONGPAYLOAD
Packed payload vector has an unexpected size or layout.
CONSTRUCTOR
NORMAL
DESTRUCTOR
Stores one integrated readout payload sample.