gdata
Loading...
Searching...
No Matches
gFrameDataCollection.h
Go to the documentation of this file.
1#pragma once
2
29
30#include "gFrameHeader.h"
31#include "gIntegralPayload.h"
33#include <vector>
34
43
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(
135 NORMAL, " adding integral payload for crate %1 slot %2 channel %3 charge %4 time %5", crate,
136 slot, channel, charge, time);
137 }
138 else {
139 // Reject malformed packed payloads and keep the collection unchanged.
140 log->error(ERR_WRONGPAYLOAD, "payload size is not 5 but %1", payload.size());
141 }
142 }
143
154 void addEvent(int evn);
155
167 [[nodiscard]] bool shouldWriteFrame() const;
168
178 [[nodiscard]] inline const GFrameHeader* getHeader() const { return gevent_header; }
179
191 [[nodiscard]] inline const std::vector<GIntegralPayload*>* getIntegralPayload() const { return integralPayloads; }
192
201 [[nodiscard]] inline long int getFrameID() const { return gevent_header->getFrameID(); }
202
203private:
204 std::shared_ptr<GLogger> log;
205 GFrameHeader* gevent_header = nullptr;
206 std::vector<GIntegralPayload*>* integralPayloads;
207};
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.
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.