CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/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.16 2011/02/16 18:38:36 amraktad Exp $
00006 //
00007 
00008 // system include files
00009 #include <fstream>
00010 
00011 #include "TEveWindow.h"
00012 #include "TGComboBox.h"
00013 #include "TGLabel.h"
00014 #include "TGTextEntry.h"
00015 //#include "TGHorizontalFrame.h"
00016 
00017 // user include files
00018 #include "Fireworks/Core/interface/FWColorManager.h"
00019 #include "Fireworks/Core/interface/FWConfiguration.h"
00020 #include "Fireworks/Core/interface/FWTriggerTableView.h"
00021 #include "Fireworks/Core/interface/FWTriggerTableViewManager.h"
00022 #include "Fireworks/Core/interface/FWEventItem.h"
00023 #include "Fireworks/Core/interface/FWTriggerTableViewTableManager.h"
00024 #include "Fireworks/Core/interface/FWJobMetadataManager.h"
00025 #include "Fireworks/Core/interface/CmsShowViewPopup.h"
00026 #include "Fireworks/Core/interface/FWGUIManager.h"
00027 #include "Fireworks/Core/interface/fwLog.h"
00028 #include "Fireworks/TableWidget/interface/FWTableWidget.h"
00029 
00030 
00031 #include "DataFormats/FWLite/interface/Event.h"
00032 
00033 // configuration keys
00034 static const std::string kColumns = "columns";
00035 static const std::string kSortColumn = "sortColumn";
00036 static const std::string kDescendingSort = "descendingSort";
00037 
00038 //
00039 //
00040 // constructors and destructor
00041 //
00042 FWTriggerTableView::FWTriggerTableView (TEveWindowSlot* iParent, FWViewType::EType id)
00043    : FWViewBase(id, 2),
00044      m_regex(this,"Filter",std::string()),
00045      m_process(this,"Process",std::string((id == FWViewType::FWViewType::kTableHLT) ? "HLT" : "")),
00046      m_tableManager(new FWTriggerTableViewTableManager(this)),
00047      m_combo(0),
00048      m_eveWindow(0),
00049      m_vert(0),
00050      m_tableWidget(0),
00051      m_processList(0)
00052 {  
00053    m_regex.changed_.connect(boost::bind(&FWTriggerTableView::dataChanged,this));
00054 
00055 
00056    m_eveWindow = iParent->MakeFrame(0);
00057    TGCompositeFrame *frame = m_eveWindow->GetGUICompositeFrame();
00058 
00059    m_vert = new TGVerticalFrame(frame);
00060    frame->AddFrame(m_vert, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00061 
00062    // have to have at least one column when call  FWTableWidget constructor
00063    m_columns.push_back( Column( "Name" ));
00064 
00065    m_tableWidget = new FWTableWidget(m_tableManager, frame); 
00066    m_tableWidget->SetHeaderBackgroundColor( gVirtualX->GetPixel( kWhite ));
00067 
00068    m_tableWidget->Connect("columnClicked(Int_t,Int_t,Int_t)", "FWTriggerTableView",
00069                           this, "columnSelected(Int_t,Int_t,Int_t)");
00070    m_vert->AddFrame(m_tableWidget, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00071 
00072    frame->MapSubwindows();
00073    frame->Layout();
00074    frame->MapWindow();
00075 }
00076 
00077 FWTriggerTableView::~FWTriggerTableView()
00078 {
00079    // take out composite frame and delete it directly (without the timeout)
00080    TGCompositeFrame *frame = m_eveWindow->GetGUICompositeFrame();
00081    frame->RemoveFrame( m_vert );
00082    delete m_vert;
00083 
00084    m_eveWindow->DestroyWindowAndSlot();
00085    delete m_tableManager;
00086 }
00087 
00088 void
00089 FWTriggerTableView::setBackgroundColor(Color_t iColor)
00090 {
00091    m_backgroundColor = iColor;
00092    m_tableWidget->SetBackgroundColor(gVirtualX->GetPixel(iColor));
00093    m_tableWidget->SetLineSeparatorColor( gVirtualX->GetPixel(iColor == kWhite ?  kBlack : kWhite));
00094 }
00095 
00096 //
00097 // const member functions
00098 //
00099 
00100 void
00101 FWTriggerTableView::saveImageTo( const std::string& iName ) const
00102 {
00103    std::string fileName = iName + ".txt";
00104    std::ofstream triggers( fileName.c_str() );
00105 
00106    triggers << m_columns[2].title << " " << m_columns[0].title << "\n";
00107    for( unsigned int i = 0, vend = m_columns[0].values.size(); i != vend; ++i )
00108       if( m_columns[1].values[i] == "1" )
00109          triggers << m_columns[2].values[i] << "\t" << m_columns[0].values[i] << "\n";
00110    triggers.close();
00111 }
00112 
00113 
00114 void FWTriggerTableView::dataChanged ()
00115 {
00116    for(std::vector<Column>::iterator i = m_columns.begin(); i!= m_columns.end(); ++i)
00117       (*i).values.clear();
00118 
00119    edm::EventBase *base = const_cast<edm::EventBase*>(FWGUIManager::getGUIManager()->getCurrentEvent());
00120    if (fwlite::Event* event = dynamic_cast<fwlite::Event*>(base))
00121       fillTable(event);
00122 
00123    m_tableManager->dataChanged();
00124 }
00125 
00126 void
00127 FWTriggerTableView::columnSelected (Int_t iCol, Int_t iButton, Int_t iKeyMod)
00128 {
00129 }
00130 
00131 
00132 //______________________________________________________________________________
00133 
00134 void
00135 FWTriggerTableView::addTo( FWConfiguration& iTo ) const
00136 {
00137    FWConfigurableParameterizable::addTo(iTo);
00138    FWConfiguration sortColumn( m_tableWidget->sortedColumn());
00139    iTo.addKeyValue( kSortColumn, sortColumn );
00140    FWConfiguration descendingSort( m_tableWidget->descendingSort());
00141    iTo.addKeyValue( kDescendingSort, descendingSort );
00142 }
00143 
00144 void
00145 FWTriggerTableView::setFrom( const FWConfiguration& iFrom )
00146 {
00147    const FWConfiguration *main = &iFrom;
00148 
00149    // unnecessary nesting for old version
00150    if (version() < 2)
00151    {
00152       if (typeId() == FWViewType::kTableHLT)
00153          main = iFrom.valueForKey( "HLTTriggerTableView" );
00154       else
00155          main = iFrom.valueForKey( "L1TriggerTableView" );
00156    }
00157 
00158    const FWConfiguration *sortColumn = main->valueForKey( kSortColumn );
00159    const FWConfiguration *descendingSort = main->valueForKey( kDescendingSort );
00160    if( sortColumn != 0 && descendingSort != 0 ) 
00161    {
00162       unsigned int sort = sortColumn->version();
00163       bool descending = descendingSort->version();
00164       if( sort < (( unsigned int ) m_tableManager->numberOfColumns()))
00165          m_tableWidget->sort( sort, descending );
00166    }
00167 
00168    if ( typeId() == FWViewType::kTableHLT )
00169    {
00170       const FWConfiguration* vp = iFrom.valueForKey("Process" );
00171       if ( vp && (vp->value() != m_process.value()))
00172          m_process.setFrom(iFrom);
00173    } 
00174 
00175    {
00176       const FWConfiguration* vp = iFrom.valueForKey("Filter" );
00177       if (vp && (vp->value() != m_regex.value()))
00178          m_regex.setFrom(iFrom);
00179    }
00180 }
00181 
00182 //______________________________________________________________________________
00183 
00184 void
00185 FWTriggerTableView::resetCombo() const
00186 {
00187    if (m_combo && m_processList)
00188    {
00189       m_combo->RemoveAll();
00190       int cnt = 0;
00191       int id = -1;    
00192       for (std::vector<std::string>::iterator i = m_processList->begin(); i != m_processList->end(); ++i)
00193       {
00194          if (m_process.value() == *i ) id = cnt;
00195 
00196          m_combo->AddEntry((*i).c_str(), cnt);
00197          cnt++;
00198       }
00199 
00200       if(id < 0)
00201       {
00202          // fwLog(fwlog::kWarning) << "FWTriggerTableView: no trigger results with process name "<< m_process.value() << " is available" << std::endl;
00203          m_combo->AddEntry(m_process.value().c_str(), cnt);
00204          id = cnt;
00205       }
00206 
00207       m_combo->SortByName();
00208       m_combo->Select(id, false);
00209    }
00210 }
00211 
00212 void 
00213 FWTriggerTableView::processChanged(const char* x)
00214 {
00215    m_process.set(x);
00216    dataChanged();
00217 }
00218 
00219 bool
00220 FWTriggerTableView::isProcessValid() const
00221 {
00222    for (std::vector<std::string>::iterator i = m_processList->begin(); i!= m_processList->end(); ++i)
00223    {
00224       if (*i == m_process.value())
00225          return true;
00226    }
00227    return false;
00228 }
00229 
00230 void 
00231 FWTriggerTableView::populateController(ViewerParameterGUI& gui) const
00232 {
00233    gui.requestTab("Style").addParam(&m_regex);
00234 
00235    // resize filter frame
00236    TGCompositeFrame* parent =  gui.getTabContainer();
00237    TGFrameElement* el =  (TGFrameElement*) parent->GetList()->Last();
00238    el->fLayout->SetLayoutHints(kLHintsNormal);
00239    el->fFrame->Resize(180);
00240    
00241    // add combo for processes
00242    if (typeId() == FWViewType::kTableHLT)
00243    {
00244       TGHorizontalFrame* f = new TGHorizontalFrame(gui.getTabContainer());
00245       gui.getTabContainer()->AddFrame(f, new TGLayoutHints(kLHintsNormal, 2, 2,2,2 ));
00246 
00247       m_combo = new TGComboBox(f);
00248       f->AddFrame(m_combo);
00249       m_combo->Resize(140, 20);
00250       f->AddFrame(new TGLabel(f, "Process"),  new TGLayoutHints(kLHintsLeft, 8,2,2,2));
00251 
00252       resetCombo();
00253       FWTriggerTableView* tt = (FWTriggerTableView*)this;
00254       m_combo->Connect("Selected(const char*)", "FWTriggerTableView", tt, "processChanged(const char*)");
00255    }
00256 }