CMS 3D CMS Logo

Public Member Functions | Private Types | Private Member Functions | Private Attributes

FWFFLooper Class Reference

#include <FWFFLooper.h>

Inheritance diagram for FWFFLooper:
CmsShowMainBase edm::EDLooperBase

List of all members.

Public Member Functions

virtual void attachTo (edm::ActivityRegistry &)
 Override this method if you need to monitor the state of the processing.
virtual void autoLoadNewEvent ()
virtual void beginRun (const edm::Run &, const edm::EventSetup &)
 Called after all event modules have processed the begin of a Run.
virtual void checkPosition ()
void display (const std::string &info="")
virtual void doBeginLuminosityBlock (edm::LuminosityBlockPrincipal &, edm::EventSetup const &)
virtual void doEndLuminosityBlock (edm::LuminosityBlockPrincipal &, edm::EventSetup const &)
virtual edm::EDLooperBase::Status duringLoop (const edm::Event &, const edm::EventSetup &, edm::ProcessingController &)
virtual edm::EDLooperBase::Status endOfLoop (const edm::EventSetup &, unsigned int)
 FWFFLooper (const edm::ParameterSet &)
TEveMagField * getMagField ()
void postBeginJob ()
void postEndJob ()
void quit ()
void remakeGeometry (const DisplayGeomRecord &dgRec)
void requestChanges (const std::string &, const edm::ParameterSet &)
void setupFieldForPropagator (TEveTrackPropagator *prop)
void showPathsGUI (const TGWindow *p)
virtual void startingNewLoop (unsigned int)
virtual void stopPlaying ()
virtual ~FWFFLooper ()

Private Types

typedef std::map< std::string,
edm::ParameterSet
ModuleChanges

Private Member Functions

 FWFFLooper (const FWFFLooper &)
void loadDefaultGeometryFile (void)
const FWFFLooperoperator= (const FWFFLooper &)

Private Attributes

bool m_AllowStep
edm::Service< FWFFHelperm_appHelper
bool m_autoReload
std::auto_ptr< fireworks::Contextm_context
TEveManager * m_EveManager
bool m_firstTime
edm::ESWatcher< DisplayGeomRecordm_geomWatcher
bool m_isFirstEvent
bool m_isLastEvent
TEveMagField * m_MagField
std::auto_ptr
< FWFFMetadataManager
m_metadataManager
std::auto_ptr< FWFFNavigatorm_navigator
edm::EventID m_nextEventId
FWPathsPopupm_pathsGUI
TRint * m_Rint
ModuleChanges m_scheduledChanges
bool m_ShowEvent

Detailed Description

Definition at line 44 of file FWFFLooper.h.


Member Typedef Documentation

typedef std::map<std::string, edm::ParameterSet> FWFFLooper::ModuleChanges [private]

Definition at line 105 of file FWFFLooper.h.


Constructor & Destructor Documentation

FWFFLooper::FWFFLooper ( const edm::ParameterSet ps)

Definition at line 123 of file FWFFLooper.cc.

