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