CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/Fireworks/Core/src/FWTriggerTableView.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWTriggerTableView
00005 // $Id: FWTriggerTableView.cc,v 1.17 2012/09/27 16:51:25 eulisse Exp $
00006 //
00007 
00008 // system include files
00009 #include <fstream>
00010 #include <cassert>
00011 
00012 #include "TEveWindow.h"
00013 #include "TGComboBox.h"
00014 #include "TGLabel.h"
00015 #include "TGTextEntry.h"
00016 //#include "TGHorizontalFrame.h"
00017 
00018 // user include files
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 // configuration keys
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 // constructors and destructor
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    // have to have at least one column when call  FWTableWidget constructor
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    // take out composite frame and delete it directly (without the timeout)
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 // const member functions
00099 //
00100 
00101 void
00102 FWTriggerTableView::saveImageTo( const std::string& iName ) const
00103 {
00104    std::string fileName = iName + ".txt";
00105    std::ofstream triggers( fileName.c_str() );
00106 
00107    triggers << m_columns[2].title << " " << m_columns[0].title << "\n";
00108    for( unsigned int i = 0, vend = m_columns[0].values.size(); i != vend; ++i )
00109       if( m_columns[1].values[i] == "1" )
00110          triggers << m_columns[2].values[i] << "\t" << m_columns[0].values[i] << "\n";
00111    triggers.close();
00112 }
00113 
00114 
00115 void FWTriggerTableView::dataChanged ()
00116 {
00117    for(std::vector<Column>::iterator i = m_columns.begin(); i!= m_columns.end(); ++i)
00118       (*i).values.clear();
00119 
00120    edm::EventBase *base = const_cast<edm::EventBase*>(FWGUIManager::getGUIManager()->getCurrentEvent());
00121    if (fwlite::Event* event = dynamic_cast<fwlite::Event*>(base))
00122       fillTable(event);
00123 
00124    m_tableManager->dataChanged();
00125 }
00126 
00127 void
00128 FWTriggerTableView::columnSelected (Int_t iCol, Int_t iButton, Int_t iKeyMod)
00129 {
00130 }
00131 
00132 
00133 //______________________________________________________________________________
00134 
00135 void
00136 FWTriggerTableView::addTo( FWConfiguration& iTo ) const
00137 {
00138    FWConfigurableParameterizable::addTo(iTo);
00139    FWConfiguration sortColumn( m_tableWidget->sortedColumn());
00140    iTo.addKeyValue( kSortColumn, sortColumn );
00141    FWConfiguration descendingSort( m_tableWidget->descendingSort());
00142    iTo.addKeyValue( kDescendingSort, descendingSort );
00143 }
00144 
00145 void
00146 FWTriggerTableView::setFrom( const FWConfiguration& iFrom )
00147 {
00148    const FWConfiguration *main = &iFrom;
00149 
00150    // unnecessary nesting for old version
00151    if (version() < 2)
00152    {
00153       if (typeId() == FWViewType::kTableHLT)
00154          main = iFrom.valueForKey( "HLTTriggerTableView" );
00155       else
00156          main = iFrom.valueForKey( "L1TriggerTableView" );
00157    }
00158 
00159    const FWConfiguration *sortColumn = main->valueForKey( kSortColumn );
00160    const FWConfiguration *descendingSort = main->valueForKey( kDescendingSort );
00161    if( sortColumn != 0 && descendingSort != 0 ) 
00162    {
00163       unsigned int sort = sortColumn->version();
00164       bool descending = descendingSort->version();
00165       if( sort < (( unsigned int ) m_tableManager->numberOfColumns()))
00166          m_tableWidget->sort( sort, descending );
00167    }
00168 
00169    if ( typeId() == FWViewType::kTableHLT )
00170    {
00171       const FWConfiguration* vp = iFrom.valueForKey("Process" );
00172       if ( vp && (vp->value() != m_process.value()))
00173          m_process.setFrom(iFrom);
00174    } 
00175 
00176    {
00177       const FWConfiguration* vp = iFrom.valueForKey("Filter" );
00178       if (vp && (vp->value() != m_regex.value()))
00179          m_regex.setFrom(iFrom);
00180    }
00181 }
00182 
00183 //______________________________________________________________________________
00184 
00185 void
00186 FWTriggerTableView::resetCombo() const
00187 {
00188    if (m_combo && m_processList)
00189    {
00190       m_combo->RemoveAll();
00191       int cnt = 0;
00192       int id = -1;    
00193       for (std::vector<std::string>::iterator i = m_processList->begin(); i != m_processList->end(); ++i)
00194       {
00195          if (m_process.value() == *i ) id = cnt;
00196 
00197          m_combo->AddEntry((*i).c_str(), cnt);
00198          cnt++;
00199       }
00200 
00201       if(id < 0)
00202       {
00203          // fwLog(fwlog::kWarning) << "FWTriggerTableView: no trigger results with process name "<< m_process.value() << " is available" << std::endl;
00204          m_combo->AddEntry(m_process.value().c_str(), cnt);
00205          id = cnt;
00206       }
00207 
00208       m_combo->SortByName();
00209       m_combo->Select(id, false);
00210    }
00211 }
00212 
00213 void 
00214 FWTriggerTableView::processChanged(const char* x)
00215 {
00216    m_process.set(x);
00217    dataChanged();
00218 }
00219 
00220 bool
00221 FWTriggerTableView::isProcessValid() const
00222 {
00223    for (std::vector<std::string>::iterator i = m_processList->begin(); i!= m_processList->end(); ++i)
00224    {
00225       if (*i == m_process.value())
00226          return true;
00227    }
00228    return false;
00229 }
00230 
00231 void 
00232 FWTriggerTableView::populateController(ViewerParameterGUI& gui) const
00233 {
00234    gui.requestTab("Style").addParam(&m_regex);
00235 
00236    // resize filter frame
00237    TGCompositeFrame* parent =  gui.getTabContainer();
00238    TGFrameElement* el =  (TGFrameElement*) parent->GetList()->Last();
00239    el->fLayout->SetLayoutHints(kLHintsNormal);
00240    el->fFrame->Resize(180);
00241    
00242    // add combo for processes
00243    if (typeId() == FWViewType::kTableHLT)
00244    {
00245       TGHorizontalFrame* f = new TGHorizontalFrame(gui.getTabContainer());
00246       gui.getTabContainer()->AddFrame(f, new TGLayoutHints(kLHintsNormal, 2, 2,2,2 ));
00247 
00248       m_combo = new TGComboBox(f);
00249       f->AddFrame(m_combo);
00250       m_combo->Resize(140, 20);
00251       f->AddFrame(new TGLabel(f, "Process"),  new TGLayoutHints(kLHintsLeft, 8,2,2,2));
00252 
00253       resetCombo();
00254       FWTriggerTableView* tt = (FWTriggerTableView*)this;
00255       m_combo->Connect("Selected(const char*)", "FWTriggerTableView", tt, "processChanged(const char*)");
00256    }
00257 }