References CmsShowMainBase::eiManager(), CmsShowMainBase::geometryFilename(), edm::ParameterSet::getUntrackedParameter(), loadDefaultGeometryFile(), m_context, m_MagField, m_metadataManager, m_navigator, CmsShowMainBase::setConfigFilename(), FWEventItemsManager::setContext(), CmsShowMainBase::setGeometryFilename(), CmsShowMainBase::setup(), and AlCaHLTBitMon_QueryRunRegistry::string.

   : CmsShowMainBase(),
     m_navigator(new FWFFNavigator(*this)), 
     m_metadataManager(new FWFFMetadataManager()),
     m_context(new fireworks::Context(changeManager(),
                                      selectionManager(),
                                      eiManager(),
                                      colorManager(),
                                      m_metadataManager.get())),
     m_Rint(m_appHelper->app()),
     m_AllowStep(true),
     m_ShowEvent(true),
     m_firstTime(true),
     m_pathsGUI(0),
     m_geomWatcher(this, &FWFFLooper::remakeGeometry)
{
   setup(m_navigator.get(), m_context.get(), m_metadataManager.get());

   eiManager()->setContext(m_context.get());

   // By default, we look up geometry and configuration in the workarea, then
   // in the release area then in the local directory.  It is also possible to
   // override those locations by using the displayConfigurationFilename and
   // geometryFilename in the parameterset.
   const char *releaseBase = getenv("CMSSW_RELEASE_BASE");
   const char *workarea = getenv("CMSSW_BASE");
   std::string displayConfigRelFilename = "/src/Fireworks/FWInterface/macros/ffw.fwc";
   std::string geometryRelFilename = "/src/Fireworks/FWInterface/data/cmsGeom10.root";

   std::string displayConfigFilename = "ffw.fwc";
   std::string geometryFilename;

   if (releaseBase && access((releaseBase + displayConfigFilename).c_str(), R_OK) == 0)
      displayConfigFilename = releaseBase + displayConfigRelFilename; 
   if (workarea && access((workarea + displayConfigRelFilename).c_str(), R_OK) == 0)
      displayConfigFilename = workarea + displayConfigRelFilename;   

   if (releaseBase && access((releaseBase + geometryRelFilename).c_str(), R_OK) == 0)
      geometryFilename = releaseBase + geometryRelFilename;
   if (workarea && access((workarea + geometryRelFilename).c_str(), R_OK) == 0)
      geometryFilename = workarea + geometryRelFilename;

   displayConfigFilename = ps.getUntrackedParameter<std::string>("displayConfigFilename", displayConfigFilename);
   geometryFilename = ps.getUntrackedParameter<std::string>("geometryFilename", geometryFilename);

   setGeometryFilename(geometryFilename);
   setConfigFilename(displayConfigFilename);

   if( !geometryFilename.empty())
   {
      loadDefaultGeometryFile();
   }

   m_MagField = new CmsEveMagField();
}
FWFFLooper::~FWFFLooper ( ) [virtual]

Definition at line 198 of file FWFFLooper.cc.

References m_MagField.

{
   delete m_MagField;
}
FWFFLooper::FWFFLooper ( const FWFFLooper ) [private]

Member Function Documentation

void FWFFLooper::attachTo ( edm::ActivityRegistry ) [virtual]
void FWFFLooper::autoLoadNewEvent ( ) [virtual]

This actually needs to be different from the standalone case because nextEvent() / previousEvent() will immediately interrupt the GUI event loop and fall back to the looper.

Implements CmsShowMainBase.

Definition at line 265 of file FWFFLooper.cc.

References FWGUIManager::enableActions(), CmsShowMainFrame::enableComplexNavigation(), CmsShowMainBase::forward(), FWGUIManager::getMainFrame(), CmsShowMainBase::guiManager(), CmsShowMainBase::loop(), m_autoReload, m_isFirstEvent, m_isLastEvent, m_navigator, CmsShowMainBase::setIsPlaying(), and CmsShowMainBase::stopAutoLoadTimer().

{
   stopAutoLoadTimer();
   bool reachedEnd = (forward() && m_isLastEvent) || (!forward() && m_isFirstEvent);

   if (!reachedEnd || loop())
   {
      // Will exit the loop here!
      m_autoReload = true;
      forward() ? m_navigator->nextEvent() : m_navigator->previousEvent();
   }
   else
   {
      m_autoReload = false;
      setIsPlaying(false);
      guiManager()->enableActions();
      guiManager()->getMainFrame()->enableComplexNavigation(false);
   }
}
void FWFFLooper::beginRun ( const edm::Run ,
const edm::EventSetup  
) [virtual]

Called after all event modules have processed the begin of a Run.

Reimplemented from edm::EDLooperBase.

Definition at line 300 of file FWFFLooper.cc.

