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 }
00036
00037 Worker::Worker(ModuleDescription const& iMD,
00038 WorkerParams const& iWP) :
00039 stopwatch_(),
00040 timesRun_(),
00041 timesVisited_(),
00042 timesPassed_(),
00043 timesFailed_(),
00044 timesExcept_(),
00045 state_(Ready),
00046 md_(iMD),
00047 actions_(iWP.actions_),
00048 cached_exception_(),
00049 actReg_()
00050 {
00051 }
00052
00053 Worker::~Worker() {
00054 }
00055
00056 void Worker::setActivityRegistry(boost::shared_ptr<ActivityRegistry> areg) {
00057 actReg_ = areg;
00058 }
00059
00060 void Worker::beginJob() {
00061
00062 try {
00063 ModuleBeginJobSignalSentry cpp(actReg_.get(), md_);
00064 implBeginJob();
00065 }
00066 catch(cms::Exception& e) {
00067 LogError("BeginJob")
00068 << "A cms::Exception is going through " << workerType() << ":\n";
00069 state_ = Exception;
00070 e << "A cms::Exception is going through " << workerType() << ":\n";
00071 exceptionContext(md_, e);
00072 throw;
00073 }
00074 catch(std::bad_alloc& bda) {
00075 LogError("BeginJob")
00076 << "A std::bad_alloc is going through " << workerType() << ":\n"
00077 << description() << "\n";
00078 state_ = Exception;
00079 cached_exception_.reset(new edm::Exception(errors::BadAlloc));
00080 *cached_exception_
00081 << "A std::bad_alloc exception occurred during a call to the module ";
00082 exceptionContext(md_, *cached_exception_)
00083 << "The job has probably exhausted the virtual memory available to the process.\n";
00084 throw *cached_exception_;
00085 }
00086 catch(std::exception& e) {
00087 LogError("BeginJob")
00088 << "A std::exception is going through " << workerType() << ":\n"
00089 << description() << "\n";
00090 state_ = Exception;
00091 cached_exception_.reset(new edm::Exception(errors::StdException));
00092 *cached_exception_
00093 << "A std::exception occurred during a call to the module ";
00094 exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n"
00095 << "Previous information:\n" << e.what();
00096 throw *cached_exception_;
00097 }
00098 catch(std::string& s) {
00099 LogError("BeginJob")
00100 << "module caught a std::string during endJob\n";
00101 state_ = Exception;
00102 cached_exception_.reset(new edm::Exception(errors::BadExceptionType, "std::string"));
00103 *cached_exception_
00104 << "A std::string thrown as an exception occurred during a call to the module ";
00105 exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n"
00106 << "Previous information:\n string = " << s;
00107 throw *cached_exception_;
00108 }
00109 catch(char const* c) {
00110 LogError("BeginJob")
00111 << "module caught a const char* during endJob\n";
00112 state_ = Exception;
00113 cached_exception_.reset(new edm::Exception(errors::BadExceptionType, "const char *"));
00114 *cached_exception_
00115 << "A const char* thrown as an exception occurred during a call to the module ";
00116 exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n"
00117 << "Previous information:\n const char* = " << c << "\n";
00118 throw *cached_exception_;
00119 }
00120 catch(...) {
00121 LogError("BeginJob")
00122 << "An unknown Exception occurred in\n" << description() << "\n";
00123 state_ = Exception;
00124 cached_exception_.reset(new edm::Exception(errors::Unknown, "repeated"));
00125 *cached_exception_
00126 << "An unknown occurred during a previous call to the module ";
00127 exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n";
00128 throw *cached_exception_;
00129 }
00130 }
00131
00132 void Worker::endJob() {
00133 try {
00134 ModuleEndJobSignalSentry cpp(actReg_.get(), md_);
00135 implEndJob();
00136 }
00137 catch(cms::Exception& e) {
00138 LogError("EndJob")
00139 << "A cms::Exception is going through " << workerType() << ":\n";
00140 state_ = Exception;
00141 e << "A cms::Exception is going through " << workerType() << ":\n";
00142 exceptionContext(md_, e);
00143 throw;
00144 }
00145 catch(std::bad_alloc& bda) {
00146 LogError("EndJob")
00147 << "A std::bad_alloc is going through " << workerType() << ":\n"
00148 << description() << "\n";
00149 state_ = Exception;
00150 cached_exception_.reset(new edm::Exception(errors::BadAlloc));
00151 *cached_exception_
00152 << "A std::bad_alloc exception occurred during a call to the module ";
00153 exceptionContext(md_, *cached_exception_)
00154 << "The job has probably exhausted the virtual memory available to the process.\n";
00155 throw *cached_exception_;
00156 }
00157 catch(std::exception& e) {
00158 LogError("EndJob")
00159 << "A std::exception is going through " << workerType() << ":\n"
00160 << description() << "\n";
00161 state_ = Exception;
00162 cached_exception_.reset(new edm::Exception(errors::StdException));
00163 *cached_exception_
00164 << "A std::exception occurred during a call to the module ";
00165 exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n"
00166 << "Previous information:\n" << e.what();
00167 throw *cached_exception_;
00168 }
00169 catch(std::string& s) {
00170 LogError("EndJob")
00171 << "module caught a std::string during endJob\n";
00172 state_ = Exception;
00173 cached_exception_.reset(new edm::Exception(errors::BadExceptionType, "std::string"));
00174 *cached_exception_
00175 << "A std::string thrown as an exception occurred during a call to the module ";
00176 exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n"
00177 << "Previous information:\n string = " << s;
00178 throw *cached_exception_;
00179 }
00180 catch(char const* c) {
00181 LogError("EndJob")
00182 << "module caught a const char* during endJob\n";
00183 state_ = Exception;
00184 cached_exception_.reset(new edm::Exception(errors::BadExceptionType, "const char *"));
00185 *cached_exception_
00186 << "A const char* thrown as an exception occurred during a call to the module ";
00187 exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n"
00188 << "Previous information:\n const char* = " << c << "\n";
00189 throw *cached_exception_;
00190 }
00191 catch(...) {
00192 LogError("EndJob")
00193 << "An unknown Exception occurred in\n" << description() << "\n";
00194 state_ = Exception;
00195 cached_exception_.reset(new edm::Exception(errors::Unknown, "repeated"));
00196 *cached_exception_
00197 << "An unknown occurred during a previous call to the module ";
00198 exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n";
00199 throw *cached_exception_;
00200 }
00201
00202 }
00203
00204 void Worker::useStopwatch(){
00205 stopwatch_.reset(new RunStopwatch::StopwatchPointer::element_type);
00206 }
00207
00208 }