CMS 3D CMS Logo

GlobalSchedule.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_GlobalSchedule_h
2 #define FWCore_Framework_GlobalSchedule_h
3 
4 /*
5 */
6 
25 
26 #include <map>
27 #include <memory>
28 #include <set>
29 #include <string>
30 #include <vector>
31 #include <sstream>
32 #include "boost/range/adaptor/reversed.hpp"
33 
34 namespace edm {
35 
36  namespace {
37  template <typename T>
38  class GlobalScheduleSignalSentry {
39  public:
40  GlobalScheduleSignalSentry(ActivityRegistry* a, typename T::Context const* context)
41  : a_(a), context_(context), allowThrow_(false) {
42  if (a_)
43  T::preScheduleSignal(a_, context_);
44  }
45  ~GlobalScheduleSignalSentry() noexcept(false) {
46  // Caught exception is rethrown
47  CMS_SA_ALLOW try {
48  if (a_)
49  T::postScheduleSignal(a_, context_);
50  } catch (...) {
51  if (allowThrow_) {
52  throw;
53  }
54  }
55  }
56 
57  void allowThrow() { allowThrow_ = true; }
58 
59  private:
60  // We own none of these resources.
61  ActivityRegistry* a_; // We do not use propagate_const because the registry itself is mutable.
62  typename T::Context const* context_;
63  bool allowThrow_;
64  };
65  } // namespace
66 
67  class ActivityRegistry;
68  class EventSetupImpl;
69  class ExceptionCollector;
70  class ProcessContext;
71  class PreallocationConfiguration;
72  class ModuleRegistry;
73  class TriggerResultInserter;
74  class PathStatusInserter;
75  class EndPathStatusInserter;
76 
78  public:
79  typedef std::vector<std::string> vstring;
80  typedef std::vector<Worker*> AllWorkers;
81  typedef std::shared_ptr<Worker> WorkerPtr;
82  typedef std::vector<Worker*> Workers;
83 
84  GlobalSchedule(std::shared_ptr<TriggerResultInserter> inserter,
85  std::vector<edm::propagate_const<std::shared_ptr<PathStatusInserter>>>& pathStatusInserters,
86  std::vector<edm::propagate_const<std::shared_ptr<EndPathStatusInserter>>>& endPathStatusInserters,
87  std::shared_ptr<ModuleRegistry> modReg,
88  std::vector<std::string> const& modulesToUse,
89  ParameterSet& proc_pset,
90  ProductRegistry& pregistry,
91  PreallocationConfiguration const& prealloc,
93  std::shared_ptr<ActivityRegistry> areg,
94  std::shared_ptr<ProcessConfiguration> processConfiguration,
95  ProcessContext const* processContext);
96  GlobalSchedule(GlobalSchedule const&) = delete;
97 
98  template <typename T>
100  typename T::MyPrincipal& principal,
101  EventSetupImpl const& eventSetup,
102  ServiceToken const& token,
103  bool cleaningUpAfterException = false);
104 
106  void endJob(ExceptionCollector& collector);
107 
110 
114  std::vector<ModuleDescription const*> getAllModuleDescriptions() const;
115 
118  void getTriggerReport(TriggerReport& rep) const;
119 
121  bool terminate() const;
122 
124  void replaceModule(maker::ModuleHolder* iMod, std::string const& iLabel);
125 
127  AllWorkers const& allWorkers() const { return workerManagers_[0].allWorkers(); }
128 
129  private:
130  //Sentry class to only send a signal if an
131  // exception occurs. An exception is identified
132  // by the destructor being called without first
133  // calling completedSuccessfully().
135  public:
137  : reg_(iReg), context_(iContext) {}
139  if (reg_) {
141  }
142  }
143  void completedSuccessfully() { reg_ = nullptr; }
144 
145  private:
146  edm::ActivityRegistry* reg_; // We do not use propagate_const because the registry itself is mutable.
148  };
149 
151  ExceptionToActionTable const& actionTable() const { return workerManagers_[0].actionTable(); }
152 
153  std::vector<WorkerManager> workerManagers_;
154  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
155  std::vector<edm::propagate_const<WorkerPtr>> extraWorkers_;
157  };
158 
159  template <typename T>
161  typename T::MyPrincipal& ep,
162  EventSetupImpl const& es,
163  ServiceToken const& token,
164  bool cleaningUpAfterException) {
165  // Caught exception is propagated via WaitingTaskHolder
166  CMS_SA_ALLOW try {
167  //need the doneTask to own the memory
168  auto globalContext = std::make_shared<GlobalContext>(T::makeGlobalContext(ep, processContext_));
169 
170  if (actReg_) {
171  //Services may depend upon each other
173  T::preScheduleSignal(actReg_.get(), globalContext.get());
174  }
175 
176  auto doneTask = make_waiting_task(
177  tbb::task::allocate_root(),
178  [this, iHolder, cleaningUpAfterException, globalContext, token](std::exception_ptr const* iPtr) mutable {
179  std::exception_ptr excpt;
180  if (iPtr) {
181  excpt = *iPtr;
182  //add context information to the exception and print message
183  try {
184  convertException::wrap([&]() { std::rethrow_exception(excpt); });
185  } catch (cms::Exception& ex) {
186  //TODO: should add the transition type info
187  std::ostringstream ost;
188  if (ex.context().empty()) {
189  ost << "Processing " << T::transitionName() << " ";
190  }
192  addContextAndPrintException(ost.str().c_str(), ex, cleaningUpAfterException);
193  excpt = std::current_exception();
194  }
195  if (actReg_) {
197  actReg_->preGlobalEarlyTerminationSignal_(*globalContext, TerminationOrigin::ExceptionFromThisContext);
198  }
199  }
200  if (actReg_) {
201  // Caught exception is propagated via WaitingTaskHolder
202  CMS_SA_ALLOW try {
204  T::postScheduleSignal(actReg_.get(), globalContext.get());
205  } catch (...) {
206  if (not excpt) {
207  excpt = std::current_exception();
208  }
209  }
210  }
211  iHolder.doneWaiting(excpt);
212  });
213  workerManagers_[ep.index()].resetAll();
214 
215  ParentContext parentContext(globalContext.get());
216  //make sure the ProductResolvers know about their
217  // workers to allow proper data dependency handling
218  workerManagers_[ep.index()].setupOnDemandSystem(ep, es);
219 
220  //make sure the task doesn't get run until all workers have beens started
221  WaitingTaskHolder holdForLoop(doneTask);
222  auto& aw = workerManagers_[ep.index()].allWorkers();
223  for (Worker* worker : boost::adaptors::reverse(aw)) {
224  worker->doWorkAsync<T>(
225  doneTask, ep, es, token, StreamID::invalidStreamID(), parentContext, globalContext.get());
226  }
227  } catch (...) {
228  iHolder.doneWaiting(std::current_exception());
229  }
230  }
231 } // namespace edm
232 
233 #endif
edm::GlobalSchedule::allWorkers
AllWorkers const & allWorkers() const
returns the collection of pointers to workers
Definition: GlobalSchedule.h:127
WorkerManager.h
edm::TerminationOrigin::ExceptionFromThisContext
edm::eventsetup::ESRecordsToProxyIndices
Definition: ESRecordsToProxyIndices.h:35
funct::false
false
Definition: Factorize.h:34
edm::GlobalSchedule::SendTerminationSignalIfException::completedSuccessfully
void completedSuccessfully()
Definition: GlobalSchedule.h:143
BranchType.h
ActivityRegistry
propagate_const.h
edm::EventSetupImpl
Definition: EventSetupImpl.h:44
WaitingTaskHolder.h
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::ProcessContext
Definition: ProcessContext.h:27
edm::GlobalSchedule::terminate
bool terminate() const
Return whether each output module has reached its maximum count.
Algorithms.h
edm::maker::ModuleHolder
Definition: ModuleHolder.h:37
edm::GlobalSchedule::vstring
std::vector< std::string > vstring
Definition: GlobalSchedule.h:79
edm::GlobalSchedule::Workers
std::vector< Worker * > Workers
Definition: GlobalSchedule.h:82
edm::WaitingTaskHolder::doneWaiting
void doneWaiting(std::exception_ptr iExcept)
Definition: WaitingTaskHolder.h:75
edm::GlobalSchedule::SendTerminationSignalIfException::reg_
edm::ActivityRegistry * reg_
Definition: GlobalSchedule.h:146
edm::GlobalSchedule::beginJob
void beginJob(ProductRegistry const &, eventsetup::ESRecordsToProxyIndices const &)
Definition: GlobalSchedule.cc:93
CMS_SA_ALLOW
#define CMS_SA_ALLOW
Definition: thread_safety_macros.h:5
groupFilesInBlocks.reverse
reverse
Definition: groupFilesInBlocks.py:131
edm::ProductRegistry
Definition: ProductRegistry.h:34
ModuleDescription.h
edm::ServiceToken
Definition: ServiceToken.h:40
edm::propagate_const
Definition: propagate_const.h:32
edm::GlobalSchedule::SendTerminationSignalIfException::~SendTerminationSignalIfException
~SendTerminationSignalIfException()
Definition: GlobalSchedule.h:138
edm::GlobalSchedule::SendTerminationSignalIfException::context_
GlobalContext const * context_
Definition: GlobalSchedule.h:147
edm::GlobalSchedule::actReg_
std::shared_ptr< ActivityRegistry > actReg_
Definition: GlobalSchedule.h:154
edm::GlobalSchedule::getAllModuleDescriptions
std::vector< ModuleDescription const * > getAllModuleDescriptions() const
Definition: GlobalSchedule.cc:116
edm::ExceptionCollector
Definition: ExceptionCollector.h:33
edm::convertException::wrap
auto wrap(F iFunc) -> decltype(iFunc())
Definition: ConvertException.h:19
edm::ActivityRegistry
Definition: ActivityRegistry.h:132
edm::GlobalSchedule
Definition: GlobalSchedule.h:77
ConvertException.h
edm::Worker
Definition: Worker.h:83
edm::make_waiting_task
FunctorWaitingTask< F > * make_waiting_task(ALLOC &&iAlloc, F f)
Definition: WaitingTask.h:87
edm::GlobalSchedule::processContext_
ProcessContext const * processContext_
Definition: GlobalSchedule.h:156
edm::GlobalSchedule::workerManagers_
std::vector< WorkerManager > workerManagers_
Definition: GlobalSchedule.h:153
edm::ParentContext
Definition: ParentContext.h:27
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::GlobalSchedule::endJob
void endJob(ExceptionCollector &collector)
Definition: GlobalSchedule.cc:91
edm::GlobalContext
Definition: GlobalContext.h:29
edm::ParameterSet
Definition: ParameterSet.h:36
a
double a
Definition: hdecay.h:119
GlobalContext.h
cms::Exception::context
std::list< std::string > const & context() const
Definition: Exception.cc:147
edm::WaitingTaskHolder
Definition: WaitingTaskHolder.h:30
edm::GlobalSchedule::processOneGlobalAsync
void processOneGlobalAsync(WaitingTaskHolder holder, typename T::MyPrincipal &principal, EventSetupImpl const &eventSetup, ServiceToken const &token, bool cleaningUpAfterException=false)
Definition: GlobalSchedule.h:160
ExceptionMessages.h
thread_safety_macros.h
edm::StreamID::invalidStreamID
static StreamID invalidStreamID()
Definition: StreamID.h:44
edm::GlobalSchedule::actionTable
ExceptionToActionTable const & actionTable() const
returns the action table
Definition: GlobalSchedule.h:151
edm::addContextAndPrintException
void addContextAndPrintException(char const *context, cms::Exception &ex, bool disablePrint)
Definition: ExceptionHelpers.cc:11
cuy.rep
rep
Definition: cuy.py:1190
ExceptionActions.h
edm::GlobalSchedule::extraWorkers_
std::vector< edm::propagate_const< WorkerPtr > > extraWorkers_
Definition: GlobalSchedule.h:155
edm::ExceptionToActionTable
Definition: ExceptionActions.h:16
edm::TriggerReport
Definition: TriggerReport.h:56
edm::GlobalSchedule::GlobalSchedule
GlobalSchedule(std::shared_ptr< TriggerResultInserter > inserter, std::vector< edm::propagate_const< std::shared_ptr< PathStatusInserter >>> &pathStatusInserters, std::vector< edm::propagate_const< std::shared_ptr< EndPathStatusInserter >>> &endPathStatusInserters, std::shared_ptr< ModuleRegistry > modReg, std::vector< std::string > const &modulesToUse, ParameterSet &proc_pset, ProductRegistry &pregistry, PreallocationConfiguration const &prealloc, ExceptionToActionTable const &actions, std::shared_ptr< ActivityRegistry > areg, std::shared_ptr< ProcessConfiguration > processConfiguration, ProcessContext const *processContext)
Definition: GlobalSchedule.cc:22
OccurrenceTraits.h
edm::PreallocationConfiguration
Definition: PreallocationConfiguration.h:27
edm::GlobalSchedule::SendTerminationSignalIfException::SendTerminationSignalIfException
SendTerminationSignalIfException(edm::ActivityRegistry *iReg, edm::GlobalContext const *iContext)
Definition: GlobalSchedule.h:136
edm::GlobalSchedule::WorkerPtr
std::shared_ptr< Worker > WorkerPtr
Definition: GlobalSchedule.h:81
edm::GlobalSchedule::getTriggerReport
void getTriggerReport(TriggerReport &rep) const
ExceptionHelpers.h
Frameworkfwd.h
T
long double T
Definition: Basic3DVectorLD.h:48
Worker.h
WorkerRegistry.h
Exception.h
edm::GlobalSchedule::SendTerminationSignalIfException
Definition: GlobalSchedule.h:134
edm::GlobalSchedule::replaceModule
void replaceModule(maker::ModuleHolder *iMod, std::string const &iLabel)
clone the type of module with label iLabel but configure with iPSet.
Definition: GlobalSchedule.cc:98
actions
roAction_t actions[nactions]
Definition: GenABIO.cc:181
cms::Exception
Definition: Exception.h:70
StreamID.h
edm::ServiceRegistry::Operate
Definition: ServiceRegistry.h:40
SiStripBadComponentsDQMServiceTemplate_cfg.ep
ep
Definition: SiStripBadComponentsDQMServiceTemplate_cfg.py:86
edm::GlobalSchedule::AllWorkers
std::vector< Worker * > AllWorkers
Definition: GlobalSchedule.h:80
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316
edm::ActivityRegistry::preGlobalEarlyTerminationSignal_
PreGlobalEarlyTermination preGlobalEarlyTerminationSignal_
Definition: ActivityRegistry.h:433