CMS 3D CMS Logo

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

edm::Worker Class Reference

#include <Worker.h>

Inheritance diagram for edm::Worker:
edm::WorkerT< T > edm::WorkerT< OutputModule > edm::OutputWorker

List of all members.

Public Types

enum  State { Ready, Pass, Fail, Exception }

Public Member Functions

void beginJob ()
void clearCounters ()
ModuleDescription const * descPtr () const
ModuleDescription const & description () const
template<typename T >
bool doWork (typename T::MyPrincipal &, EventSetup const &c, CurrentProcessingContext const *cpc, CPUTimer *const timer)
void endJob ()
void postForkReacquireResources (unsigned int iChildIndex, unsigned int iNumberOfChildren)
void preForkReleaseResources ()
void reset ()
void respondToCloseInputFile (FileBlock const &fb)
void respondToCloseOutputFiles (FileBlock const &fb)
void respondToOpenInputFile (FileBlock const &fb)
void respondToOpenOutputFiles (FileBlock const &fb)
void setActivityRegistry (boost::shared_ptr< ActivityRegistry > areg)
State state () const
std::pair< double, double > timeCpuReal () const
int timesExcept () const
int timesFailed () const
int timesPass () const
int timesPassed () const
int timesRun () const
int timesVisited () const
void useStopwatch ()
 Worker (ModuleDescription const &iMD, WorkerParams const &iWP)
virtual ~Worker ()

Protected Member Functions

virtual void implBeginJob ()=0
virtual bool implDoBegin (EventPrincipal &, EventSetup const &c, CurrentProcessingContext const *cpc)=0
virtual bool implDoBegin (RunPrincipal &rp, EventSetup const &c, CurrentProcessingContext const *cpc)=0
virtual bool implDoBegin (LuminosityBlockPrincipal &lbp, EventSetup const &c, CurrentProcessingContext const *cpc)=0
virtual bool implDoEnd (EventPrincipal &, EventSetup const &c, CurrentProcessingContext const *cpc)=0
virtual bool implDoEnd (RunPrincipal &rp, EventSetup const &c, CurrentProcessingContext const *cpc)=0
virtual bool implDoEnd (LuminosityBlockPrincipal &lbp, EventSetup const &c, CurrentProcessingContext const *cpc)=0
virtual void implEndJob ()=0
virtual std::string workerType () const =0

Private Member Functions

virtual void implPostForkReacquireResources (unsigned int iChildIndex, unsigned int iNumberOfChildren)=0
virtual void implPreForkReleaseResources ()=0
virtual void implRespondToCloseInputFile (FileBlock const &fb)=0
virtual void implRespondToCloseOutputFiles (FileBlock const &fb)=0
virtual void implRespondToOpenInputFile (FileBlock const &fb)=0
virtual void implRespondToOpenOutputFiles (FileBlock const &fb)=0

Private Attributes

ActionTable const * actions_
boost::shared_ptr
< ActivityRegistry
actReg_
boost::shared_ptr< edm::Exceptioncached_exception_
ModuleDescription md_
State state_
RunStopwatch::StopwatchPointer stopwatch_
int timesExcept_
int timesFailed_
int timesPassed_
int timesRun_
int timesVisited_

Detailed Description

Definition at line 40 of file Worker.h.


Member Enumeration Documentation

Enumerator:
Ready 
Pass 
Fail 
Exception 

Definition at line 42 of file Worker.h.


Constructor & Destructor Documentation

edm::Worker::Worker ( ModuleDescription const &  iMD,
WorkerParams const &  iWP 
)

Definition at line 37 of file Worker.cc.

edm::Worker::~Worker ( ) [virtual]

Definition at line 53 of file Worker.cc.

                  {
  }

Member Function Documentation

void edm::Worker::beginJob ( void  )

Definition at line 60 of file Worker.cc.

References actReg_, edm::errors::BadAlloc, edm::errors::BadExceptionType, trackerHits::c, cached_exception_, description(), ExpressReco_HICollisions_FallBack::e, exception, Exception, implBeginJob(), md_, asciidump::s, state_, edm::errors::StdException, edm::errors::Unknown, and workerType().