References edm::ESWatcher< T >::check(), cond::rpcobimon::current, exception, FWGUIManager::filterButtonClicked_, edm::EventSetup::find(), fwLog, edm::EventSetup::get(), edm::Run::getByLabel(), CmsShowMainBase::getGeom(), CmsShowMainBase::guiManager(), FWGeometry::initMap(), edm::HandleBase::isValid(), fwlog::kInfo, CmsShowMainBase::loadGeometry(), m_autoReload, m_context, m_firstTime, m_geomWatcher, m_MagField, edm::ESHandle< T >::product(), FWGUIManager::setFilterButtonText(), CmsShowMainBase::setGeometryFilename(), CmsShowMainBase::setupActions(), CmsShowMainBase::setupConfiguration(), CmsShowMainBase::setupViewManagers(), FWGUIManager::showEventFilterGUI(), FWGUIManager::showEventFilterGUI_, showPathsGUI(), and FWGUIManager::updateStatus().

{
   // Check DisplayGeomRecord changes.
   try {
      m_geomWatcher.check(iSetup);
   }
   catch (...) {}
   
   // If the geometry was not picked up from a file, we try to get it from the
   // EventSetup!
   // FIXME: we need to check we execute only once because the view managers
   //        depend on geometry and they cannot be initialised more than once.
   //        This should actually be cleaned up so that the various view manager
   //        don't care about geometry.
   // FIXME: we should actually be able to update the geometry when requested.
   //        this is not possible at the moment.
   if (m_firstTime == true)
   {
      if (m_context->getGeom() == 0)
      {
         try
         {
            guiManager()->updateStatus("Loading geometry...");
            edm::ESHandle<FWRecoGeometry> geoh;
            iSetup.get<FWRecoGeometryRecord>().get(geoh);
            getGeom().initMap(geoh.product()->idToName);
            m_context->setGeom(&(getGeom()));
         }
         catch( const cms::Exception& exception )
         {
            setGeometryFilename("cmsGeom10.root");
            CmsShowMainBase::loadGeometry();
         }
      }

      setupViewManagers();
      setupConfiguration();
      setupActions();
      
      guiManager()->showEventFilterGUI_.connect(boost::bind(&FWFFLooper::showPathsGUI, this, _1));
      guiManager()->setFilterButtonText("Show paths / CMSSW configuration editor");
      guiManager()->filterButtonClicked_.connect(boost::bind(&FWGUIManager::showEventFilterGUI, guiManager()));

      m_firstTime = false;
      m_autoReload = false;
   }

   float current = 18160.0f;
   try {
      edm::Handle<edm::ConditionsInRunBlock> runCond;
      // bool res = iRun.getByType(runCond);
      bool res = iRun.getByLabel("conditionsInEdm", runCond);
      if (res && runCond.isValid())
      {
         printf("Got current from conds in edm %f\n", runCond->BAvgCurrent);
         current = runCond->BAvgCurrent;
      }
      else
      {
         printf("Could not extract run-conditions get-result=%d, is-valid=%d\n", res, runCond.isValid());

         const edm::eventsetup::EventSetupRecord* rec = iSetup.find( edm::eventsetup::EventSetupRecordKey::makeKey<RunInfoRcd>());
         if( 0 != rec )
         {
            edm::ESHandle<RunInfo> sum;
            iSetup.get<RunInfoRcd>().get(sum);

            current = sum->m_avg_current;
            printf("Got current from RunInfoRcd %f\n", sum->m_avg_current);
         }
      }
   }
   catch (...) {
      fwLog(fwlog::kInfo) << "ConditionsInRunBlock not available\n";
   }
   static_cast<CmsEveMagField*>(m_MagField)->SetFieldByCurrent(current);
}
void FWFFLooper::checkPosition ( ) [virtual]
void FWFFLooper::display ( const std::string &  info = "")

Definition at line 445 of file FWFFLooper.cc.

References m_AllowStep, and m_Rint.

{
   // Display whatever was registered so far, wait until user presses
   // the "Step" button.

   if (m_AllowStep)
   {
      gEve->Redraw3D();
      m_Rint->Run(kTRUE);
   }
}
void FWFFLooper::doBeginLuminosityBlock ( edm::LuminosityBlockPrincipal iLB,
edm::EventSetup const &  iES 
) [virtual]

Reimplemented from edm::EDLooperBase.

