CMS 3D CMS Logo

edm::Worker Class Reference

#include <FWCore/Framework/src/Worker.h>

Inheritance diagram for edm::Worker:

edm::WorkerT< T > edm::WorkerT< edm::OutputModule > edm::OutputWorker

List of all members.

Public Types

enum  State { Ready, Pass, Fail, Exception }

Public Member Functions

void beginJob (EventSetup const &)
void clearCounters ()
ModuleDescription const * descPtr () const
ModuleDescription const & description () const
template<typename T>
bool doWork (typename T::MyPrincipal &, EventSetup const &c, CurrentProcessingContext const *cpc)
void endJob ()
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)
 The signals are required to live longer than the last call to 'doWork' this was done to improve performance based on profiling.
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
 Worker (ModuleDescription const &iMD, WorkerParams const &iWP)
virtual ~Worker ()

Protected Member Functions

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

Private Member Functions

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 43 of file Worker.h.


Member Enumeration Documentation

enum edm::Worker::State

Enumerator:
Ready 
Pass 
Fail 
Exception 

Definition at line 45 of file Worker.h.

00045 { Ready, Pass, Fail, Exception };


Constructor & Destructor Documentation

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

Definition at line 38 of file Worker.cc.

00039                                           :
00040     stopwatch_(new RunStopwatch::StopwatchPointer::element_type),
00041     timesRun_(),
00042     timesVisited_(),
00043     timesPassed_(),
00044     timesFailed_(),
00045     timesExcept_(),
00046     state_(Ready),
00047     md_(iMD),
00048     actions_(iWP.actions_),
00049     cached_exception_(),
00050     actReg_()
00051   {
00052   }

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

Definition at line 54 of file Worker.cc.

00054                   {
00055   }


Member Function Documentation

void edm::Worker::beginJob ( EventSetup const &  es  ) 

Definition at line 61 of file Worker.cc.

References actReg_, edm::errors::BadExceptionType, c, description(), e, exception, implBeginJob(), md_, edm::errors::OtherCMS, s, edm::errors::StdException, edm::errors::Unknown, and workerType().

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

00061                                             {
00062     
00063     try {
00064         ModuleBeginJobSignalSentry cpp(actReg_.get(), md_);
00065         implBeginJob(es);
00066     }
00067     catch(cms::Exception& e) {
00068         // should event id be included?
00069         LogError("BeginJob")
00070           << "A cms::Exception is going through " << workerType() << ":\n";
00071 
00072         e << "A cms::Exception is going through " << workerType() << ":\n"
00073           << description();
00074         throw edm::Exception(errors::OtherCMS, std::string(), e);
00075     }
00076     catch(std::bad_alloc& e) {
00077         LogError("BeginJob")
00078           << "A std::bad_alloc is going through " << workerType() << ":\n"
00079           << description() << "\n";
00080         throw;
00081     }
00082     catch(std::exception& e) {
00083         LogError("BeginJob")
00084           << "A std::exception is going through " << workerType() << ":\n"
00085           << description() << "\n";
00086         throw edm::Exception(errors::StdException)
00087           << "A std::exception is going through " << workerType() << ":\n"
00088           << description() << "\n";
00089     }
00090     catch(std::string& s) {
00091         LogError("BeginJob") 
00092           << "module caught an std::string during beginJob\n";
00093 
00094         throw edm::Exception(errors::BadExceptionType)
00095           << "std::string = " << s << "\n"
00096           << description() << "\n";
00097     }
00098     catch(char const* c) {
00099         LogError("BeginJob") 
00100           << "module caught an const char* during beginJob\n";
00101 
00102         throw edm::Exception(errors::BadExceptionType)
00103           << "cstring = " << c << "\n"
00104           << description();
00105     }
00106     catch(...) {
00107         LogError("BeginJob")
00108           << "An unknown Exception occured in\n" << description() << "\n";
00109         throw edm::Exception(errors::Unknown)
00110           << "An unknown Exception occured in\n" << description() << "\n";
00111     }
00112   }

void edm::Worker::clearCounters (  )  [inline]

Definition at line 72 of file Worker.h.

References timesExcept_, timesFailed_, timesPassed_, timesRun_, and timesVisited_.

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

00072                          {
00073       timesRun_ = timesVisited_ = timesPassed_ = timesFailed_ = timesExcept_ = 0;
00074     }

ModuleDescription const* edm::Worker::descPtr (  )  const [inline]

Definition at line 63 of file Worker.h.

References md_.

00063 {return &md_; }

ModuleDescription const& edm::Worker::description (  )  const [inline]

Definition at line 62 of file Worker.h.

References md_.

Referenced by edm::UnscheduledCallProducer::addWorker(), beginJob(), endJob(), edm::fillModuleInPathSummary(), and edm::fillWorkerSummaryAux().