Referenced by edm::Schedule::beginJob(), and edm::Schedule::changeModule().

                        {
    
    try {
        ModuleBeginJobSignalSentry cpp(actReg_.get(), md_);
        implBeginJob();
    }
    catch(cms::Exception& e) {
        LogError("BeginJob")
          << "A cms::Exception is going through " << workerType() << ":\n";
        state_ = Exception;
        e << "A cms::Exception is going through " << workerType() << ":\n";
        exceptionContext(md_, e);
        throw;
    }
    catch(std::bad_alloc& bda) {
        LogError("BeginJob")
          << "A std::bad_alloc is going through " << workerType() << ":\n"
          << description() << "\n";
        state_ = Exception;
        cached_exception_.reset(new edm::Exception(errors::BadAlloc));
        *cached_exception_
          << "A std::bad_alloc exception occurred during a call to the module ";
        exceptionContext(md_, *cached_exception_)
          << "The job has probably exhausted the virtual memory available to the process.\n";
        throw *cached_exception_;
    }
    catch(std::exception& e) {
        LogError("BeginJob")
          << "A std::exception is going through " << workerType() << ":\n"
          << description() << "\n";
        state_ = Exception;
        cached_exception_.reset(new edm::Exception(errors::StdException));
        *cached_exception_
          << "A std::exception occurred during a call to the module ";
        exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n"
          << "Previous information:\n" << e.what();
        throw *cached_exception_;
    }
    catch(std::string& s) {
        LogError("BeginJob") 
          << "module caught a std::string during endJob\n";
        state_ = Exception;
        cached_exception_.reset(new edm::Exception(errors::BadExceptionType, "std::string"));
        *cached_exception_
          << "A std::string thrown as an exception occurred during a call to the module ";
        exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n"
          << "Previous information:\n string = " << s;
        throw *cached_exception_;
    }
    catch(char const* c) {
        LogError("BeginJob") 
          << "module caught a const char* during endJob\n";
        state_ = Exception;
        cached_exception_.reset(new edm::Exception(errors::BadExceptionType, "const char *"));
        *cached_exception_
          << "A const char* thrown as an exception occurred during a call to the module ";
        exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n"
          << "Previous information:\n const char* = " << c << "\n";
        throw *cached_exception_;
    }
    catch(...) {
        LogError("BeginJob")
          << "An unknown Exception occurred in\n" << description() << "\n";
        state_ = Exception;
        cached_exception_.reset(new edm::Exception(errors::Unknown, "repeated"));
        *cached_exception_
          << "An unknown occurred during a previous call to the module ";
        exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n";
        throw *cached_exception_;
    }
  }
void edm::Worker::clearCounters ( ) [inline]
ModuleDescription const* edm::Worker::descPtr ( ) const [inline]

Definition at line 64 of file Worker.h.

References md_.

{return &md_; }
ModuleDescription const& edm::Worker::description ( ) const [inline]
template<typename T >
bool edm::Worker::doWork ( typename T::MyPrincipal &  ep,
EventSetup const &  c,
CurrentProcessingContext const *  cpc,
CPUTimer *const  timer 
)

Definition at line 162 of file Worker.h.

References alignmentValidation::action, actions_, actReg_, edm::errors::BadAlloc, edm::errors::BadExceptionType, trackerHits::c, cached_exception_, ExpressReco_HICollisions_FallBack::e, exception, Exception, Fail, edm::actions::FailModule, edm::actions::FailPath, edm::ActionTable::find(), edm::actions::IgnoreCompletely, implDoBegin(), implDoEnd(), edm::CurrentProcessingContext::isEndPath(), edm::CurrentProcessingContext::isUnscheduled(), md_, edm::errors::OtherCMS, Pass, Ready, edm::actions::Rethrow, cms::Exception::rootCause(), asciidump::s, edm::actions::SkipEvent, state_, edm::errors::StdException, stopwatch_, timesExcept_, timesFailed_, timesPassed_, timesRun_, timesVisited_, edm::errors::Unknown, and cms::Exception::what().

