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 
23 
25 
30 
33 
35 
36 #include <map>
37 #include <memory>
38 #include <set>
39 #include <string>
40 #include <vector>
41 #include <exception>
42 #include <mutex>
43 
44 namespace edm {
45 
46  class ExceptionToActionTable;
47  class BranchIDListHelper;
48  class MergeableRunProductMetadata;
49  class ThinnedAssociationsHelper;
50  class EDLooperBase;
51  class HistoryAppender;
52  class ProcessDesc;
53  class SubProcess;
54  class WaitingTaskHolder;
56  class IOVSyncValue;
57 
58  namespace eventsetup {
59  class EventSetupProvider;
60  class EventSetupsController;
61  }
62 
64  public:
65 
66  // Status codes:
67  // 0 successful completion
68  // 1 exception of unknown type caught
69  // 2 everything else
70  // 3 signal received
71  // 4 input complete
72  // 5 call timed out
73  // 6 input count complete
74  enum StatusCode { epSuccess=0, epException=1, epOther=2, epSignal=3,
75  epInputComplete=4, epTimedOut=5, epCountComplete=6 };
76 
77  // The input string 'config' contains the entire contents of a configuration file.
78  // Also allows the attachement of pre-existing services specified by 'token', and
79  // the specification of services by name only (defaultServices and forcedServices).
80  // 'defaultServices' are overridden by 'config'.
81  // 'forcedServices' the 'config'.
82  explicit EventProcessor(std::string const& config,
83  ServiceToken const& token = ServiceToken(),
85  std::vector<std::string> const& defaultServices = std::vector<std::string>(),
86  std::vector<std::string> const& forcedServices = std::vector<std::string>());
87 
88  // Same as previous constructor, but without a 'token'. Token will be defaulted.
89 
90  EventProcessor(std::string const& config,
91  std::vector<std::string> const& defaultServices,
92  std::vector<std::string> const& forcedServices = std::vector<std::string>());
93 
94  EventProcessor(std::shared_ptr<ProcessDesc> processDesc,
95  ServiceToken const& token,
97 
99  EventProcessor(std::string const& config, bool isPython);
100 
101  ~EventProcessor();
102 
103  EventProcessor(EventProcessor const&) = delete; // Disallow copying and moving
104  EventProcessor& operator=(EventProcessor const&) = delete; // Disallow copying and moving
105 
110  void beginJob();
111 
115  void endJob();
116 
117  // -------------
118 
119  // Same as runToCompletion(false) but since it was used extensively
120  // outside of the framework (and is simpler) will keep
121  StatusCode run();
122 
125 
129 
130  std::vector<ModuleDescription const*>
131  getAllModuleDescriptions() const;
132 
133  ProcessConfiguration const& processConfiguration() const { return *processConfiguration_; }
134 
138  int totalEvents() const;
139 
142  int totalEventsPassed() const;
143 
146  int totalEventsFailed() const;
147 
150  void enableEndPaths(bool active);
151 
154  bool endPathsEnabled() const;
155 
158  void getTriggerReport(TriggerReport& rep) const;
159 
161  void clearCounters();
162 
163  // Really should not be public,
164  // but the EventFilter needs it for now.
166 
167  //------------------------------------------------------------------
168  //
169  // Nested classes and structs below.
170 
171  // The function "runToCompletion" will run until the job is "complete",
172  // which means:
173  // 1 - no more input data
174  // 2 - input maxEvents parameter limit reached
175  // 3 - output maxEvents parameter limit reached
176  // 4 - input maxLuminosityBlocks parameter limit reached
177  // 5 - looper directs processing to end
178  //
179  // The return values from the function are as follows:
180  // epSignal - processing terminated early, SIGUSR2 encountered
181  // epCountComplete - "runEventCount" processed the number of events
182  // requested by the argument
183  // epSuccess - all other cases
184  //
185  StatusCode runToCompletion();
186 
187  // The following functions are used by the code implementing
188  // transition handling.
189 
190  InputSource::ItemType nextTransitionType();
191  InputSource::ItemType lastTransitionType() const { if(deferredExceptionPtrIsSet_) {return InputSource::IsStop;}
192  return lastSourceTransition_;}
193  std::pair<edm::ProcessHistoryID, edm::RunNumber_t> nextRunID();
194  edm::LuminosityBlockNumber_t nextLuminosityBlockID();
195 
196  void readFile();
197  void closeInputFile(bool cleaningUpAfterException);
198  void openOutputFiles();
199  void closeOutputFiles();
200 
201  void respondToOpenInputFile();
202  void respondToCloseInputFile();
203 
204  void startingNewLoop();
205  bool endOfLoop();
206  void rewindInput();
207  void prepareForNextLoop();
208  bool shouldWeCloseOutput() const;
209 
210  void doErrorStuff();
211 
212  void beginRun(ProcessHistoryID const& phid, RunNumber_t run, bool& globalBeginSucceeded,
213  bool& eventSetupForInstanceSucceeded);
214  void endRun(ProcessHistoryID const& phid, RunNumber_t run, bool globalBeginSucceeded, bool cleaningUpAfterException);
215  void endUnfinishedRun(ProcessHistoryID const& phid, RunNumber_t run,
216  bool globalBeginSucceeded, bool cleaningUpAfterException,
217  bool eventSetupForInstanceSucceeded);
218 
219  InputSource::ItemType processLumis(std::shared_ptr<void> const& iRunResource);
220  void endUnfinishedLumi();
221 
222  void beginLumiAsync(edm::IOVSyncValue const& iSyncValue,
223  std::shared_ptr<void> const& iRunResource,
224  edm::WaitingTaskHolder iHolder);
225  void continueLumiAsync(edm::WaitingTaskHolder iHolder);
226 
227  void globalEndLumiAsync(edm::WaitingTaskHolder iTask, std::shared_ptr<LuminosityBlockProcessingStatus> iLumiStatus);
228  void streamEndLumiAsync(edm::WaitingTaskHolder iTask,
229  unsigned int iStreamIndex,
230  std::shared_ptr<LuminosityBlockProcessingStatus> iLumiStatus);
231  std::pair<ProcessHistoryID,RunNumber_t> readRun();
232  std::pair<ProcessHistoryID,RunNumber_t> readAndMergeRun();
233  void readLuminosityBlock(LuminosityBlockProcessingStatus&);
234  int readAndMergeLumi(LuminosityBlockProcessingStatus&);
235  void writeRunAsync(WaitingTaskHolder, ProcessHistoryID const& phid, RunNumber_t run, MergeableRunProductMetadata const*);
236  void deleteRunFromCache(ProcessHistoryID const& phid, RunNumber_t run);
237  void writeLumiAsync(WaitingTaskHolder, std::shared_ptr<LuminosityBlockProcessingStatus> );
238  void deleteLumiFromCache(LuminosityBlockProcessingStatus&);
239 
240  bool shouldWeStop() const;
241 
242  void setExceptionMessageFiles(std::string& message);
243  void setExceptionMessageRuns(std::string& message);
244  void setExceptionMessageLumis(std::string& message);
245 
246  bool setDeferredException(std::exception_ptr);
247 
248  private:
249  //------------------------------------------------------------------
250  //
251  // Now private functions.
252  // init() is used by only by constructors
253  void init(std::shared_ptr<ProcessDesc>& processDesc,
254  ServiceToken const& token,
256 
257  bool readNextEventForStream(unsigned int iStreamIndex,
258  LuminosityBlockProcessingStatus& iLumiStatus);
259 
260  void handleNextEventForStreamAsync(WaitingTaskHolder iTask,
261  unsigned int iStreamIndex);
262 
263 
264  //read the next event using Stream iStreamIndex
265  void readEvent(unsigned int iStreamIndex);
266 
267  //process the already read event using Stream iStreamIndex
268  void processEventAsync(WaitingTaskHolder iHolder,
269  unsigned int iStreamIndex);
270 
271  void processEventAsyncImpl(WaitingTaskHolder iHolder,
272  unsigned int iStreamIndex);
273 
274  //returns true if an asynchronous stop was requested
275  bool checkForAsyncStopRequest(StatusCode&);
276 
277  void processEventWithLooper(EventPrincipal&);
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 {return get_underlying_safe(branchIDListHelper_);}
282  std::shared_ptr<BranchIDListHelper>& branchIDListHelper() {return get_underlying_safe(branchIDListHelper_);}
283  std::shared_ptr<ThinnedAssociationsHelper const> thinnedAssociationsHelper() const {return get_underlying_safe(thinnedAssociationsHelper_);}
284  std::shared_ptr<ThinnedAssociationsHelper>& thinnedAssociationsHelper() {return get_underlying_safe(thinnedAssociationsHelper_);}
285  std::shared_ptr<EDLooperBase const> looper() const {return get_underlying_safe(looper_);}
286  std::shared_ptr<EDLooperBase>& looper() {return get_underlying_safe(looper_);}
287  //------------------------------------------------------------------
288  //
289  // Data members below.
290  // Are all these data members really needed? Some of them are used
291  // only during construction, and never again. If they aren't
292  // really needed, we should remove them.
293 
294  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
304  std::unique_ptr<ExceptionToActionTable const> act_table_;
305  std::shared_ptr<ProcessConfiguration const> processConfiguration_;
310  std::vector<edm::SerialTaskQueue> streamQueues_;
311  std::unique_ptr<edm::LimitedTaskQueue> lumiQueue_;
312  std::vector<std::shared_ptr<LuminosityBlockProcessingStatus>> streamLumiStatus_;
313  std::atomic<unsigned int> streamLumiActive_{0}; //works as guard for streamLumiStatus
314 
315  std::vector<SubProcess> subProcesses_;
317 
320 
321  //The atomic protects concurrent access of deferredExceptionPtr_
322  std::atomic<bool> deferredExceptionPtrIsSet_;
323  std::exception_ptr deferredExceptionPtr_;
324 
326  std::shared_ptr<std::recursive_mutex> sourceMutex_;
337 
339 
342  bool firstEventInBlock_=true;
343 
344  typedef std::set<std::pair<std::string, std::string> > ExcludedData;
345  typedef std::map<std::string, ExcludedData> ExcludedDataMap;
347 
348  bool printDependencies_ = false;
349  }; // class EventProcessor
350 
351  //--------------------------------------------------------------------
352 
353  inline
356  return runToCompletion();
357  }
358 }
359 #endif
ProcessContext processContext_
SharedResourcesAcquirer sourceResourcesAcquirer_
edm::propagate_const< std::unique_ptr< InputSource > > input_
std::unique_ptr< ExceptionToActionTable const > act_table_
ProcessConfiguration const & processConfiguration() const
edm::propagate_const< std::unique_ptr< HistoryAppender > > historyAppender_
std::unique_ptr< edm::LimitedTaskQueue > lumiQueue_
int init
Definition: HydjetWrapper.h:67
std::shared_ptr< BranchIDListHelper const > branchIDListHelper() const
edm::propagate_const< std::shared_ptr< ProductRegistry > > preg_
Definition: config.py:1
std::set< std::pair< std::string, std::string > > ExcludedData
std::string exceptionMessageRuns_
PreallocationConfiguration preallocations_
unsigned int LuminosityBlockNumber_t
std::vector< SubProcess > subProcesses_
void beginJob()
Definition: Breakpoints.cc:15
MergeableRunProductProcesses mergeableRunProductProcesses_
ServiceToken serviceToken_
std::atomic< bool > deferredExceptionPtrIsSet_
std::shared_ptr< ThinnedAssociationsHelper const > thinnedAssociationsHelper() const
std::string exceptionMessageLumis_
std::shared_ptr< ProductRegistry const > preg() const
std::vector< edm::SerialTaskQueue > streamQueues_
InputSource::ItemType lastTransitionType() const
ExcludedDataMap eventSetupDataToExcludeFromPrefetching_
edm::propagate_const< std::shared_ptr< EDLooperBase > > looper_
edm::propagate_const< std::unique_ptr< Schedule > > schedule_
std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
std::shared_ptr< ProcessConfiguration const > processConfiguration_
std::shared_ptr< std::recursive_mutex > sourceMutex_
rep
Definition: cuy.py:1190
std::string exceptionMessageFiles_
std::shared_ptr< BranchIDListHelper > & branchIDListHelper()
std::shared_ptr< EDLooperBase > & looper()
InputSource::ItemType lastSourceTransition_
StatusCode asyncStopStatusCodeFromProcessingEvents_
edm::propagate_const< std::unique_ptr< FileBlock > > fb_
std::map< std::string, ExcludedData > ExcludedDataMap
edm::propagate_const< std::unique_ptr< eventsetup::EventSetupsController > > espController_
std::vector< std::shared_ptr< LuminosityBlockProcessingStatus > > streamLumiStatus_
edm::propagate_const< std::shared_ptr< ThinnedAssociationsHelper > > thinnedAssociationsHelper_
std::shared_ptr< ProductRegistry > & preg()
edm::propagate_const< std::shared_ptr< eventsetup::EventSetupProvider > > esp_
HLT enums.
std::exception_ptr deferredExceptionPtr_
edm::SerialTaskQueue iovQueue_
PathsAndConsumesOfModules pathsAndConsumesOfModules_
unsigned int RunNumber_t
bool asyncStopRequestedWhileProcessingEvents_
std::shared_ptr< ActivityRegistry > actReg_
edm::propagate_const< std::shared_ptr< BranchIDListHelper > > branchIDListHelper_
std::shared_ptr< ThinnedAssociationsHelper > & thinnedAssociationsHelper()
std::shared_ptr< EDLooperBase const > looper() const
PrincipalCache principalCache_
def getToken(db, tag, since)