00062 {return md_;}

template<typename T>
bool edm::Worker::doWork ( typename T::MyPrincipal &  ep,
EventSetup const &  c,
CurrentProcessingContext const *  cpc 
) [inline]

Definition at line 150 of file Worker.h.

References cmsRelvalreport::action, actions_, actReg_, edm::errors::BadAlloc, edm::errors::BadExceptionType, c, cached_exception_, e, exception, edm::exceptionContext(), Fail, edm::actions::FailModule, edm::actions::FailPath, edm::ActionTable::find(), edm::actions::IgnoreCompletely, implDoBegin(), implDoEnd(), edm::CurrentProcessingContext::isEndPath(), md_, edm::errors::OtherCMS, Pass, Ready, edm::actions::Rethrow, cms::Exception::rootCause(), 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().

00151                                                            {
00152 
00153     // A RunStopwatch, but only if we are processing an event.
00154     std::auto_ptr<RunStopwatch> stopwatch(T::isEvent_ ? new RunStopwatch(stopwatch_) : 0);
00155 
00156     if (T::isEvent_) {
00157       ++timesVisited_;
00158     }
00159     bool rc = false;
00160 
00161     switch(state_) {
00162       case Ready: break;
00163       case Pass: return true;
00164       case Fail: return false;
00165       case Exception: {
00166           // rethrow the cached exception again
00167           // It seems impossible to
00168           // get here a second time until a cms::Exception has been 
00169           // thrown prviously.
00170           LogWarning("repeat") << "A module has been invoked a second "
00171                                << "time even though it caught an "
00172                                << "exception during the previous "
00173                                << "invocation.\n"
00174                                << "This may be an indication of a "
00175                                << "configuration problem.\n";
00176 
00177           throw *cached_exception_;
00178       }
00179     }
00180 
00181     if (T::isEvent_) ++timesRun_;
00182 
00183     try {
00184 
00185         ModuleSignalSentry<T> cpp(actReg_.get(), md_);
00186         if (T::begin_) {
00187           rc = implDoBegin(ep, es, cpc);
00188         } else {
00189           rc = implDoEnd(ep, es, cpc);
00190         }
00191 
00192         if (rc) {
00193           state_ = Pass;
00194           if (T::isEvent_) ++timesPassed_;
00195         } else {
00196           state_ = Fail;
00197           if (T::isEvent_) ++timesFailed_;
00198         }
00199     }
00200 
00201     catch(cms::Exception& e) {
00202       
00203         // NOTE: the warning printed as a result of ignoring or failing
00204         // a module will only be printed during the full true processing
00205         // pass of this module
00206 
00207         // Get the action corresponding to this exception.  However, if processing
00208         // something other than an event (e.g. run, lumi) always rethrow.
00209         actions::ActionCodes action = (T::isEvent_ ? actions_->find(e.rootCause()) : actions::Rethrow);
00210 
00211         // If we are processing an endpath, treat SkipEvent or FailPath
00212         // as FailModule, so any subsequent OutputModules are still run.
00213         if (cpc && cpc->isEndPath()) {
00214           if (action == actions::SkipEvent || action == actions::FailPath) action = actions::FailModule;
00215         }
00216         switch(action) {
00217           case actions::IgnoreCompletely: {
00218               rc=true;
00219               ++timesPassed_;
00220               state_ = Pass;
00221               LogWarning("IgnoreCompletely")
00222                 << "Module ignored an exception\n"
00223                 <<e.what()<<"\n";
00224               break;
00225           }
00226 
00227           case actions::FailModule: {
00228               rc=true;
00229               LogWarning("FailModule")
00230                 << "Module failed due to an exception\n"
00231                 << e.what() << "\n";
00232               ++timesFailed_;
00233               state_ = Fail;
00234               break;
00235           }
00236             
00237           default: {
00238 
00239               // we should not need to include the event/run/module names
00240               // the exception because the error logger will pick this
00241               // up automatically.  I'm leaving it in until this is 
00242               // verified
00243 
00244               // here we simply add a small amount of data to the
00245               // exception to add some context, we could have rethrown
00246               // it as something else and embedded with this exception
00247               // as an argument to the constructor.
00248 
00249               if (T::isEvent_) ++timesExcept_;
00250               state_ = Exception;
00251               e << "cms::Exception going through module ";
00252               exceptionContext(md_, ep, e);
00253               edm::Exception *edmEx = dynamic_cast<edm::Exception *>(&e);
00254               if (edmEx) {
00255                 cached_exception_.reset(new edm::Exception(*edmEx));
00256               } else {
00257                 cached_exception_.reset(new edm::Exception(errors::OtherCMS, std::string(), e));
00258               }
00259               throw;
00260           }
00261         }
00262       }
00263     
00264     catch(std::bad_alloc& bda) {
00265         if (T::isEvent_) ++timesExcept_;
00266         state_ = Exception;
00267         cached_exception_.reset(new edm::Exception(errors::BadAlloc));
00268         *cached_exception_
00269           << "A std::bad_alloc exception occurred during a call to the module ";
00270         exceptionContext(md_, ep, *cached_exception_)
00271           << "The job has probably exhausted the virtual memory available to the process.\n";
00272         throw *cached_exception_;
00273     }
00274     catch(std::exception& e) {
00275         if (T::isEvent_) ++timesExcept_;
00276         state_ = Exception;
00277         cached_exception_.reset(new edm::Exception(errors::StdException));
00278         *cached_exception_
00279           << "A std::exception occurred during a call to the module ";
00280         exceptionContext(md_, ep, *cached_exception_) << "and cannot be repropagated.\n"
00281           << "Previous information:\n" << e.what();
00282         throw *cached_exception_;
00283     }
00284     catch(std::string& s) {
00285         if (T::isEvent_) ++timesExcept_;
00286         state_ = Exception;
00287         cached_exception_.reset(new edm::Exception(errors::BadExceptionType, "std::string"));
00288         *cached_exception_
00289           << "A std::string thrown as an exception occurred during a call to the module ";
00290         exceptionContext(md_, ep, *cached_exception_) << "and cannot be repropagated.\n"
00291           << "Previous information:\n string = " << s;
00292         throw *cached_exception_;
00293     }
00294     catch(char const* c) {
00295         if (T::isEvent_) ++timesExcept_;
00296         state_ = Exception;
00297         cached_exception_.reset(new edm::Exception(errors::BadExceptionType, "const char *"));
00298         *cached_exception_
00299           << "A const char* thrown as an exception occurred during a call to the module ";
00300         exceptionContext(md_, ep, *cached_exception_) << "and cannot be repropagated.\n"
00301           << "Previous information:\n const char* = " << c << "\n";
00302         throw *cached_exception_;
00303     }
00304     catch(...) {
00305         if (T::isEvent_) ++timesExcept_;
00306         state_ = Exception;
00307         cached_exception_.reset(new edm::Exception(errors::Unknown, "repeated"));
00308         *cached_exception_
00309           << "An unknown occurred during a previous call to the module ";
00310         exceptionContext(md_, ep, *cached_exception_) << "and cannot be repropagated.\n";
00311         throw *cached_exception_;
00312     }
00313 
00314     return rc;
00315   }

