Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-05 22:48:08

0001 // -*- C++ -*-
0002 //
0003 // Package:     newVersion
0004 // Class  :     CmsShowNavigator
0005 //
0006 
0007 #include "DataFormats/FWLite/interface/Event.h"
0008 #include "Fireworks/Core/interface/CmsShowMain.h"
0009 
0010 #include "Fireworks/Core/interface/FWEventItem.h"
0011 
0012 // system include files
0013 #include <functional>
0014 #include "boost/regex.hpp"
0015 #include "TROOT.h"
0016 #include "TTree.h"
0017 #include "TFile.h"
0018 #include "TError.h"
0019 #include "TGTextEntry.h"
0020 #include "TGNumberEntry.h"
0021 #include "TBranch.h"
0022 #include "TAxis.h"
0023 
0024 #include "TApplication.h"
0025 #include "TSystem.h"
0026 #include "TObject.h"
0027 
0028 // user include files
0029 #include "Fireworks/Core/interface/CmsShowNavigator.h"
0030 #include "Fireworks/Core/interface/CSGAction.h"
0031 #include "Fireworks/Core/interface/FWEventItemsManager.h"
0032 #include "Fireworks/Core/interface/FWGUIEventFilter.h"
0033 #include "Fireworks/Core/interface/FWTEventList.h"
0034 #include "Fireworks/Core/interface/FWGUIManager.h"
0035 #include "Fireworks/Core/interface/FWGUIEventSelector.h"
0036 #include "Fireworks/Core/interface/FWJobMetadataManager.h"
0037 #include "Fireworks/Core/interface/FWConfiguration.h"
0038 #include "Fireworks/Core/interface/Context.h"
0039 #include "Fireworks/Core/interface/fwLog.h"
0040 
0041 #include "Fireworks/Core/src/FWTTreeCache.h"
0042 
0043 //
0044 // constructors and destructor
0045 //
0046 CmsShowNavigator::CmsShowNavigator(const CmsShowMain& main)
0047     : FWNavigatorBase(main),
0048       m_currentEvent(0),
0049 
0050       m_filterState(kOff),
0051       m_filterMode(kOr),
0052 
0053       m_filesNeedUpdate(true),
0054       m_newFileOnNextEvent(false),
0055 
0056       m_maxNumberOfFilesToChain(1),
0057 
0058       m_main(main),
0059       m_guiFilter(nullptr) {
0060   m_guiFilter = new FWGUIEventFilter(this);
0061   filterStateChanged_.connect(std::bind(&FWGUIEventFilter::updateFilterStateLabel, m_guiFilter, std::placeholders::_1));
0062 }
0063 
0064 CmsShowNavigator::~CmsShowNavigator() { delete m_guiFilter; }
0065 
0066 //
0067 // member functions
0068 //
0069 
0070 bool CmsShowNavigator::openFile(const std::string& fileName) {
0071   fwLog(fwlog::kDebug) << "CmsShowNavigator::openFile [" << fileName << "]" << std::endl;
0072   FWFileEntry* newFile = nullptr;
0073   try {
0074     newFile = new FWFileEntry(fileName, m_main.getVersionCheck(), m_main.getGlobalTagCheck());
0075   } catch (std::exception& iException) {
0076     fwLog(fwlog::kError) << "Navigator::openFile ecaught exception FWFileEntry constructor " << iException.what()
0077                          << std::endl;
0078 
0079     delete newFile;
0080     return false;
0081   }
0082 
0083   try {
0084     // delete all previous files
0085     while (!m_files.empty()) {
0086       FWFileEntry* file = m_files.front();
0087       m_files.pop_front();
0088       file->closeFile();
0089       delete file;
0090     }
0091 
0092     m_files.push_back(newFile);
0093     setCurrentFile(m_files.begin());
0094 
0095     // set filters
0096     for (std::list<FWEventSelector*>::iterator i = m_selectors.begin(); i != m_selectors.end(); ++i)
0097       newFile->filters().push_back(new FWFileEntry::Filter(*i));
0098 
0099     if (m_filterState != kOff)
0100       updateFileFilters();
0101 
0102     return true;
0103   } catch (std::exception& iException) {
0104     fwLog(fwlog::kError) << "Navigator::openFile caught exception " << iException.what() << std::endl;
0105     return false;
0106   }
0107 }
0108 
0109 bool CmsShowNavigator::appendFile(const std::string& fileName, bool checkFileQueueSize, bool live) {
0110   fwLog(fwlog::kDebug) << "CmsShowNavigator::appendFile [" << fileName << "]" << std::endl;
0111   FWFileEntry* newFile = nullptr;
0112   try {
0113     newFile = new FWFileEntry(fileName, m_main.getVersionCheck(), m_main.getGlobalTagCheck());
0114   } catch (std::exception& iException) {
0115     fwLog(fwlog::kError) << "Navigator::appendFile caught exception FWFileEntry constructor " << iException.what()
0116                          << std::endl;
0117     delete newFile;
0118     return false;
0119   }
0120 
0121   try {
0122     if (checkFileQueueSize) {
0123       int toErase = m_files.size() - (m_maxNumberOfFilesToChain + 1);
0124       while (toErase > 0) {
0125         FileQueue_i si = m_files.begin();
0126         if (m_currentFile == si)
0127           si++;
0128         FWFileEntry* file = *si;
0129         file->closeFile();
0130         delete file;
0131 
0132         m_files.erase(si);
0133         --toErase;
0134       }
0135 
0136       if (m_files.size() > m_maxNumberOfFilesToChain)
0137         fwLog(fwlog::kWarning) << "  " << m_files.size() << " chained files more than maxNumberOfFilesToChain \n"
0138                                << m_maxNumberOfFilesToChain << std::endl;
0139     }
0140 
0141     m_files.push_back(newFile);
0142 
0143     // Needed for proper handling of first registered file when -port option is in effect.
0144     if (!m_currentFile.isSet())
0145       setCurrentFile(m_files.begin());
0146 
0147     // set filters
0148     for (std::list<FWEventSelector*>::iterator i = m_selectors.begin(); i != m_selectors.end(); ++i)
0149       newFile->filters().push_back(new FWFileEntry::Filter(*i));
0150 
0151     if (m_filterState != kOff)
0152       updateFileFilters();
0153 
0154   } catch (std::exception& iException) {
0155     std::cerr << "Navigator::openFile caught exception " << iException.what() << std::endl;
0156     return false;
0157   }
0158 
0159   return true;
0160 }
0161 
0162 //______________________________________________________________________________
0163 
0164 void CmsShowNavigator::setCurrentFile(FileQueue_i fi) {
0165   if (fwlog::presentLogLevel() == fwlog::kDebug) {
0166     int cnt = 0;
0167     for (FileQueue_i i = m_files.begin(); i != m_files.end(); i++) {
0168       if (i == fi)
0169         break;
0170       cnt++;
0171     }
0172 
0173     fwLog(fwlog::kDebug) << "CmsShowNavigator::setCurrentFile [" << (*fi)->file()->GetName() << "] file idx in chain ["
0174                          << cnt << "/" << m_files.size() - 1 << "]" << std::endl;
0175   } else {
0176     fwLog(fwlog::kInfo) << "Set current file to " << (*fi)->file()->GetName() << ".\n";
0177   }
0178 
0179   m_currentFile = fi;
0180   fileChanged_.emit((*m_currentFile)->file());
0181 }
0182 
0183 void CmsShowNavigator::goTo(FileQueue_i fi, int event) {
0184   if (fi != m_currentFile)
0185     setCurrentFile(fi);
0186 
0187   if (fwlog::presentLogLevel() == fwlog::kDebug) {
0188     int total = (*fi)->tree()->GetEntries();
0189     fwLog(fwlog::kDebug) << "CmsShowNavigator::goTo  current file event [" << event << "/" << total - 1 << "]"
0190                          << std::endl;
0191 
0192     CpuInfo_t cpuInfo;
0193     MemInfo_t memInfo;
0194     ProcInfo_t procInfo;
0195     gSystem->GetCpuInfo(&cpuInfo, 0);
0196     gSystem->GetMemInfo(&memInfo);
0197     gSystem->GetProcInfo(&procInfo);
0198 
0199     time_t curtime;
0200     time(&curtime);
0201 
0202     fwLog(fwlog::kDebug) << "Current Time: " << ctime(&curtime);
0203     fwLog(fwlog::kDebug) << "memInfo.fMemUsed \t" << memInfo.fMemUsed << std::endl;
0204     fwLog(fwlog::kDebug) << "memInfo.fSwapUsed\t" << memInfo.fSwapUsed << std::endl;
0205     fwLog(fwlog::kDebug) << "procInfo.fMemResident\t" << procInfo.fMemResident << std::endl;
0206     fwLog(fwlog::kDebug) << "procInfo.fMemVirtual\t" << procInfo.fMemVirtual << std::endl;
0207     fwLog(fwlog::kDebug) << "cpuInfo.fLoad1m \t" << cpuInfo.fLoad1m << std::endl;
0208     fwLog(fwlog::kDebug) << "cpuInfo.fLoad5m \t" << cpuInfo.fLoad5m << std::endl;
0209   }
0210 
0211   if (FWTTreeCache::IsLogging()) {
0212     printf("FWTTreeCache statistics before going to event %d:\n", event);
0213     (*m_currentFile)->tree()->PrintCacheStats();  // ("cachedbranches");
0214   }
0215 
0216   (*m_currentFile)->event()->to(event);
0217   (*m_currentFile)->tree()->LoadTree(event);
0218   m_currentEvent = event;
0219 
0220   newEvent_.emit();
0221 }
0222 
0223 void CmsShowNavigator::goToRunEvent(edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi, edm::EventNumber_t event) {
0224   for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file) {
0225     Long64_t index = (*file)->event()->indexFromEventId(run, lumi, event);
0226     if (index >= 0) {
0227       goTo(file, index);
0228       break;
0229     }
0230   }
0231 }
0232 
0233 //______________________________________________________________________________
0234 
0235 void CmsShowNavigator::firstEvent() {
0236   FileQueue_i x = m_files.begin();
0237   if (m_filterState == kOn) {
0238     while (x != m_files.end()) {
0239       if ((*x)->hasSelectedEvents()) {
0240         goTo(x, (*x)->firstSelectedEvent());
0241         return;
0242       }
0243       ++x;
0244     }
0245   } else {
0246     goTo(x, 0);
0247   }
0248 }
0249 
0250 void CmsShowNavigator::lastEvent() {
0251   FileQueue_i x = m_files.end();
0252   if (m_filterState == kOn) {
0253     while (x != m_files.begin()) {
0254       --x;
0255       if ((*x)->hasSelectedEvents()) {
0256         goTo(x, (*x)->lastSelectedEvent());
0257         return;
0258       }
0259     }
0260   } else {
0261     --x;
0262     goTo(x, (*x)->lastEvent());
0263   }
0264 }
0265 
0266 //______________________________________________________________________________
0267 
0268 bool CmsShowNavigator::nextSelectedEvent() {
0269   int nextEv = (*m_currentFile)->nextSelectedEvent(m_currentEvent);
0270   if (nextEv > -1) {
0271     goTo(m_currentFile, nextEv);
0272     return true;
0273   } else {
0274     FileQueue_i i = m_currentFile;
0275     ++i;
0276     while (i != m_files.end()) {
0277       if ((*i)->hasSelectedEvents()) {
0278         goTo(i, (*i)->firstSelectedEvent());
0279         return true;
0280       }
0281       ++i;
0282     }
0283   }
0284 
0285   return false;
0286 }
0287 
0288 //______________________________________________________________________________
0289 
0290 void CmsShowNavigator::nextEvent() {
0291   if (m_newFileOnNextEvent) {
0292     FileQueue_i last = m_files.end();
0293     --last;
0294     if (m_filterState == kOn)
0295       goTo(last, (*last)->firstSelectedEvent());
0296     else
0297       goTo(last, 0);
0298 
0299     m_newFileOnNextEvent = false;
0300     return;
0301   }
0302 
0303   if (m_filterState == kOn) {
0304     nextSelectedEvent();
0305     return;
0306   } else {
0307     if (m_currentEvent < (*m_currentFile)->lastEvent()) {
0308       goTo(m_currentFile, m_currentEvent + 1);
0309     } else {
0310       FileQueue_i x = m_currentFile;
0311       ++x;
0312       if (x != m_files.end()) {
0313         goTo(x, 0);
0314       }
0315     }
0316   }
0317 }
0318 
0319 //______________________________________________________________________________
0320 
0321 bool CmsShowNavigator::previousSelectedEvent() {
0322   int prevEv = (*m_currentFile)->previousSelectedEvent(m_currentEvent);
0323   if (prevEv > -1) {
0324     goTo(m_currentFile, prevEv);
0325     return true;
0326   } else {
0327     FileQueue_i i(m_currentFile);
0328     i.previous(m_files);
0329     while (i != m_files.end()) {
0330       if ((*i)->hasSelectedEvents()) {
0331         goTo(i, (*i)->lastSelectedEvent());
0332         return true;
0333       }
0334       i.previous(m_files);
0335     }
0336   }
0337   return false;
0338 }
0339 
0340 //______________________________________________________________________________
0341 
0342 void CmsShowNavigator::previousEvent() {
0343   if (m_filterState == kOn) {
0344     previousSelectedEvent();
0345   } else {
0346     if (m_currentEvent > 0) {
0347       goTo(m_currentFile, m_currentEvent - 1);
0348     } else {
0349       // last event in previous file
0350       FileQueue_i x = m_currentFile;
0351       if (x != m_files.begin()) {
0352         --x;
0353         goTo(x, (*x)->lastEvent());
0354       }
0355     }
0356   }
0357 }
0358 
0359 //______________________________________________________________________________
0360 
0361 void CmsShowNavigator::toggleFilterEnable() {
0362   // callback
0363 
0364   fwLog(fwlog::kInfo) << "CmsShowNavigator::toggleFilterEnable filters enabled [" << (m_filterState == kOff) << "]"
0365                       << std::endl;
0366 
0367   if (m_filterState == kOff) {
0368     m_filterState = kOn;
0369     m_guiFilter->setupDisableFilteringButton(true);
0370 
0371     updateFileFilters();
0372   } else {
0373     m_filterState = kOff;
0374     m_guiFilter->setupDisableFilteringButton(false);
0375   }
0376 
0377   filterStateChanged_.emit(m_filterState);
0378 }
0379 
0380 void CmsShowNavigator::withdrawFilter() {
0381   fwLog(fwlog::kInfo) << "CmsShowNavigator::witdrawFilter" << std::endl;
0382   m_filterState = kWithdrawn;
0383   filterStateChanged_.emit(m_filterState);
0384 }
0385 
0386 void CmsShowNavigator::resumeFilter() {
0387   fwLog(fwlog::kInfo) << "CmsShowNavigator::resumeFilter" << std::endl;
0388   m_filterState = kOn;
0389   filterStateChanged_.emit(m_filterState);
0390 }
0391 
0392 void CmsShowNavigator::updateFileFilters() {
0393   // run filters on files
0394   std::list<FWFileEntry::Filter>::iterator it;
0395   for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file) {
0396     if (m_filesNeedUpdate)
0397       (*file)->needUpdate();
0398     (*file)->updateFilters(m_main.context()->eventItemsManager(), m_filterMode == kOr);
0399   }
0400   updateSelectorsInfo();
0401   m_filesNeedUpdate = false;
0402 
0403   int nSelected = getNSelectedEvents();
0404   if (nSelected) {
0405     // go to the nearest selected event/file
0406     bool changeCurrentEvent = !(*m_currentFile)->isEventSelected(m_currentEvent);
0407     if (changeCurrentEvent) {
0408       if (!nextSelectedEvent())
0409         previousSelectedEvent();
0410     }
0411 
0412     if (m_filterState == kWithdrawn)
0413       resumeFilter();
0414 
0415     postFiltering_.emit(changeCurrentEvent);
0416   } else {
0417     withdrawFilter();
0418   }
0419 
0420   if (fwlog::presentLogLevel() == fwlog::kDebug) {
0421     fwLog(fwlog::kDebug) << "CmsShowNavigator::updateFileFilters selected events over files [" << getNSelectedEvents()
0422                          << "/" << getNTotalEvents() << "]" << std::endl;
0423   }
0424 }
0425 
0426 //=======================================================================
0427 void CmsShowNavigator::removeFilter(std::list<FWEventSelector*>::iterator si) {
0428   fwLog(fwlog::kDebug) << "CmsShowNavigator::removeFilter " << (*si)->m_expression << std::endl;
0429 
0430   std::list<FWFileEntry::Filter*>::iterator it;
0431   for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file) {
0432     for (it = (*file)->filters().begin(); it != (*file)->filters().end(); ++it) {
0433       if ((*it)->m_selector == *si) {
0434         FWFileEntry::Filter* f = *it;
0435         delete f;
0436         (*file)->filters().erase(it);
0437         break;
0438       }
0439     }
0440   }
0441 
0442   delete *si;
0443   m_selectors.erase(si);
0444   m_filesNeedUpdate = true;
0445 }
0446 
0447 void CmsShowNavigator::addFilter(FWEventSelector* ref) {
0448   fwLog(fwlog::kDebug) << "CmsShowNavigator::addFilter " << ref->m_expression << std::endl;
0449 
0450   FWEventSelector* selector = new FWEventSelector(ref);
0451   m_selectors.push_back(selector);
0452 
0453   for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file) {
0454     (*file)->filters().push_back(new FWFileEntry::Filter(selector));
0455   }
0456   m_filesNeedUpdate = true;
0457 }
0458 
0459 void CmsShowNavigator::changeFilter(FWEventSelector* selector, bool updateFilter) {
0460   fwLog(fwlog::kDebug) << "CmsShowNavigator::changeFilter " << selector->m_expression << std::endl;
0461 
0462   std::list<FWFileEntry::Filter*>::iterator it;
0463   for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file) {
0464     for (it = (*file)->filters().begin(); it != (*file)->filters().end(); ++it) {
0465       if ((*it)->m_selector == selector) {
0466         if (updateFilter)
0467           (*it)->m_needsUpdate = true;
0468         (*it)->m_selector->m_expression = selector->m_expression;
0469         break;
0470       }
0471     }
0472   }
0473   m_filesNeedUpdate = true;
0474 }
0475 
0476 void CmsShowNavigator::applyFiltersFromGUI() {
0477   m_filesNeedUpdate = false;
0478 
0479   // check if filters are set ON
0480   if (m_filterState == kOff) {
0481     m_filesNeedUpdate = true;
0482     m_filterState = kOn;
0483     m_guiFilter->setupDisableFilteringButton(true);
0484   }
0485 
0486   // compare changes and then call updateFileFilters
0487   std::list<FWEventSelector*>::iterator si = m_selectors.begin();
0488   std::list<FWGUIEventSelector*>::iterator gi = m_guiFilter->guiSelectors().begin();
0489 
0490   if (m_filterMode != m_guiFilter->getFilterMode()) {
0491     m_filterMode = m_guiFilter->getFilterMode();
0492     m_filesNeedUpdate = true;
0493   }
0494 
0495   while (si != m_selectors.end() || gi != m_guiFilter->guiSelectors().end()) {
0496     if (gi == m_guiFilter->guiSelectors().end() && si != m_selectors.end()) {
0497       removeFilter(si++);
0498     } else if (si == m_selectors.end() && gi != m_guiFilter->guiSelectors().end()) {
0499       addFilter((*gi)->guiSelector());
0500       (*gi)->setOrigSelector(m_selectors.back());
0501       ++gi;
0502     } else {
0503       if (*si == (*gi)->origSelector()) {
0504         FWEventSelector* g = (*gi)->guiSelector();
0505         FWEventSelector* o = *si;
0506         bool filterNeedUpdate = o->m_expression != g->m_expression;
0507         if (filterNeedUpdate || o->m_enabled != g->m_enabled) {
0508           *o = *g;
0509           changeFilter(*si, filterNeedUpdate);
0510         } else {
0511           o->m_description = g->m_description;
0512         }
0513         ++si;
0514         ++gi;
0515       } else if ((*gi)->origSelector() == nullptr) {
0516         addFilter((*gi)->guiSelector());
0517         (*gi)->setOrigSelector(m_selectors.back());
0518         ++gi;
0519       } else {
0520         removeFilter(si++);
0521       }
0522     }
0523   }
0524 
0525   if (m_filesNeedUpdate)
0526     updateFileFilters();
0527 
0528   filterStateChanged_.emit(m_filterState);
0529 }
0530 //______________________________________________________________________________
0531 // helpers for gui state
0532 
0533 bool CmsShowNavigator::isFirstEvent() {
0534   if (m_filterState == kOn) {
0535     FileQueue_i firstSelectedFile;
0536     for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file) {
0537       if ((*file)->hasSelectedEvents()) {
0538         firstSelectedFile = file;
0539         break;
0540       }
0541     }
0542 
0543     if (firstSelectedFile == m_currentFile)
0544       return (*m_currentFile)->firstSelectedEvent() == m_currentEvent;
0545   } else {
0546     if (m_currentFile == m_files.begin()) {
0547       return m_currentEvent == 0;
0548     }
0549   }
0550   return false;
0551 }
0552 
0553 bool CmsShowNavigator::isLastEvent() {
0554   if (m_filterState == kOn) {
0555     FileQueue_i lastSelectedFile;
0556     for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file) {
0557       if ((*file)->hasSelectedEvents())
0558         lastSelectedFile = file;
0559     }
0560     if (lastSelectedFile == m_currentFile)
0561       return (*m_currentFile)->lastSelectedEvent() == m_currentEvent;
0562   } else {
0563     FileQueue_i lastFile = m_files.end();
0564     --lastFile;
0565     if (m_currentFile == lastFile) {
0566       return (*m_currentFile)->lastEvent() == m_currentEvent;
0567     }
0568   }
0569   return false;
0570 }
0571 
0572 //______________________________________________________________________________
0573 void CmsShowNavigator::updateSelectorsInfo() {
0574   // reset
0575   std::list<FWEventSelector*>::const_iterator sel = m_selectors.begin();
0576   while (sel != m_selectors.end()) {
0577     (*sel)->m_selected = 0;
0578     (*sel)->m_updated = true;
0579     ++sel;
0580   }
0581 
0582   // loop file filters
0583   std::list<FWFileEntry::Filter*>::iterator i;
0584   for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file) {
0585     std::list<FWFileEntry::Filter*>& filters = (*file)->filters();
0586     for (i = filters.begin(); i != filters.end(); ++i) {
0587       if ((*i)->m_eventList) {
0588         (*i)->m_selector->m_selected += (*i)->m_eventList->GetN();
0589       }
0590 
0591       if ((*i)->m_needsUpdate)
0592         (*i)->m_selector->m_updated = false;
0593     }
0594   }
0595   if (m_guiFilter) {
0596     std::list<FWGUIEventSelector*>::const_iterator gs = m_guiFilter->guiSelectors().begin();
0597     while (gs != m_guiFilter->guiSelectors().end()) {
0598       (*gs)->updateNEvents();
0599       ++gs;
0600     }
0601   }
0602 }
0603 
0604 int CmsShowNavigator::getNSelectedEvents() {
0605   int sum = 0;
0606   for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file) {
0607     if ((*file)->globalSelection())
0608       sum += (*file)->globalSelection()->GetN();
0609   }
0610   return sum;
0611 }
0612 
0613 int CmsShowNavigator::getNTotalEvents() {
0614   int sum = 0;
0615   for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file) {
0616     sum += (*file)->tree()->GetEntries();
0617   }
0618 
0619   return sum;
0620 }
0621 
0622 const char* CmsShowNavigator::filterStatusMessage() {
0623   if (m_filterState == kOn)
0624     return Form("%d events are selected from %d.", getNSelectedEvents(), getNTotalEvents());
0625   else if (m_filterState == kOff)
0626     return "Filtering is OFF.";
0627   else
0628     return "Filtering is disabled.";
0629 }
0630 
0631 bool CmsShowNavigator::canEditFiltersExternally() {
0632   bool haveActiveFilters = false;
0633   for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file) {
0634     if ((*file)->hasActiveFilters()) {
0635       haveActiveFilters = true;
0636       break;
0637     }
0638   }
0639 
0640   bool btnEnabled = haveActiveFilters;
0641 
0642   if (m_guiFilter && m_guiFilter->isOpen())
0643     btnEnabled = false;
0644 
0645   return btnEnabled;
0646 }
0647 
0648 void CmsShowNavigator::editFiltersExternally() { editFiltersExternally_.emit(canEditFiltersExternally()); }
0649 
0650 void CmsShowNavigator::showEventFilterGUI(const TGWindow* p) {
0651   if (m_guiFilter->IsMapped()) {
0652     m_guiFilter->CloseWindow();
0653   } else {
0654     m_guiFilter->show(&m_selectors, m_filterMode, m_filterState);
0655     editFiltersExternally_.emit(canEditFiltersExternally());
0656   }
0657 }
0658 
0659 //______________________________________________________________________________
0660 
0661 void CmsShowNavigator::setFrom(const FWConfiguration& iFrom) {
0662   m_filesNeedUpdate = true;
0663 
0664   EFilterState oldFilterState = m_filterState;
0665 
0666   m_selectors.clear();
0667 
0668   // selectors
0669   const FWConfiguration* sConf = iFrom.valueForKey("EventFilters");
0670 
0671   if (sConf) {
0672     const FWConfiguration::KeyValues* keyVals = sConf->keyValues();
0673     if (keyVals) {
0674       for (FWConfiguration::KeyValuesIt it = keyVals->begin(); it != keyVals->end(); ++it) {
0675         const FWConfiguration& conf = (*it).second;
0676         FWEventSelector* selector = new FWEventSelector();
0677         selector->m_expression = conf.valueForKey("expression")->value();
0678         selector->m_description = conf.valueForKey("comment")->value();
0679         selector->m_enabled = atoi(conf.valueForKey("enabled")->value().c_str());
0680         if (conf.valueForKey("triggerProcess"))
0681           selector->m_triggerProcess = conf.valueForKey("triggerProcess")->value();
0682         m_selectors.push_back(selector);
0683       }
0684     }
0685   } else {
0686     int numberOfFilters = 0;
0687     const FWConfiguration* nfvalue = iFrom.valueForKey("EventFilter_total");
0688     if (nfvalue)
0689       numberOfFilters = atoi(nfvalue->value().c_str());
0690 
0691     for (int i = 0; i < numberOfFilters; ++i) {
0692       FWEventSelector* selector = new FWEventSelector();
0693       {
0694         const FWConfiguration* value = iFrom.valueForKey(Form("EventFilter%d_enabled", i));
0695         assert(value);
0696         std::istringstream s(value->value());
0697         s >> selector->m_enabled;
0698       }
0699       selector->m_expression = iFrom.valueForKey(Form("EventFilter%d_selection", i))->value();
0700       selector->m_description = iFrom.valueForKey(Form("EventFilter%d_comment", i))->value();
0701 
0702       if (strstr(selector->m_expression.c_str(), "HLT"))
0703         selector->m_triggerProcess = "HLT";
0704 
0705       m_selectors.push_back(selector);
0706     }
0707   }
0708 
0709   // filter mode
0710   {
0711     const FWConfiguration* value = iFrom.valueForKey("EventFilter_mode");
0712     if (value) {
0713       std::istringstream s(value->value());
0714       s >> m_filterMode;
0715     }
0716   }
0717 
0718   // filter on
0719   {
0720     const FWConfiguration* value = iFrom.valueForKey("EventFilter_enabled");
0721     std::istringstream s(value->value());
0722     int x;
0723     s >> x;
0724     m_filterState = x ? kOn : kOff;
0725   }
0726 
0727   // redesplay new filters in event filter dialog if already mapped
0728   if (m_guiFilter) {
0729     m_guiFilter->reset();
0730     if (m_guiFilter->IsMapped())
0731       m_guiFilter->show(&m_selectors, m_filterMode, m_filterState);
0732   }
0733 
0734   if (!m_files.empty()) {
0735     // change filters in existing files
0736     for (FileQueue_i file = m_files.begin(); file != m_files.end(); ++file) {
0737       (*file)->filters().clear();
0738       for (std::list<FWEventSelector*>::iterator i = m_selectors.begin(); i != m_selectors.end(); ++i)
0739         (*file)->filters().push_back(new FWFileEntry::Filter(*i));
0740     }
0741 
0742     // run new filters if enabled, else just reset
0743     if (m_filterState == kOn)
0744       updateFileFilters();
0745     else
0746       postFiltering_.emit(true);
0747   }
0748   // update CmsShowMainFrame checkBoxIcon and button text
0749   if (oldFilterState != m_filterState)
0750     filterStateChanged_.emit(m_filterState);
0751 }
0752 
0753 void CmsShowNavigator::addTo(FWConfiguration& iTo) const {
0754   // selectors
0755   FWConfiguration tmp;
0756   int cnt = 0;
0757   for (std::list<FWEventSelector*>::const_iterator sel = m_selectors.begin(); sel != m_selectors.end(); ++sel) {
0758     FWConfiguration filter;
0759 
0760     filter.addKeyValue("expression", FWConfiguration((*sel)->m_expression));
0761     filter.addKeyValue("enabled", FWConfiguration((*sel)->m_enabled ? "1" : "0"));
0762     filter.addKeyValue("comment", FWConfiguration((*sel)->m_description));
0763 
0764     if (!(*sel)->m_triggerProcess.empty())
0765       filter.addKeyValue("triggerProcess", FWConfiguration((*sel)->m_triggerProcess));
0766 
0767     tmp.addKeyValue(Form("------Filter[%d]------", cnt), filter, true);
0768     ++cnt;
0769   }
0770 
0771   iTo.addKeyValue("EventFilters", tmp, true);
0772 
0773   // mode
0774   {
0775     std::stringstream s;
0776     s << m_filterMode;
0777     iTo.addKeyValue("EventFilter_mode", s.str());
0778   }
0779 
0780   // enabled
0781   iTo.addKeyValue("EventFilter_enabled", FWConfiguration(m_filterState == kOn ? "1" : "0"));
0782 }
0783 
0784 std::vector<std::string>& CmsShowNavigator::getProcessList() const {
0785   return m_main.context()->metadataManager()->processNamesInJob();
0786 }
0787 
0788 const edm::EventBase* CmsShowNavigator::getCurrentEvent() const {
0789   return m_currentFile.isSet() ? (*m_currentFile)->event() : nullptr;
0790 }
0791 
0792 const char* CmsShowNavigator::frameTitle() {
0793   if (m_files.empty())
0794     return "";
0795 
0796   int nf = 0;
0797   for (FileQueue_t::const_iterator i = m_files.begin(); i != m_files.end(); i++) {
0798     if (i == m_currentFile)
0799       break;
0800     nf++;
0801   }
0802 
0803   TString name = (*m_currentFile)->file()->GetName();
0804   int l = name.Last('/');
0805   if (l != kNPOS)
0806     name.Remove(0, l + 1);
0807 
0808   return Form("%s [%d/%d], event [%d/%d]",
0809               name.Data(),
0810               nf + 1,
0811               (int)m_files.size(),
0812               m_currentEvent + 1,
0813               (*m_currentFile)->lastEvent() + 1);
0814 }
0815 
0816 std::string CmsShowNavigator::getCurrentGlobalTag() {
0817   std::string res;
0818   if (!m_files.empty()) {
0819     res = (*m_currentFile)->getGlobalTag();
0820   }
0821   return res;
0822 }