gdata
Loading...
Searching...
No Matches
gframe_event_example.cc
Go to the documentation of this file.
1
21// gdata
23#include "frame/gFrameHeader.h"
25
26// gemc
27#include "glogger.h"
28#include <gtouchable_options.h>
29
30// c++
31#include <iostream>
32#include <vector>
33#include <string>
34
35using namespace std;
36
37
38// TODO: run this in multiple threads and collect results in frames like in runAction
39int main(int argc, char *argv[]) {
40 // Create GOptions using gevent_data::defineOptions, which aggregates options from all gdata and gtouchable.
41 auto gopts = std::make_shared<GOptions>(argc, argv, gevent_data::defineOptions());
42
43 // Create loggers: one for gdata and one for gtouchable.
44 auto log = std::make_shared<GLogger>(gopts, SFUNCTION_NAME, GEVENTDATA_LOGGER);
45
46 auto logt = std::make_shared<GLogger>(gopts, SFUNCTION_NAME, TOUCHABLE_LOGGER);
47
48 // Define a frame with a frame ID and frame duration.
49 long int frameID = 1;
50 double frameDuration = 33.33; // Example frame duration (units could be ms or other)
51
52 // Create a frame header. The header logs its construction.
53 auto frameHeader = new GFrameHeader(frameID, frameDuration, log);
54
55 // Create the frame data collection using the header and logger.
56 auto frameData = new GFrameDataCollection(frameHeader, log);
57
58 // Create several integral payloads.
59 // Each payload vector must contain exactly 5 integers: [crate, slot, channel, charge, time]
60 vector<int> payload1 = {1, 2, 3, 100, 50};
61 vector<int> payload2 = {4, 5, 6, 200, 75};
62 vector<int> payload3 = {7, 8, 9, 150, 60};
63
64 // Add the payloads to the frame data.
65 frameData->addIntegralPayload(payload1);
66 frameData->addIntegralPayload(payload2);
67 frameData->addIntegralPayload(payload3);
68
69 // Test getters: Print the frame ID and computed time from the header.
70 cout << "Frame ID: " << frameData->getFrameID() << endl;
71 cout << "Frame Header Time: " << frameData->getHeader()->getTime() << endl;
72
73 // Retrieve the integral payloads vector.
74 const vector<GIntegralPayload*> *payloads = frameData->getIntegralPayload();
75 cout << "Number of integral payloads: " << payloads->size() << endl;
76
77 // Print details of each integral payload.
78 for (size_t i = 0; i < payloads->size(); ++i) {
79 vector<int> p = (*payloads)[i]->getPayload();
80 cout << "Payload " << (i + 1) << ": ";
81 for (auto v : p) {
82 cout << v << " ";
83 }
84 cout << endl;
85 }
86
87 // Cleanup: Delete frame data and options.
88 delete frameData; // This deletes the header and all integral payloads inside.
89
90 return EXIT_SUCCESS;
91}
constexpr const char * GEVENTDATA_LOGGER
int main(int argc, char *argv[])
GOptions defineOptions()