Project
Loading...
Searching...
No Matches
SpyServiceHelpers.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#include <uv.h>
13#include "SpyServiceHelpers.h"
14#include "DebugGUI/imgui.h"
16#include "SpyService.h"
19#include "Headers/DataHeader.h"
20#include <cinttypes>
21#include <bitset>
22
23namespace o2::framework
24{
25struct GUIData {
27 std::vector<char*> dataParts;
28 std::vector<size_t> dataLength;
29};
30
32{
33 auto& spy = registry.get<SpyService>();
34 auto partsAlive = spy.partsAlive;
35 if (partsAlive) {
36 auto parts = spy.parts;
37
38 static std::vector<GUIData> guiData;
39 guiData.clear();
40
41 int i = 0;
42
43 while (i < parts->Size()) {
44 std::string headerString((char*)(*parts)[i].GetData(), (*parts)[i].GetSize());
45
46 GUIData guiDataPacket;
47
48 auto header = o2::header::get<o2::header::DataHeader*>(headerString.c_str());
49 guiDataPacket.header = header;
50
51 int payloadParts = (int)header->splitPayloadParts;
52
53 int lastPart = i + payloadParts;
54
55 while (i < lastPart) {
56 i++;
57 guiDataPacket.dataParts.push_back((char*)(*parts)[i].GetData());
58 guiDataPacket.dataLength.push_back((*parts)[i].GetSize());
59 }
60
61 guiData.push_back(guiDataPacket);
62
63 i++;
64 }
65
66 int selectedFrame = spy.selectedFrame;
67 int selectedData = spy.selectedData;
69
70 header = guiData.size() ? guiData[selectedFrame].header : nullptr;
71
72 if (header != nullptr) {
73 ImGui::Begin(fmt::format("Spy {}", header->dataDescription.str).c_str());
74 ImGui::CollapsingHeader("Actions", ImGuiTreeNodeFlags_DefaultOpen);
75 if (ImGui::Button("Skip 10s")) {
76 auto loop = registry.get<DeviceState>().loop;
77 spy.enableAfter = uv_now(loop) + 10000;
78 uv_stop(loop);
79 }
80
81 static int selectedHeaderIndex = 0;
82
83 if (ImGui::BeginCombo("Header", std::string(std::string(header->dataOrigin.str) + " " + std::string(header->dataDescription.str) + " " + std::to_string(selectedHeaderIndex)).c_str())) {
84 int i = 0;
85 for (const auto d : guiData) {
86 // auto h = o2::header::get<o2::header::DataHeader*>(d.header);
87 auto h = d.header;
88 if (h) {
89 std::string value = std::string(h->dataOrigin.str) + " " + std::string(h->dataDescription.str) + " " + std::to_string(i);
90 // bool isSelected = selectedFrame == i;
91 bool isSelected = selectedHeaderIndex == i;
92 if (ImGui::Selectable(value.c_str(), isSelected)) {
93 spy.selectedFrame = i;
94 selectedHeaderIndex = i;
95 }
96 if (isSelected) {
97 ImGui::SetItemDefaultFocus();
98 }
99 }
100 i++;
101 }
102 ImGui::EndCombo();
103 }
104 ImGui::Text("Selected Frame Index: %d", selectedFrame);
105 if (ImGui::CollapsingHeader("Header", ImGuiTreeNodeFlags_DefaultOpen)) {
106 ImGui::Columns(2);
107 ImGui::Text("sMagicString: %d", header->sMagicString);
108 ImGui::Text("sVersion: %d", header->sVersion);
109 ImGui::Text("sHeaderType: %s", header->sHeaderType.str);
110 ImGui::Text("sSerializationMethod: %s", header->sSerializationMethod.str);
111 ImGui::NextColumn();
112 ImGui::Text("Header size: %d", header->headerSize);
113 ImGui::Text("Payload Size: %" PRIu64, header->payloadSize);
114 ImGui::Text("Header Version: %d", header->headerVersion);
115 ImGui::Text("flagsNextHeader: %d", header->flagsNextHeader);
116 ImGui::Text("serialization: %s", header->serialization.str);
117 ImGui::Text("Data Description: %s", header->dataDescription.str);
118 ImGui::Text("Data Origin: %s", header->dataOrigin.str);
119 ImGui::Text("Run Number: %d", header->runNumber);
120 ImGui::Text("Sub Specification: %d", header->subSpecification);
121
122 ImGui::Columns(1);
123 }
124
125 auto data = guiData[selectedFrame].dataParts[selectedData];
126 auto size = guiData[selectedFrame].dataLength[selectedData];
127
128 static int rowStart = 0;
129 static int numRows = 10;
130
131 static bool displayHex = false;
132
133 if (ImGui::CollapsingHeader("Payload", ImGuiTreeNodeFlags_DefaultOpen)) {
134 ImGui::SliderInt("Rows", &numRows, 10, 40);
135 ImGui::SliderInt("Starting Row", &rowStart, 0, size / 4);
136 ImGui::Checkbox("Hexadecimal", &displayHex);
137 ImGui::Text("Number of Rows, %lu", size / 4);
138 ImGui::BeginChild("##ScrollingRegion", ImVec2(0, 430), false, ImGuiWindowFlags_HorizontalScrollbar);
139
140 if (data != nullptr && size > 0 && ImGui::BeginTable("Data", 5, ImGuiTableFlags_Borders)) {
141 ImGui::TableSetupColumn("");
142 ImGui::TableSetupColumn("#0");
143 ImGui::TableSetupColumn("#1");
144 ImGui::TableSetupColumn("#2");
145 ImGui::TableSetupColumn("#3");
146 ImGui::TableHeadersRow();
147 for (int row = rowStart; row < rowStart + numRows && row < size / 4; row++) {
148 ImGui::TableNextRow();
149 ImGui::TableSetColumnIndex(0);
150 ImGui::Text("%04d", row * 4);
151
152 for (int column = 1; column < 5; column++) {
153 std::stringstream hex;
154 if (size > row * 4) {
155 ImGui::TableSetColumnIndex(column);
156 unsigned char dataElem = data[row * 4 + (column - 1)];
157 if (displayHex) {
158 hex << std::hex << (int)dataElem;
159 } else {
160 hex << std::bitset<8>{static_cast<unsigned long long>(dataElem)};
161 }
162 }
163 std::string hexStr = hex.str();
164 if (displayHex && hexStr.length() == 1) {
165 hexStr.insert(0, "0");
166 }
167 ImGui::Text("%s", hexStr.c_str());
168 }
169 }
170 ImGui::EndTable();
171 }
172 ImGui::EndChild();
173 }
174 ImGui::End();
175 }
176 }
177}
178
179} // namespace o2::framework
std::vector< std::string > header
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events d
Class for time synchronization of RawReader instances.
static void webGUI(ServiceRegistryRef registry)
GLsizeiptr size
Definition glcorearb.h:659
GLsizei const GLfloat * value
Definition glcorearb.h:819
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
Running state information of a given device.
Definition DeviceState.h:34
std::vector< size_t > dataLength
const o2::header::DataHeader * header
std::vector< char * > dataParts
the main header struct
Definition DataHeader.h:623
std::vector< int > row