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 
22 
24 
29 
32 
34 
35 #include <map>
36 #include <memory>
37 #include <set>
38 #include <string>
39 #include <vector>
40 #include <exception>
41 #include <mutex>
42 
43 namespace edm {
44 
45  class ExceptionToActionTable;
46  class BranchIDListHelper;
47  class ThinnedAssociationsHelper;
48  class EDLooperBase;
49  class HistoryAppender;
50  class ProcessDesc;
51  class SubProcess;
52  class WaitingTaskHolder;
54  class IOVSyncValue;
55 
56  namespace eventsetup {
57  class EventSetupProvider;
58  class EventSetupsController;
59  }
60 
62  public:
63 
64  // Status codes:
65  // 0 successful completion
66  // 1 exception of unknown type caught
67  // 2 everything else
68  // 3 signal received
69  // 4 input complete
70  // 5 call timed out
71  // 6 input count complete
72  enum StatusCode { epSuccess=0, epException=1, epOther=2, epSignal=3,
73  epInputComplete=4, epTimedOut=5, epCountComplete=6 };
74 
75  // The input string 'config' contains the entire contents of a configuration file.
76  // Also allows the attachement of pre-existing services specified by 'token', and
77  // the specification of services by name only (defaultServices and forcedServices).
78  // 'defaultServices' are overridden by 'config'.
79  // 'forcedServices' the 'config'.
80  explicit EventProcessor(std::string const& config,
81  ServiceToken const& token = ServiceToken(),
83  std::vector<std::string> const& defaultServices = std::vector<std::string>(),
84  std::vector<std::string> const& forcedServices = std::vector<std::string>());
85 
86  // Same as previous constructor, but without a 'token'. Token will be defaulted.
87 
88  EventProcessor(std::string const& config,
89  std::vector<std::string> const& defaultServices,
90  std::vector<std::string> const& forcedServices = std::vector<std::string>());
91 
92  EventProcessor(std::shared_ptr<ProcessDesc> processDesc,
93  ServiceToken const& token,
95 
97  EventProcessor(std::string const& config, bool isPython);
98 
99  ~EventProcessor();
100 
101  EventProcessor(EventProcessor const&) = delete; // Disallow copying and moving
102  EventProcessor& operator=(EventProcessor const&) = delete; // Disallow copying and moving
103 
108  void beginJob();
109 
113  void endJob();
114 
115  // -------------
116 
117  // Same as runToCompletion(false) but since it was used extensively
118  // outside of the framework (and is simpler) will keep
119  StatusCode run();
120 
123 
127 
128  std::vector<ModuleDescription const*>
129  getAllModuleDescriptions() const;
130 
131  ProcessConfiguration const& processConfiguration() const { return *processConfiguration_; }
132 
136  int totalEvents() const;
137 
140  int totalEventsPassed() const;
141 
144  int totalEventsFailed() const;
145 
148  void enableEndPaths(bool active);
149 
152  bool endPathsEnabled() const;
153 
156  void getTriggerReport(TriggerReport& rep) 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  //
183  StatusCode runToCompletion();
184 
185  // The following functions are used by the code implementing
186  // transition handling.
187 
188  InputSource::ItemType nextTransitionType();
189  InputSource::ItemType lastTransitionType() const { if(deferredExceptionPtrIsSet_) {return InputSource::IsStop;}
190  return lastSourceTransition_;}
191  std::pair<edm::ProcessHistoryID, edm::RunNumber_t> nextRunID();
192  edm::LuminosityBlockNumber_t nextLuminosityBlockID();
193 
194  void readFile();
195  void closeInputFile(bool cleaningUpAfterException);
196  void openOutputFiles();
197  void closeOutputFiles();
198 
199  void respondToOpenInputFile();
200  void respondToCloseInputFile();
201 
202  void startingNewLoop();
203  bool endOfLoop();
204  void rewindInput();
205  void prepareForNextLoop();
206  bool shouldWeCloseOutput() const;
207 
208  void doErrorStuff();
209 
210  void beginRun(ProcessHistoryID const& phid, RunNumber_t run, bool& globalBeginSucceeded);
211  void endRun(ProcessHistoryID const& phid, RunNumber_t run, bool globalBeginSucceeded, bool cleaningUpAfterException);
212  void endUnfinishedRun(ProcessHistoryID const& phid, RunNumber_t run, bool globalBeginSucceeded, bool cleaningUpAfterException);
213 
214  InputSource::ItemType processLumis(std::shared_ptr<void> const& iRunResource);
215  void endUnfinishedLumi();
216 
217  void beginLumiAsync(edm::IOVSyncValue const& iSyncValue,
218  std::shared_ptr<void> const& iRunResource,
219  edm::WaitingTaskHolder iHolder);
220  void continueLumiAsync(edm::WaitingTaskHolder iHolder);
221 
222  void globalEndLumiAsync(edm::WaitingTaskHolder iTask, std::shared_ptr<LuminosityBlockProcessingStatus> iLumiStatus);
223  void streamEndLumiAsync(edm::WaitingTaskHolder iTask,
224  unsigned int iStreamIndex,
225  std::shared_ptr<LuminosityBlockProcessingStatus> iLumiStatus);
226  std::pair<ProcessHistoryID,RunNumber_t> readRun();
227  std::pair<ProcessHistoryID,RunNumber_t> readAndMergeRun();
228  void readLuminosityBlock(LuminosityBlockProcessingStatus&);
229  int readAndMergeLumi(LuminosityBlockProcessingStatus&);
230  void writeRunAsync(WaitingTaskHolder, ProcessHistoryID const& phid, RunNumber_t run);
231  void deleteRunFromCache(ProcessHistoryID const& phid, RunNumber_t run);
232  void writeLumiAsync(WaitingTaskHolder, std::shared_ptr<LuminosityBlockProcessingStatus> );
233  void deleteLumiFromCache(LuminosityBlockProcessingStatus&);
234 
235  bool shouldWeStop() const;
236 
237  void setExceptionMessageFiles(std::string& message);
238  void setExceptionMessageRuns(std::string& message);
239  void setExceptionMessageLumis(std::string& message);
240 
241  bool setDeferredException(std::exception_ptr);
242 
243  private:
244  //------------------------------------------------------------------
245  //
246  // Now private functions.
247  // init() is used by only by constructors
248  void init(std::shared_ptr<ProcessDesc>& processDesc,
249  ServiceToken const& token,
251 
252  bool readNextEventForStream(unsigned int iStreamIndex,
253  LuminosityBlockProcessingStatus& iLumiStatus);
254 
255  void handleNextEventForStreamAsync(WaitingTaskHolder iTask,
256  unsigned int iStreamIndex);
257 
258 
259  //read the next event using Stream iStreamIndex
260  void readEvent(unsigned int iStreamIndex);
261 
262  //process the already read event using Stream iStreamIndex
263  void processEventAsync(WaitingTaskHolder iHolder,
264  unsigned int iStreamIndex);
265 
266  void processEventAsyncImpl(WaitingTaskHolder iHolder,
267  unsigned int iStreamIndex);
268 
269  //returns true if an asynchronous stop was requested
270  bool checkForAsyncStopRequest(StatusCode&);
271 
272  void processEventWithLooper(EventPrincipal&);
273 
274  std::shared_ptr<ProductRegistry const> preg() const {return get_underlying_safe(preg_);}
275  std::shared_ptr<ProductRegistry>& preg() {return get_underlying_safe(preg_);}
276  std::shared_ptr<BranchIDListHelper const> branchIDListHelper() const {return get_underlying_safe(branchIDListHelper_);}
277  std::shared_ptr<BranchIDListHelper>& branchIDListHelper() {return get_underlying_safe(branchIDListHelper_);}
278  std::shared_ptr<ThinnedAssociationsHelper const> thinnedAssociationsHelper() const {return get_underlying_safe(thinnedAssociationsHelper_);}
279  std::shared_ptr<ThinnedAssociationsHelper>& thinnedAssociationsHelper() {return get_underlying_safe(thinnedAssociationsHelper_);}
280  std::shared_ptr<EDLooperBase const> looper() const {return get_underlying_safe(looper_);}
281  std::shared_ptr<EDLooperBase>& looper() {return get_underlying_safe(looper_);}
282  //------------------------------------------------------------------
283  //
284  // Data members below.
285  // Are all these data members really needed? Some of them are used
286  // only during construction, and never again. If they aren't
287  // really needed, we should remove them.
288 
289  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
299  std::unique_ptr<ExceptionToActionTable const> act_table_;
300  std::shared_ptr<ProcessConfiguration const> processConfiguration_;
304  std::vector<edm::SerialTaskQueue> streamQueues_;
305  std::unique_ptr<edm::LimitedTaskQueue> lumiQueue_;
306  std::vector<std::shared_ptr<LuminosityBlockProcessingStatus>> streamLumiStatus_;
307  std::atomic<unsigned int> streamLumiActive_{0}; //works as guard for streamLumiStatus
308 
309  std::vector<SubProcess> subProcesses_;
311 
314 
315  //The atomic protects concurrent access of deferredExceptionPtr_
316  std::atomic<bool> deferredExceptionPtrIsSet_;
317  std::exception_ptr deferredExceptionPtr_;
318 
320  std::shared_ptr<std::recursive_mutex> sourceMutex_;
331 
333 
336  bool firstEventInBlock_=true;
337 
338  typedef std::set<std::pair<std::string, std::string> > ExcludedData;
339  typedef std::map<std::string, ExcludedData> ExcludedDataMap;
341 
342  bool printDependencies_ = false;
343  }; // class EventProcessor
344 
345  //--------------------------------------------------------------------
346 
347  inline
350  return runToCompletion();
351  }
352 }
353 #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
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:1188
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)