Definition at line 539 of file FWFFLooper.cc.

References edm::ESWatcher< T >::check(), and m_geomWatcher.

{
   try {
      m_geomWatcher.check(iES);
   } catch (...) {}
   
   EDLooperBase::doBeginLuminosityBlock(iLB, iES);
}
void FWFFLooper::doEndLuminosityBlock ( edm::LuminosityBlockPrincipal iLB,
edm::EventSetup const &  iES 
) [virtual]

Reimplemented from edm::EDLooperBase.

Definition at line 548 of file FWFFLooper.cc.

References edm::ESWatcher< T >::check(), and m_geomWatcher.

{
   try {
      m_geomWatcher.check(iES);
   }  catch (...) {}
   
   EDLooperBase::doEndLuminosityBlock(iLB, iES);
}
edm::EDLooperBase::Status FWFFLooper::duringLoop ( const edm::Event ,
const edm::EventSetup ,
edm::ProcessingController  
) [virtual]

Called after all event modules have had a chance to process the Event.

Implements edm::EDLooperBase.

Definition at line 380 of file FWFFLooper.cc.

References edm::ESWatcher< T >::check(), checkPosition(), CmsShowMainBase::draw(), edm::ProcessingController::forwardState(), FWPathsPopup::hasChanges(), edm::ProcessingController::kAtFirstEvent, edm::ProcessingController::kAtLastEvent, edm::EDLooperBase::kContinue, FWFFNavigator::kFirstEvent, FWFFNavigator::kLastEvent, FWFFNavigator::kNextEvent, FWFFNavigator::kPreviousEvent, edm::EDLooperBase::kStop, m_autoReload, m_geomWatcher, m_isFirstEvent, m_isLastEvent, m_metadataManager, m_navigator, m_nextEventId, m_pathsGUI, m_Rint, edm::ProcessingController::reverseState(), edm::ProcessingController::setTransitionToEvent(), edm::ProcessingController::setTransitionToNextEvent(), edm::ProcessingController::setTransitionToPreviousEvent(), and CmsShowMainBase::startAutoLoadTimer().

{
   // Check DisplayGeomRecord changes.
   try { 
      m_geomWatcher.check(es);
   } catch (...) {}
   

   m_isLastEvent = controller.forwardState() == edm::ProcessingController::kAtLastEvent;
   m_isFirstEvent = controller.reverseState() == edm::ProcessingController::kAtFirstEvent;
   // If the next event id is valid, set the transition so 
   // that we go to it go to to it.
   if (m_nextEventId != edm::EventID())
   {
      controller.setTransitionToEvent(m_nextEventId);
      m_nextEventId = edm::EventID();
      return kContinue;
   }
   // We handle "last event" by going to the first event and then moving to the
   // previous event.
   if (m_navigator->currentTransition() == FWFFNavigator::kLastEvent)
   {
      m_navigator->resetTransition();
      controller.setTransitionToPreviousEvent();
      return kContinue;
   }

   m_pathsGUI->hasChanges() = false;
   m_metadataManager->update(new FWFFMetadataUpdateRequest(event));
   m_navigator->setCurrentEvent(&event);
   if (m_autoReload == true)
      startAutoLoadTimer();

   checkPosition();
   draw();
      
   m_Rint->Run(kTRUE);
   // If the GUI changed the PSet, save the current event to reload
   // it on next iteration.
   if (m_pathsGUI->hasChanges())
   {
      m_nextEventId = edm::EventID();
      return kStop;
   }
   else if (m_navigator->currentTransition() == FWFFNavigator::kFirstEvent)
   {
      m_nextEventId = m_navigator->getFirstEventID();
      return kStop;
   }
   else if (m_navigator->currentTransition() == FWFFNavigator::kLastEvent)
   {
      m_nextEventId = m_navigator->getFirstEventID();
      return kStop;
   }
   else if (m_navigator->currentTransition() == FWFFNavigator::kNextEvent)
      controller.setTransitionToNextEvent();
   else if (m_navigator->currentTransition() == FWFFNavigator::kPreviousEvent)
      controller.setTransitionToPreviousEvent();
   return kContinue;
}
edm::EDLooperBase::Status FWFFLooper::endOfLoop ( const edm::EventSetup ,
unsigned int   
) [virtual]

