CMS 3D CMS Logo

FWTableViewTableManager.cc
Go to the documentation of this file.
1 
2 #include <cmath>
3 #include <sstream>
4 #include <cassert>
5 
6 #include "TClass.h"
7 #include "TGClient.h"
8 #include "TVirtualX.h"
9 
15 
18 
20  : m_view(view),
21  m_graphicsContext(nullptr),
22  m_renderer(nullptr),
23  m_rowContext(nullptr),
24  m_rowRenderer(nullptr),
25  m_tableFormats(nullptr),
26  m_caughtExceptionInCellRender(false) {
27  GCValues_t gc = *(m_view->m_tableWidget->GetWhiteGC().GetAttributes());
28  m_graphicsContext = gClient->GetResourcePool()->GetGCPool()->GetGC(&gc, kTRUE);
29  m_highlightContext = gClient->GetResourcePool()->GetGCPool()->GetGC(&gc, kTRUE);
30  m_highlightContext->SetForeground(gVirtualX->GetPixel(kBlue));
31  m_highlightContext->SetBackground(gVirtualX->GetPixel(kBlue));
32  m_renderer =
34  //m_rowContext = gClient->GetResourcePool()->GetGCPool()->GetGC(&gc,kTRUE);
35  //m_rowContext->SetForeground(gVirtualX->GetPixel(kWhite));
36  //m_rowContext->SetBackground(gVirtualX->GetPixel(kBlack));
37  m_rowFillContext = gClient->GetResourcePool()->GetGCPool()->GetGC(&gc, kTRUE);
40 }
41 
43  delete m_renderer;
44  delete m_rowRenderer;
45 }
46 
48  if (m_view->item() != nullptr)
49  return m_view->item()->size();
50  else
51  return 0;
52 }
53 
55 
56 std::vector<std::string> FWTableViewTableManager::getTitles() const {
57  unsigned int n = numberOfColumns();
58  std::vector<std::string> ret;
59  ret.reserve(n);
60  for (unsigned int i = 0; i < n; ++i) {
61  ret.push_back(m_tableFormats->at(i).name);
62  // printf("%s\n", ret.back().c_str());
63  }
64  return ret;
65 }
66 
67 int FWTableViewTableManager::unsortedRowNumber(int iSortedRowNumber) const {
68  if (iSortedRowNumber >= (int)m_sortedToUnsortedIndices.size())
69  return 0;
70  return m_sortedToUnsortedIndices[iSortedRowNumber];
71 }
72 
73 FWTableCellRendererBase *FWTableViewTableManager::cellRenderer(int iSortedRowNumber, int iCol) const {
74  const int realRowNumber = unsortedRowNumber(iSortedRowNumber);
75  if (m_view->item() != nullptr && m_view->item()->size() && m_view->item()->modelData(realRowNumber) != nullptr &&
76  iCol < (int)m_evaluators.size()) {
77  double ret;
78  try {
79  // printf("iCol %d, size %d\n", iCol, m_evaluators.size());
80  ret = m_evaluators[iCol].evalExpression(m_view->item()->modelData(realRowNumber));
81  } catch (...) {
83  fwLog(fwlog::kError) << "Error: caught exception in the cell renderer while evaluating an expression. Return "
84  "-999. Error is suppressed in future\n";
85  }
87  ret = -999;
88  }
89  int precision = m_tableFormats->at(iCol).precision;
90  char s[100];
91  char fs[100];
92  switch (precision) {
94  snprintf(s, sizeof(s), "%d", int(rint(ret)));
95  break;
97  snprintf(s, sizeof(s), "0x%x", int(rint(ret)));
98  break;
100  snprintf(s, sizeof(s), int(rint(ret)) != 0 ? "true" : "false");
101  break;
102  default:
103  snprintf(fs, sizeof(fs), "%%.%df", precision);
104  snprintf(s, sizeof(s), fs, ret);
105  break;
106  }
107  if (not m_view->item()->modelInfo(realRowNumber).isSelected()) {
108  if (m_view->item()->modelInfo(realRowNumber).displayProperties().isVisible())
109  if (m_view->m_manager->colorManager().background() == kBlack) {
110  m_graphicsContext->SetForeground(gVirtualX->GetPixel(kWhite));
111  } else {
112  m_graphicsContext->SetForeground(gVirtualX->GetPixel(kBlack));
113  }
114  else {
115  if (m_view->m_manager->colorManager().background() == kBlack) {
116  m_graphicsContext->SetForeground(0x888888);
117  } else {
118  m_graphicsContext->SetForeground(0x888888);
119  }
120  }
122  } else {
123  m_graphicsContext->SetForeground(0xffffff);
125  }
126  m_renderer->setData(s, m_view->item()->modelInfo(realRowNumber).isSelected());
127  } else {
128  m_renderer->setData("invalid", false);
129  }
130  return m_renderer;
131 }
132 
133 namespace {
134  struct itemOrderGt {
135  bool operator()(const std::pair<bool, double> &i1, const std::pair<bool, double> &i2) const {
136  // sort first by visibility
137  if (i1.first and not i2.first)
138  return true;
139  if (i2.first and not i1.first)
140  return false;
141  // then by value
142  else
143  return i1.second > i2.second;
144  }
145  };
146  struct itemOrderLt {
147  bool operator()(const std::pair<bool, double> &i1, const std::pair<bool, double> &i2) const {
148  // sort first by visibility
149  if (i1.first and not i2.first)
150  return true;
151  if (i2.first and not i1.first)
152  return false;
153  // then by value
154  else
155  return i1.second < i2.second;
156  }
157  };
158  template <typename S>
159  void doSort(const FWEventItem &iItem,
160  int iCol,
161  const std::vector<FWExpressionEvaluator> &evaluators,
162  std::multimap<std::pair<bool, double>, int, S> &iMap,
163  std::vector<int> &oNewSort) {
164  int size = iItem.size();
165  for (int index = 0; index < size; ++index) {
166  double ret;
167  try {
168  // printf("iCol %d, size %d\n", iCol, m_evaluators.size());
169  ret = evaluators[iCol].evalExpression(iItem.modelData(index));
170  } catch (...) {
171  ret = -999;
172  }
173  iMap.insert(std::make_pair(std::make_pair(iItem.modelInfo(index).displayProperties().isVisible(), ret), index));
174  }
175  std::vector<int>::iterator itVec = oNewSort.begin();
176  for (typename std::multimap<std::pair<bool, double>, int, S>::iterator it = iMap.begin(), itEnd = iMap.end();
177  it != itEnd;
178  ++it, ++itVec) {
179  *itVec = it->second;
180  }
181  }
182 } // namespace
183 
184 void FWTableViewTableManager::implSort(int iCol, bool iSortOrder) {
185  static const bool sort_down = true;
186  if (iCol >= (int)m_evaluators.size())
187  return;
188  if (nullptr != m_view->item()) {
189  // printf("sorting %s\n", iSortOrder == sort_down ? "down" : "up");
190  if (iSortOrder == sort_down) {
191  std::multimap<std::pair<bool, double>, int, itemOrderGt> s;
192  doSort(*m_view->item(), iCol, m_evaluators, s, m_sortedToUnsortedIndices);
193  } else {
194  std::multimap<std::pair<bool, double>, int, itemOrderLt> s;
195  doSort(*m_view->item(), iCol, m_evaluators, s, m_sortedToUnsortedIndices);
196  }
197  }
199 }
200 
202  if (nullptr != m_view->item()) {
203  std::vector<int> visible;
204  visible.reserve(m_view->item()->size());
205  std::vector<int> invisible;
206  invisible.reserve(m_view->item()->size());
208  m_sortedToUnsortedIndices.reserve(m_view->item()->size());
209  for (int i = 0; i < static_cast<int>(m_view->item()->size()); ++i) {
211  visible.push_back(i);
212  else
213  invisible.push_back(i);
214  }
215  m_sortedToUnsortedIndices.insert(m_sortedToUnsortedIndices.end(), visible.begin(), visible.end());
216  m_sortedToUnsortedIndices.insert(m_sortedToUnsortedIndices.end(), invisible.begin(), invisible.end());
218  } else {
220  }
222 }
223 
225  if (m_view->m_iColl == -1) {
226  //printf("what should I do with collection -1?\n");
227  m_evaluators.clear();
228  return;
229  }
231  if (nullptr == item) {
232  return;
233  }
234  std::vector<FWExpressionEvaluator> &ev = m_evaluators;
235  ev.clear();
236  for (std::vector<FWTableViewManager::TableEntry>::const_iterator i = m_tableFormats->begin(),
237  end = m_tableFormats->end();
238  i != end;
239  ++i) {
240  try {
241  ev.push_back(FWExpressionEvaluator(i->expression, item->modelType()->GetName()));
242  } catch (...) {
243  fwLog(fwlog::kError) << "expression " << i->expression << " is not valid, skipping\n";
244  ev.push_back(FWExpressionEvaluator("0", item->modelType()->GetName()));
245  }
246  }
247  //printf("Got evaluators\n");
248 }
249 
250 bool FWTableViewTableManager::hasRowHeaders() const { return true; }
252  const int realRowNumber = unsortedRowNumber(iSortedRowNumber);
253  if (m_view->item() != nullptr && m_view->item()->size() && m_view->item()->modelData(realRowNumber) != nullptr) {
254  if (m_view->item()->modelInfo(realRowNumber).displayProperties().isVisible()) {
255  if (m_view->m_manager->colorManager().background() == kBlack) {
256  m_graphicsContext->SetForeground(gVirtualX->GetPixel(kWhite));
257  } else {
258  m_graphicsContext->SetForeground(gVirtualX->GetPixel(kBlack));
259  }
260  m_rowFillContext->SetForeground(
261  gVirtualX->GetPixel(m_view->item()->modelInfo(realRowNumber).displayProperties().color()));
262  } else {
263  m_graphicsContext->SetForeground(0x888888);
265  }
266 
267  std::ostringstream s;
268  s << realRowNumber;
269  m_rowRenderer->setData(s.str());
270  } else {
271  m_rowRenderer->setData("");
272  }
273  return m_rowRenderer;
274 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:543
FWTableViewTableManager::cellRenderer
FWTableCellRendererBase * cellRenderer(int iSortedRowNumber, int iCol) const override
Definition: FWTableViewTableManager.cc:73
FWTableViewTableManager::dataChanged
void dataChanged()
Called if mouse button pressed in Row Header, defaults is to do nothing.
Definition: FWTableViewTableManager.cc:201
testProducerWithPsetDescEmpty_cfi.i2
i2
Definition: testProducerWithPsetDescEmpty_cfi.py:46
fwLog
#define fwLog(_level_)
Definition: fwLog.h:45
FWTableViewTableManager::m_caughtExceptionInCellRender
bool m_caughtExceptionInCellRender
Definition: FWTableViewTableManager.h:115
FWTableViewTableManager.h
FWEventItem::modelInfo
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:446
FWDisplayProperties::isVisible
bool isVisible() const
Definition: FWDisplayProperties.h:51
mps_fire.i
i
Definition: mps_fire.py:428
boostedTaus_cff.precision
precision
Definition: boostedTaus_cff.py:29
FWTableView::m_iColl
int m_iColl
Definition: FWTableView.h:89
funct::false
false
Definition: Factorize.h:29
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
FWTableViewTableManager::m_tableFormats
std::vector< FWTableViewManager::TableEntry > * m_tableFormats
Definition: FWTableViewTableManager.h:110
FWFramedTextTableCellRenderer::setData
void setData(const std::string &)
Definition: FWFramedTextTableCellRenderer.cc:86
FWViewManagerBase::colorManager
FWColorManager & colorManager() const
Definition: FWViewManagerBase.cc:123
FWTableWidget::dataChanged
void dataChanged()
Definition: FWTableWidget.cc:425
testProducerWithPsetDescEmpty_cfi.i1
i1
Definition: testProducerWithPsetDescEmpty_cfi.py:45
FWTableViewTableManager::m_rowFillContext
TGGC * m_rowFillContext
Definition: FWTableViewTableManager.h:106
FWTableViewManager::items
const Items & items() const
Definition: FWTableViewManager.h:70
FWTableViewTableManager::FWTableViewTableManager
FWTableViewTableManager(const FWTableView *)
Definition: FWTableViewTableManager.cc:19
cms::cuda::assert
assert(be >=bs)
FWTableView
Definition: FWTableView.h:50
FWTableViewTableManager::m_rowRenderer
FWFramedTextTableCellRenderer * m_rowRenderer
Definition: FWTableViewTableManager.h:107
FWEventItem::modelData
const void * modelData(int iIndex) const
Definition: FWEventItem.cc:466
FWTableViewTableManager::m_sortedToUnsortedIndices
std::vector< int > m_sortedToUnsortedIndices
Definition: FWTableViewTableManager.h:98
FWTableViewTableManager::m_evaluators
std::vector< FWExpressionEvaluator > m_evaluators
Definition: FWTableViewTableManager.h:109
FWTableView::m_manager
FWTableViewManager * m_manager
Definition: FWTableView.h:90
FWTableView.h
FWTextTableCellRenderer
Definition: FWTextTableCellRenderer.h:32
FWTableViewTableManager::unsortedRowNumber
int unsortedRowNumber(int iSortedRowNumber) const override
Definition: FWTableViewTableManager.cc:67
FWTableViewTableManager::m_graphicsContext
TGGC * m_graphicsContext
Definition: FWTableViewTableManager.h:101
FWDisplayProperties::color
Color_t color() const
Definition: FWDisplayProperties.h:47
FWTableViewTableManager::~FWTableViewTableManager
~FWTableViewTableManager() override
Definition: FWTableViewTableManager.cc:42
FWFramedTextTableCellRenderer
Definition: FWFramedTextTableCellRenderer.h:33
FWTableViewTableManager::implSort
void implSort(int iCol, bool iSortOrder) override
Definition: FWTableViewTableManager.cc:184
FWTextTableCellRenderer::kJustifyRight
Definition: FWTextTableCellRenderer.h:37
alignCSCRings.s
s
Definition: alignCSCRings.py:92
FWTableViewTableManager::numberOfRows
int numberOfRows() const override
Number of rows in the table.
Definition: FWTableViewTableManager.cc:47
FWTableView::m_tableWidget
FWTableWidget * m_tableWidget
Definition: FWTableView.h:92
FWTableViewTableManager::rowHeader
FWTableCellRendererBase * rowHeader(int iSortedRowNumber) const override
Returns the renderer for the row header for the sorted row number iSortedRowNumber.
Definition: FWTableViewTableManager.cc:251
FWColorManager.h
FWTableWidget.h
mps_fire.end
end
Definition: mps_fire.py:242
FWTableViewTableManager::updateEvaluators
void updateEvaluators()
Definition: FWTableViewTableManager.cc:224
FWTableViewManager::TableEntry::INT_HEX
Definition: FWTableViewManager.h:44
FWTextTableCellRenderer::setGraphicsContext
void setGraphicsContext(const TGGC *iContext)
Definition: FWTextTableCellRenderer.h:57
FWTableViewTableManager::m_renderer
FWTextTableCellRenderer * m_renderer
Definition: FWTableViewTableManager.h:103
FWTableManagerBase::dataChanged
void dataChanged()
Classes which inherit from FWTableManagerBase must call this when their underlying data changes.
Definition: FWTableManagerBase.cc:63
FWTableViewTableManager::getTitles
std::vector< std::string > getTitles() const override
returns the title names for each column
Definition: FWTableViewTableManager.cc:56
FWFramedTextTableCellRenderer::kJustifyRight
Definition: FWFramedTextTableCellRenderer.h:38
FWTableView::item
const FWEventItem * item() const
Definition: FWTableView.cc:545
FWEventItem::ModelInfo::isSelected
bool isSelected() const
Definition: FWEventItem.h:65
createfilelist.int
int
Definition: createfilelist.py:10
FWTableCellRendererBase
Definition: FWTableCellRendererBase.h:44
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
fwLog.h
FWEventItem.h
FWEventItem::ModelInfo::displayProperties
const FWDisplayProperties & displayProperties() const
Definition: FWEventItem.h:64
FWTableViewTableManager::numberOfColumns
int numberOfColumns() const override
Number of columns in the table.
Definition: FWTableViewTableManager.cc:54
FWTableViewTableManager::m_view
const FWTableView * m_view
Definition: FWTableViewTableManager.h:100
FWTextTableCellRenderer::setData
void setData(const std::string &, bool isSelected)
Definition: FWTextTableCellRenderer.cc:98
FWEventItem
Definition: FWEventItem.h:56
FWTableViewTableManager::m_highlightContext
TGGC * m_highlightContext
Definition: FWTableViewTableManager.h:102
FWFramedTextTableCellRenderer.h
ev
bool ev
Definition: Hydjet2Hadronizer.cc:97
S
Definition: CSCDBL1TPParametersExtended.h:16
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
FWExpressionEvaluator
Definition: FWExpressionEvaluator.h:33
fwlog::kError
Definition: fwLog.h:35
FWTableViewManager::TableEntry::INT
Definition: FWTableViewManager.h:44
FWTableViewManager::TableEntry::BOOL
Definition: FWTableViewManager.h:44
FWColorManager::background
Color_t background() const
Definition: FWColorManager.h:55
FWTableViewTableManager::hasRowHeaders
bool hasRowHeaders() const override
require all cells to be the same height
Definition: FWTableViewTableManager.cc:250
FWEventItem::size
size_t size() const
Definition: FWEventItem.cc:457
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443