00001
00002
00003
00004
00005
00006
00007
00008 #include "DataFormats/FWLite/interface/Event.h"
00009 #include "Fireworks/Core/src/CmsShowMain.h"
00010
00011 #include "Fireworks/Core/interface/FWEventItem.h"
00012
00013
00014 #include <boost/regex.hpp>
00015 #include "TROOT.h"
00016 #include "TTree.h"
00017 #include "TFile.h"
00018 #include "TError.h"
00019 #include "TGTextEntry.h"
00020 #include "TGNumberEntry.h"
00021 #include "TBranch.h"
00022 #include "TAxis.h"
00023
00024 #include <TApplication.h>
00025 #include <TSystem.h>
00026 #include <TObject.h>
00027
00028
00029 #include "Fireworks/Core/interface/CmsShowNavigator.h"
00030 #include "Fireworks/Core/interface/CSGAction.h"
00031 #include "Fireworks/Core/interface/FWEventItemsManager.h"
00032 #include "Fireworks/Core/interface/FWGUIEventFilter.h"
00033 #include "Fireworks/Core/interface/FWTEventList.h"
00034 #include "Fireworks/Core/interface/FWGUIManager.h"
00035 #include "Fireworks/Core/interface/FWGUIEventSelector.h"
00036 #include "Fireworks/Core/interface/FWJobMetadataManager.h"
00037 #include "Fireworks/Core/interface/FWConfiguration.h"
00038 #include "Fireworks/Core/interface/Context.h"
00039 #include "Fireworks/Core/interface/fwLog.h"
00040
00041
00042
00043
00044 CmsShowNavigator::CmsShowNavigator(const CmsShowMain &main):
00045 FWNavigatorBase(main),
00046 m_currentEvent(0),
00047
00048 m_filterState(kOff),
00049 m_filterMode(kOr),
00050
00051 m_filesNeedUpdate(true),
00052 m_newFileOnNextEvent(false),
00053
00054 m_maxNumberOfFilesToChain(1),
00055
00056 m_main(main),
00057 m_guiFilter(0)
00058 {
00059 m_guiFilter = new FWGUIEventFilter(this);
00060 filterStateChanged_.connect(boost::bind(&FWGUIEventFilter::updateFilterStateLabel, m_guiFilter, _1));
00061 }
00062
00063 CmsShowNavigator::~CmsShowNavigator()
00064 {
00065 delete m_guiFilter;
00066 }
00067
00068
00069
00070
00071
00072 bool
00073 CmsShowNavigator::openFile(const std::string& fileName)
00074 {
00075 fwLog(fwlog::kDebug) << "CmsShowNavigator::openFile [" << fileName << "]" << std::endl;
00076 FWFileEntry* newFile = 0;
00077 try
00078 {
00079 newFile = new FWFileEntry(fileName, m_main.getVersionCheck());
00080 }
00081 catch (std::exception& iException)
00082 {
00083 fwLog(fwlog::kError) <<"Navigator::openFile ecaught exception FWFileEntry constructor " << iException.what()<<std::endl;
00084
00085 delete newFile;
00086 return false;
00087 }
00088
00089 try
00090 {
00091
00092 while ( m_files.size() > 0 )
00093 {
00094 FWFileEntry* file = m_files.front();
00095 m_files.pop_front();
00096 file->closeFile();
00097 delete file;
00098 }
00099
00100 m_files.push_back(newFile);
00101 setCurrentFile(m_files.begin());
00102
00103
00104 for (std::list<FWEventSelector*>::iterator i = m_selectors.begin(); i != m_selectors.end(); ++i)
00105 newFile->filters().push_back(new FWFileEntry::Filter(*i));
00106
00107 if (m_filterState != kOff)
00108 updateFileFilters();
00109
00110 return true;
00111 }
00112 catch (std::exception& iException)
00113 {
00114 fwLog(fwlog::kError) <<"Navigator::openFile caught exception "<<iException.what()<<std::endl;
00115 return false;
00116 }
00117 }
00118
00119 bool
00120 CmsShowNavigator::appendFile(const std::string& fileName, bool checkFileQueueSize, bool live)
00121 {
00122 fwLog(fwlog::kDebug) << "CmsShowNavigator::appendFile [" << fileName << "]" << std::endl;
00123 FWFileEntry* newFile = 0;
00124 try
00125 {
00126 newFile = new FWFileEntry(fileName, m_main.getVersionCheck());
00127 }
00128 catch(std::exception& iException)
00129 {
00130 fwLog(fwlog::kError) <<"Navigator::appendFile caught exception FWFileEntry constructor "<<iException.what()<<std::endl;
00131 delete newFile;
00132 return false;
00133 }
00134
00135 try
00136 {
00137 if (checkFileQueueSize)
00138 {
00139 int toErase = m_files.size() - (m_maxNumberOfFilesToChain + 1);
00140 while (toErase > 0)
00141 {
00142 FileQueue_i si = m_files.begin();
00143 if (m_currentFile == si)
00144 si++;
00145 FWFileEntry* file = *si;
00146 file->closeFile();
00147 delete file;
00148
00149 m_files.erase(si);
00150 --toErase;
00151 }
00152
00153 if (m_files.size() > m_maxNumberOfFilesToChain)
00154 fwLog(fwlog::kWarning) << " " << m_files.size() << " chained files more than maxNumberOfFilesToChain \n" << m_maxNumberOfFilesToChain << std::endl;
00155 }
00156
00157 m_files.push_back(newFile);
00158
00159
00160 if (!m_currentFile.isSet())
00161 setCurrentFile(m_files.begin());
00162
00163
00164 for (std::list<FWEventSelector*>::iterator i = m_selectors.begin(); i != m_selectors.end(); ++i)
00165 newFile->filters().push_back(new FWFileEntry::Filter(*i));
00166
00167 if (m_filterState != kOff)
00168 updateFileFilters();
00169
00170 }
00171 catch(std::exception& iException)
00172 {
00173 std::cerr <<"Navigator::openFile caught exception "<<iException.what()<<std::endl;
00174 return false;
00175 }
00176
00177 return true;
00178 }
00179
00180
00181
00182 void CmsShowNavigator::setCurrentFile(FileQueue_i fi)
00183 {
00184 if (fwlog::presentLogLevel() == fwlog::kDebug)
00185 {
00186 int cnt = 0;
00187 for (FileQueue_i i = m_files.begin(); i!= m_files.end(); i++)
00188 {
00189 if ( i == fi) break;
00190 cnt++;
00191 }
00192
00193 fwLog(fwlog::kDebug) << "CmsShowNavigator::setCurrentFile [" << (*fi)->file()->GetName() << "] file idx in chain [" << cnt << "/" << m_files.size() -1 << "]" << std::endl;
00194 }
00195
00196 m_currentFile = fi;
00197 fileChanged_.emit((*m_currentFile)->file());
00198 }
00199
00200 void
00201 CmsShowNavigator::goTo(FileQueue_i fi, int event)
00202 {
00203 if (fi != m_currentFile)
00204 setCurrentFile(fi);
00205
00206 if (fwlog::presentLogLevel() == fwlog::kDebug)
00207 {
00208 int total = (*fi)->tree()->GetEntries();
00209 fwLog(fwlog::kDebug) << "CmsShowNavigator::goTo current file event [" << event << "/" << total -1<< "]" << std::endl;
00210
00211 CpuInfo_t cpuInfo;
00212 MemInfo_t memInfo;
00213 ProcInfo_t procInfo;
00214 gSystem->GetCpuInfo(&cpuInfo, 0);
00215 gSystem->GetMemInfo(&memInfo);
00216 gSystem->GetProcInfo(&procInfo);
00217
00218 fwLog(fwlog::kDebug) << "memInfo.fMemUsed \t" << memInfo.fMemUsed << std::endl;
00219 fwLog(fwlog::kDebug) << "memInfo.fSwapUsed\t" << memInfo.fSwapUsed<< std::endl;
00220 fwLog(fwlog::kDebug) << "procInfo.fMemResident\t" << procInfo.fMemResident << std::endl;
00221 fwLog(fwlog::kDebug) << "procInfo.fMemVirtual\t" << procInfo.fMemVirtual << std::endl;
00222 fwLog(fwlog::kDebug) << "cpuInfo.fLoad1m \t" << cpuInfo.fLoad1m << std::endl;
00223 fwLog(fwlog::kDebug) << "cpuInfo.fLoad5m \t" << cpuInfo.fLoad5m << std::endl;
00224 }
00225
00226 (*m_currentFile)->event()->to(event);
00227 (*m_currentFile)->tree()->LoadTree(event);
00228 m_currentEvent = event;
00229
00230 newEvent_.emit();
00231 }
00232
00233 void
00234 CmsShowNavigator::goToRunEvent(edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi, edm::EventNumber_t event)
00235 {
00236 for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00237 {
00238 Long64_t index = (*file)->event()->indexFromEventId(run, lumi, event);
00239 if (index >= 0)
00240 {
00241 goTo(file, index);
00242 break;
00243 }
00244 }
00245 }
00246
00247
00248
00249 void
00250 CmsShowNavigator::firstEvent()
00251 {
00252 FileQueue_i x = m_files.begin();
00253 if (m_filterState == kOn)
00254 {
00255 while (x != m_files.end())
00256 {
00257 if ((*x)->hasSelectedEvents())
00258 {
00259 goTo(x, (*x)->firstSelectedEvent());
00260 return;
00261 }
00262 ++x;
00263 }
00264 }
00265 else
00266 {
00267 goTo(x, 0);
00268 }
00269 }
00270
00271 void
00272 CmsShowNavigator::lastEvent()
00273 {
00274 FileQueue_i x = m_files.end();
00275 if (m_filterState == kOn)
00276 {
00277 while (x != m_files.begin())
00278 {
00279 --x;
00280 if ((*x)->hasSelectedEvents())
00281 {
00282 goTo(x, (*x)->lastSelectedEvent());
00283 return;
00284 }
00285 }
00286 }
00287 else
00288 {
00289 --x;
00290 goTo(x, (*x)->lastEvent());
00291 }
00292 }
00293
00294
00295
00296 bool
00297 CmsShowNavigator::nextSelectedEvent()
00298 {
00299 int nextEv = (*m_currentFile)->nextSelectedEvent(m_currentEvent);
00300 if (nextEv > -1)
00301 {
00302 goTo(m_currentFile, nextEv);
00303 return true;
00304 }
00305 else
00306 {
00307 FileQueue_i i = m_currentFile; ++i;
00308 while (i != m_files.end())
00309 {
00310 if ((*i)->hasSelectedEvents())
00311 {
00312 goTo(i, (*i)->firstSelectedEvent());
00313 return true;
00314 }
00315 ++i;
00316 }
00317 }
00318
00319 return false;
00320 }
00321
00322
00323
00324 void
00325 CmsShowNavigator::nextEvent()
00326 {
00327 if (m_newFileOnNextEvent)
00328 {
00329 FileQueue_i last = m_files.end(); --last;
00330 if (m_filterState == kOn)
00331 goTo(last, (*last)->firstSelectedEvent());
00332 else
00333 goTo(last, 0);
00334
00335 m_newFileOnNextEvent = false;
00336 return;
00337 }
00338
00339 if (m_filterState == kOn)
00340 {
00341 nextSelectedEvent();
00342 return;
00343 }
00344 else
00345 {
00346 if (m_currentEvent < (*m_currentFile)->lastEvent())
00347 {
00348 goTo(m_currentFile, m_currentEvent + 1);
00349 }
00350 else
00351 {
00352 FileQueue_i x = m_currentFile ; ++x;
00353 if (x != m_files.end())
00354 {
00355 goTo(x, 0);
00356 }
00357 }
00358 }
00359 }
00360
00361
00362
00363 bool
00364 CmsShowNavigator::previousSelectedEvent()
00365 {
00366 int prevEv = (*m_currentFile)->previousSelectedEvent(m_currentEvent);
00367 if (prevEv > -1)
00368 {
00369 goTo(m_currentFile, prevEv);
00370 return true;
00371 }
00372 else
00373 {
00374 FileQueue_i i(m_currentFile); i.previous(m_files);
00375 while (i != m_files.end())
00376 {
00377 if ((*i)->hasSelectedEvents())
00378 {
00379 goTo(i, (*i)->lastSelectedEvent());
00380 return true;
00381 }
00382 i.previous(m_files);
00383 }
00384 }
00385 return false;
00386 }
00387
00388
00389
00390 void
00391 CmsShowNavigator::previousEvent()
00392 {
00393 if (m_filterState == kOn)
00394 {
00395 previousSelectedEvent();
00396 }
00397 else
00398 {
00399 if (m_currentEvent > 0)
00400 {
00401 goTo(m_currentFile, m_currentEvent - 1);
00402 }
00403 else
00404 {
00405
00406 FileQueue_i x = m_currentFile;
00407 if (x != m_files.begin())
00408 {
00409 --x;
00410 goTo(x, (*x)->lastEvent());
00411 }
00412 }
00413 }
00414 }
00415
00416
00417
00418 void
00419 CmsShowNavigator::toggleFilterEnable()
00420 {
00421
00422
00423 fwLog(fwlog::kInfo) << "CmsShowNavigator::toggleFilterEnable filters enabled [" << ( m_filterState == kOff) << "]" << std::endl;
00424
00425 if (m_filterState == kOff)
00426 {
00427 m_filterState = kOn;
00428 m_guiFilter->setupDisableFilteringButton(true);
00429
00430 updateFileFilters();
00431 }
00432 else
00433 {
00434 m_filterState = kOff;
00435 m_guiFilter->setupDisableFilteringButton(false);
00436 }
00437
00438 filterStateChanged_.emit(m_filterState);
00439 }
00440
00441 void
00442 CmsShowNavigator::withdrawFilter()
00443 {
00444 fwLog(fwlog::kInfo) << "CmsShowNavigator::witdrawFilter" << std::endl;
00445 m_filterState = kWithdrawn;
00446 filterStateChanged_.emit(m_filterState);
00447 }
00448
00449 void
00450 CmsShowNavigator::resumeFilter()
00451 {
00452 fwLog(fwlog::kInfo) << "CmsShowNavigator::resumeFilter" << std::endl;
00453 m_filterState = kOn;
00454 filterStateChanged_.emit(m_filterState);
00455 }
00456
00457 void
00458 CmsShowNavigator::updateFileFilters()
00459 {
00460
00461 std::list<FWFileEntry::Filter>::iterator it;
00462 for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00463 {
00464 if ( m_filesNeedUpdate) (*file)->needUpdate();
00465 (*file)->updateFilters(m_main.context()->eventItemsManager(), m_filterMode == kOr);
00466 }
00467 updateSelectorsInfo();
00468 m_filesNeedUpdate = false;
00469
00470 int nSelected = getNSelectedEvents();
00471 if (nSelected)
00472 {
00473
00474 if (!(*m_currentFile)->isEventSelected(m_currentEvent))
00475 {
00476 if (!nextSelectedEvent())
00477 previousSelectedEvent();
00478 }
00479
00480 if (m_filterState == kWithdrawn)
00481 resumeFilter();
00482
00483 postFiltering_.emit();
00484 }
00485 else
00486 {
00487 withdrawFilter();
00488 }
00489
00490 if (fwlog::presentLogLevel() == fwlog::kDebug)
00491 {
00492 fwLog(fwlog::kDebug) << "CmsShowNavigator::updateFileFilters selected events over files [" << getNSelectedEvents() << "/" << getNTotalEvents() << "]" << std::endl;
00493 }
00494 }
00495
00496
00497 void
00498 CmsShowNavigator::removeFilter(std::list<FWEventSelector*>::iterator si)
00499 {
00500 fwLog(fwlog::kDebug) << "CmsShowNavigator::removeFilter " << (*si)->m_expression << std::endl;
00501
00502 std::list<FWFileEntry::Filter*>::iterator it;
00503 for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00504 {
00505 for (it = (*file)->filters().begin(); it != (*file)->filters().end(); ++it)
00506 {
00507 if ((*it)->m_selector == *si)
00508 {
00509 FWFileEntry::Filter* f = *it;
00510 delete f;
00511 (*file)->filters().erase(it);
00512 break;
00513 }
00514 }
00515 }
00516
00517 delete *si;
00518 m_selectors.erase(si);
00519 m_filesNeedUpdate = true;
00520 }
00521
00522 void
00523 CmsShowNavigator::addFilter(FWEventSelector* ref)
00524 {
00525 fwLog(fwlog::kDebug) << "CmsShowNavigator::addFilter " << ref->m_expression << std::endl;
00526
00527 FWEventSelector* selector = new FWEventSelector(ref);
00528 m_selectors.push_back(selector);
00529
00530 for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00531 {
00532 (*file)->filters ().push_back(new FWFileEntry::Filter(selector));
00533 }
00534 m_filesNeedUpdate = true;
00535 }
00536
00537 void
00538 CmsShowNavigator::changeFilter(FWEventSelector* selector, bool updateFilter)
00539 {
00540 fwLog(fwlog::kDebug) << "CmsShowNavigator::changeFilter " << selector->m_expression << std::endl;
00541
00542 std::list<FWFileEntry::Filter*>::iterator it;
00543 for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00544 {
00545 for (it = (*file)->filters().begin(); it != (*file)->filters().end(); ++it)
00546 {
00547 if ((*it)->m_selector == selector)
00548 {
00549 if (updateFilter) (*it)->m_needsUpdate = true;
00550 (*it)->m_selector->m_expression = selector->m_expression;
00551 break;
00552 }
00553 }
00554 }
00555 m_filesNeedUpdate = true;
00556 }
00557
00558 void
00559 CmsShowNavigator::applyFiltersFromGUI()
00560 {
00561 m_filesNeedUpdate = false;
00562
00563
00564 if (m_filterState == kOff)
00565 {
00566 m_filesNeedUpdate = true;
00567 m_filterState = kOn;
00568 m_guiFilter->setupDisableFilteringButton(true);
00569 }
00570
00571
00572 std::list<FWEventSelector*>::iterator si = m_selectors.begin();
00573 std::list<FWGUIEventSelector*>::iterator gi = m_guiFilter->guiSelectors().begin();
00574
00575 if (m_filterMode != m_guiFilter->getFilterMode()) {
00576 m_filterMode = m_guiFilter->getFilterMode();
00577 m_filesNeedUpdate = true;
00578 }
00579
00580 while (si != m_selectors.end() || gi != m_guiFilter->guiSelectors().end())
00581 {
00582 if (gi == m_guiFilter->guiSelectors().end() && si != m_selectors.end())
00583 {
00584 removeFilter(si++);
00585 }
00586 else if (si == m_selectors.end() && gi != m_guiFilter->guiSelectors().end() )
00587 {
00588 addFilter((*gi)->guiSelector());
00589 (*gi)->setOrigSelector(m_selectors.back());
00590 ++gi;
00591 }
00592 else
00593 {
00594 if (*si == (*gi)->origSelector())
00595 {
00596 FWEventSelector* g = (*gi)->guiSelector();
00597 FWEventSelector* o = *si;
00598 bool filterNeedUpdate = o->m_expression != g->m_expression;
00599 if (filterNeedUpdate || o->m_enabled != g->m_enabled) {
00600 *o = *g;
00601 changeFilter(*si, filterNeedUpdate);
00602 }
00603 else
00604 {
00605 o->m_description = g->m_description;
00606 }
00607 ++si; ++gi;
00608 }
00609 else if ((*gi)->origSelector() == 0)
00610 {
00611 addFilter((*gi)->guiSelector());
00612 (*gi)->setOrigSelector(m_selectors.back());
00613 ++gi;
00614 }
00615 else
00616 {
00617 removeFilter(si++);
00618 }
00619 }
00620 }
00621
00622 if ( m_filesNeedUpdate )
00623 updateFileFilters();
00624
00625 filterStateChanged_.emit(m_filterState);
00626
00627 }
00628
00629
00630
00631 bool
00632 CmsShowNavigator::isFirstEvent()
00633 {
00634 if (m_filterState == kOn)
00635 {
00636 FileQueue_i firstSelectedFile;
00637 for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00638 {
00639 if ((*file)->hasSelectedEvents())
00640 {
00641 firstSelectedFile = file;
00642 break;
00643 }
00644 }
00645
00646 if (firstSelectedFile == m_currentFile)
00647 return (*m_currentFile)->firstSelectedEvent() == m_currentEvent;
00648 }
00649 else
00650 {
00651 if (m_currentFile == m_files.begin())
00652 {
00653 return m_currentEvent == 0;
00654 }
00655 }
00656 return false;
00657 }
00658
00659 bool
00660 CmsShowNavigator::isLastEvent()
00661 {
00662 if (m_filterState == kOn)
00663 {
00664 FileQueue_i lastSelectedFile;
00665 for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00666 {
00667 if ((*file)->hasSelectedEvents())
00668 lastSelectedFile = file;
00669 }
00670 if (lastSelectedFile == m_currentFile)
00671 return (*m_currentFile)->lastSelectedEvent() == m_currentEvent;
00672 }
00673 else
00674 {
00675 FileQueue_i lastFile = m_files.end();
00676 --lastFile;
00677 if (m_currentFile == lastFile)
00678 {
00679 return (*m_currentFile)->lastEvent() == m_currentEvent;
00680 }
00681 }
00682 return false;
00683 }
00684
00685
00686 void
00687 CmsShowNavigator::updateSelectorsInfo()
00688 {
00689
00690
00691 std::list<FWEventSelector*>::const_iterator sel = m_selectors.begin();
00692 while ( sel != m_selectors.end())
00693 {
00694 (*sel)->m_selected = 0;
00695 (*sel)->m_updated = true;
00696 ++sel;
00697 }
00698
00699
00700 std::list<FWFileEntry::Filter*>::iterator i;
00701 for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00702 {
00703 std::list<FWFileEntry::Filter*>& filters = (*file)->filters();
00704 for (i = filters.begin(); i != filters.end(); ++i)
00705 {
00706 if ((*i)->m_eventList)
00707 {
00708 (*i)->m_selector->m_selected += (*i)->m_eventList->GetN();
00709 }
00710
00711 if ((*i)->m_needsUpdate)
00712 (*i)->m_selector->m_updated = false;
00713 }
00714 }
00715 if (m_guiFilter)
00716 {
00717 std::list<FWGUIEventSelector*>::const_iterator gs = m_guiFilter->guiSelectors().begin();
00718 while ( gs != m_guiFilter->guiSelectors().end())
00719 {
00720 (*gs)->updateNEvents();
00721 ++gs;
00722 }
00723 }
00724 }
00725
00726 int
00727 CmsShowNavigator::getNSelectedEvents()
00728 {
00729 int sum = 0;
00730 for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00731 {
00732 if ((*file)->globalSelection())
00733 sum += (*file)->globalSelection()->GetN();
00734 }
00735 return sum;
00736 }
00737
00738 int
00739 CmsShowNavigator::getNTotalEvents()
00740 {
00741 int sum = 0;
00742 for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00743 {
00744 sum += (*file)->tree()->GetEntries();
00745 }
00746
00747 return sum;
00748 }
00749
00750 const char*
00751 CmsShowNavigator::filterStatusMessage()
00752 {
00753 if (m_filterState == kOn)
00754 return Form("%d events are selected from %d.", getNSelectedEvents(), getNTotalEvents());
00755 else if (m_filterState == kOff)
00756 return "Filtering is OFF.";
00757 else
00758 return "Filtering is disabled.";
00759 }
00760
00761 bool
00762 CmsShowNavigator::canEditFiltersExternally()
00763 {
00764 bool haveActiveFilters = false;
00765 for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00766 {
00767 if ((*file)->hasActiveFilters())
00768 {
00769 haveActiveFilters = true;
00770 break;
00771 }
00772 }
00773
00774 bool btnEnabled = haveActiveFilters;
00775
00776 if (m_guiFilter && m_guiFilter->isOpen())
00777 btnEnabled = false;
00778
00779 return btnEnabled;
00780 }
00781
00782 void
00783 CmsShowNavigator::editFiltersExternally()
00784 {
00785 editFiltersExternally_.emit(canEditFiltersExternally());
00786 }
00787
00788 void
00789 CmsShowNavigator::showEventFilterGUI(const TGWindow* p)
00790 {
00791 if (m_guiFilter->IsMapped())
00792 {
00793 m_guiFilter->CloseWindow();
00794 }
00795 else
00796 {
00797 m_guiFilter->show(&m_selectors, m_filterMode, m_filterState);
00798 editFiltersExternally_.emit(canEditFiltersExternally());
00799 }
00800 }
00801
00802
00803
00804 void
00805 CmsShowNavigator::setFrom(const FWConfiguration& iFrom)
00806 {
00807 m_filesNeedUpdate = true;
00808
00809 EFilterState oldFilterState = m_filterState;
00810
00811
00812 m_selectors.clear();
00813
00814
00815 const FWConfiguration* sConf = iFrom.valueForKey("EventFilters");
00816
00817 if (sConf)
00818 {
00819 const FWConfiguration::KeyValues* keyVals = sConf->keyValues();
00820 if (keyVals) {
00821 for(FWConfiguration::KeyValuesIt it = keyVals->begin(); it!= keyVals->end(); ++it)
00822 {
00823 const FWConfiguration& conf = (*it).second;
00824 FWEventSelector* selector = new FWEventSelector();
00825 selector->m_expression = conf.valueForKey("expression")->value();
00826 selector->m_description = conf.valueForKey("comment")->value();
00827 selector->m_enabled = atoi(conf.valueForKey("enabled")->value().c_str());
00828 if (conf.valueForKey("triggerProcess"))
00829 selector->m_triggerProcess = conf.valueForKey("triggerProcess")->value();
00830 m_selectors.push_back(selector);
00831 }
00832 }
00833 }
00834 else
00835 {
00836 int numberOfFilters = 0;
00837 const FWConfiguration* value = iFrom.valueForKey( "EventFilter_total" );
00838 std::istringstream s(value->value());
00839 s>>numberOfFilters;
00840
00841 for(int i=0; i<numberOfFilters; ++i)
00842 {
00843 FWEventSelector* selector = new FWEventSelector();
00844 {
00845 const FWConfiguration* value = iFrom.valueForKey( Form("EventFilter%d_enabled",i));
00846 assert(value);
00847 std::istringstream s(value->value());
00848 s>>selector->m_enabled;
00849 }
00850 selector->m_expression = iFrom.valueForKey( Form("EventFilter%d_selection",i))->value();
00851 selector->m_description = iFrom.valueForKey( Form("EventFilter%d_comment",i) )->value();
00852
00853
00854 if (strstr(selector->m_expression.c_str(), "HLT"))
00855 selector->m_triggerProcess = "HLT";
00856
00857 m_selectors.push_back(selector);
00858 }
00859 }
00860
00861
00862 {
00863 const FWConfiguration* value = iFrom.valueForKey( "EventFilter_mode" );
00864 if (value)
00865 {
00866 std::istringstream s(value->value());
00867 s>> m_filterMode;
00868 }
00869 }
00870
00871
00872 {
00873 const FWConfiguration* value = iFrom.valueForKey( "EventFilter_enabled" );
00874 std::istringstream s(value->value());
00875 int x;
00876 s>> x;
00877 m_filterState = x ? kOn : kOff;
00878 }
00879
00880
00881
00882 if (m_guiFilter)
00883 {
00884 m_guiFilter->reset();
00885 if (m_guiFilter->IsMapped()) m_guiFilter->show(&m_selectors, m_filterMode, m_filterState);
00886 }
00887
00888 if (!m_files.empty())
00889 {
00890
00891 for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00892 {
00893 (*file)->filters().clear();
00894 for (std::list<FWEventSelector*>::iterator i = m_selectors.begin(); i != m_selectors.end(); ++i)
00895 (*file)->filters().push_back(new FWFileEntry::Filter(*i));
00896 }
00897
00898
00899
00900 if (m_filterState == kOn)
00901 updateFileFilters();
00902 else
00903 postFiltering_.emit();
00904 }
00905
00906 if (oldFilterState != m_filterState)
00907 filterStateChanged_.emit(m_filterState);
00908 }
00909
00910 void
00911 CmsShowNavigator::addTo(FWConfiguration& iTo) const
00912 {
00913
00914 FWConfiguration tmp;
00915 int cnt = 0;
00916 for (std::list<FWEventSelector*>::const_iterator sel = m_selectors.begin(); sel != m_selectors.end(); ++sel)
00917 {
00918 FWConfiguration filter;
00919
00920 filter.addKeyValue("expression",FWConfiguration((*sel)->m_expression));
00921 filter.addKeyValue("enabled", FWConfiguration((*sel)->m_enabled ? "1" : "0"));
00922 filter.addKeyValue("comment", FWConfiguration((*sel)->m_description));
00923
00924 if (!(*sel)->m_triggerProcess.empty())
00925 filter.addKeyValue("triggerProcess",FWConfiguration((*sel)->m_triggerProcess));
00926
00927 tmp.addKeyValue(Form("------Filter[%d]------", cnt), filter,true);
00928 ++cnt;
00929 }
00930
00931 iTo.addKeyValue("EventFilters", tmp,true);
00932
00933
00934 {
00935 std::stringstream s;
00936 s<< m_filterMode;
00937 iTo.addKeyValue("EventFilter_mode", s.str());
00938 }
00939
00940
00941 iTo.addKeyValue("EventFilter_enabled",FWConfiguration( m_filterState == kOn ? "1" : "0"));
00942 }
00943
00944 std::vector<std::string>&
00945 CmsShowNavigator::getProcessList() const
00946 {
00947 return m_main.context()->metadataManager()->processNamesInJob();
00948 }
00949
00950 const edm::EventBase*
00951 CmsShowNavigator::getCurrentEvent() const
00952 {
00953 return m_currentFile.isSet() ? (*m_currentFile)->event() : 0;
00954 }
00955
00956 const char*
00957 CmsShowNavigator::frameTitle()
00958 {
00959 if (m_files.empty()) return "";
00960
00961 int nf = 0;
00962 for (FileQueue_t::const_iterator i = m_files.begin(); i!= m_files.end(); i++)
00963 {
00964
00965 if ( i == m_currentFile) break;
00966 nf++;
00967 }
00968
00969 TString name = (*m_currentFile)->file()->GetName();
00970 int l = name.Last('/');
00971 if (l != kNPOS)
00972 name.Remove(0, l+1);
00973
00974 return Form("%s [%d/%d], event [%d/%d]", name.Data(),
00975 nf+1, (int) m_files.size(),
00976 m_currentEvent+1, (*m_currentFile)->lastEvent()+1);
00977 }