void edm::Worker::endJob ( void   ) 

Definition at line 114 of file Worker.cc.

References actReg_, edm::errors::BadExceptionType, c, description(), e, exception, implEndJob(), md_, edm::errors::OtherCMS, s, edm::errors::StdException, edm::errors::Unknown, and workerType().

00114                       {
00115     try {
00116         ModuleEndJobSignalSentry cpp(actReg_.get(), md_);
00117         implEndJob();
00118     }
00119     catch(cms::Exception& e) {
00120         LogError("EndJob")
00121           << "A cms::Exception is going through " << workerType() << ":\n";
00122 
00123         // should event id be included?
00124         e << "A cms::Exception is going through " << workerType() << ":\n"
00125           << description();
00126         throw edm::Exception(errors::OtherCMS, std::string(), e);
00127     }
00128     catch(std::bad_alloc& e) {
00129         LogError("EndJob")
00130           << "A std::bad_alloc is going through " << workerType() << ":\n"
00131           << description() << "\n";
00132         throw;
00133     }
00134     catch(std::exception& e) {
00135         LogError("EndJob")
00136           << "An std::exception is going through " << workerType() << ":\n"
00137           << description() << "\n";
00138         throw edm::Exception(errors::StdException)
00139           << "A std::exception is going through " << workerType() << ":\n"
00140           << description() << "\n";
00141     }
00142     catch(std::string& s) {
00143         LogError("EndJob") 
00144           << "module caught an std::string during endJob\n";
00145 
00146         throw edm::Exception(errors::BadExceptionType)
00147           << "std::string = " << s << "\n"
00148           << description() << "\n";
00149     }
00150     catch(char const* c) {
00151         LogError("EndJob") 
00152           << "module caught an const char* during endJob\n";
00153 
00154         throw edm::Exception(errors::BadExceptionType)
00155           << "cstring = " << c << "\n"
00156           << description() << "\n";
00157     }
00158     catch(...) {
00159         LogError("EndJob")
00160           << "An unknown Exception occured in\n" << description() << "\n";
00161         throw edm::Exception(errors::Unknown)
00162           << "An unknown Exception occured in\n" << description() << "\n";
00163     }
00164   }

virtual void edm::Worker::implBeginJob ( EventSetup const &   )  [protected, pure virtual]

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

