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