This is called at the end of looping. We always continue because we want the transition set in the ProcessingController to happen.

Implements edm::EDLooperBase.

Definition at line 491 of file FWFFLooper.cc.

References dtNoiseDBValidation_cfg::cerr, alignCSCRings::e, fwLog, i, edm::EDLooperBase::kContinue, fwlog::kError, m_scheduledChanges, edm::EDLooperBase::moduleChanger(), and cms::Exception::what().

{
   // Looks like the module changer is availble only here.
   for (ModuleChanges::iterator i = m_scheduledChanges.begin(),
                                e = m_scheduledChanges.end();
        i != e; ++i)
   {
      try {
         moduleChanger()->changeModule(i->first, i->second);
      }
      catch (cms::Exception const& e)
      { 
         fwLog(fwlog::kError) << "FWFFLooper::endOfLoop caught exception.\n";
         std::cerr << e.what() << std::endl;
      } 
   }
   m_scheduledChanges.clear();
   return kContinue;
}
TEveMagField * FWFFLooper::getMagField ( )

Definition at line 462 of file FWFFLooper.cc.

References m_MagField.

{
   return m_MagField;
}
void FWFFLooper::loadDefaultGeometryFile ( void  ) [private]
const FWFFLooper& FWFFLooper::operator= ( const FWFFLooper ) [private]
void FWFFLooper::postBeginJob ( )
void FWFFLooper::postEndJob ( )

Definition at line 233 of file FWFFLooper.cc.

Referenced by attachTo().

{
//   printf("FWFFLooper::postEndJob\n");
//   TEveManager::Terminate();
}
void FWFFLooper::quit ( ) [virtual]

Implements CmsShowMainBase.

Definition at line 474 of file FWFFLooper.cc.

{
   gSystem->ExitLoop();

   // Throwing exception here is bad because:
   //   a) it does not work when in a "debug step";
   //   b) does not restore terminal state.
   // So we do exit instead for now.
   // throw cms::Exception("UserTerminationRequest");
   gSystem->Exit(0);
}
void FWFFLooper::remakeGeometry ( const DisplayGeomRecord dgRec)

Definition at line 560 of file FWFFLooper.cc.

References fwLog, relativeConstraints::geom, edm::eventsetup::EventSetupRecord::get(), fwlog::kInfo, edm::ESHandle< T >::product(), and FWGeometryTableViewManager::setGeoManagerRuntime().

{
   fwLog(fwlog::kInfo) << "FWFFLooper set TGeo geomtery from DisplayGeomRecord.\n";

   edm::ESHandle<TGeoManager> geom;
   dgRec.get(geom);
   TEveGeoManagerHolder _tgeo(const_cast<TGeoManager*>(geom.product()));
   FWGeometryTableViewManager::setGeoManagerRuntime(gGeoManager);
}
void FWFFLooper::requestChanges ( const std::string &  moduleLabel,
const edm::ParameterSet ps 
)

Definition at line 529 of file FWFFLooper.cc.

References m_scheduledChanges.

Referenced by FWPathsPopup::scheduleReloadEvent().

{
   m_scheduledChanges[moduleLabel] = ps;
}
void FWFFLooper::setupFieldForPropagator ( TEveTrackPropagator *  prop)

Definition at line 468 of file FWFFLooper.cc.

References m_MagField.

{
   prop->SetMagFieldObj(m_MagField, kFALSE);
}
void FWFFLooper::showPathsGUI ( const TGWindow *  p)

Definition at line 512 of file FWFFLooper.cc.

References CmsShowMainBase::guiManager(), m_pathsGUI, and FWGUIManager::setFilterButtonText().

Referenced by beginRun().