Referenced by beginJob().

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

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

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

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

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

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

Referenced by doWork().

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

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

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

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

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

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

Referenced by doWork().

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

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

Referenced by endJob().

virtual void edm::Worker::implRespondToCloseInputFile ( FileBlock const &  fb  )  [private, pure virtual]

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

Referenced by respondToCloseInputFile().

virtual void edm::Worker::implRespondToCloseOutputFiles ( FileBlock const &  fb  )  [private, pure virtual]

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

Referenced by respondToCloseOutputFiles().

virtual void edm::Worker::implRespondToOpenInputFile ( FileBlock const &  fb  )  [private, pure virtual]

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

Referenced by respondToOpenInputFile().

virtual void edm::Worker::implRespondToOpenOutputFiles ( FileBlock const &  fb  )  [private, pure virtual]

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

Referenced by respondToOpenOutputFiles().

void edm::Worker::reset ( void   )  [inline]

Definition at line 60 of file Worker.h.

References Ready, and state_.

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

00060 { state_ = Ready; }

void edm::Worker::respondToCloseInputFile ( FileBlock const &  fb  )  [inline]

Definition at line 56 of file Worker.h.

References implRespondToCloseInputFile().

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

void edm::Worker::respondToCloseOutputFiles ( FileBlock const &  fb  )  [inline]

Definition at line 58 of file Worker.h.

References implRespondToCloseOutputFiles().

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

void edm::Worker::respondToOpenInputFile ( FileBlock const &  fb  )  [inline]

Definition at line 55 of file Worker.h.

References implRespondToOpenInputFile().

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

void edm::Worker::respondToOpenOutputFiles ( FileBlock const &  fb  )  [inline]

Definition at line 57 of file Worker.h.

References implRespondToOpenOutputFiles().

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

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 57 of file Worker.cc.

References actReg_.

00057                                                                          {
00058     actReg_ = areg;
00059   }

State edm::Worker::state (  )  const [inline]

Definition at line 81 of file Worker.h.

References state_.

00081 { return state_; }

std::pair<double,double> edm::Worker::timeCpuReal (  )  const [inline]

Definition at line 68 of file Worker.h.

References stopwatch_.

00068                                                {
00069       return std::pair<double,double>(stopwatch_->cpuTime(),stopwatch_->realTime());
00070     }

int edm::Worker::timesExcept (  )  const [inline]

Definition at line 80 of file Worker.h.

References timesExcept_.

Referenced by edm::fillWorkerSummaryAux().

00080 { return timesExcept_; }

int edm::Worker::timesFailed (  )  const [inline]

Definition at line 79 of file Worker.h.

References timesFailed_.

Referenced by edm::fillWorkerSummaryAux().

00079 { return timesFailed_; }

int edm::Worker::timesPass (  )  const [inline]

Definition at line 83 of file Worker.h.

References timesPassed().

00083 { return timesPassed(); } // for backward compatibility only - to be removed soon

int edm::Worker::timesPassed (  )  const [inline]

Definition at line 78 of file Worker.h.

References timesPassed_.

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

00078 { return timesPassed_; }

int edm::Worker::timesRun (  )  const [inline]

Definition at line 76 of file Worker.h.

References timesRun_.

Referenced by edm::fillWorkerSummaryAux().

00076 { return timesRun_; }

int edm::Worker::timesVisited (  )  const [inline]

Definition at line 77 of file Worker.h.

References timesVisited_.

Referenced by edm::fillWorkerSummaryAux().

00077 { return timesVisited_; }

virtual std::string edm::Worker::workerType (  )  const [protected, pure virtual]

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

Referenced by beginJob(), and endJob().


Member Data Documentation

ActionTable const* edm::Worker::actions_ [private]

Definition at line 118 of file Worker.h.

Referenced by doWork().

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

Definition at line 121 of file Worker.h.

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

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

Definition at line 119 of file Worker.h.

Referenced by doWork().

ModuleDescription edm::Worker::md_ [private]

Definition at line 117 of file Worker.h.

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

State edm::Worker::state_ [private]

Definition at line 115 of file Worker.h.

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

RunStopwatch::StopwatchPointer edm::Worker::stopwatch_ [private]

Definition at line 108 of file Worker.h.

Referenced by doWork(), and timeCpuReal().

int edm::Worker::timesExcept_ [private]

Definition at line 114 of file Worker.h.

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

int edm::Worker::timesFailed_ [private]

Definition at line 113 of file Worker.h.

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

int edm::Worker::timesPassed_ [private]

Definition at line 112 of file Worker.h.

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

int edm::Worker::timesRun_ [private]

Definition at line 110 of file Worker.h.

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

int edm::Worker::timesVisited_ [private]

Definition at line 111 of file Worker.h.

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


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:44:47 2009 for CMSSW by  doxygen 1.5.4