Referenced by edm::WorkerInPath::runWorker().

                                               {

    // A RunStopwatch, but only if we are processing an event.
    RunDualStopwatches stopwatch(T::isEvent_ ? stopwatch_ : RunStopwatch::StopwatchPointer(),
                                 iTimer);

    if (T::isEvent_) {
      ++timesVisited_;
    }
    bool rc = false;

    switch(state_) {
      case Ready: break;
      case Pass: return true;
      case Fail: return false;
      case Exception: {
          // rethrow the cached exception again
          // It seems impossible to
          // get here a second time until a cms::Exception has been
          // thrown prviously.
          LogWarning("repeat") << "A module has been invoked a second "
                               << "time even though it caught an "
                               << "exception during the previous "
                               << "invocation.\n"
                               << "This may be an indication of a "
                               << "configuration problem.\n";

          cached_exception_->raise();
      }
    }

    if (T::isEvent_) ++timesRun_;

    try {

        ModuleSignalSentry<T> cpp(actReg_.get(), md_);
        if (T::begin_) {
          rc = implDoBegin(ep, es, cpc);
        } else {
          rc = implDoEnd(ep, es, cpc);
        }

        if (rc) {
          state_ = Pass;
          if (T::isEvent_) ++timesPassed_;
        } else {
          state_ = Fail;
          if (T::isEvent_) ++timesFailed_;
        }
    }

    catch(cms::Exception& e) {

        // NOTE: the warning printed as a result of ignoring or failing
        // a module will only be printed during the full true processing
        // pass of this module

        // Get the action corresponding to this exception.  However, if processing
        // something other than an event (e.g. run, lumi) always rethrow.
        actions::ActionCodes action = (T::isEvent_ ? actions_->find(e.rootCause()) : actions::Rethrow);

        // If we are processing an endpath and the module was scheduled, treat SkipEvent or FailPath
        // as FailModule, so any subsequent OutputModules are still run.
        // For unscheduled modules only treat FailPath as a FailModule but still allow SkipEvent to throw
        if (cpc && cpc->isEndPath()) {
          if ((action == actions::SkipEvent && !cpc->isUnscheduled()) ||
               action == actions::FailPath) action = actions::FailModule;
        }
        switch(action) {
          case actions::IgnoreCompletely: {
              rc = true;
              ++timesPassed_;
              state_ = Pass;
              LogWarning("IgnoreCompletely")
                << "Module ignored an exception\n"
                << e.what() << "\n";
              break;
          }

          case actions::FailModule: {
              rc = true;
              LogWarning("FailModule")
                << "Module failed due to an exception\n"
                << e.what() << "\n";
              ++timesFailed_;
              state_ = Fail;
              break;
          }

          default: {

              // we should not need to include the event/run/module names
              // the exception because the error logger will pick this
              // up automatically.  I'm leaving it in until this is
              // verified

              // here we simply add a small amount of data to the
              // exception to add some context, we could have rethrown
              // it as something else and embedded with this exception
              // as an argument to the constructor.

              if (T::isEvent_) ++timesExcept_;
              state_ = Exception;
              e << "cms::Exception going through module ";
              exceptionContext(md_, ep, e);
              edm::Exception *edmEx = dynamic_cast<edm::Exception *>(&e);
              if (edmEx) {
                cached_exception_.reset(new edm::Exception(*edmEx));
              } else {
                cached_exception_.reset(new edm::Exception(errors::OtherCMS, std::string(), e));
              }
              throw;
          }
        }
      }

    catch(std::bad_alloc& bda) {
        if (T::isEvent_) ++timesExcept_;
        state_ = Exception;
        cached_exception_.reset(new edm::Exception(errors::BadAlloc));
        *cached_exception_
          << "A std::bad_alloc exception occurred during a call to the module ";
        exceptionContext(md_, ep, *cached_exception_)
          << "The job has probably exhausted the virtual memory available to the process.\n";
        cached_exception_->raise();
    }
    catch(std::exception& e) {
        if (T::isEvent_) ++timesExcept_;
        state_ = Exception;
        cached_exception_.reset(new edm::Exception(errors::StdException));
        *cached_exception_
          << "A std::exception occurred during a call to the module ";
        exceptionContext(md_, ep, *cached_exception_) << "and cannot be repropagated.\n"
          << "Previous information:\n" << e.what();
        cached_exception_->raise();
    }
    catch(std::string& s) {
        if (T::isEvent_) ++timesExcept_;
        state_ = Exception;
        cached_exception_.reset(new edm::Exception(errors::BadExceptionType, "std::string"));
        *cached_exception_
          << "A std::string thrown as an exception occurred during a call to the module ";
        exceptionContext(md_, ep, *cached_exception_) << "and cannot be repropagated.\n"
          << "Previous information:\n string = " << s;
        cached_exception_->raise();
    }
    catch(char const* c) {
        if (T::isEvent_) ++timesExcept_;
        state_ = Exception;
        cached_exception_.reset(new edm::Exception(errors::BadExceptionType, "const char *"));
        *cached_exception_
          << "A const char* thrown as an exception occurred during a call to the module ";
        exceptionContext(md_, ep, *cached_exception_) << "and cannot be repropagated.\n"
          << "Previous information:\n const char* = " << c << "\n";
        cached_exception_->raise();
    }
    catch(...) {
        if (T::isEvent_) ++timesExcept_;
        state_ = Exception;
        cached_exception_.reset(new edm::Exception(errors::Unknown, "repeated"));
        *cached_exception_
          << "An unknown occurred during a previous call to the module ";
        exceptionContext(md_, ep, *cached_exception_) << "and cannot be repropagated.\n";
        cached_exception_->raise();
    }

    return rc;
  }
