CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Worker.cc
Go to the documentation of this file.
1 
2 /*----------------------------------------------------------------------
3 ----------------------------------------------------------------------*/
4 
6 
7 namespace edm {
8  namespace {
9  class ModuleBeginJobSignalSentry {
10 public:
11  ModuleBeginJobSignalSentry(ActivityRegistry* a, ModuleDescription& md):a_(a), md_(&md) {
12  if(a_) a_->preModuleBeginJobSignal_(*md_);
13  }
14  ~ModuleBeginJobSignalSentry() {
15  if(a_) a_->postModuleBeginJobSignal_(*md_);
16  }
17 private:
18  ActivityRegistry* a_;
19  ModuleDescription* md_;
20  };
21 
22  class ModuleEndJobSignalSentry {
23 public:
24  ModuleEndJobSignalSentry(ActivityRegistry* a, ModuleDescription& md):a_(a), md_(&md) {
25  if(a_) a_->preModuleEndJobSignal_(*md_);
26  }
27  ~ModuleEndJobSignalSentry() {
28  if(a_) a_->postModuleEndJobSignal_(*md_);
29  }
30 private:
31  ActivityRegistry* a_;
32  ModuleDescription* md_;
33  };
34 
35  cms::Exception& exceptionContext(ModuleDescription const& iMD,
36  cms::Exception& iEx) {
37  iEx << iMD.moduleName() << "/" << iMD.moduleLabel() << "\n";
38  return iEx;
39  }
40 
41  }
42 
44  WorkerParams const& iWP) :
45  stopwatch_(),
46  timesRun_(),
47  timesVisited_(),
48  timesPassed_(),
49  timesFailed_(),
50  timesExcept_(),
51  state_(Ready),
52  md_(iMD),
53  actions_(iWP.actions_),
54  cached_exception_(),
55  actReg_()
56  {
57  }
58 
60  }
61 
62  void Worker::setActivityRegistry(boost::shared_ptr<ActivityRegistry> areg) {
63  actReg_ = areg;
64  }
65 
67 
68  try {
69  ModuleBeginJobSignalSentry cpp(actReg_.get(), md_);
70  implBeginJob();
71  }
72  catch(cms::Exception& e) {
73  LogError("BeginJob")
74  << "A cms::Exception is going through " << workerType() << ":\n";
75  state_ = Exception;
76  e << "A cms::Exception is going through " << workerType() << ":\n";
77  exceptionContext(md_, e);
78  throw;
79  }
80  catch(std::bad_alloc& bda) {
81  LogError("BeginJob")
82  << "A std::bad_alloc is going through " << workerType() << ":\n"
83  << description() << "\n";
84  state_ = Exception;
87  << "A std::bad_alloc exception occurred during a call to the module ";
88  exceptionContext(md_, *cached_exception_)
89  << "The job has probably exhausted the virtual memory available to the process.\n";
90  throw *cached_exception_;
91  }
92  catch(std::exception& e) {
93  LogError("BeginJob")
94  << "A std::exception is going through " << workerType() << ":\n"
95  << description() << "\n";
96  state_ = Exception;
99  << "A std::exception occurred during a call to the module ";
100  exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n"
101  << "Previous information:\n" << e.what();
102  throw *cached_exception_;
103  }
104  catch(std::string& s) {
105  LogError("BeginJob")
106  << "module caught a std::string during endJob\n";
107  state_ = Exception;
108  cached_exception_.reset(new edm::Exception(errors::BadExceptionType, "std::string"));
110  << "A std::string thrown as an exception occurred during a call to the module ";
111  exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n"
112  << "Previous information:\n string = " << s;
113  throw *cached_exception_;
114  }
115  catch(char const* c) {
116  LogError("BeginJob")
117  << "module caught a const char* during endJob\n";
118  state_ = Exception;
119  cached_exception_.reset(new edm::Exception(errors::BadExceptionType, "const char *"));
121  << "A const char* thrown as an exception occurred during a call to the module ";
122  exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n"
123  << "Previous information:\n const char* = " << c << "\n";
124  throw *cached_exception_;
125  }
126  catch(...) {
127  LogError("BeginJob")
128  << "An unknown Exception occurred in\n" << description() << "\n";
129  state_ = Exception;
130  cached_exception_.reset(new edm::Exception(errors::Unknown, "repeated"));
132  << "An unknown occurred during a previous call to the module ";
133  exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n";
134  throw *cached_exception_;
135  }
136  }
137 
138  void Worker::endJob() {
139  try {
140  ModuleEndJobSignalSentry cpp(actReg_.get(), md_);
141  implEndJob();
142  }
143  catch(cms::Exception& e) {
144  LogError("EndJob")
145  << "A cms::Exception is going through " << workerType() << ":\n";
146  state_ = Exception;
147  e << "A cms::Exception is going through " << workerType() << ":\n";
148  exceptionContext(md_, e);
149  throw;
150  }
151  catch(std::bad_alloc& bda) {
152  LogError("EndJob")
153  << "A std::bad_alloc is going through " << workerType() << ":\n"
154  << description() << "\n";
155  state_ = Exception;
158  << "A std::bad_alloc exception occurred during a call to the module ";
159  exceptionContext(md_, *cached_exception_)
160  << "The job has probably exhausted the virtual memory available to the process.\n";
161  throw *cached_exception_;
162  }
163  catch(std::exception& e) {
164  LogError("EndJob")
165  << "A std::exception is going through " << workerType() << ":\n"
166  << description() << "\n";
167  state_ = Exception;
170  << "A std::exception occurred during a call to the module ";
171  exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n"
172  << "Previous information:\n" << e.what();
173  throw *cached_exception_;
174  }
175  catch(std::string& s) {
176  LogError("EndJob")
177  << "module caught a std::string during endJob\n";
178  state_ = Exception;
179  cached_exception_.reset(new edm::Exception(errors::BadExceptionType, "std::string"));
181  << "A std::string thrown as an exception occurred during a call to the module ";
182  exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n"
183  << "Previous information:\n string = " << s;
184  throw *cached_exception_;
185  }
186  catch(char const* c) {
187  LogError("EndJob")
188  << "module caught a const char* during endJob\n";
189  state_ = Exception;
190  cached_exception_.reset(new edm::Exception(errors::BadExceptionType, "const char *"));
192  << "A const char* thrown as an exception occurred during a call to the module ";
193  exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n"
194  << "Previous information:\n const char* = " << c << "\n";
195  throw *cached_exception_;
196  }
197  catch(...) {
198  LogError("EndJob")
199  << "An unknown Exception occurred in\n" << description() << "\n";
200  state_ = Exception;
201  cached_exception_.reset(new edm::Exception(errors::Unknown, "repeated"));
203  << "An unknown occurred during a previous call to the module ";
204  exceptionContext(md_, *cached_exception_) << "and cannot be repropagated.\n";
205  throw *cached_exception_;
206  }
207 
208  }
209 
211  stopwatch_.reset(new RunStopwatch::StopwatchPointer::element_type);
212  }
213 
214 }
ModuleDescription const & description() const
Definition: Worker.h:63
not [yet] run
Definition: HLTenums.h:21
virtual ~Worker()
Definition: Worker.cc:59
void endJob()
Definition: Worker.cc:138
boost::shared_ptr< ActivityRegistry > actReg_
Definition: Worker.h:127
void setActivityRegistry(boost::shared_ptr< ActivityRegistry > areg)
Definition: Worker.cc:62
virtual std::string workerType() const =0
void useStopwatch()
Definition: Worker.cc:210
virtual void implEndJob()=0
virtual void implBeginJob()=0
Worker(ModuleDescription const &iMD, WorkerParams const &iWP)
Definition: Worker.cc:43
ModuleDescription md_
Definition: Worker.h:123
double a
Definition: hdecay.h:121
void beginJob()
Definition: Worker.cc:66
boost::shared_ptr< edm::Exception > cached_exception_
Definition: Worker.h:125
RunStopwatch::StopwatchPointer stopwatch_
Definition: Worker.h:114
string s
Definition: asciidump.py:422
State state_
Definition: Worker.h:121