CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/Fireworks/Core/src/CmsShowNavigator.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     newVersion
00004 // Class  :     CmsShowNavigator
00005 // $Id: CmsShowNavigator.cc,v 1.114 2012/07/07 03:36:43 amraktad Exp $
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 // system include files
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 // user include files
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 // constructors and destructor
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 // member functions
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       // delete all previous files
00092       while ( !m_files.empty() )
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       // set filters
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       // Needed for proper handling of first registered file when -port option is in effect.
00160       if (!m_currentFile.isSet())
00161          setCurrentFile(m_files.begin());
00162 
00163       // set filters
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    else
00196    {
00197       fwLog(fwlog::kInfo) << "Set current file to "<< (*fi)->file()->GetName() << ".\n";
00198    }
00199 
00200    m_currentFile = fi;
00201    fileChanged_.emit((*m_currentFile)->file());
00202 }
00203 
00204 void
00205 CmsShowNavigator::goTo(FileQueue_i fi, int event)
00206 {
00207    if (fi != m_currentFile)
00208       setCurrentFile(fi);
00209 
00210    if (fwlog::presentLogLevel() == fwlog::kDebug)
00211    {
00212       int total = (*fi)->tree()->GetEntries();
00213       fwLog(fwlog::kDebug) << "CmsShowNavigator::goTo  current file event [" << event  << "/" << total -1<< "]"  << std::endl;
00214 
00215       CpuInfo_t  cpuInfo;
00216       MemInfo_t  memInfo;
00217       ProcInfo_t procInfo;
00218       gSystem->GetCpuInfo(&cpuInfo, 0);
00219       gSystem->GetMemInfo(&memInfo);
00220       gSystem->GetProcInfo(&procInfo);
00221 
00222       time_t curtime;
00223       time(&curtime);
00224       
00225       fwLog(fwlog::kDebug) << "Current Time: "  << ctime(&curtime);
00226       fwLog(fwlog::kDebug) << "memInfo.fMemUsed \t"  << memInfo.fMemUsed << std::endl;
00227       fwLog(fwlog::kDebug) << "memInfo.fSwapUsed\t" << memInfo.fSwapUsed << std::endl; 
00228       fwLog(fwlog::kDebug) << "procInfo.fMemResident\t" << procInfo.fMemResident << std::endl;
00229       fwLog(fwlog::kDebug) << "procInfo.fMemVirtual\t" << procInfo.fMemVirtual << std::endl;
00230       fwLog(fwlog::kDebug) << "cpuInfo.fLoad1m \t" << cpuInfo.fLoad1m << std::endl;
00231       fwLog(fwlog::kDebug) << "cpuInfo.fLoad5m \t" << cpuInfo.fLoad5m << std::endl;
00232    }
00233    
00234    (*m_currentFile)->event()->to(event);
00235    (*m_currentFile)->tree()->LoadTree(event);
00236    m_currentEvent = event;
00237 
00238    newEvent_.emit();
00239 }
00240 
00241 void
00242 CmsShowNavigator::goToRunEvent(edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi, edm::EventNumber_t event)
00243 {
00244    for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00245    {
00246       Long64_t index = (*file)->event()->indexFromEventId(run, lumi, event);
00247       if (index >= 0)
00248       {
00249          goTo(file, index);
00250          break;
00251       }
00252    }
00253 }
00254 
00255 //______________________________________________________________________________
00256 
00257 void
00258 CmsShowNavigator::firstEvent()
00259 {
00260    FileQueue_i x = m_files.begin();
00261    if (m_filterState == kOn)
00262    {
00263       while (x != m_files.end())
00264       {
00265          if ((*x)->hasSelectedEvents())
00266          {
00267             goTo(x, (*x)->firstSelectedEvent());
00268             return;
00269          }
00270          ++x;
00271       }
00272    }
00273    else
00274    {
00275       goTo(x, 0);
00276    }
00277 }
00278 
00279 void
00280 CmsShowNavigator::lastEvent()
00281 {
00282    FileQueue_i x = m_files.end();
00283    if (m_filterState == kOn)
00284    {
00285       while (x != m_files.begin())
00286       {
00287          --x;
00288          if ((*x)->hasSelectedEvents())
00289          {
00290             goTo(x, (*x)->lastSelectedEvent());
00291             return;
00292          }
00293       }
00294    }
00295    else
00296    {
00297       --x;
00298       goTo(x, (*x)->lastEvent());
00299    }
00300 }
00301 
00302 //______________________________________________________________________________
00303 
00304 bool
00305 CmsShowNavigator::nextSelectedEvent()
00306 {
00307    int nextEv = (*m_currentFile)->nextSelectedEvent(m_currentEvent);
00308    if (nextEv > -1)
00309    {
00310       goTo(m_currentFile, nextEv);
00311       return true;
00312    }
00313    else
00314    {
00315       FileQueue_i i = m_currentFile; ++i;
00316       while (i != m_files.end())
00317       {
00318          if ((*i)->hasSelectedEvents())
00319          {
00320             goTo(i, (*i)->firstSelectedEvent());
00321             return true;
00322          }
00323          ++i;
00324       }
00325    }
00326 
00327    return false;
00328 }
00329 
00330 //______________________________________________________________________________
00331 
00332 void
00333 CmsShowNavigator::nextEvent()
00334 {
00335    if (m_newFileOnNextEvent)
00336    {
00337       FileQueue_i last = m_files.end(); --last;
00338       if (m_filterState == kOn)
00339          goTo(last, (*last)->firstSelectedEvent());
00340       else
00341          goTo(last, 0);
00342 
00343       m_newFileOnNextEvent = false;
00344       return;
00345    }
00346    
00347    if (m_filterState == kOn)
00348    {
00349       nextSelectedEvent();
00350       return;
00351    }
00352    else
00353    {
00354       if (m_currentEvent < (*m_currentFile)->lastEvent())
00355       {
00356          goTo(m_currentFile, m_currentEvent + 1);
00357       }
00358       else
00359       {
00360          FileQueue_i x = m_currentFile ; ++x;
00361          if (x != m_files.end())
00362          {
00363             goTo(x, 0);
00364          }
00365       }
00366    }
00367 }
00368 
00369 //______________________________________________________________________________
00370 
00371 bool
00372 CmsShowNavigator::previousSelectedEvent()
00373 {
00374    int prevEv = (*m_currentFile)->previousSelectedEvent(m_currentEvent);
00375    if (prevEv > -1)
00376    {
00377       goTo(m_currentFile, prevEv);
00378       return true;
00379    }
00380    else
00381    {
00382       FileQueue_i i(m_currentFile); i.previous(m_files);
00383       while (i != m_files.end())
00384       {
00385          if ((*i)->hasSelectedEvents())
00386          {
00387             goTo(i, (*i)->lastSelectedEvent());
00388             return true;
00389          }
00390          i.previous(m_files);
00391       }
00392    }
00393    return false;
00394 }
00395 
00396 //______________________________________________________________________________
00397 
00398 void
00399 CmsShowNavigator::previousEvent()
00400 {
00401    if (m_filterState == kOn)
00402    {
00403       previousSelectedEvent();
00404    }
00405    else
00406    {
00407       if (m_currentEvent > 0)
00408       {
00409          goTo(m_currentFile, m_currentEvent - 1);
00410       }
00411       else
00412       {
00413          // last event in previous file
00414          FileQueue_i x = m_currentFile;
00415          if (x != m_files.begin())
00416          {
00417             --x;
00418             goTo(x, (*x)->lastEvent());
00419          }
00420       }
00421    }
00422 }
00423 
00424 //______________________________________________________________________________
00425 
00426 void
00427 CmsShowNavigator::toggleFilterEnable()
00428 {
00429    // callback
00430 
00431    fwLog(fwlog::kInfo) << "CmsShowNavigator::toggleFilterEnable filters enabled [" << ( m_filterState == kOff) << "]" << std::endl;
00432 
00433    if (m_filterState == kOff)
00434    {
00435       m_filterState = kOn;
00436       m_guiFilter->setupDisableFilteringButton(true);
00437 
00438       updateFileFilters();
00439    }
00440    else
00441    {
00442       m_filterState = kOff;
00443       m_guiFilter->setupDisableFilteringButton(false);
00444    }
00445 
00446    filterStateChanged_.emit(m_filterState);
00447 }
00448 
00449 void
00450 CmsShowNavigator::withdrawFilter()
00451 {
00452    fwLog(fwlog::kInfo) << "CmsShowNavigator::witdrawFilter" << std::endl;
00453    m_filterState = kWithdrawn;
00454    filterStateChanged_.emit(m_filterState);
00455 }
00456 
00457 void
00458 CmsShowNavigator::resumeFilter()
00459 {
00460    fwLog(fwlog::kInfo) << "CmsShowNavigator::resumeFilter" << std::endl;
00461    m_filterState = kOn;
00462    filterStateChanged_.emit(m_filterState);
00463 }
00464 
00465 void
00466 CmsShowNavigator::updateFileFilters()
00467 {
00468    // run filters on files
00469    std::list<FWFileEntry::Filter>::iterator it;
00470    for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00471    {
00472       if ( m_filesNeedUpdate) (*file)->needUpdate();
00473       (*file)->updateFilters(m_main.context()->eventItemsManager(), m_filterMode == kOr);
00474    }
00475    updateSelectorsInfo();
00476    m_filesNeedUpdate = false;
00477  
00478    int nSelected = getNSelectedEvents();
00479    if (nSelected)
00480    {
00481       // go to the nearest selected event/file
00482       bool changeCurrentEvent = !(*m_currentFile)->isEventSelected(m_currentEvent);
00483       if (changeCurrentEvent)
00484       {
00485          if (!nextSelectedEvent())
00486             previousSelectedEvent();
00487       }
00488 
00489       if (m_filterState == kWithdrawn)
00490          resumeFilter();
00491 
00492       postFiltering_.emit(changeCurrentEvent);
00493    }
00494    else
00495    {
00496       withdrawFilter();
00497    }
00498 
00499    if (fwlog::presentLogLevel() == fwlog::kDebug)
00500    {
00501       fwLog(fwlog::kDebug) << "CmsShowNavigator::updateFileFilters selected events over files [" << getNSelectedEvents() << "/" << getNTotalEvents() << "]" << std::endl;
00502    }
00503 }
00504 
00505 //=======================================================================
00506 void
00507 CmsShowNavigator::removeFilter(std::list<FWEventSelector*>::iterator si)
00508 {
00509    fwLog(fwlog::kDebug) << "CmsShowNavigator::removeFilter " << (*si)->m_expression << std::endl;
00510 
00511    std::list<FWFileEntry::Filter*>::iterator it;
00512    for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00513    {
00514       for (it = (*file)->filters().begin(); it != (*file)->filters().end(); ++it)
00515       {
00516          if ((*it)->m_selector == *si)
00517          {
00518             FWFileEntry::Filter* f = *it;
00519             delete f;
00520             (*file)->filters().erase(it);
00521             break;
00522          }
00523       }
00524    }
00525 
00526    delete *si;
00527    m_selectors.erase(si);
00528    m_filesNeedUpdate = true;
00529 }
00530 
00531 void
00532 CmsShowNavigator::addFilter(FWEventSelector* ref)
00533 {
00534    fwLog(fwlog::kDebug) << "CmsShowNavigator::addFilter " << ref->m_expression << std::endl;
00535 
00536    FWEventSelector* selector = new FWEventSelector(ref);
00537    m_selectors.push_back(selector);
00538 
00539    for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00540    {
00541       (*file)->filters ().push_back(new FWFileEntry::Filter(selector));
00542    }
00543    m_filesNeedUpdate = true;
00544 }
00545 
00546 void
00547 CmsShowNavigator::changeFilter(FWEventSelector* selector, bool updateFilter)
00548 {
00549    fwLog(fwlog::kDebug) << "CmsShowNavigator::changeFilter " << selector->m_expression << std::endl;
00550 
00551    std::list<FWFileEntry::Filter*>::iterator it;
00552    for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00553    {
00554       for (it = (*file)->filters().begin(); it != (*file)->filters().end(); ++it)
00555       {
00556          if ((*it)->m_selector == selector)
00557          {
00558             if (updateFilter)  (*it)->m_needsUpdate = true;
00559             (*it)->m_selector->m_expression  = selector->m_expression;
00560             break;
00561          }
00562       }
00563    }
00564    m_filesNeedUpdate = true;
00565 }
00566 
00567 void
00568 CmsShowNavigator::applyFiltersFromGUI()
00569 {
00570    m_filesNeedUpdate = false;
00571 
00572    // check if filters are set ON
00573    if (m_filterState == kOff)
00574    {
00575       m_filesNeedUpdate = true;
00576       m_filterState = kOn;
00577       m_guiFilter->setupDisableFilteringButton(true);
00578    }
00579 
00580    // compare changes and then call updateFileFilters
00581    std::list<FWEventSelector*>::iterator    si = m_selectors.begin();
00582    std::list<FWGUIEventSelector*>::iterator gi = m_guiFilter->guiSelectors().begin();
00583 
00584    if (m_filterMode != m_guiFilter->getFilterMode()) {
00585       m_filterMode = m_guiFilter->getFilterMode();
00586       m_filesNeedUpdate = true;
00587    }
00588 
00589    while (si != m_selectors.end() || gi != m_guiFilter->guiSelectors().end())
00590    {
00591       if (gi == m_guiFilter->guiSelectors().end() && si != m_selectors.end())
00592       {
00593          removeFilter(si++);
00594       }
00595       else if (si == m_selectors.end() && gi != m_guiFilter->guiSelectors().end() )
00596       {
00597          addFilter((*gi)->guiSelector());
00598          (*gi)->setOrigSelector(m_selectors.back());
00599          ++gi;
00600       }
00601       else
00602       {
00603          if (*si == (*gi)->origSelector())
00604          {
00605             FWEventSelector* g  = (*gi)->guiSelector();
00606             FWEventSelector* o = *si;
00607             bool filterNeedUpdate = o->m_expression != g->m_expression;
00608             if (filterNeedUpdate || o->m_enabled != g->m_enabled) {
00609                *o = *g;
00610                changeFilter(*si, filterNeedUpdate);
00611             }
00612             else
00613             {
00614                o->m_description = g->m_description;
00615             }
00616             ++si; ++gi;
00617          }
00618          else if ((*gi)->origSelector() == 0)
00619          {
00620             addFilter((*gi)->guiSelector());
00621             (*gi)->setOrigSelector(m_selectors.back());
00622             ++gi;
00623          }
00624          else
00625          {
00626             removeFilter(si++);
00627          }
00628       }
00629    }
00630 
00631    if ( m_filesNeedUpdate )
00632       updateFileFilters();
00633 
00634    filterStateChanged_.emit(m_filterState);
00635 
00636 }
00637 //______________________________________________________________________________
00638 // helpers for gui state
00639 
00640 bool
00641 CmsShowNavigator::isFirstEvent()
00642 {
00643    if (m_filterState == kOn)
00644    {
00645       FileQueue_i firstSelectedFile;
00646       for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00647       {
00648          if ((*file)->hasSelectedEvents())
00649          {
00650             firstSelectedFile = file;
00651             break;
00652          }
00653       }
00654 
00655       if (firstSelectedFile == m_currentFile)
00656          return (*m_currentFile)->firstSelectedEvent() == m_currentEvent;
00657    }
00658    else
00659    {
00660       if (m_currentFile == m_files.begin())
00661       {
00662          return m_currentEvent == 0;
00663       }
00664    }
00665    return false;
00666 }
00667 
00668 bool
00669 CmsShowNavigator::isLastEvent()
00670 {
00671    if (m_filterState == kOn)
00672    {
00673       FileQueue_i lastSelectedFile;
00674       for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00675       {
00676          if ((*file)->hasSelectedEvents())
00677             lastSelectedFile = file;
00678       }
00679       if (lastSelectedFile == m_currentFile)
00680          return (*m_currentFile)->lastSelectedEvent() == m_currentEvent;
00681    }
00682    else
00683    {
00684       FileQueue_i lastFile = m_files.end();
00685       --lastFile;
00686       if (m_currentFile == lastFile)
00687       {
00688          return (*m_currentFile)->lastEvent() == m_currentEvent;
00689       }
00690    }
00691    return false;
00692 }
00693 
00694 //______________________________________________________________________________
00695 void
00696 CmsShowNavigator::updateSelectorsInfo()
00697 {
00698  
00699    // reset
00700    std::list<FWEventSelector*>::const_iterator sel = m_selectors.begin();
00701    while ( sel != m_selectors.end())
00702    {
00703       (*sel)->m_selected = 0;
00704       (*sel)->m_updated  = true;
00705       ++sel;
00706    }
00707 
00708    // loop file filters
00709    std::list<FWFileEntry::Filter*>::iterator i;
00710    for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00711    {
00712       std::list<FWFileEntry::Filter*>& filters = (*file)->filters();
00713       for (i = filters.begin(); i != filters.end(); ++i)
00714       {
00715          if ((*i)->m_eventList)
00716          {
00717             (*i)->m_selector->m_selected += (*i)->m_eventList->GetN();
00718          }
00719 
00720          if ((*i)->m_needsUpdate) 
00721             (*i)->m_selector->m_updated = false;
00722       }
00723    }
00724    if (m_guiFilter) 
00725    {
00726       std::list<FWGUIEventSelector*>::const_iterator gs = m_guiFilter->guiSelectors().begin();
00727       while ( gs !=  m_guiFilter->guiSelectors().end())
00728       {
00729          (*gs)->updateNEvents();
00730          ++gs;
00731       }
00732    }
00733 }
00734 
00735 int
00736 CmsShowNavigator::getNSelectedEvents()
00737 {
00738    int sum = 0;
00739    for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00740    {
00741       if ((*file)->globalSelection())
00742          sum += (*file)->globalSelection()->GetN();
00743    }
00744    return sum;
00745 }
00746 
00747 int
00748 CmsShowNavigator::getNTotalEvents()
00749 {
00750    int sum = 0;
00751    for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00752    {
00753       sum += (*file)->tree()->GetEntries();
00754    }
00755 
00756    return sum;
00757 }
00758 
00759 const char*
00760 CmsShowNavigator::filterStatusMessage()
00761 {
00762    if (m_filterState == kOn)
00763       return Form("%d events are selected from %d.", getNSelectedEvents(), getNTotalEvents());
00764    else if (m_filterState == kOff)
00765       return "Filtering is OFF.";
00766    else
00767       return "Filtering is disabled.";
00768 }
00769 
00770 bool
00771 CmsShowNavigator::canEditFiltersExternally()
00772 {
00773    bool haveActiveFilters = false;
00774    for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00775    {
00776       if ((*file)->hasActiveFilters())
00777       {
00778          haveActiveFilters = true;
00779          break;
00780       }
00781    }
00782 
00783    bool btnEnabled = haveActiveFilters;
00784 
00785    if (m_guiFilter && m_guiFilter->isOpen())
00786       btnEnabled = false;
00787 
00788    return btnEnabled;
00789 }
00790 
00791 void
00792 CmsShowNavigator::editFiltersExternally()
00793 {
00794    editFiltersExternally_.emit(canEditFiltersExternally());
00795 }
00796 
00797 void
00798 CmsShowNavigator::showEventFilterGUI(const TGWindow* p)
00799 {
00800    if (m_guiFilter->IsMapped())
00801    {
00802       m_guiFilter->CloseWindow();
00803    }
00804    else
00805    {
00806       m_guiFilter->show(&m_selectors, m_filterMode, m_filterState);
00807       editFiltersExternally_.emit(canEditFiltersExternally());
00808    }
00809 }
00810 
00811 //______________________________________________________________________________
00812 
00813 void
00814 CmsShowNavigator::setFrom(const FWConfiguration& iFrom)
00815 {
00816    m_filesNeedUpdate = true;
00817 
00818    EFilterState oldFilterState =  m_filterState;
00819 
00820   
00821    m_selectors.clear();
00822 
00823    // selectors   
00824    const FWConfiguration* sConf = iFrom.valueForKey("EventFilters");
00825 
00826    if (sConf)
00827    {
00828       const FWConfiguration::KeyValues* keyVals = sConf->keyValues();
00829       if (keyVals) {
00830          for(FWConfiguration::KeyValuesIt it = keyVals->begin(); it!= keyVals->end(); ++it)
00831          {
00832             const FWConfiguration& conf = (*it).second;
00833             FWEventSelector* selector = new FWEventSelector();
00834             selector->m_expression   = conf.valueForKey("expression")->value();
00835             selector->m_description  = conf.valueForKey("comment")->value();
00836             selector->m_enabled      = atoi(conf.valueForKey("enabled")->value().c_str());
00837             if (conf.valueForKey("triggerProcess"))
00838                selector->m_triggerProcess = conf.valueForKey("triggerProcess")->value();
00839             m_selectors.push_back(selector);
00840          }
00841       }
00842    }
00843    else
00844    {
00845       int numberOfFilters = 0;
00846       const FWConfiguration* nfvalue = iFrom.valueForKey( "EventFilter_total" );
00847       if(nfvalue)
00848          numberOfFilters = atoi(nfvalue->value().c_str());
00849 
00850       for(int i=0; i<numberOfFilters; ++i)
00851       {
00852          FWEventSelector* selector = new FWEventSelector();
00853          {
00854             const FWConfiguration* value = iFrom.valueForKey( Form("EventFilter%d_enabled",i));
00855             assert(value);
00856             std::istringstream s(value->value());
00857             s>>selector->m_enabled;
00858          }
00859          selector->m_expression  = iFrom.valueForKey( Form("EventFilter%d_selection",i))->value();
00860          selector->m_description = iFrom.valueForKey( Form("EventFilter%d_comment",i) )->value();
00861 
00862          
00863          if (strstr(selector->m_expression.c_str(), "HLT"))
00864             selector->m_triggerProcess = "HLT";
00865          
00866          m_selectors.push_back(selector);
00867       }
00868    }
00869 
00870    // filter mode
00871    {
00872       const FWConfiguration* value = iFrom.valueForKey( "EventFilter_mode" );
00873       if (value)
00874       {
00875          std::istringstream s(value->value());
00876          s>> m_filterMode;
00877       }
00878    }
00879    
00880    // filter on
00881    {
00882       const FWConfiguration* value = iFrom.valueForKey( "EventFilter_enabled" );
00883       std::istringstream s(value->value());
00884       int x;
00885       s>> x;
00886       m_filterState = x ? kOn : kOff;
00887    }
00888    
00889 
00890    // redesplay new filters in event filter dialog if already mapped
00891    if (m_guiFilter)
00892    {
00893       m_guiFilter->reset();
00894       if (m_guiFilter->IsMapped()) m_guiFilter->show(&m_selectors, m_filterMode, m_filterState);
00895    }
00896    
00897    if (!m_files.empty())
00898    {
00899       // change filters in existing files 
00900       for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file)
00901       { 
00902          (*file)->filters().clear();
00903          for (std::list<FWEventSelector*>::iterator i = m_selectors.begin(); i != m_selectors.end(); ++i)
00904             (*file)->filters().push_back(new FWFileEntry::Filter(*i));
00905       }
00906       
00907       
00908       // run new filters if enabled, else just reset 
00909       if  (m_filterState == kOn)
00910          updateFileFilters();
00911       else
00912          postFiltering_.emit(true);
00913    }
00914    // update CmsShowMainFrame checkBoxIcon and button text
00915    if (oldFilterState != m_filterState)
00916       filterStateChanged_.emit(m_filterState);
00917 }
00918 
00919 void
00920 CmsShowNavigator::addTo(FWConfiguration& iTo) const
00921 {
00922    // selectors
00923    FWConfiguration tmp;
00924    int cnt = 0;
00925    for (std::list<FWEventSelector*>::const_iterator sel = m_selectors.begin(); sel != m_selectors.end(); ++sel) 
00926    {
00927       FWConfiguration filter;
00928 
00929       filter.addKeyValue("expression",FWConfiguration((*sel)->m_expression));
00930       filter.addKeyValue("enabled", FWConfiguration((*sel)->m_enabled ? "1" : "0"));
00931       filter.addKeyValue("comment", FWConfiguration((*sel)->m_description));
00932   
00933       if (!(*sel)->m_triggerProcess.empty())
00934          filter.addKeyValue("triggerProcess",FWConfiguration((*sel)->m_triggerProcess));
00935 
00936       tmp.addKeyValue(Form("------Filter[%d]------", cnt), filter,true);
00937       ++cnt;
00938    }
00939 
00940    iTo.addKeyValue("EventFilters", tmp,true);
00941 
00942    // mode
00943    {
00944       std::stringstream s;
00945       s<< m_filterMode;
00946       iTo.addKeyValue("EventFilter_mode", s.str());
00947    }
00948 
00949    // enabled
00950    iTo.addKeyValue("EventFilter_enabled",FWConfiguration( m_filterState == kOn ? "1" : "0"));
00951 }
00952 
00953 std::vector<std::string>& 
00954 CmsShowNavigator::getProcessList() const
00955 {
00956   return  m_main.context()->metadataManager()->processNamesInJob();
00957 }
00958 
00959 const edm::EventBase* 
00960 CmsShowNavigator::getCurrentEvent() const
00961 {
00962    return m_currentFile.isSet() ? (*m_currentFile)->event() : 0; 
00963 }
00964 
00965 const char*
00966 CmsShowNavigator::frameTitle()
00967 {
00968    if (m_files.empty()) return "";
00969 
00970    int nf = 0;
00971    for (FileQueue_t::const_iterator i = m_files.begin(); i!= m_files.end(); i++)
00972    {
00973 
00974       if ( i == m_currentFile) break;
00975       nf++;
00976    }
00977 
00978    TString name = (*m_currentFile)->file()->GetName();
00979    int l = name.Last('/');
00980    if (l != kNPOS)
00981       name.Remove(0, l+1);
00982 
00983    return Form("%s [%d/%d], event [%d/%d]", name.Data(),
00984                nf+1,  (int) m_files.size(),
00985                m_currentEvent+1, (*m_currentFile)->lastEvent()+1);
00986 }