void edm::Worker::endJob ( void  )

Definition at line 132 of file Worker.cc.

References actReg_, edm::errors::BadAlloc, edm::errors::BadExceptionType, trackerHits::c, cached_exception_, description(), ExpressReco_HICollisions_FallBack::e, exception, Exception, implEndJob(), md_, asciidump::s, state_, edm::errors::StdException, edm::errors::Unknown, and workerType().

                      {
    try {
        ModuleEndJobSignalSentry cpp(actReg_.get(), md_);
        implEndJob();
    }
    catch(cms::Exception& e) {
        LogError("EndJob")
          << "A cms::Exception is going through " << workerType() << ":\n";
        state_ = Exception;
        e << "A cms::Exception is going through " << workerType() << ":\n";
        exceptionContext(md_, e);
        throw;
    }
    catch(std::bad_alloc& bda) {
        LogError("EndJob")
          << "A std::bad_alloc is going through " << workerType() << ":\n"
          << description() << "\n";
        state_ = Exception;
        cached_exception_.reset(new edm::Exception(errors::BadAlloc));
        *cached_exception_
          << "A std::bad_alloc exception occurred during a call to the module ";
        exceptionContext(md_, *cached_exception_)
          << "The job has probably exhausted the virtual memory available to the process.\n";
        throw *cached_exception_;
    }
    catch(std::exception& e) {
        LogError("EndJob")
          << "A std::exception is going through " << workerType() << ":\n"
          << description() << "\n";
        state_ = Exception;
        cached_exception_.reset(new edm::Exception(errors::StdException));
        *cached_exception_
          << "A std::exception occurred during a call to the module ";
        exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n"
          << "Previous information:\n" << e.what();
        throw *cached_exception_;
    }
    catch(std::string& s) {
        LogError("EndJob") 
          << "module caught a std::string during endJob\n";
        state_ = Exception;
        cached_exception_.reset(new edm::Exception(errors::BadExceptionType, "std::string"));
        *cached_exception_
          << "A std::string thrown as an exception occurred during a call to the module ";
        exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n"
          << "Previous information:\n string = " << s;
        throw *cached_exception_;
    }
    catch(char const* c) {
        LogError("EndJob") 
          << "module caught a const char* during endJob\n";
        state_ = Exception;
        cached_exception_.reset(new edm::Exception(errors::BadExceptionType, "const char *"));
        *cached_exception_
          << "A const char* thrown as an exception occurred during a call to the module ";
        exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n"
          << "Previous information:\n const char* = " << c << "\n";
        throw *cached_exception_;
    }
    catch(...) {
        LogError("EndJob")
          << "An unknown Exception occurred in\n" << description() << "\n";
        state_ = Exception;
        cached_exception_.reset(new edm::Exception(errors::Unknown, "repeated"));
        *cached_exception_
          << "An unknown occurred during a previous call to the module ";
        exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n";
        throw *cached_exception_;
    }

  }
