CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/Fireworks/FWInterface/src/FWPathsPopup.cc

Go to the documentation of this file.
00001 #include "Fireworks/FWInterface/src/FWPathsPopup.h"
00002 #include "Fireworks/FWInterface/src/FWPSetTableManager.h"
00003 #include "Fireworks/FWInterface/src/FWPSetCellEditor.h"
00004 
00005 #include "Fireworks/FWInterface/interface/FWFFLooper.h"
00006 #include "Fireworks/TableWidget/interface/FWTableWidget.h"
00007 
00008 
00009 #include "Fireworks/Core/src/FWDialogBuilder.h"
00010 #include "Fireworks/Core/interface/FWGUIManager.h"
00011 
00012 #include "FWCore/Framework/interface/ScheduleInfo.h"
00013 #include "FWCore/Framework/interface/Event.h"
00014 #include "FWCore/Framework/interface/EventSetup.h"
00015 #include "FWCore/Common/interface/TriggerNames.h"
00016 
00017 #include "FWCore/PythonParameterSet/interface/PythonProcessDesc.h"
00018 #include "FWCore/Utilities/interface/Exception.h"
00019 
00020 #include "DataFormats/Provenance/interface/ModuleDescription.h"
00021 #include "DataFormats/Provenance/interface/ProcessHistory.h"
00022 #include "DataFormats/Common/interface/TriggerResults.h"
00023 
00024 
00025 
00026 #include "TGLabel.h"
00027 #include "KeySymbols.h"
00028 
00029 void
00030 FWPathsPopup::windowIsClosing()
00031 {
00032    UnmapWindow();
00033    DontCallClose();
00034 }
00035 
00036 FWPathsPopup::FWPathsPopup(FWFFLooper *looper, FWGUIManager *guiManager)
00037    : TGMainFrame(gClient->GetRoot(), 400, 600),
00038      m_info(0),
00039      m_looper(looper),
00040      m_hasChanges(false),
00041      m_moduleLabel(0),
00042      m_moduleName(0),
00043      m_apply(0),
00044      m_psTable(new FWPSetTableManager()),
00045      m_guiManager(guiManager)
00046 {
00047    gVirtualX->SelectInput(GetId(), kKeyPressMask | kKeyReleaseMask | kExposureMask |
00048                           kPointerMotionMask | kStructureNotifyMask | kFocusChangeMask |
00049                           kEnterWindowMask | kLeaveWindowMask);
00050    this->Connect("CloseWindow()","FWPathsPopup",this,"windowIsClosing()");
00051 
00052    FWDialogBuilder builder(this);
00053    builder.indent(4)
00054       .spaceDown(10)
00055       .addLabel("Filter:").floatLeft(4).expand(false, false)
00056       .addTextEntry("", &m_search).expand(true, false)
00057       .spaceDown(10)
00058       .addTable(m_psTable, &m_tableWidget).expand(true, true)
00059       .addTextButton("Apply changes and reload", &m_apply);
00060 
00061    FWPSetCellEditor *editor = new  FWPSetCellEditor(m_tableWidget->body(), "");
00062    editor->SetBackgroundColor(gVirtualX->GetPixel(kYellow-7));
00063    editor->SetFrameDrawn(false);
00064    m_psTable->setCellValueEditor(editor);
00065    m_psTable->m_editor->Connect("ReturnPressed()", "FWPathsPopup", this, "applyEditor()");
00066 
00067    m_apply->Connect("Clicked()", "FWPathsPopup", this, "scheduleReloadEvent()");
00068    m_apply->SetEnabled(false);
00069    m_search->SetEnabled(true);
00070    m_search->Connect("TextChanged(const char *)", "FWPathsPopup",
00071                      this, "updateFilterString(const char *)");
00072    m_tableWidget->SetBackgroundColor(0xffffff);
00073    m_tableWidget->SetLineSeparatorColor(0x000000);
00074    m_tableWidget->SetHeaderBackgroundColor(0xececec);
00075    m_tableWidget->Connect("cellClicked(Int_t,Int_t,Int_t,Int_t,Int_t,Int_t)",
00076                           "FWPathsPopup",this,
00077                           "cellClicked(Int_t,Int_t,Int_t,Int_t,Int_t,Int_t)");
00078    m_tableWidget->disableGrowInWidth();
00079 
00080    SetWindowName("CMSSW Configuration Editor");
00081    MapSubwindows();
00082    editor->UnmapWindow();
00083 
00084    Layout();
00085 }
00086 
00089 Bool_t
00090 FWPathsPopup::HandleKey(Event_t*event)
00091 {
00092    UInt_t keysym = event->fCode;
00093 
00094    if (keysym == (UInt_t) gVirtualX->KeysymToKeycode(kKey_Escape))
00095    {
00096       // called from FWPSetCellEditor
00097       m_psTable->cancelEditor();
00098       m_psTable->setSelection(-1, -1, 0);
00099    }
00100    return TGMainFrame::HandleKey(event);
00101 }
00102 
00105 void
00106 FWPathsPopup::applyEditor()
00107 {
00108    bool applied = m_psTable->applyEditor();
00109    if (applied)
00110       m_apply->SetEnabled(true);
00111 }
00112 
00119 void 
00120 FWPathsPopup::cellClicked(Int_t iRow, Int_t iColumn, Int_t iButton, Int_t iKeyMod, Int_t, Int_t)
00121 {
00122    if (iButton != kButton1)
00123       return;
00124    
00125 
00126    if (iColumn == 0 || iColumn == 1)
00127    {
00128       // Save and close the previous editor, if required.
00129       if (m_psTable->selectedColumn() == 1
00130           && m_psTable->selectedRow() != -1)
00131       {
00132          int oldIndex = m_psTable->rowToIndex()[m_psTable->selectedRow()];
00133          FWPSetTableManager::PSetData& oldData = m_psTable->data()[oldIndex];
00134 
00135          if (oldData.editable)
00136             applyEditor();
00137       }
00138 
00139       m_psTable->setSelection(iRow, iColumn, iKeyMod);
00140 
00141       if (iColumn == 0)
00142          m_psTable->setExpanded(iRow);
00143    }
00144 }
00145 
00146 void
00147 FWPathsPopup::updateFilterString(const char *str)
00148 {
00149    m_psTable->applyEditor();
00150    m_psTable->setSelection(-1, -1, 0);
00151    m_psTable->updateFilter(str);
00152 }
00153 
00155 void
00156 FWPathsPopup::setup(const edm::ScheduleInfo *info)
00157 {
00158    assert(info);
00159    m_info = info;
00160 }
00161 
00163 void
00164 FWPathsPopup::postModule(edm::ModuleDescription const& description)
00165 {
00166    m_guiManager->updateStatus((description.moduleName() + " processed.").c_str());
00167    gSystem->ProcessEvents();
00168 }
00169 
00171 void
00172 FWPathsPopup::preModule(edm::ModuleDescription const& description)
00173 {
00174    m_guiManager->updateStatus(("Processing " + description.moduleName() + "...").c_str());
00175    gSystem->ProcessEvents();
00176 }
00177 
00178 
00179 void
00180 FWPathsPopup::postProcessEvent(edm::Event const& event, edm::EventSetup const& eventSetup)
00181 {
00182    m_guiManager->updateStatus("Done processing.");
00183    gSystem->ProcessEvents();
00184 
00185    // Get the last process name from the process history:
00186    // this should be the one specified in the cfg file
00187    edm::ProcessHistory::const_iterator pi = event.processHistory().end() - 1;
00188    std::string processName = pi->processName();
00189    
00190    // It's called TriggerResults but actually contains info on all paths
00191    edm::InputTag tag("TriggerResults", "", processName);
00192    edm::Handle<edm::TriggerResults> triggerResults;
00193    event.getByLabel(tag, triggerResults);
00194 
00195    std::vector<FWPSetTableManager::PathUpdate> pathUpdates;
00196 
00197    if (triggerResults.isValid())
00198    {
00199       edm::TriggerNames triggerNames = event.triggerNames(*triggerResults);
00200      
00201       for (size_t i = 0, e = triggerResults->size(); i != e; ++i)
00202       {
00203          FWPSetTableManager::PathUpdate update;
00204          update.pathName = triggerNames.triggerName(i);
00205          update.passed = triggerResults->accept(i);
00206          update.choiceMaker = triggerResults->index(i);
00207          pathUpdates.push_back(update);
00208       }
00209    }
00210    m_psTable->updateSchedule(m_info);
00211    m_psTable->update(pathUpdates);
00212    m_psTable->dataChanged();
00213    m_tableWidget->body()->DoRedraw();
00214 }
00215 
00216 
00217 
00227 void
00228 FWPathsPopup::scheduleReloadEvent()
00229 {
00230    applyEditor();
00231    try
00232    {
00233       for (size_t mni = 0, mne = m_psTable->modules().size(); mni != mne; ++mni)
00234       {
00235          FWPSetTableManager::ModuleInfo &module = m_psTable->modules()[mni];
00236          if (module.dirty == false)
00237             continue;
00238          FWPSetTableManager::PSetData &data = m_psTable->entries()[module.entry];
00239          m_looper->requestChanges(data.label, data.pset);
00240       }
00241       m_hasChanges = true;
00242       m_apply->SetEnabled(false);
00243       gSystem->ExitLoop();
00244    }
00245    catch (boost::python::error_already_set)
00246    {
00247       edm::pythonToCppException("Configuration");
00248       Py_Finalize();
00249    }
00250    catch (cms::Exception &exception)
00251    {
00252       std::cout << exception.what() << std::endl;
00253    }
00254    // Return control to the FWFFLooper so that it can decide what to do next.
00255 }