Go to the documentation of this file.00001
00002
00003
00004
00005 #include "FWCore/Framework/src/Worker.h"
00006
00007 namespace edm {
00008 namespace {
00009 class ModuleBeginJobSignalSentry {
00010 public:
00011 ModuleBeginJobSignalSentry(ActivityRegistry* a, ModuleDescription& md):a_(a), md_(&md) {
00012 if(a_) a_->preModuleBeginJobSignal_(*md_);
00013 }
00014 ~ModuleBeginJobSignalSentry() {
00015 if(a_) a_->postModuleBeginJobSignal_(*md_);
00016 }
00017 private:
00018 ActivityRegistry* a_;
00019 ModuleDescription* md_;
00020 };
00021
00022 class ModuleEndJobSignalSentry {
00023 public:
00024 ModuleEndJobSignalSentry(ActivityRegistry* a, ModuleDescription& md):a_(a), md_(&md) {
00025 if(a_) a_->preModuleEndJobSignal_(*md_);
00026 }
00027 ~ModuleEndJobSignalSentry() {
00028 if(a_) a_->postModuleEndJobSignal_(*md_);
00029 }
00030 private:
00031 ActivityRegistry* a_;
00032 ModuleDescription* md_;
00033 };
00034
00035 cms::Exception& exceptionContext(ModuleDescription const& iMD,
00036 cms::Exception& iEx) {
00037 iEx << iMD.moduleName() << "/" << iMD.moduleLabel() << "\n";
00038 return iEx;
00039 }
00040
00041 }
00042
00043 Worker::Worker(ModuleDescription const& iMD,
00044 WorkerParams const& iWP) :
00045 stopwatch_(),
00046 timesRun_(),
00047 timesVisited_(),
00048 timesPassed_(),
00049 timesFailed_(),
00050 timesExcept_(),
00051 state_(Ready),
00052 md_(iMD),
00053 actions_(iWP.actions_),
00054 cached_exception_(),
00055 actReg_()
00056 {
00057 }
00058
00059 Worker::~Worker() {
00060 }
00061
00062 void Worker::setActivityRegistry(boost::shared_ptr<ActivityRegistry> areg) {
00063 actReg_ = areg;
00064 }
00065
00066 void Worker::beginJob() {
00067 try {
00068 try {
00069 ModuleBeginJobSignalSentry cpp(actReg_.get(), md_);
00070 implBeginJob();
00071 }
00072 catch (cms::Exception& e) { throw; }
00073 catch(std::bad_alloc& bda) { convertException::badAllocToEDM(); }
00074 catch (std::exception& e) { convertException::stdToEDM(e); }
00075 catch(std::string& s) { convertException::stringToEDM(s); }
00076 catch(char const* c) { convertException::charPtrToEDM(c); }
00077 catch (...) { convertException::unknownToEDM(); }
00078 }
00079 catch(cms::Exception& ex) {
00080 state_ = Exception;
00081 std::ostringstream ost;
00082 ost << "Calling beginJob for module " << md_.moduleName() << "/'" << md_.moduleLabel() << "'";
00083 ex.addContext(ost.str());
00084 throw;
00085 }
00086 }
00087
00088 void Worker::endJob() {
00089 try {
00090 try {
00091 ModuleEndJobSignalSentry cpp(actReg_.get(), md_);
00092 implEndJob();
00093 }
00094 catch (cms::Exception& e) { throw; }
00095 catch(std::bad_alloc& bda) { convertException::badAllocToEDM(); }
00096 catch (std::exception& e) { convertException::stdToEDM(e); }
00097 catch(std::string& s) { convertException::stringToEDM(s); }
00098 catch(char const* c) { convertException::charPtrToEDM(c); }
00099 catch (...) { convertException::unknownToEDM(); }
00100 }
00101 catch(cms::Exception& ex) {
00102 state_ = Exception;
00103 std::ostringstream ost;
00104 ost << "Calling endJob for module " << md_.moduleName() << "/'" << md_.moduleLabel() << "'";
00105 ex.addContext(ost.str());
00106 throw;
00107 }
00108 }
00109
00110 void Worker::useStopwatch(){
00111 stopwatch_.reset(new RunStopwatch::StopwatchPointer::element_type);
00112 }
00113
00114 }