CMS 3D CMS Logo

globalTransitionAsync.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_globalTransitionAsync_h
2 #define FWCore_Framework_globalTransitionAsync_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/Framework
6 // Function: globalTransitionAsync
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Tue, 06 Sep 2016 16:04:26 GMT
19 //
20 
27 
28 #include <exception>
29 #include <utility>
30 #include <vector>
31 
32 namespace edm {
33 
34  //This is code in common between beginStreamRun and beginGlobalLuminosityBlock
35  template <typename T>
37  SubProcess& iSubProcess,
38  LumiTransitionInfo const& iTransitionInfo,
39  bool) {
40  iSubProcess.doBeginLuminosityBlockAsync(std::move(iHolder), iTransitionInfo);
41  }
42 
43  template <typename T>
45  SubProcess& iSubProcess,
46  RunTransitionInfo const& iTransitionInfo,
47  bool) {
48  iSubProcess.doBeginRunAsync(std::move(iHolder), iTransitionInfo);
49  }
50 
51  template <typename Traits>
53  SubProcess& iSubProcess,
54  ProcessBlockTransitionInfo const& iTransitionInfo,
55  bool cleaningUpAfterException) {
56  iSubProcess.doBeginProcessBlockAsync<Traits>(std::move(iHolder), iTransitionInfo, cleaningUpAfterException);
57  }
58 
60  SubProcess& iSubProcess,
61  LumiTransitionInfo const& iTransitionInfo,
62  bool cleaningUpAfterException) {
63  iSubProcess.doEndLuminosityBlockAsync(std::move(iHolder), iTransitionInfo, cleaningUpAfterException);
64  }
65 
67  SubProcess& iSubProcess,
68  RunTransitionInfo const& iTransitionInfo,
69  bool cleaningUpAfterException) {
70  iSubProcess.doEndRunAsync(std::move(iHolder), iTransitionInfo, cleaningUpAfterException);
71  }
72 
74  SubProcess& iSubProcess,
75  ProcessBlockTransitionInfo const& iTransitionInfo,
76  bool cleaningUpAfterException) {
77  iSubProcess.doEndProcessBlockAsync(std::move(iHolder), iTransitionInfo, cleaningUpAfterException);
78  }
79 
80  template <typename Traits>
82  Schedule& iSchedule,
83  typename Traits::TransitionInfoType& transitionInfo,
84  ServiceToken const& token,
85  std::vector<SubProcess>& iSubProcesses,
86  bool cleaningUpAfterException = false) {
87  // When we are done processing the global for this process,
88  // we need to run the global for all SubProcesses
89  using namespace edm::waiting_task;
90 
91  chain::first([&](auto nextTask) {
92  iSchedule.processOneGlobalAsync<Traits>(std::move(nextTask), transitionInfo, token, cleaningUpAfterException);
93  }) |
94  chain::then([&iSubProcesses, info = transitionInfo, cleaningUpAfterException](std::exception_ptr const* iPtr,
95  auto nextTask) {
96  if (iPtr) {
97  //delay handling exception until after subProcesses run
98  chain::first([&](auto nextTask) {
99  for (auto& subProcess : iSubProcesses) {
100  subProcessDoGlobalBeginTransitionAsync<Traits>(nextTask, subProcess, info, cleaningUpAfterException);
101  }
102  }) | chain::then([excpt = *iPtr](std::exception_ptr const*, auto nextTask) {
103  nextTask.doneWaiting(excpt);
104  }) | chain::runLast(nextTask);
105  } else {
106  for (auto& subProcess : iSubProcesses) {
107  subProcessDoGlobalBeginTransitionAsync<Traits>(nextTask, subProcess, info, cleaningUpAfterException);
108  }
109  }
110  }) |
111  chain::runLast(iWait);
112  }
113 
114  template <typename Traits>
116  Schedule& iSchedule,
117  typename Traits::TransitionInfoType& transitionInfo,
118  ServiceToken const& token,
119  std::vector<SubProcess>& iSubProcesses,
120  bool cleaningUpAfterException) {
121  using namespace edm::waiting_task;
122  chain::first([&](auto nextTask) {
123  iSchedule.processOneGlobalAsync<Traits>(std::move(nextTask), transitionInfo, token, cleaningUpAfterException);
124  })
125  // When we are done processing the global for this process,
126  // we need to run the global for all SubProcesses
127  | chain::then([&iSubProcesses, info = transitionInfo, cleaningUpAfterException](std::exception_ptr const* iPtr,
128  auto nextTask) {
129  if (iPtr) {
130  //still run the sub process but pass this exception to the nextTask
131  auto excpt = *iPtr;
132  chain::first([&](auto nextTask) {
133  for (auto& subProcess : iSubProcesses) {
134  subProcessDoGlobalEndTransitionAsync(nextTask, subProcess, info, cleaningUpAfterException);
135  }
136  }) | chain::then([excpt](std::exception_ptr const*, auto nextTask) { nextTask.doneWaiting(excpt); }) |
137  chain::runLast(std::move(nextTask));
138  } else {
139  for (auto& subProcess : iSubProcesses) {
140  subProcessDoGlobalEndTransitionAsync(nextTask, subProcess, info, cleaningUpAfterException);
141  }
142  }
143  }) |
144  chain::runLast(iWait);
145  }
146 
147 }; // namespace edm
148 
149 #endif
static const TGPicture * info(bool iBackgroundIsBlack)
void processOneGlobalAsync(WaitingTaskHolder iTask, typename T::TransitionInfoType &transitionInfo, ServiceToken const &token, bool cleaningUpAfterException=false)
Definition: Schedule.h:345
void subProcessDoGlobalEndTransitionAsync(WaitingTaskHolder iHolder, SubProcess &iSubProcess, LumiTransitionInfo const &iTransitionInfo, bool cleaningUpAfterException)
void doBeginProcessBlockAsync(WaitingTaskHolder iHolder, ProcessBlockTransitionInfo const &iTransitionInfo, bool cleaningUpAfterException)
constexpr auto first(F &&iF)
Definition: chain_first.h:260
constexpr auto then(O &&iO)
Definition: chain_first.h:277
void doEndProcessBlockAsync(WaitingTaskHolder iHolder, ProcessBlockTransitionInfo const &iTransitionInfo, bool cleaningUpAfterException)
Definition: SubProcess.cc:499
void beginGlobalTransitionAsync(WaitingTaskHolder iWait, Schedule &iSchedule, typename Traits::TransitionInfoType &transitionInfo, ServiceToken const &token, std::vector< SubProcess > &iSubProcesses, bool cleaningUpAfterException=false)
void doBeginLuminosityBlockAsync(WaitingTaskHolder iHolder, LumiTransitionInfo const &iTransitionInfo)
Definition: SubProcess.cc:631
auto runLast(edm::WaitingTaskHolder iTask)
Definition: chain_first.h:297
void subProcessDoGlobalBeginTransitionAsync(WaitingTaskHolder iHolder, SubProcess &iSubProcess, LumiTransitionInfo const &iTransitionInfo, bool)
void doEndRunAsync(WaitingTaskHolder iHolder, RunTransitionInfo const &iTransitionInfo, bool cleaningUpAfterException)
Definition: SubProcess.cc:569
void doBeginRunAsync(WaitingTaskHolder iHolder, RunTransitionInfo const &iTransitionInfo)
Definition: SubProcess.cc:547
HLT enums.
void doEndLuminosityBlockAsync(WaitingTaskHolder iHolder, LumiTransitionInfo const &iTransitionInfo, bool cleaningUpAfterException)
Definition: SubProcess.cc:653
def move(src, dest)
Definition: eostools.py:511
void endGlobalTransitionAsync(WaitingTaskHolder iWait, Schedule &iSchedule, typename Traits::TransitionInfoType &transitionInfo, ServiceToken const &token, std::vector< SubProcess > &iSubProcesses, bool cleaningUpAfterException)