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 
63  namespace eventsetup {
64  class EventSetupProvider;
65  class EventSetupsController;
66  } // namespace eventsetup
67 
69  public:
70  // Status codes:
71  // 0 successful completion
72  // 1 exception of unknown type caught
73  // 2 everything else
74  // 3 signal received
75  // 4 input complete
76  // 5 call timed out
77  // 6 input count complete
78  enum StatusCode {
79  epSuccess = 0,
81  epOther = 2,
82  epSignal = 3,
86  };
87 
88  // The input 'parameterSet' contains the entire contents of a configuration file.
89  // Also allows the attachement of pre-existing services specified by 'token', and
90  // the specification of services by name only (defaultServices and forcedServices).
91  // 'defaultServices' are overridden by 'parameterSet'.
92  // 'forcedServices' the 'parameterSet'.
93  explicit EventProcessor(std::unique_ptr<ParameterSet> parameterSet,
94  ServiceToken const& token = ServiceToken(),
96  std::vector<std::string> const& defaultServices = std::vector<std::string>(),
97  std::vector<std::string> const& forcedServices = std::vector<std::string>());
98 
99  // Same as previous constructor, but without a 'token'. Token will be defaulted.
100 
101  EventProcessor(std::unique_ptr<ParameterSet> parameterSet,
102  std::vector<std::string> const& defaultServices,
103  std::vector<std::string> const& forcedServices = std::vector<std::string>());
104 
105  EventProcessor(std::shared_ptr<ProcessDesc> processDesc,
106  ServiceToken const& token,
108 
109  ~EventProcessor();
110 
111  EventProcessor(EventProcessor const&) = delete; // Disallow copying and moving
112  EventProcessor& operator=(EventProcessor const&) = delete; // Disallow copying and moving
113 
114  void taskCleanup();
115 
120  void beginJob();
121 
125  void endJob();
126 
127  // -------------
128 
129  // Same as runToCompletion(false) but since it was used extensively
130  // outside of the framework (and is simpler) will keep
131  StatusCode run();
132 
135 
139 
140  std::vector<ModuleDescription const*> getAllModuleDescriptions() const;
141 
143 
147  int totalEvents() const;
148 
151  int totalEventsPassed() const;
152 
155  int totalEventsFailed() const;
156 
158  void clearCounters();
159 
160  // Really should not be public,
161  // but the EventFilter needs it for now.
163 
164  //------------------------------------------------------------------
165  //
166  // Nested classes and structs below.
167 
168  // The function "runToCompletion" will run until the job is "complete",
169  // which means:
170  // 1 - no more input data
171  // 2 - input maxEvents parameter limit reached
172  // 3 - output maxEvents parameter limit reached
173  // 4 - input maxLuminosityBlocks parameter limit reached
174  // 5 - looper directs processing to end
175  //
176  // The return values from the function are as follows:
177  // epSignal - processing terminated early, SIGUSR2 encountered
178  // epCountComplete - "runEventCount" processed the number of events
179  // requested by the argument
180  // epSuccess - all other cases
181  //
183 
184  // The following functions are used by the code implementing
185  // transition handling.
186 
189 
190  void readFile();
191  bool fileBlockValid() { return fb_.get() != nullptr; }
192  void closeInputFile(bool cleaningUpAfterException);
193  void openOutputFiles();
194  void closeOutputFiles();
195 
196  void respondToOpenInputFile();
198 
199  void startingNewLoop();
200  bool endOfLoop();
201  void rewindInput();
202  void prepareForNextLoop();
203  bool shouldWeCloseOutput() const;
204 
205  void doErrorStuff();
206 
207  void beginProcessBlock(bool& beginProcessBlockSucceeded);
208  void inputProcessBlocks();
209  void endProcessBlock(bool cleaningUpAfterException, bool beginProcessBlockSucceeded);
210 
213  void streamBeginRunAsync(unsigned int iStream,
214  std::shared_ptr<RunProcessingStatus>,
215  bool precedingTasksSucceeded,
217  void releaseBeginRunResources(unsigned int iStream);
218  void endRunAsync(std::shared_ptr<RunProcessingStatus>, WaitingTaskHolder);
219  void handleEndRunExceptions(std::exception_ptr, WaitingTaskHolder const&);
220  void globalEndRunAsync(WaitingTaskHolder, std::shared_ptr<RunProcessingStatus>);
221  void streamEndRunAsync(WaitingTaskHolder, unsigned int iStreamIndex);
222  void endUnfinishedRun(bool cleaningUpAfterException);
223  void beginLumiAsync(IOVSyncValue const&, std::shared_ptr<RunProcessingStatus>, WaitingTaskHolder);
225  void handleEndLumiExceptions(std::exception_ptr, WaitingTaskHolder const&);
226  void globalEndLumiAsync(WaitingTaskHolder, std::shared_ptr<LuminosityBlockProcessingStatus>);
227  void streamEndLumiAsync(WaitingTaskHolder, unsigned int iStreamIndex);
228  void endUnfinishedLumi(bool cleaningUpAfterException);
230  std::shared_ptr<RunPrincipal> readRun();
232  std::shared_ptr<LuminosityBlockPrincipal> readLuminosityBlock(std::shared_ptr<RunPrincipal> rp);
240 
241  bool shouldWeStop() const;
242 
243  void setExceptionMessageFiles(std::string& message);
246 
247  bool setDeferredException(std::exception_ptr);
248 
249  private:
250  //------------------------------------------------------------------
251  //
252  // Now private functions.
253  // init() is used by only by constructors
254  void init(std::shared_ptr<ProcessDesc>& processDesc, ServiceToken const& token, serviceregistry::ServiceLegacy);
255 
256  void readAndMergeRunEntriesAsync(std::shared_ptr<RunProcessingStatus>, WaitingTaskHolder);
257  void readAndMergeLumiEntriesAsync(std::shared_ptr<LuminosityBlockProcessingStatus>, WaitingTaskHolder);
258 
259  void handleNextItemAfterMergingRunEntries(std::shared_ptr<RunProcessingStatus>, WaitingTaskHolder);
260 
261  bool readNextEventForStream(WaitingTaskHolder const&, unsigned int iStreamIndex, LuminosityBlockProcessingStatus&);
262 
263  void handleNextEventForStreamAsync(WaitingTaskHolder, unsigned int iStreamIndex);
264 
265  //read the next event using Stream iStreamIndex
266  void readEvent(unsigned int iStreamIndex);
267 
268  //process the already read event using Stream iStreamIndex
269  void processEventAsync(WaitingTaskHolder iHolder, unsigned int iStreamIndex);
270 
271  void processEventAsyncImpl(WaitingTaskHolder iHolder, unsigned int iStreamIndex);
272 
273  //returns true if an asynchronous stop was requested
275 
276  void processEventWithLooper(EventPrincipal&, unsigned int iStreamIndex);
277 
278  std::shared_ptr<ProductRegistry const> preg() const { return get_underlying_safe(preg_); }
279  std::shared_ptr<ProductRegistry>& preg() { return get_underlying_safe(preg_); }
280  std::shared_ptr<BranchIDListHelper const> branchIDListHelper() const {
282  }
283  std::shared_ptr<BranchIDListHelper>& branchIDListHelper() { return get_underlying_safe(branchIDListHelper_); }
284  std::shared_ptr<ThinnedAssociationsHelper const> thinnedAssociationsHelper() const {
286  }
287  std::shared_ptr<ThinnedAssociationsHelper>& thinnedAssociationsHelper() {
289  }
290  std::shared_ptr<EDLooperBase const> looper() const { return get_underlying_safe(looper_); }
291  std::shared_ptr<EDLooperBase>& looper() { return get_underlying_safe(looper_); }
292 
295  void warnAboutLegacyModules() const;
296  //------------------------------------------------------------------
297  //
298  // Data members below.
299  // Are all these data members really needed? Some of them are used
300  // only during construction, and never again. If they aren't
301  // really needed, we should remove them.
302 
303  //Guarantee that task group is the last to be destroyed
304  oneapi::tbb::task_group taskGroup_;
305 
306  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
317  std::unique_ptr<ExceptionToActionTable const> act_table_;
318  std::shared_ptr<ProcessConfiguration const> processConfiguration_;
323  std::vector<edm::SerialTaskQueue> streamQueues_;
325  std::unique_ptr<edm::LimitedTaskQueue> runQueue_;
326  std::unique_ptr<edm::LimitedTaskQueue> lumiQueue_;
327  std::vector<std::shared_ptr<RunProcessingStatus>> streamRunStatus_;
328  std::shared_ptr<RunProcessingStatus> exceptionRunStatus_;
329  std::vector<std::shared_ptr<LuminosityBlockProcessingStatus>> streamLumiStatus_;
330  std::atomic<unsigned int> streamRunActive_{0}; //works as guard for streamRunStatus
331  std::atomic<unsigned int> streamLumiActive_{0}; //works as guard for streamLumiStatus
332 
333  std::vector<std::string> branchesToDeleteEarly_;
334  std::multimap<std::string, std::string> referencesToBranches_;
335  std::vector<std::string> modulesToIgnoreForDeleteEarly_;
336 
337  std::vector<SubProcess> subProcesses_;
339 
342 
343  //The atomic protects concurrent access of deferredExceptionPtr_
344  std::atomic<bool> deferredExceptionPtrIsSet_;
345  std::exception_ptr deferredExceptionPtr_;
346 
348  std::shared_ptr<std::recursive_mutex> sourceMutex_;
354  std::atomic<bool> exceptionMessageRuns_;
355  std::atomic<bool> exceptionMessageLumis_;
359 
361 
362  bool firstEventInBlock_ = true;
363 
364  typedef std::set<std::pair<std::string, std::string>> ExcludedData;
365  typedef std::map<std::string, ExcludedData> ExcludedDataMap;
367 
368  bool printDependencies_ = false;
371  }; // class EventProcessor
372 
373  //--------------------------------------------------------------------
374 
376 } // namespace edm
377 #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
InputSource::ItemType nextTransitionType()
std::shared_ptr< ProductRegistry const > preg() const
void warnAboutLegacyModules() const
void processEventAsync(WaitingTaskHolder iHolder, unsigned int iStreamIndex)
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)
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_
void writeLumiAsync(WaitingTaskHolder, LuminosityBlockPrincipal &)
std::shared_ptr< EDLooperBase const > looper() const
InputSource::ItemType lastTransitionType() 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
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_
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)
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()
InputSource::ItemType lastSourceTransition_
void readAndMergeRun(RunProcessingStatus &)
void warnAboutModulesRequiringRunSynchronization() const
void beginLumiAsync(IOVSyncValue const &, std::shared_ptr< RunProcessingStatus >, WaitingTaskHolder)
void handleNextItemAfterMergingRunEntries(std::shared_ptr< RunProcessingStatus >, WaitingTaskHolder)
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 >())