{
   if (!m_pathsGUI)
      return;
   if (m_pathsGUI->IsMapped())
   {
      guiManager()->setFilterButtonText("Show paths / CMSSW configuration editor");
      m_pathsGUI->UnmapWindow();
   }
   else
   {
      guiManager()->setFilterButtonText("Hide paths / CMSSW configuration editor");
      m_pathsGUI->MapWindow();
   }
}
void FWFFLooper::startingNewLoop ( unsigned  int) [virtual]

Called before system starts to loop over the events. The argument is a count of how many loops have been processed. For the first time through the events the argument will be 0.

Implements edm::EDLooperBase.

Definition at line 209 of file FWFFLooper.cc.

References CmsShowTaskExecutor::addTask(), f, info, m_pathsGUI, m_Rint, edm::EDLooperBase::scheduleInfo(), FWPathsPopup::setup(), CmsShowTaskExecutor::startDoingTasks(), and CmsShowMainBase::startupTasks().

{
   // Initialise on first loop.
   if (count == 0)
   {
      const edm::ScheduleInfo *info = scheduleInfo();
      m_pathsGUI->setup(info);

      // We need to enter the GUI loop in order to 
      // have all the callbacks executed. The last callback will
      // be responsible for returning the control to CMSSW. 
      assert(m_Rint);
      CmsShowTaskExecutor::TaskFunctor f;
      f=boost::bind(&TApplication::Terminate, m_Rint, 0);
      startupTasks()->addTask(f);
      // FIXME: do we really need to delay tasks like this?
      startupTasks()->startDoingTasks(); 
      m_Rint->Run(kTRUE);
      // Show the GUI ...
      gSystem->ProcessEvents();
   }
}
void FWFFLooper::stopPlaying ( ) [virtual]

Member Data Documentation

bool FWFFLooper::m_AllowStep [private]

Definition at line 100 of file FWFFLooper.h.

Referenced by display().

Definition at line 90 of file FWFFLooper.h.

bool FWFFLooper::m_autoReload [private]

Definition at line 108 of file FWFFLooper.h.

Referenced by autoLoadNewEvent(), beginRun(), duringLoop(), and stopPlaying().

std::auto_ptr<fireworks::Context> FWFFLooper::m_context [private]

Definition at line 93 of file FWFFLooper.h.

Referenced by beginRun(), and FWFFLooper().

TEveManager* FWFFLooper::m_EveManager [private]

Definition at line 95 of file FWFFLooper.h.

bool FWFFLooper::m_firstTime [private]

Definition at line 102 of file FWFFLooper.h.

Referenced by beginRun().

Definition at line 112 of file FWFFLooper.h.

Referenced by beginRun(), doBeginLuminosityBlock(), doEndLuminosityBlock(), and duringLoop().

Definition at line 109 of file FWFFLooper.h.

Referenced by autoLoadNewEvent(), checkPosition(), and duringLoop().

bool FWFFLooper::m_isLastEvent [private]

Definition at line 110 of file FWFFLooper.h.

Referenced by autoLoadNewEvent(), checkPosition(), and duringLoop().

TEveMagField* FWFFLooper::m_MagField [private]

Definition at line 98 of file FWFFLooper.h.

Referenced by beginRun(), FWFFLooper(), getMagField(), setupFieldForPropagator(), and ~FWFFLooper().

Definition at line 92 of file FWFFLooper.h.

Referenced by duringLoop(), and FWFFLooper().

std::auto_ptr<FWFFNavigator> FWFFLooper::m_navigator [private]

Definition at line 91 of file FWFFLooper.h.

Referenced by autoLoadNewEvent(), duringLoop(), and FWFFLooper().

Definition at line 107 of file FWFFLooper.h.

Referenced by duringLoop().

Definition at line 103 of file FWFFLooper.h.

Referenced by attachTo(), duringLoop(), showPathsGUI(), and startingNewLoop().

TRint* FWFFLooper::m_Rint [private]

Definition at line 96 of file FWFFLooper.h.

Referenced by display(), duringLoop(), and startingNewLoop().

Definition at line 106 of file FWFFLooper.h.

Referenced by endOfLoop(), and requestChanges().

bool FWFFLooper::m_ShowEvent [private]

Definition at line 101 of file FWFFLooper.h.