2424#include " Framework/PaletteHelpers.h"
2525#include " Framework/FrameworkGUIState.h"
2626
27+ // Simplify debugging
28+ template class std ::vector<o2::framework::DeviceMetricsInfo>;
29+
2730static inline ImVec2 operator +(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2 (lhs.x + rhs.x , lhs.y + rhs.y ); }
2831static inline ImVec2 operator -(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2 (lhs.x - rhs.x , lhs.y - rhs.y ); }
2932
@@ -296,40 +299,44 @@ void displayDeviceMetrics(const char* label, ImVec2 canvasSize, std::string cons
296299 }
297300}
298301
299- void metricsTable (gui::WorkspaceGUIState& globalGUIState, const DeviceMetricsInfo& metricsInfo)
300- {
301- // / Nothing to draw, if no metric selected.
302- if (globalGUIState.selectedMetric == -1 ) {
303- return ;
304- }
302+ struct ColumnInfo {
303+ MetricType type;
304+ int index;
305+ };
305306
306- auto currentMetricName = globalGUIState.availableMetrics [globalGUIState.selectedMetric ];
307+ void metricsTableRow (std::vector<ColumnInfo> columnInfos,
308+ std::vector<DeviceMetricsInfo> const & metricsInfos,
309+ int row)
310+ {
311+ ImGui::Text (" %d" , row);
312+ ImGui::NextColumn ();
307313
308- size_t i = DeviceMetricsHelper::metricIdxByName (currentMetricName, metricsInfo);
314+ for (size_t j = 0 ; j < columnInfos.size (); j++) {
315+ auto & info = columnInfos[j];
316+ auto & metricsInfo = metricsInfos[j];
309317
310- // We did not find any plot, skipping this.
311- if (i == metricsInfo.metricLabelsIdx .size ()) {
312- ImGui::TextUnformatted (" -" );
313- ImGui::NextColumn ();
314- return ;
315- }
316- auto & metric = metricsInfo.metrics [i];
317- switch (metric.type ) {
318- case MetricType::Int: {
319- ImGui::Text (" %i" , metricsInfo.intMetrics [metric.storeIdx ][0 ]);
320- ImGui::NextColumn ();
321- } break ;
322- case MetricType::Float: {
323- ImGui::Text (" %f" , metricsInfo.floatMetrics [metric.storeIdx ][0 ]);
324- ImGui::NextColumn ();
325- } break ;
326- case MetricType::String: {
327- ImGui::Text (" %s" , metricsInfo.stringMetrics [metric.storeIdx ][0 ].data );
328- ImGui::NextColumn ();
329- } break ;
330- default :
318+ if (info.index == -1 ) {
319+ ImGui::TextUnformatted (" -" );
331320 ImGui::NextColumn ();
332- break ;
321+ continue ;
322+ }
323+ switch (info.type ) {
324+ case MetricType::Int: {
325+ ImGui::Text (" %i (%i)" , metricsInfo.intMetrics [info.index ][row], info.index );
326+ ImGui::NextColumn ();
327+ } break ;
328+ case MetricType::Float: {
329+ ImGui::Text (" %f (%i)" , metricsInfo.floatMetrics [info.index ][row], info.index );
330+ ImGui::NextColumn ();
331+ } break ;
332+ case MetricType::String: {
333+ ImGui::Text (" %s (%i)" , metricsInfo.stringMetrics [info.index ][row].data , info.index );
334+ ImGui::NextColumn ();
335+ } break ;
336+ default :
337+ ImGui::NextColumn ();
338+ break ;
339+ }
333340 }
334341}
335342
@@ -397,6 +404,31 @@ void historyBar(gui::WorkspaceGUIState& globalGUIState, size_t rangeBegin, size_
397404 }
398405}
399406
407+ // / Calculate where to find the coliumns for a give metric
408+ std::vector<ColumnInfo> calculateTableIndex (gui::WorkspaceGUIState& globalGUIState, int selectedMetric, std::vector<DeviceMetricsInfo> const & metricsInfos)
409+ {
410+ std::vector<ColumnInfo> columns;
411+ for (size_t j = 0 ; j < globalGUIState.devices .size (); ++j) {
412+ const DeviceMetricsInfo& metricsInfo = metricsInfos[j];
413+ // / Nothing to draw, if no metric selected.
414+ if (selectedMetric == -1 ) {
415+ columns.push_back ({ MetricType::Int, -1 });
416+ continue ;
417+ }
418+ auto currentMetricName = globalGUIState.availableMetrics [selectedMetric];
419+ size_t idx = DeviceMetricsHelper::metricIdxByName (currentMetricName, metricsInfo);
420+
421+ // We did not find any plot, skipping this.
422+ if (idx == metricsInfo.metricLabelsIdx .size ()) {
423+ columns.push_back ({ MetricType::Int, -1 });
424+ continue ;
425+ }
426+ auto metric = metricsInfos[j].metrics [idx];
427+ columns.push_back ({ metric.type , static_cast <int >(metric.storeIdx ) });
428+ }
429+ return columns;
430+ };
431+
400432void displayDeviceHistograms (gui::WorkspaceGUIState& state,
401433 const std::vector<DeviceInfo>& infos, const std::vector<DeviceSpec>& devices,
402434 std::vector<DeviceControl>& controls, const std::vector<DeviceMetricsInfo>& metricsInfos)
@@ -519,7 +551,6 @@ void displayDeviceHistograms(gui::WorkspaceGUIState& state,
519551 for (size_t j = 0 ; j < state.devices .size (); ++j) {
520552 gui::DeviceGUIState& deviceGUIState = state.devices [j];
521553 const DeviceSpec& spec = devices[j];
522- const DeviceMetricsInfo& metricsInfo = metricsInfos[j];
523554
524555 ImGui::SetColumnOffset (-1 , offset);
525556 textsize = ImGui::CalcTextSize (spec.name .c_str (), NULL , true );
@@ -528,16 +559,13 @@ void displayDeviceHistograms(gui::WorkspaceGUIState& state,
528559 ImGui::NextColumn ();
529560 }
530561 ImGui::Separator ();
562+
563+ auto columns = calculateTableIndex (state, state.selectedMetric , metricsInfos);
564+
565+ // Calculate which columns we want to see.
531566 // FIXME: only one column for now.
532- for (size_t i = 0 ; i < 1 ; ++i) {
533- ImGui::Text (" %li" , i);
534- ImGui::NextColumn ();
535- for (size_t j = 0 ; j < state.devices .size (); ++j) {
536- gui::DeviceGUIState& deviceGUIState = state.devices [j];
537- const DeviceSpec& spec = devices[j];
538- const DeviceMetricsInfo& metricsInfo = metricsInfos[j];
539- metricsTable (state, metricsInfo);
540- }
567+ for (size_t i = 0 ; i < 10 ; ++i) {
568+ metricsTableRow (columns, metricsInfos, i);
541569 }
542570 ImGui::Columns (1 );
543571
0 commit comments