virtual void edm::Worker::implBeginJob ( ) [protected, pure virtual]

Implemented in edm::WorkerT< T >, and edm::WorkerT< OutputModule >.

Referenced by beginJob().

virtual bool edm::Worker::implDoBegin ( EventPrincipal ,
EventSetup const &  c,
CurrentProcessingContext const *  cpc 
) [protected, pure virtual]

Implemented in edm::WorkerT< T >, and edm::WorkerT< OutputModule >.

Referenced by doWork().

virtual bool edm::Worker::implDoBegin ( RunPrincipal rp,
EventSetup const &  c,
CurrentProcessingContext const *  cpc 
) [protected, pure virtual]
virtual bool edm::Worker::implDoBegin ( LuminosityBlockPrincipal lbp,
EventSetup const &  c,
CurrentProcessingContext const *  cpc 
) [protected, pure virtual]
virtual bool edm::Worker::implDoEnd ( EventPrincipal ,
EventSetup const &  c,
CurrentProcessingContext const *  cpc 
) [protected, pure virtual]

Implemented in edm::WorkerT< T >, and edm::WorkerT< OutputModule >.

Referenced by doWork().

virtual bool edm::Worker::implDoEnd ( RunPrincipal rp,
EventSetup const &  c,
CurrentProcessingContext const *  cpc 
) [protected, pure virtual]
virtual bool edm::Worker::implDoEnd ( LuminosityBlockPrincipal lbp,
EventSetup const &  c,
CurrentProcessingContext const *  cpc 
) [protected, pure virtual]
virtual void edm::Worker::implEndJob ( ) [protected, pure virtual]

Implemented in edm::WorkerT< T >, and edm::WorkerT< OutputModule >.

Referenced by endJob().

virtual void edm::Worker::implPostForkReacquireResources ( unsigned int  iChildIndex,
unsigned int  iNumberOfChildren 
) [private, pure virtual]
virtual void edm::Worker::implPreForkReleaseResources ( ) [private, pure virtual]
virtual void edm::Worker::implRespondToCloseInputFile ( FileBlock const &  fb) [private, pure virtual]
virtual void edm::Worker::implRespondToCloseOutputFiles ( FileBlock const &  fb) [private, pure virtual]
virtual void edm::Worker::implRespondToOpenInputFile ( FileBlock const &  fb) [private, pure virtual]
virtual void edm::Worker::implRespondToOpenOutputFiles ( FileBlock const &  fb) [private, pure virtual]
void edm::Worker::postForkReacquireResources ( unsigned int  iChildIndex,
unsigned int  iNumberOfChildren 
) [inline]

Definition at line 59 of file Worker.h.

References implPostForkReacquireResources().

Referenced by edm::Schedule::postForkReacquireResources().

{implPostForkReacquireResources(iChildIndex, iNumberOfChildren);}
void edm::Worker::preForkReleaseResources ( ) [inline]
void edm::Worker::reset ( void  ) [inline]

Definition at line 61 of file Worker.h.

References Ready, and state_.

Referenced by edm::Schedule::resetAll().

