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 
191  void readFile();
192  bool fileBlockValid() { return fb_.get() != nullptr; }
193  void closeInputFile(bool cleaningUpAfterException);
194  void openOutputFiles();
195  void closeOutputFiles();
196 
197  void respondToOpenInputFile();
199 
200  void startingNewLoop();
201  bool endOfLoop();
202  void rewindInput();
203  void prepareForNextLoop();
204  bool shouldWeCloseOutput() const;
205 
206  void doErrorStuff();
207 
208  void beginProcessBlock(bool& beginProcessBlockSucceeded);
209  void inputProcessBlocks();
210  void endProcessBlock(bool cleaningUpAfterException, bool beginProcessBlockSucceeded);
211 
214  void streamBeginRunAsync(unsigned int iStream,
215  std::shared_ptr<RunProcessingStatus>,
216  bool precedingTasksSucceeded,
218  void releaseBeginRunResources(unsigned int iStream);
219  void endRunAsync(std::shared_ptr<RunProcessingStatus>, WaitingTaskHolder);
220  void handleEndRunExceptions(std::exception_ptr, WaitingTaskHolder const&);
221  void globalEndRunAsync(WaitingTaskHolder, std::shared_ptr<RunProcessingStatus>);
222  void streamEndRunAsync(WaitingTaskHolder, unsigned int iStreamIndex);
223  void endUnfinishedRun(bool cleaningUpAfterException);
224  void beginLumiAsync(IOVSyncValue const&, std::shared_ptr<RunProcessingStatus>, WaitingTaskHolder);
226  void handleEndLumiExceptions(std::exception_ptr, WaitingTaskHolder const&);
227  void globalEndLumiAsync(WaitingTaskHolder, std::shared_ptr<LuminosityBlockProcessingStatus>);
228  void streamEndLumiAsync(WaitingTaskHolder, unsigned int iStreamIndex);
229  void endUnfinishedLumi(bool cleaningUpAfterException);
231  std::shared_ptr<RunPrincipal> readRun();
233  std::shared_ptr<LuminosityBlockPrincipal> readLuminosityBlock(std::shared_ptr<RunPrincipal> rp);
241 
242  bool shouldWeStop() const;
243 
244  void setExceptionMessageFiles(std::string& message);
247 
248  bool setDeferredException(std::exception_ptr);
249 
250  private:
251  //------------------------------------------------------------------
252  //
253  // Now private functions.
254  // init() is used by only by constructors
255  void init(std::shared_ptr<ProcessDesc>& processDesc, ServiceToken const& token, serviceregistry::ServiceLegacy);
256 
257  void readAndMergeRunEntriesAsync(std::shared_ptr<RunProcessingStatus>, WaitingTaskHolder);
258  void readAndMergeLumiEntriesAsync(std::shared_ptr<LuminosityBlockProcessingStatus>, WaitingTaskHolder);
259 
260  void handleNextItemAfterMergingRunEntries(std::shared_ptr<RunProcessingStatus>, WaitingTaskHolder);
261 
262  bool readNextEventForStream(WaitingTaskHolder const&, unsigned int iStreamIndex, LuminosityBlockProcessingStatus&);
263 
264  void handleNextEventForStreamAsync(WaitingTaskHolder, unsigned int iStreamIndex);
265 
266  //read the next event using Stream iStreamIndex
267  void readEvent(unsigned int iStreamIndex);
268 
269  //process the already read event using Stream iStreamIndex
270  void processEventAsync(WaitingTaskHolder iHolder, unsigned int iStreamIndex);
271 
272  void processEventAsyncImpl(WaitingTaskHolder iHolder, unsigned int iStreamIndex);
273 
274  //returns true if an asynchronous stop was requested
276 
277  void processEventWithLooper(EventPrincipal&, unsigned int iStreamIndex);
278 
279  std::shared_ptr<ProductRegistry const> preg() const { return get_underlying_safe(preg_); }
280  std::shared_ptr<ProductRegistry>& preg() { return get_underlying_safe(preg_); }
281  std::shared_ptr<BranchIDListHelper const> branchIDListHelper() const {
283  }
284  std::shared_ptr<BranchIDListHelper>& branchIDListHelper() { return get_underlying_safe(branchIDListHelper_); }
285  std::shared_ptr<ThinnedAssociationsHelper const> thinnedAssociationsHelper() const {
287  }
288  std::shared_ptr<ThinnedAssociationsHelper>& thinnedAssociationsHelper() {
290  }
291  std::shared_ptr<EDLooperBase const> looper() const { return get_underlying_safe(looper_); }
292  std::shared_ptr<EDLooperBase>& looper() { return get_underlying_safe(looper_); }
293 
296  void warnAboutLegacyModules() const;
297  //------------------------------------------------------------------
298  //
299  // Data members below.
300  // Are all these data members really needed? Some of them are used
301  // only during construction, and never again. If they aren't
302  // really needed, we should remove them.
303 
304  //Guarantee that task group is the last to be destroyed
305  oneapi::tbb::task_group taskGroup_;
306 
307  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
319  std::unique_ptr<ExceptionToActionTable const> act_table_;
320  std::shared_ptr<ProcessConfiguration const> processConfiguration_;
325  std::vector<edm::SerialTaskQueue> streamQueues_;
327  std::unique_ptr<edm::LimitedTaskQueue> runQueue_;
328  std::unique_ptr<edm::LimitedTaskQueue> lumiQueue_;
329  std::vector<std::shared_ptr<RunProcessingStatus>> streamRunStatus_;
330  std::shared_ptr<RunProcessingStatus> exceptionRunStatus_;
331  std::vector<std::shared_ptr<LuminosityBlockProcessingStatus>> streamLumiStatus_;
332  std::atomic<unsigned int> streamRunActive_{0}; //works as guard for streamRunStatus
333  std::atomic<unsigned int> streamLumiActive_{0}; //works as guard for streamLumiStatus
334 
335  std::vector<std::string> branchesToDeleteEarly_;
336  std::multimap<std::string, std::string> referencesToBranches_;
337  std::vector<std::string> modulesToIgnoreForDeleteEarly_;
338 
339  std::vector<SubProcess> subProcesses_;
341 
344 
345  //The atomic protects concurrent access of deferredExceptionPtr_
346  std::atomic<bool> deferredExceptionPtrIsSet_;
347  std::exception_ptr deferredExceptionPtr_;
348 
350  std::shared_ptr<std::recursive_mutex> sourceMutex_;
356  std::atomic<bool> exceptionMessageRuns_;
357  std::atomic<bool> exceptionMessageLumis_;
361 
363 
364  bool firstEventInBlock_ = true;
365 
366  typedef std::set<std::pair<std::string, std::string>> ExcludedData;
367  typedef std::map<std::string, ExcludedData> ExcludedDataMap;
369 
370  bool printDependencies_ = false;
373  }; // class EventProcessor
374 
375  //--------------------------------------------------------------------
376 
378 } // namespace edm
379 #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
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_
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 >())