CMS 3D CMS Logo

EventProcessor.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_EventProcessor_h
2 #define FWCore_Framework_EventProcessor_h
3 
4 /*----------------------------------------------------------------------
5 
6 EventProcessor: This defines the 'framework application' object. It is
7 configured in the user's main() function, and is set running.
8 
9 ----------------------------------------------------------------------*/
10 
14 
24 
26 
31 
34 
37 
38 #include <atomic>
39 #include <map>
40 #include <memory>
41 #include <set>
42 #include <string>
43 #include <vector>
44 #include <exception>
45 #include <mutex>
46 
47 namespace edm {
48 
49  class ExceptionToActionTable;
50  class BranchIDListHelper;
51  class MergeableRunProductMetadata;
52  class ThinnedAssociationsHelper;
53  class EDLooperBase;
54  class HistoryAppender;
55  class ProcessDesc;
56  class SubProcess;
57  class WaitingTaskHolder;
58  class LuminosityBlockPrincipal;
59  class LuminosityBlockProcessingStatus;
60  class RunProcessingStatus;
61  class IOVSyncValue;
62  class ModuleTypeResolverMaker;
63 
64  namespace eventsetup {
65  class EventSetupProvider;
66  class EventSetupsController;
67  } // namespace eventsetup
68 
70  public:
71  // Status codes:
72  // 0 successful completion
73  // 1 exception of unknown type caught
74  // 2 everything else
75  // 3 signal received
76  // 4 input complete
77  // 5 call timed out
78  // 6 input count complete
79  enum StatusCode {
80  epSuccess = 0,
82  epOther = 2,
83  epSignal = 3,
87  };
88 
89  // The input 'parameterSet' contains the entire contents of a configuration file.
90  // Also allows the attachement of pre-existing services specified by 'token', and
91  // the specification of services by name only (defaultServices and forcedServices).
92  // 'defaultServices' are overridden by 'parameterSet'.
93  // 'forcedServices' the 'parameterSet'.
94  explicit EventProcessor(std::unique_ptr<ParameterSet> parameterSet,
95  ServiceToken const& token = ServiceToken(),
97  std::vector<std::string> const& defaultServices = std::vector<std::string>(),
98  std::vector<std::string> const& forcedServices = std::vector<std::string>());
99 
100  // Same as previous constructor, but without a 'token'. Token will be defaulted.
101 
102  EventProcessor(std::unique_ptr<ParameterSet> parameterSet,
103  std::vector<std::string> const& defaultServices,
104  std::vector<std::string> const& forcedServices = std::vector<std::string>());
105 
106  EventProcessor(std::shared_ptr<ProcessDesc> processDesc,
107  ServiceToken const& token,
109 
110  ~EventProcessor();
111 
112  EventProcessor(EventProcessor const&) = delete; // Disallow copying and moving
113  EventProcessor& operator=(EventProcessor const&) = delete; // Disallow copying and moving
114 
115  void taskCleanup();
116 
121  void beginJob();
122 
126  void endJob();
127 
128  // -------------
129 
130  // Same as runToCompletion(false) but since it was used extensively
131  // outside of the framework (and is simpler) will keep
132  StatusCode run();
133 
136 
140 
141  std::vector<ModuleDescription const*> getAllModuleDescriptions() const;
142 
144 
148  int totalEvents() const;
149 
152  int totalEventsPassed() const;
153 
156  int totalEventsFailed() const;
157 
159  void clearCounters();
160 
161  // Really should not be public,
162  // but the EventFilter needs it for now.
164 
165  //------------------------------------------------------------------
166  //
167  // Nested classes and structs below.
168 
169  // The function "runToCompletion" will run until the job is "complete",
170  // which means:
171  // 1 - no more input data
172  // 2 - input maxEvents parameter limit reached
173  // 3 - output maxEvents parameter limit reached
174  // 4 - input maxLuminosityBlocks parameter limit reached
175  // 5 - looper directs processing to end
176  //
177  // The return values from the function are as follows:
178  // epSignal - processing terminated early, SIGUSR2 encountered
179  // epCountComplete - "runEventCount" processed the number of events
180  // requested by the argument
181  // epSuccess - all other cases
182  //
184 
185  // The following functions are used by the code implementing
186  // transition handling.
187 
190  void nextTransitionTypeAsync(std::shared_ptr<RunProcessingStatus> iRunStatus, WaitingTaskHolder nextTask);
191 
192  void readFile();
193  bool fileBlockValid() { return fb_.get() != nullptr; }
194  void closeInputFile(bool cleaningUpAfterException);
195  void openOutputFiles();
196  void closeOutputFiles();
197 
198  void respondToOpenInputFile();
200 
201  void startingNewLoop();
202  bool endOfLoop();
203  void rewindInput();
204  void prepareForNextLoop();
205  bool shouldWeCloseOutput() const;
206 
207  void doErrorStuff();
208 
209  void beginProcessBlock(bool& beginProcessBlockSucceeded);
210  void inputProcessBlocks();
211  void endProcessBlock(bool cleaningUpAfterException, bool beginProcessBlockSucceeded);
212 
215  void streamBeginRunAsync(unsigned int iStream,
216  std::shared_ptr<RunProcessingStatus>,
217  bool precedingTasksSucceeded,
219  void releaseBeginRunResources(unsigned int iStream);
220  void endRunAsync(std::shared_ptr<RunProcessingStatus>, WaitingTaskHolder);
221  void handleEndRunExceptions(std::exception_ptr, WaitingTaskHolder const&);
222  void globalEndRunAsync(WaitingTaskHolder, std::shared_ptr<RunProcessingStatus>);
223  void streamEndRunAsync(WaitingTaskHolder, unsigned int iStreamIndex);
224  void endUnfinishedRun(bool cleaningUpAfterException);
225  void beginLumiAsync(IOVSyncValue const&, std::shared_ptr<RunProcessingStatus>, WaitingTaskHolder);
227  void handleEndLumiExceptions(std::exception_ptr, WaitingTaskHolder const&);
228  void globalEndLumiAsync(WaitingTaskHolder, std::shared_ptr<LuminosityBlockProcessingStatus>);
229  void streamEndLumiAsync(WaitingTaskHolder, unsigned int iStreamIndex);
230  void endUnfinishedLumi(bool cleaningUpAfterException);
232  std::shared_ptr<RunPrincipal> readRun();
234  std::shared_ptr<LuminosityBlockPrincipal> readLuminosityBlock(std::shared_ptr<RunPrincipal> rp);
242 
243  bool shouldWeStop() const;
244 
245  void setExceptionMessageFiles(std::string& message);
248 
249  bool setDeferredException(std::exception_ptr);
250 
251  private:
252  //------------------------------------------------------------------
253  //
254  // Now private functions.
255  // init() is used by only by constructors
256  void init(std::shared_ptr<ProcessDesc>& processDesc, ServiceToken const& token, serviceregistry::ServiceLegacy);
257 
258  void readAndMergeRunEntriesAsync(std::shared_ptr<RunProcessingStatus>, WaitingTaskHolder);
259  void readAndMergeLumiEntriesAsync(std::shared_ptr<LuminosityBlockProcessingStatus>, WaitingTaskHolder);
260 
261  void handleNextItemAfterMergingRunEntries(std::shared_ptr<RunProcessingStatus>, WaitingTaskHolder);
262 
263  bool readNextEventForStream(WaitingTaskHolder const&, unsigned int iStreamIndex, LuminosityBlockProcessingStatus&);
264 
265  void handleNextEventForStreamAsync(WaitingTaskHolder, unsigned int iStreamIndex);
266 
267  //read the next event using Stream iStreamIndex
268  void readEvent(unsigned int iStreamIndex);
269 
270  //process the already read event using Stream iStreamIndex
271  void processEventAsync(WaitingTaskHolder iHolder, unsigned int iStreamIndex);
272 
273  void processEventAsyncImpl(WaitingTaskHolder iHolder, unsigned int iStreamIndex);
274 
275  //returns true if an asynchronous stop was requested
277 
278  void processEventWithLooper(EventPrincipal&, unsigned int iStreamIndex);
279 
280  std::shared_ptr<ProductRegistry const> preg() const { return get_underlying_safe(preg_); }
281  std::shared_ptr<ProductRegistry>& preg() { return get_underlying_safe(preg_); }
282  std::shared_ptr<BranchIDListHelper const> branchIDListHelper() const {
284  }
285  std::shared_ptr<BranchIDListHelper>& branchIDListHelper() { return get_underlying_safe(branchIDListHelper_); }
286  std::shared_ptr<ThinnedAssociationsHelper const> thinnedAssociationsHelper() const {
288  }
289  std::shared_ptr<ThinnedAssociationsHelper>& thinnedAssociationsHelper() {
291  }
292  std::shared_ptr<EDLooperBase const> looper() const { return get_underlying_safe(looper_); }
293  std::shared_ptr<EDLooperBase>& looper() { return get_underlying_safe(looper_); }
294 
297  void warnAboutLegacyModules() const;
298 
299  bool needToCallNext() const { return needToCallNext_; }
301 
302  //------------------------------------------------------------------
303  //
304  // Data members below.
305  // Are all these data members really needed? Some of them are used
306  // only during construction, and never again. If they aren't
307  // really needed, we should remove them.
308 
309  //Guarantee that task group is the last to be destroyed
310  oneapi::tbb::task_group taskGroup_;
311 
312  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
324  std::unique_ptr<ExceptionToActionTable const> act_table_;
325  std::shared_ptr<ProcessConfiguration const> processConfiguration_;
330  std::vector<edm::SerialTaskQueue> streamQueues_;
332  std::unique_ptr<edm::LimitedTaskQueue> runQueue_;
333  std::unique_ptr<edm::LimitedTaskQueue> lumiQueue_;
334  std::vector<std::shared_ptr<RunProcessingStatus>> streamRunStatus_;
335  std::shared_ptr<RunProcessingStatus> exceptionRunStatus_;
336  std::vector<std::shared_ptr<LuminosityBlockProcessingStatus>> streamLumiStatus_;
337  std::atomic<unsigned int> streamRunActive_{0}; //works as guard for streamRunStatus
338  std::atomic<unsigned int> streamLumiActive_{0}; //works as guard for streamLumiStatus
339 
340  std::vector<std::string> branchesToDeleteEarly_;
341  std::multimap<std::string, std::string> referencesToBranches_;
342  std::vector<std::string> modulesToIgnoreForDeleteEarly_;
343 
344  std::vector<SubProcess> subProcesses_;
346 
349 
350  //The atomic protects concurrent access of deferredExceptionPtr_
351  std::atomic<bool> deferredExceptionPtrIsSet_;
352  std::exception_ptr deferredExceptionPtr_;
353 
355  std::shared_ptr<std::recursive_mutex> sourceMutex_;
361  std::atomic<bool> exceptionMessageRuns_;
362  std::atomic<bool> exceptionMessageLumis_;
366 
368 
369  bool firstEventInBlock_ = true;
370 
371  typedef std::set<std::pair<std::string, std::string>> ExcludedData;
372  typedef std::map<std::string, ExcludedData> ExcludedDataMap;
374 
375  bool printDependencies_ = false;
377  bool needToCallNext_ = true;
378  }; // class EventProcessor
379 
380  //--------------------------------------------------------------------
381 
383 } // namespace edm
384 #endif
std::atomic< bool > exceptionMessageLumis_
bool readNextEventForStream(WaitingTaskHolder const &, unsigned int iStreamIndex, LuminosityBlockProcessingStatus &)
void readEvent(unsigned int iStreamIndex)
void streamEndRunAsync(WaitingTaskHolder, unsigned int iStreamIndex)
ProcessContext processContext_
void init(std::shared_ptr< ProcessDesc > &processDesc, ServiceToken const &token, serviceregistry::ServiceLegacy)
void clearRunPrincipal(RunProcessingStatus &)
void globalEndRunAsync(WaitingTaskHolder, std::shared_ptr< RunProcessingStatus >)
SharedResourcesAcquirer sourceResourcesAcquirer_
void handleNextEventForStreamAsync(WaitingTaskHolder, unsigned int iStreamIndex)
int totalEventsFailed() const
std::shared_ptr< ProductRegistry const > preg() const
void warnAboutLegacyModules() const
void processEventAsync(WaitingTaskHolder iHolder, unsigned int iStreamIndex)
InputSource::ItemTypeInfo lastSourceTransition_
std::shared_ptr< RunPrincipal > readRun()
void handleEndLumiExceptions(std::exception_ptr, WaitingTaskHolder const &)
edm::propagate_const< std::unique_ptr< InputSource > > input_
std::unique_ptr< ExceptionToActionTable const > act_table_
SerialTaskQueue streamQueuesInserter_
void endUnfinishedRun(bool cleaningUpAfterException)
void setExceptionMessageFiles(std::string &message)
InputSource::ItemTypeInfo nextTransitionType()
void processEventAsyncImpl(WaitingTaskHolder iHolder, unsigned int iStreamIndex)
void processEventWithLooper(EventPrincipal &, unsigned int iStreamIndex)
void handleEndRunExceptions(std::exception_ptr, WaitingTaskHolder const &)
edm::propagate_const< std::unique_ptr< HistoryAppender > > historyAppender_
std::unique_ptr< edm::LimitedTaskQueue > lumiQueue_
void clearCounters()
Clears counters used by trigger report.
bool checkForAsyncStopRequest(StatusCode &)
edm::propagate_const< std::shared_ptr< ProductRegistry > > preg_
bool needToCallNext() const
void writeLumiAsync(WaitingTaskHolder, LuminosityBlockPrincipal &)
std::shared_ptr< EDLooperBase const > looper() const
constexpr std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
std::set< std::pair< std::string, std::string > > ExcludedData
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
PreallocationConfiguration preallocations_
edm::propagate_const< std::shared_ptr< FileBlock > > fb_
std::vector< SubProcess > subProcesses_
std::atomic< bool > exceptionMessageRuns_
edm::SerialTaskQueue queueWhichWaitsForIOVsToFinish_
MergeableRunProductProcesses mergeableRunProductProcesses_
std::vector< ModuleDescription const * > getAllModuleDescriptions() const
edm::propagate_const< std::unique_ptr< ModuleTypeResolverMaker const > > moduleTypeResolverMaker_
void endProcessBlock(bool cleaningUpAfterException, bool beginProcessBlockSucceeded)
std::multimap< std::string, std::string > referencesToBranches_
std::shared_ptr< ThinnedAssociationsHelper const > thinnedAssociationsHelper() const
ServiceToken serviceToken_
std::atomic< bool > deferredExceptionPtrIsSet_
std::vector< edm::SerialTaskQueue > streamQueues_
void nextTransitionTypeAsync(std::shared_ptr< RunProcessingStatus > iRunStatus, WaitingTaskHolder nextTask)
std::vector< std::string > modulesToIgnoreForDeleteEarly_
ExcludedDataMap eventSetupDataToExcludeFromPrefetching_
std::unique_ptr< edm::LimitedTaskQueue > runQueue_
edm::propagate_const< std::shared_ptr< EDLooperBase > > looper_
void writeRunAsync(WaitingTaskHolder, RunPrincipal const &, MergeableRunProductMetadata const *)
void writeProcessBlockAsync(WaitingTaskHolder, ProcessBlockType)
void setNeedToCallNext(bool val)
StatusCode runToCompletion()
void clearLumiPrincipal(LuminosityBlockProcessingStatus &)
EventProcessor & operator=(EventProcessor const &)=delete
edm::propagate_const< std::unique_ptr< Schedule > > schedule_
std::shared_ptr< ProcessConfiguration const > processConfiguration_
std::shared_ptr< std::recursive_mutex > sourceMutex_
std::vector< std::shared_ptr< RunProcessingStatus > > streamRunStatus_
std::string exceptionMessageFiles_
void releaseBeginRunResources(unsigned int iStream)
std::shared_ptr< BranchIDListHelper > & branchIDListHelper()
std::shared_ptr< RunProcessingStatus > exceptionRunStatus_
std::shared_ptr< EDLooperBase > & looper()
void readAndMergeRun(RunProcessingStatus &)
void warnAboutModulesRequiringRunSynchronization() const
void beginLumiAsync(IOVSyncValue const &, std::shared_ptr< RunProcessingStatus >, WaitingTaskHolder)
void handleNextItemAfterMergingRunEntries(std::shared_ptr< RunProcessingStatus >, WaitingTaskHolder)
InputSource::ItemTypeInfo lastTransitionType() const
InputSource::ItemType processRuns()
oneapi::tbb::task_group taskGroup_
void throwAboutModulesRequiringLuminosityBlockSynchronization() const
std::map< std::string, ExcludedData > ExcludedDataMap
ServiceToken getToken()
edm::propagate_const< std::unique_ptr< eventsetup::EventSetupsController > > espController_
void endRunAsync(std::shared_ptr< RunProcessingStatus >, WaitingTaskHolder)
std::vector< std::shared_ptr< LuminosityBlockProcessingStatus > > streamLumiStatus_
bool shouldWeStop() const
ProcessConfiguration const & processConfiguration() const
std::atomic< unsigned int > streamRunActive_
void readAndMergeLumi(LuminosityBlockProcessingStatus &)
edm::propagate_const< std::shared_ptr< ThinnedAssociationsHelper > > thinnedAssociationsHelper_
std::shared_ptr< ProductRegistry > & preg()
edm::propagate_const< std::shared_ptr< eventsetup::EventSetupProvider > > esp_
std::vector< std::string > branchesToDeleteEarly_
HLT enums.
void readAndMergeLumiEntriesAsync(std::shared_ptr< LuminosityBlockProcessingStatus >, WaitingTaskHolder)
void closeInputFile(bool cleaningUpAfterException)
void readAndMergeRunEntriesAsync(std::shared_ptr< RunProcessingStatus >, WaitingTaskHolder)
void readProcessBlock(ProcessBlockPrincipal &)
std::exception_ptr deferredExceptionPtr_
std::shared_ptr< LuminosityBlockPrincipal > readLuminosityBlock(std::shared_ptr< RunPrincipal > rp)
void endUnfinishedLumi(bool cleaningUpAfterException)
bool shouldWeCloseOutput() const
PathsAndConsumesOfModules pathsAndConsumesOfModules_
int totalEventsPassed() const
edm::propagate_const< std::shared_ptr< ProcessBlockHelper > > processBlockHelper_
void continueLumiAsync(WaitingTaskHolder)
void globalEndLumiAsync(WaitingTaskHolder, std::shared_ptr< LuminosityBlockProcessingStatus >)
void streamBeginRunAsync(unsigned int iStream, std::shared_ptr< RunProcessingStatus >, bool precedingTasksSucceeded, WaitingTaskHolder)
std::shared_ptr< ActivityRegistry > actReg_
std::atomic< unsigned int > streamLumiActive_
void streamEndLumiAsync(WaitingTaskHolder, unsigned int iStreamIndex)
void beginProcessBlock(bool &beginProcessBlockSucceeded)
void beginRunAsync(IOVSyncValue const &, WaitingTaskHolder)
bool setDeferredException(std::exception_ptr)
edm::propagate_const< std::shared_ptr< BranchIDListHelper > > branchIDListHelper_
bool deleteNonConsumedUnscheduledModules_
std::shared_ptr< BranchIDListHelper const > branchIDListHelper() const
std::shared_ptr< ThinnedAssociationsHelper > & thinnedAssociationsHelper()
PrincipalCache principalCache_
EventProcessor(std::unique_ptr< ParameterSet > parameterSet, ServiceToken const &token=ServiceToken(), serviceregistry::ServiceLegacy=serviceregistry::kOverlapIsError, std::vector< std::string > const &defaultServices=std::vector< std::string >(), std::vector< std::string > const &forcedServices=std::vector< std::string >())