{ state_ = Ready; }
void edm::Worker::respondToCloseInputFile ( FileBlock const &  fb) [inline]
void edm::Worker::respondToCloseOutputFiles ( FileBlock const &  fb) [inline]
void edm::Worker::respondToOpenInputFile ( FileBlock const &  fb) [inline]
void edm::Worker::respondToOpenOutputFiles ( FileBlock const &  fb) [inline]
void edm::Worker::setActivityRegistry ( boost::shared_ptr< ActivityRegistry areg)

The signals are required to live longer than the last call to 'doWork' this was done to improve performance based on profiling

Definition at line 56 of file Worker.cc.

References actReg_.

                                                                         {
    actReg_ = areg;
  }
State edm::Worker::state ( ) const [inline]

Definition at line 84 of file Worker.h.

References state_.

{ return state_; }
std::pair<double, double> edm::Worker::timeCpuReal ( ) const [inline]

Definition at line 69 of file Worker.h.

References stopwatch_.

                                                {
      return std::pair<double, double>(stopwatch_->cpuTime(), stopwatch_->realTime());
    }
int edm::Worker::timesExcept ( ) const [inline]

Definition at line 83 of file Worker.h.

References timesExcept_.

Referenced by edm::fillWorkerSummaryAux().

{ return timesExcept_; }
int edm::Worker::timesFailed ( ) const [inline]

Definition at line 82 of file Worker.h.

References timesFailed_.

Referenced by edm::fillWorkerSummaryAux().

{ return timesFailed_; }
int edm::Worker::timesPass ( ) const [inline]

Definition at line 86 of file Worker.h.

References timesPassed().

{ return timesPassed(); } // for backward compatibility only - to be removed soon
int edm::Worker::timesPassed ( ) const [inline]

Definition at line 81 of file Worker.h.

References timesPassed_.

Referenced by edm::fillWorkerSummaryAux(), and timesPass().

{ return timesPassed_; }
int edm::Worker::timesRun ( ) const [inline]

Definition at line 79 of file Worker.h.

References timesRun_.

Referenced by edm::fillWorkerSummaryAux().

{ return timesRun_; }
int edm::Worker::timesVisited ( ) const [inline]

Definition at line 80 of file Worker.h.

References timesVisited_.

Referenced by edm::fillWorkerSummaryAux().

{ return timesVisited_; }
void edm::Worker::useStopwatch ( )

Definition at line 204 of file Worker.cc.

References stopwatch_.

Referenced by edm::Schedule::addToAllWorkers().

                           {
    stopwatch_.reset(new RunStopwatch::StopwatchPointer::element_type);
  }
virtual std::string edm::Worker::workerType ( ) const [protected, pure virtual]

Implemented in edm::WorkerT< T >, and edm::WorkerT< OutputModule >.

Referenced by beginJob(), and endJob().


Member Data Documentation

Definition at line 124 of file Worker.h.

Referenced by doWork().

boost::shared_ptr<ActivityRegistry> edm::Worker::actReg_ [private]

Definition at line 127 of file Worker.h.

Referenced by beginJob(), doWork(), endJob(), and setActivityRegistry().

boost::shared_ptr<edm::Exception> edm::Worker::cached_exception_ [private]

Definition at line 125 of file Worker.h.

Referenced by beginJob(), doWork(), and endJob().

Definition at line 123 of file Worker.h.

Referenced by beginJob(), descPtr(), description(), doWork(), and endJob().

Definition at line 121 of file Worker.h.

Referenced by beginJob(), doWork(), endJob(), reset(), and state().

Definition at line 114 of file Worker.h.

Referenced by doWork(), timeCpuReal(), and useStopwatch().

Definition at line 120 of file Worker.h.

Referenced by clearCounters(), doWork(), and timesExcept().

Definition at line 119 of file Worker.h.

Referenced by clearCounters(), doWork(), and timesFailed().

Definition at line 118 of file Worker.h.

Referenced by clearCounters(), doWork(), and timesPassed().

int edm::Worker::timesRun_ [private]

Definition at line 116 of file Worker.h.

Referenced by clearCounters(), doWork(), and timesRun().

Definition at line 117 of file Worker.h.

Referenced by clearCounters(), doWork(), and timesVisited().