CMS 3D CMS Logo

FWTriggerTableView.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWTriggerTableView
5 //
6 
7 // system include files
8 #include <fstream>
9 #include <cassert>
10 
11 #include <functional>
12 
13 #include "TEveWindow.h"
14 #include "TGComboBox.h"
15 #include "TGLabel.h"
16 #include "TGTextEntry.h"
17 #include "TVirtualX.h"
18 //#include "TGHorizontalFrame.h"
19 
20 // user include files
32 
34 
35 // configuration keys
36 static const std::string kColumns = "columns";
37 static const std::string kSortColumn = "sortColumn";
38 static const std::string kDescendingSort = "descendingSort";
39 
40 //
41 //
42 // constructors and destructor
43 //
45  : FWViewBase(id, 2),
46  m_regex(this, "Filter", std::string()),
47  m_process(this, "Process", std::string((id == FWViewType::FWViewType::kTableHLT) ? "HLT" : "")),
48  m_tableManager(new FWTriggerTableViewTableManager(this)),
49  m_combo(nullptr),
50  m_eveWindow(nullptr),
51  m_vert(nullptr),
52  m_tableWidget(nullptr),
53  m_processList(nullptr) {
54  m_regex.changed_.connect(std::bind(&FWTriggerTableView::dataChanged, this));
55 
56  m_eveWindow = iParent->MakeFrame(nullptr);
57  TGCompositeFrame* frame = m_eveWindow->GetGUICompositeFrame();
58 
59  m_vert = new TGVerticalFrame(frame);
60  frame->AddFrame(m_vert, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
61 
62  // have to have at least one column when call FWTableWidget constructor
63  m_columns.push_back(Column("Name"));
64 
66  m_tableWidget->SetHeaderBackgroundColor(gVirtualX->GetPixel(kWhite));
67 
68  m_tableWidget->Connect(
69  "columnClicked(Int_t,Int_t,Int_t)", "FWTriggerTableView", this, "columnSelected(Int_t,Int_t,Int_t)");
70  m_vert->AddFrame(m_tableWidget, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
71 
72  frame->MapSubwindows();
73  frame->Layout();
74  frame->MapWindow();
75 }
76 
78  // take out composite frame and delete it directly (without the timeout)
79  TGCompositeFrame* frame = m_eveWindow->GetGUICompositeFrame();
80  frame->RemoveFrame(m_vert);
81  delete m_vert;
82 
83  m_eveWindow->DestroyWindowAndSlot();
84  delete m_tableManager;
85 }
86 
88  m_backgroundColor = iColor;
89  m_tableWidget->SetBackgroundColor(gVirtualX->GetPixel(iColor));
90  m_tableWidget->SetLineSeparatorColor(gVirtualX->GetPixel(iColor == kWhite ? kBlack : kWhite));
91 }
92 
93 //
94 // const member functions
95 //
96 
97 /*
98 void
99 FWTriggerTableView::saveImageTo( const std::string& iName ) const
100 {
101  std::string fileName = iName + ".txt";
102  std::ofstream triggers( fileName.c_str() );
103 
104  triggers << m_columns[2].title << " " << m_columns[0].title << "\n";
105  for( unsigned int i = 0, vend = m_columns[0].values.size(); i != vend; ++i )
106  if( m_columns[1].values[i] == "1" )
107  triggers << m_columns[2].values[i] << "\t" << m_columns[0].values[i] << "\n";
108  triggers.close();
109  }*/
110 
112  for (std::vector<Column>::iterator i = m_columns.begin(); i != m_columns.end(); ++i)
113  (*i).values.clear();
114 
116  if (fwlite::Event* event = dynamic_cast<fwlite::Event*>(base))
117  fillTable(event);
118 
120 }
121 
122 void FWTriggerTableView::columnSelected(Int_t iCol, Int_t iButton, Int_t iKeyMod) {}
123 
124 //______________________________________________________________________________
125 
129  iTo.addKeyValue(kSortColumn, sortColumn);
130  FWConfiguration descendingSort(m_tableWidget->descendingSort());
131  iTo.addKeyValue(kDescendingSort, descendingSort);
132 }
133 
135  const FWConfiguration* main = &iFrom;
136 
137  // unnecessary nesting for old version
138  if (version() < 2) {
139  if (typeId() == FWViewType::kTableHLT)
140  main = iFrom.valueForKey("HLTTriggerTableView");
141  else
142  main = iFrom.valueForKey("L1TriggerTableView");
143  }
144 
145  const FWConfiguration* sortColumn = main->valueForKey(kSortColumn);
146  const FWConfiguration* descendingSort = main->valueForKey(kDescendingSort);
147  if (sortColumn != nullptr && descendingSort != nullptr) {
148  unsigned int sort = sortColumn->version();
149  bool descending = descendingSort->version();
150  if (sort < ((unsigned int)m_tableManager->numberOfColumns()))
151  m_tableWidget->sort(sort, descending);
152  }
153 
154  if (typeId() == FWViewType::kTableHLT) {
155  const FWConfiguration* vp = iFrom.valueForKey("Process");
156  if (vp && (vp->value() != m_process.value()))
157  m_process.setFrom(iFrom);
158  }
159 
160  {
161  const FWConfiguration* vp = iFrom.valueForKey("Filter");
162  if (vp && (vp->value() != m_regex.value()))
163  m_regex.setFrom(iFrom);
164  }
165 }
166 
167 //______________________________________________________________________________
168 
170  if (m_combo && m_processList) {
171  m_combo->RemoveAll();
172  int cnt = 0;
173  int id = -1;
174  for (std::vector<std::string>::iterator i = m_processList->begin(); i != m_processList->end(); ++i) {
175  if (m_process.value() == *i)
176  id = cnt;
177 
178  m_combo->AddEntry((*i).c_str(), cnt);
179  cnt++;
180  }
181 
182  if (id < 0) {
183  // fwLog(fwlog::kWarning) << "FWTriggerTableView: no trigger results with process name "<< m_process.value() << " is available" << std::endl;
184  m_combo->AddEntry(m_process.value().c_str(), cnt);
185  id = cnt;
186  }
187 
188  m_combo->SortByName();
189  m_combo->Select(id, false);
190  }
191 }
192 
194  m_process.set(x);
195  dataChanged();
196 }
197 
199  for (std::vector<std::string>::iterator i = m_processList->begin(); i != m_processList->end(); ++i) {
200  if (*i == m_process.value())
201  return true;
202  }
203  return false;
204 }
205 
207  gui.requestTab("Style").addParam(&m_regex);
208 
209  // resize filter frame
210  TGCompositeFrame* parent = gui.getTabContainer();
211  TGFrameElement* el = (TGFrameElement*)parent->GetList()->Last();
212  el->fLayout->SetLayoutHints(kLHintsNormal);
213  el->fFrame->Resize(180);
214 
215  // add combo for processes
216  if (typeId() == FWViewType::kTableHLT) {
217  TGHorizontalFrame* f = new TGHorizontalFrame(gui.getTabContainer());
218  gui.getTabContainer()->AddFrame(f, new TGLayoutHints(kLHintsNormal, 2, 2, 2, 2));
219 
220  m_combo = new TGComboBox(f);
221  f->AddFrame(m_combo);
222  m_combo->Resize(140, 20);
223  f->AddFrame(new TGLabel(f, "Process"), new TGLayoutHints(kLHintsLeft, 8, 2, 2, 2));
224 
225  resetCombo();
227  m_combo->Connect("Selected(const char*)", "FWTriggerTableView", tt, "processChanged(const char*)");
228  }
229 }
230 
231 void FWTriggerTableView::saveImageTo(const std::string& /*iName*/) const {
232  TString format;
233  TString data;
234  FWTextTableCellRenderer* textRenderer;
235 
236  // calculate widths
237  std::vector<size_t> widths(m_tableManager->numberOfColumns());
238 
239  for (int c = 0; c < m_tableManager->numberOfColumns(); ++c)
240  widths[c] = m_columns[c].title.size();
241 
242  for (int c = 0; c < m_tableManager->numberOfColumns(); ++c) {
243  for (int r = 0; r < m_tableManager->numberOfRows(); r++) {
244  textRenderer = (FWTextTableCellRenderer*)m_tableManager->cellRenderer(r, c); // setup cell renderer
245  size_t ss = textRenderer->data().size();
246  if (widths[c] < ss)
247  widths[c] = ss;
248  }
249  }
250 
251  int rlen = 0;
252  for (size_t c = 0; c < (size_t)m_tableManager->numberOfColumns(); ++c)
253  rlen += widths[c];
254  rlen += (m_tableManager->numberOfColumns() - 1) * 3;
255  rlen++;
256 
257  printf("\n");
258  int lastCol = m_tableManager->numberOfColumns() - 1;
259 
260  for (int c = 0; c < m_tableManager->numberOfColumns(); ++c) {
261  format.Form("%%%ds", (int)widths[c]);
262  data.Form(format, m_columns[c].title.c_str());
263  if (c == lastCol)
264  printf("%s", data.Data());
265  else
266  printf("%s | ", data.Data());
267  }
268  printf("\n");
269 
270  std::string splitter(rlen, '-');
271  std::cout << splitter << std::endl;
272 
273  for (int r = 0; r < m_tableManager->numberOfRows(); r++) {
274  for (int c = 0; c < m_tableManager->numberOfColumns(); ++c) {
275  format.Form("%%%ds", (int)widths[c]);
276  textRenderer = (FWTextTableCellRenderer*)m_tableManager->cellRenderer(r, c); // setup cell renderer
277  data.Form(format, textRenderer->data().c_str());
278  if (c == lastCol)
279  printf("%s", data.Data());
280  else
281  printf("%s | ", data.Data());
282  }
283  printf("\n");
284  }
285 }
def splitter(iterator, n)
Definition: confdb.py:11
FWTableCellRendererBase * cellRenderer(int iSortedRowNumber, int iCol) const override
std::vector< Column > m_columns
virtual void fillTable(fwlite::Event *event)=0
int numberOfColumns() const override
Number of columns in the table.
base
Main Program
Definition: newFWLiteAna.py:92
FWStringParameter m_regex
ViewerParameterGUI & requestTab(const char *)
void setFrom(const FWConfiguration &iFrom) override
void SetHeaderBackgroundColor(Pixel_t)
~FWTriggerTableView(void) override
FWTriggerTableView(TEveWindowSlot *, FWViewType::EType)
void SetLineSeparatorColor(Pixel_t)
TGCompositeFrame * m_vert
void setBackgroundColor(Color_t)
const std::string & value(unsigned int iIndex=0) const
FWTableWidget * m_tableWidget
const edm::EventBase * getCurrentEvent() const
Definition: TTTypes.h:54
void sort(UInt_t iColumn, bool iDescendingSort)
TEveWindowFrame * m_eveWindow
void setFrom(const FWConfiguration &) override
int numberOfRows() const override
Number of rows in the table.
static const std::string kDescendingSort
double f[11][100]
void populateController(ViewerParameterGUI &) const override
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
const std::string & data()
static const std::string kSortColumn
void SetBackgroundColor(Pixel_t) override
void addTo(FWConfiguration &) const override
static FWGUIManager * getGUIManager()
void processChanged(const char *)
FWStringParameter m_process
ViewerParameterGUI & addParam(const FWParameterBase *)
TGCompositeFrame * getTabContainer()
const FWConfiguration * valueForKey(const std::string &iKey) const
void columnSelected(Int_t iCol, Int_t iButton, Int_t iKeyMod)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
bool descendingSort() const
Definition: FWTableWidget.h:88
std::vector< std::string > * m_processList
Definition: main.py:1
float x
void saveImageTo(const std::string &iName) const override
FWTriggerTableViewTableManager * m_tableManager
sigc::signal< void(T)> changed_
int sortedColumn() const
Definition: FWTableWidget.h:87
FWViewType::EType typeId() const
Definition: FWViewBase.h:42
void addTo(FWConfiguration &) const override
static const std::string kColumns
Definition: event.py:1
unsigned int version() const