Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-07-18 23:17:43

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     FWTriggerTableView
0005 //
0006 
0007 // system include files
0008 #include <fstream>
0009 #include <cassert>
0010 
0011 #include <functional>
0012 
0013 #include "TEveWindow.h"
0014 #include "TGComboBox.h"
0015 #include "TGLabel.h"
0016 #include "TGTextEntry.h"
0017 #include "TVirtualX.h"
0018 //#include "TGHorizontalFrame.h"
0019 
0020 // user include files
0021 #include "Fireworks/Core/interface/FWColorManager.h"
0022 #include "Fireworks/Core/interface/FWConfiguration.h"
0023 #include "Fireworks/Core/interface/FWTriggerTableView.h"
0024 #include "Fireworks/Core/interface/FWTriggerTableViewManager.h"
0025 #include "Fireworks/Core/interface/FWEventItem.h"
0026 #include "Fireworks/Core/interface/FWTriggerTableViewTableManager.h"
0027 #include "Fireworks/Core/interface/FWJobMetadataManager.h"
0028 #include "Fireworks/Core/interface/CmsShowViewPopup.h"
0029 #include "Fireworks/Core/interface/FWGUIManager.h"
0030 #include "Fireworks/Core/interface/fwLog.h"
0031 #include "Fireworks/TableWidget/interface/FWTableWidget.h"
0032 
0033 #include "DataFormats/FWLite/interface/Event.h"
0034 
0035 // configuration keys
0036 //static const std::string kColumns = "columns";
0037 static const std::string kSortColumn = "sortColumn";
0038 static const std::string kDescendingSort = "descendingSort";
0039 
0040 //
0041 //
0042 // constructors and destructor
0043 //
0044 FWTriggerTableView::FWTriggerTableView(TEveWindowSlot* iParent, FWViewType::EType id)
0045     : FWViewBase(id, 2),
0046       m_regex(this, "Filter", std::string()),
0047       m_process(this, "Process", std::string((id == FWViewType::FWViewType::kTableHLT) ? "HLT" : "")),
0048       m_tableManager(new FWTriggerTableViewTableManager(this)),
0049       m_combo(nullptr),
0050       m_eveWindow(nullptr),
0051       m_vert(nullptr),
0052       m_tableWidget(nullptr),
0053       m_processList(nullptr) {
0054   m_regex.changed_.connect(std::bind(&FWTriggerTableView::dataChanged, this));
0055 
0056   m_eveWindow = iParent->MakeFrame(nullptr);
0057   TGCompositeFrame* frame = m_eveWindow->GetGUICompositeFrame();
0058 
0059   m_vert = new TGVerticalFrame(frame);
0060   frame->AddFrame(m_vert, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
0061 
0062   // have to have at least one column when call  FWTableWidget constructor
0063   m_columns.push_back(Column("Name"));
0064 
0065   m_tableWidget = new FWTableWidget(m_tableManager, frame);
0066   m_tableWidget->SetHeaderBackgroundColor(gVirtualX->GetPixel(kWhite));
0067 
0068   m_tableWidget->Connect(
0069       "columnClicked(Int_t,Int_t,Int_t)", "FWTriggerTableView", this, "columnSelected(Int_t,Int_t,Int_t)");
0070   m_vert->AddFrame(m_tableWidget, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
0071 
0072   frame->MapSubwindows();
0073   frame->Layout();
0074   frame->MapWindow();
0075 }
0076 
0077 FWTriggerTableView::~FWTriggerTableView() {
0078   // take out composite frame and delete it directly (without the timeout)
0079   TGCompositeFrame* frame = m_eveWindow->GetGUICompositeFrame();
0080   frame->RemoveFrame(m_vert);
0081   delete m_vert;
0082 
0083   m_eveWindow->DestroyWindowAndSlot();
0084   delete m_tableManager;
0085 }
0086 
0087 void FWTriggerTableView::setBackgroundColor(Color_t iColor) {
0088   m_backgroundColor = iColor;
0089   m_tableWidget->SetBackgroundColor(gVirtualX->GetPixel(iColor));
0090   m_tableWidget->SetLineSeparatorColor(gVirtualX->GetPixel(iColor == kWhite ? kBlack : kWhite));
0091 }
0092 
0093 //
0094 // const member functions
0095 //
0096 
0097 /*
0098 void
0099 FWTriggerTableView::saveImageTo( const std::string& iName ) const
0100 {
0101    std::string fileName = iName + ".txt";
0102    std::ofstream triggers( fileName.c_str() );
0103 
0104    triggers << m_columns[2].title << " " << m_columns[0].title << "\n";
0105    for( unsigned int i = 0, vend = m_columns[0].values.size(); i != vend; ++i )
0106       if( m_columns[1].values[i] == "1" )
0107          triggers << m_columns[2].values[i] << "\t" << m_columns[0].values[i] << "\n";
0108    triggers.close();
0109    }*/
0110 
0111 void FWTriggerTableView::dataChanged() {
0112   for (std::vector<Column>::iterator i = m_columns.begin(); i != m_columns.end(); ++i)
0113     (*i).values.clear();
0114 
0115   edm::EventBase* base = const_cast<edm::EventBase*>(FWGUIManager::getGUIManager()->getCurrentEvent());
0116   if (fwlite::Event* event = dynamic_cast<fwlite::Event*>(base))
0117     fillTable(event);
0118 
0119   m_tableManager->dataChanged();
0120 }
0121 
0122 void FWTriggerTableView::columnSelected(Int_t iCol, Int_t iButton, Int_t iKeyMod) {}
0123 
0124 //______________________________________________________________________________
0125 
0126 void FWTriggerTableView::addTo(FWConfiguration& iTo) const {
0127   FWConfigurableParameterizable::addTo(iTo);
0128   FWConfiguration sortColumn(m_tableWidget->sortedColumn());
0129   iTo.addKeyValue(kSortColumn, sortColumn);
0130   FWConfiguration descendingSort(m_tableWidget->descendingSort());
0131   iTo.addKeyValue(kDescendingSort, descendingSort);
0132 }
0133 
0134 void FWTriggerTableView::setFrom(const FWConfiguration& iFrom) {
0135   const FWConfiguration* main = &iFrom;
0136 
0137   // unnecessary nesting for old version
0138   if (version() < 2) {
0139     if (typeId() == FWViewType::kTableHLT)
0140       main = iFrom.valueForKey("HLTTriggerTableView");
0141     else
0142       main = iFrom.valueForKey("L1TriggerTableView");
0143   }
0144 
0145   const FWConfiguration* sortColumn = main->valueForKey(kSortColumn);
0146   const FWConfiguration* descendingSort = main->valueForKey(kDescendingSort);
0147   if (sortColumn != nullptr && descendingSort != nullptr) {
0148     unsigned int sort = sortColumn->version();
0149     bool descending = descendingSort->version();
0150     if (sort < ((unsigned int)m_tableManager->numberOfColumns()))
0151       m_tableWidget->sort(sort, descending);
0152   }
0153 
0154   if (typeId() == FWViewType::kTableHLT) {
0155     const FWConfiguration* vp = iFrom.valueForKey("Process");
0156     if (vp && (vp->value() != m_process.value()))
0157       m_process.setFrom(iFrom);
0158   }
0159 
0160   {
0161     const FWConfiguration* vp = iFrom.valueForKey("Filter");
0162     if (vp && (vp->value() != m_regex.value()))
0163       m_regex.setFrom(iFrom);
0164   }
0165 }
0166 
0167 //______________________________________________________________________________
0168 
0169 void FWTriggerTableView::resetCombo() const {
0170   if (m_combo && m_processList) {
0171     m_combo->RemoveAll();
0172     int cnt = 0;
0173     int id = -1;
0174     for (std::vector<std::string>::iterator i = m_processList->begin(); i != m_processList->end(); ++i) {
0175       if (m_process.value() == *i)
0176         id = cnt;
0177 
0178       m_combo->AddEntry((*i).c_str(), cnt);
0179       cnt++;
0180     }
0181 
0182     if (id < 0) {
0183       // fwLog(fwlog::kWarning) << "FWTriggerTableView: no trigger results with process name "<< m_process.value() << " is available" << std::endl;
0184       m_combo->AddEntry(m_process.value().c_str(), cnt);
0185       id = cnt;
0186     }
0187 
0188     m_combo->SortByName();
0189     m_combo->Select(id, false);
0190   }
0191 }
0192 
0193 void FWTriggerTableView::processChanged(const char* x) {
0194   m_process.set(x);
0195   dataChanged();
0196 }
0197 
0198 bool FWTriggerTableView::isProcessValid() const {
0199   for (std::vector<std::string>::iterator i = m_processList->begin(); i != m_processList->end(); ++i) {
0200     if (*i == m_process.value())
0201       return true;
0202   }
0203   return false;
0204 }
0205 
0206 void FWTriggerTableView::populateController(ViewerParameterGUI& gui) const {
0207   gui.requestTab("Style").addParam(&m_regex);
0208 
0209   // resize filter frame
0210   TGCompositeFrame* parent = gui.getTabContainer();
0211   TGFrameElement* el = (TGFrameElement*)parent->GetList()->Last();
0212   el->fLayout->SetLayoutHints(kLHintsNormal);
0213   el->fFrame->Resize(180);
0214 
0215   // add combo for processes
0216   if (typeId() == FWViewType::kTableHLT) {
0217     TGHorizontalFrame* f = new TGHorizontalFrame(gui.getTabContainer());
0218     gui.getTabContainer()->AddFrame(f, new TGLayoutHints(kLHintsNormal, 2, 2, 2, 2));
0219 
0220     m_combo = new TGComboBox(f);
0221     f->AddFrame(m_combo);
0222     m_combo->Resize(140, 20);
0223     f->AddFrame(new TGLabel(f, "Process"), new TGLayoutHints(kLHintsLeft, 8, 2, 2, 2));
0224 
0225     resetCombo();
0226     FWTriggerTableView* tt = (FWTriggerTableView*)this;
0227     m_combo->Connect("Selected(const char*)", "FWTriggerTableView", tt, "processChanged(const char*)");
0228   }
0229 }
0230 
0231 void FWTriggerTableView::saveImageTo(const std::string& /*iName*/) const {
0232   TString format;
0233   TString data;
0234   FWTextTableCellRenderer* textRenderer;
0235 
0236   // calculate widths
0237   std::vector<size_t> widths(m_tableManager->numberOfColumns());
0238 
0239   for (int c = 0; c < m_tableManager->numberOfColumns(); ++c)
0240     widths[c] = m_columns[c].title.size();
0241 
0242   for (int c = 0; c < m_tableManager->numberOfColumns(); ++c) {
0243     for (int r = 0; r < m_tableManager->numberOfRows(); r++) {
0244       textRenderer = (FWTextTableCellRenderer*)m_tableManager->cellRenderer(r, c);  // setup cell renderer
0245       size_t ss = textRenderer->data().size();
0246       if (widths[c] < ss)
0247         widths[c] = ss;
0248     }
0249   }
0250 
0251   int rlen = 0;
0252   for (size_t c = 0; c < (size_t)m_tableManager->numberOfColumns(); ++c)
0253     rlen += widths[c];
0254   rlen += (m_tableManager->numberOfColumns() - 1) * 3;
0255   rlen++;
0256 
0257   printf("\n");
0258   int lastCol = m_tableManager->numberOfColumns() - 1;
0259 
0260   for (int c = 0; c < m_tableManager->numberOfColumns(); ++c) {
0261     format.Form("%%%ds", (int)widths[c]);
0262     data.Form(format, m_columns[c].title.c_str());
0263     if (c == lastCol)
0264       printf("%s", data.Data());
0265     else
0266       printf("%s | ", data.Data());
0267   }
0268   printf("\n");
0269 
0270   std::string splitter(rlen, '-');
0271   std::cout << splitter << std::endl;
0272 
0273   for (int r = 0; r < m_tableManager->numberOfRows(); r++) {
0274     for (int c = 0; c < m_tableManager->numberOfColumns(); ++c) {
0275       format.Form("%%%ds", (int)widths[c]);
0276       textRenderer = (FWTextTableCellRenderer*)m_tableManager->cellRenderer(r, c);  // setup cell renderer
0277       data.Form(format, textRenderer->data().c_str());
0278       if (c == lastCol)
0279         printf("%s", data.Data());
0280       else
0281         printf("%s | ", data.Data());
0282     }
0283     printf("\n");
0284   }
0285 }