gdata
Loading...
Searching...
No Matches
gframe_example.cc
Go to the documentation of this file.
1
54// gdata
56#include "frame/gFrameHeader.h"
58
59// gemc
60#include "glogger.h"
61#include <gtouchable_options.h>
62
63// c++
64#include <iostream>
65#include <string>
66#include <vector>
67
68using namespace std;
69
70// TODO: Run this in multiple threads and collect results into frames, similar to a runAction-style aggregator.
71
91int main(int argc, char* argv[]) {
92 // Build the option bundle used by this example.
93 auto gopts = std::make_shared<GOptions>(argc, argv, gevent_data::defineOptions());
94
95 // Create loggers used by the frame objects and by any touchable-related code pulled in by the options bundle.
96 auto log = std::make_shared<GLogger>(gopts, SFUNCTION_NAME, GEVENTDATA_LOGGER);
97 auto logt = std::make_shared<GLogger>(gopts, SFUNCTION_NAME, TOUCHABLE_LOGGER);
98
99 long int frameID = 1;
100 double frameDuration = 33.33; // Example frame duration, with units defined by the caller.
101
102 // Create the frame header and transfer ownership into the frame collection.
103 auto frameHeader = new GFrameHeader(frameID, frameDuration, log);
104 auto frameData = new GFrameDataCollection(frameHeader, log);
105
106 // Build three packed payload vectors matching the fixed crate/slot/channel/charge/time layout.
107 vector<int> payload1 = {1, 2, 3, 100, 50};
108 vector<int> payload2 = {4, 5, 6, 200, 75};
109 vector<int> payload3 = {7, 8, 9, 150, 60};
110
111 // Insert the payloads into the frame collection.
112 frameData->addIntegralPayload(payload1);
113 frameData->addIntegralPayload(payload2);
114 frameData->addIntegralPayload(payload3);
115
116 cout << "Frame ID: " << frameData->getFrameID() << endl;
117 cout << "Frame Header Time: " << frameData->getHeader()->getTime() << endl;
118
119 const vector<GIntegralPayload*>* payloads = frameData->getIntegralPayload();
120 cout << "Number of integral payloads: " << payloads->size() << endl;
121
122 // Print each stored payload in its fixed exported order.
123 for (size_t i = 0; i < payloads->size(); ++i) {
124 vector<int> p = (*payloads)[i]->getPayload();
125 cout << "Payload " << (i + 1) << ": ";
126 for (auto v : p) {
127 cout << v << " ";
128 }
129 cout << endl;
130 }
131
132 delete frameData; // Deletes the header and all payloads owned by the collection.
133
134 return EXIT_SUCCESS;
135}
136
137
Owns one frame header and the list of payloads accumulated for that frame.
Stores minimal metadata for one frame-style time window.
Defines GEventDataCollection, the event-level aggregation of detector hit data.
constexpr const char * GEVENTDATA_LOGGER
Defines GFrameDataCollection, a container for frame-level integrated payloads.
Defines the GFrameHeader class, a minimal header describing a frame.
#define SFUNCTION_NAME
constexpr const char * TOUCHABLE_LOGGER
auto defineOptions() -> GOptions
Aggregates the option groups needed by event-level data containers.
int main(int argc, char *argv[])