00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <fstream>
00010 #include <cassert>
00011
00012 #include "TEveWindow.h"
00013 #include "TGComboBox.h"
00014 #include "TGLabel.h"
00015 #include "TGTextEntry.h"
00016
00017
00018
00019 #include "Fireworks/Core/interface/FWColorManager.h"
00020 #include "Fireworks/Core/interface/FWConfiguration.h"
00021 #include "Fireworks/Core/interface/FWTriggerTableView.h"
00022 #include "Fireworks/Core/interface/FWTriggerTableViewManager.h"
00023 #include "Fireworks/Core/interface/FWEventItem.h"
00024 #include "Fireworks/Core/interface/FWTriggerTableViewTableManager.h"
00025 #include "Fireworks/Core/interface/FWJobMetadataManager.h"
00026 #include "Fireworks/Core/interface/CmsShowViewPopup.h"
00027 #include "Fireworks/Core/interface/FWGUIManager.h"
00028 #include "Fireworks/Core/interface/fwLog.h"
00029 #include "Fireworks/TableWidget/interface/FWTableWidget.h"
00030
00031
00032 #include "DataFormats/FWLite/interface/Event.h"
00033
00034
00035 static const std::string kColumns = "columns";
00036 static const std::string kSortColumn = "sortColumn";
00037 static const std::string kDescendingSort = "descendingSort";
00038
00039
00040
00041
00042
00043 FWTriggerTableView::FWTriggerTableView (TEveWindowSlot* iParent, FWViewType::EType id)
00044 : FWViewBase(id, 2),
00045 m_regex(this,"Filter",std::string()),
00046 m_process(this,"Process",std::string((id == FWViewType::FWViewType::kTableHLT) ? "HLT" : "")),
00047 m_tableManager(new FWTriggerTableViewTableManager(this)),
00048 m_combo(0),
00049 m_eveWindow(0),
00050 m_vert(0),
00051 m_tableWidget(0),
00052 m_processList(0)
00053 {
00054 m_regex.changed_.connect(boost::bind(&FWTriggerTableView::dataChanged,this));
00055
00056
00057 m_eveWindow = iParent->MakeFrame(0);
00058 TGCompositeFrame *frame = m_eveWindow->GetGUICompositeFrame();
00059
00060 m_vert = new TGVerticalFrame(frame);
00061 frame->AddFrame(m_vert, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00062
00063
00064 m_columns.push_back( Column( "Name" ));
00065
00066 m_tableWidget = new FWTableWidget(m_tableManager, frame);
00067 m_tableWidget->SetHeaderBackgroundColor( gVirtualX->GetPixel( kWhite ));
00068
00069 m_tableWidget->Connect("columnClicked(Int_t,Int_t,Int_t)", "FWTriggerTableView",
00070 this, "columnSelected(Int_t,Int_t,Int_t)");
00071 m_vert->AddFrame(m_tableWidget, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00072
00073 frame->MapSubwindows();
00074 frame->Layout();
00075 frame->MapWindow();
00076 }
00077
00078 FWTriggerTableView::~FWTriggerTableView()
00079 {
00080
00081 TGCompositeFrame *frame = m_eveWindow->GetGUICompositeFrame();
00082 frame->RemoveFrame( m_vert );
00083 delete m_vert;
00084
00085 m_eveWindow->DestroyWindowAndSlot();
00086 delete m_tableManager;
00087 }
00088
00089 void
00090 FWTriggerTableView::setBackgroundColor(Color_t iColor)
00091 {
00092 m_backgroundColor = iColor;
00093 m_tableWidget->SetBackgroundColor(gVirtualX->GetPixel(iColor));
00094 m_tableWidget->SetLineSeparatorColor( gVirtualX->GetPixel(iColor == kWhite ? kBlack : kWhite));
00095 }
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 void FWTriggerTableView::dataChanged ()
00117 {
00118 for(std::vector<Column>::iterator i = m_columns.begin(); i!= m_columns.end(); ++i)
00119 (*i).values.clear();
00120
00121 edm::EventBase *base = const_cast<edm::EventBase*>(FWGUIManager::getGUIManager()->getCurrentEvent());
00122 if (fwlite::Event* event = dynamic_cast<fwlite::Event*>(base))
00123 fillTable(event);
00124
00125 m_tableManager->dataChanged();
00126 }
00127
00128 void
00129 FWTriggerTableView::columnSelected (Int_t iCol, Int_t iButton, Int_t iKeyMod)
00130 {
00131 }
00132
00133
00134
00135
00136 void
00137 FWTriggerTableView::addTo( FWConfiguration& iTo ) const
00138 {
00139 FWConfigurableParameterizable::addTo(iTo);
00140 FWConfiguration sortColumn( m_tableWidget->sortedColumn());
00141 iTo.addKeyValue( kSortColumn, sortColumn );
00142 FWConfiguration descendingSort( m_tableWidget->descendingSort());
00143 iTo.addKeyValue( kDescendingSort, descendingSort );
00144 }
00145
00146 void
00147 FWTriggerTableView::setFrom( const FWConfiguration& iFrom )
00148 {
00149 const FWConfiguration *main = &iFrom;
00150
00151
00152 if (version() < 2)
00153 {
00154 if (typeId() == FWViewType::kTableHLT)
00155 main = iFrom.valueForKey( "HLTTriggerTableView" );
00156 else
00157 main = iFrom.valueForKey( "L1TriggerTableView" );
00158 }
00159
00160 const FWConfiguration *sortColumn = main->valueForKey( kSortColumn );
00161 const FWConfiguration *descendingSort = main->valueForKey( kDescendingSort );
00162 if( sortColumn != 0 && descendingSort != 0 )
00163 {
00164 unsigned int sort = sortColumn->version();
00165 bool descending = descendingSort->version();
00166 if( sort < (( unsigned int ) m_tableManager->numberOfColumns()))
00167 m_tableWidget->sort( sort, descending );
00168 }
00169
00170 if ( typeId() == FWViewType::kTableHLT )
00171 {
00172 const FWConfiguration* vp = iFrom.valueForKey("Process" );
00173 if ( vp && (vp->value() != m_process.value()))
00174 m_process.setFrom(iFrom);
00175 }
00176
00177 {
00178 const FWConfiguration* vp = iFrom.valueForKey("Filter" );
00179 if (vp && (vp->value() != m_regex.value()))
00180 m_regex.setFrom(iFrom);
00181 }
00182 }
00183
00184
00185
00186 void
00187 FWTriggerTableView::resetCombo() const
00188 {
00189 if (m_combo && m_processList)
00190 {
00191 m_combo->RemoveAll();
00192 int cnt = 0;
00193 int id = -1;
00194 for (std::vector<std::string>::iterator i = m_processList->begin(); i != m_processList->end(); ++i)
00195 {
00196 if (m_process.value() == *i ) id = cnt;
00197
00198 m_combo->AddEntry((*i).c_str(), cnt);
00199 cnt++;
00200 }
00201
00202 if(id < 0)
00203 {
00204
00205 m_combo->AddEntry(m_process.value().c_str(), cnt);
00206 id = cnt;
00207 }
00208
00209 m_combo->SortByName();
00210 m_combo->Select(id, false);
00211 }
00212 }
00213
00214 void
00215 FWTriggerTableView::processChanged(const char* x)
00216 {
00217 m_process.set(x);
00218 dataChanged();
00219 }
00220
00221 bool
00222 FWTriggerTableView::isProcessValid() const
00223 {
00224 for (std::vector<std::string>::iterator i = m_processList->begin(); i!= m_processList->end(); ++i)
00225 {
00226 if (*i == m_process.value())
00227 return true;
00228 }
00229 return false;
00230 }
00231
00232 void
00233 FWTriggerTableView::populateController(ViewerParameterGUI& gui) const
00234 {
00235 gui.requestTab("Style").addParam(&m_regex);
00236
00237
00238 TGCompositeFrame* parent = gui.getTabContainer();
00239 TGFrameElement* el = (TGFrameElement*) parent->GetList()->Last();
00240 el->fLayout->SetLayoutHints(kLHintsNormal);
00241 el->fFrame->Resize(180);
00242
00243
00244 if (typeId() == FWViewType::kTableHLT)
00245 {
00246 TGHorizontalFrame* f = new TGHorizontalFrame(gui.getTabContainer());
00247 gui.getTabContainer()->AddFrame(f, new TGLayoutHints(kLHintsNormal, 2, 2,2,2 ));
00248
00249 m_combo = new TGComboBox(f);
00250 f->AddFrame(m_combo);
00251 m_combo->Resize(140, 20);
00252 f->AddFrame(new TGLabel(f, "Process"), new TGLayoutHints(kLHintsLeft, 8,2,2,2));
00253
00254 resetCombo();
00255 FWTriggerTableView* tt = (FWTriggerTableView*)this;
00256 m_combo->Connect("Selected(const char*)", "FWTriggerTableView", tt, "processChanged(const char*)");
00257 }
00258 }
00259
00260 void
00261 FWTriggerTableView::saveImageTo(const std::string& ) const
00262 {
00263 TString format;
00264 TString data;
00265 FWTextTableCellRenderer* textRenderer;
00266
00267
00268 std::vector<size_t> widths(m_tableManager->numberOfColumns());
00269
00270 for (int c = 0; c < m_tableManager->numberOfColumns(); ++c )
00271 widths[c] = m_columns[c].title.size();
00272
00273 for (int c = 0; c < m_tableManager->numberOfColumns(); ++c )
00274 {
00275 for (int r = 0; r < m_tableManager->numberOfRows(); r++ )
00276 {
00277 textRenderer = (FWTextTableCellRenderer*) m_tableManager->cellRenderer(r, c);
00278 size_t ss = textRenderer->data().size();
00279 if (widths[c] < ss) widths[c] = ss;
00280 }
00281 }
00282
00283 int rlen = 0;
00284 for (size_t c = 0; c < (size_t)m_tableManager->numberOfColumns(); ++c )
00285 rlen += widths[c];
00286 rlen += (m_tableManager->numberOfColumns() -1 )*3 ;
00287 rlen++;
00288
00289
00290 printf("\n");
00291 int lastCol = m_tableManager->numberOfColumns() -1;
00292
00293 for (int c = 0; c < m_tableManager->numberOfColumns(); ++c )
00294 {
00295 format.Form("%%%ds", (int)widths[c]);
00296 data.Form(format,m_columns[c].title.c_str());
00297 if (c == lastCol)
00298 printf("%s", data.Data());
00299 else
00300 printf("%s | ", data.Data());
00301 }
00302 printf("\n");
00303
00304 std::string splitter(rlen, '-');
00305 std::cout << splitter << std::endl;
00306
00307 for (int r = 0; r < m_tableManager->numberOfRows(); r++ )
00308 {
00309 for (int c = 0; c < m_tableManager->numberOfColumns(); ++c )
00310 {
00311 format.Form("%%%ds", (int)widths[c]);
00312 textRenderer = (FWTextTableCellRenderer*) m_tableManager->cellRenderer(r, c);
00313 data.Form(format, textRenderer->data().c_str());
00314 if (c == lastCol)
00315 printf("%s", data.Data());
00316 else
00317 printf("%s | ", data.Data());
00318 }
00319 printf("\n");
00320 }
00321 }