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