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 
31 
32 #include <map>
33 #include <memory>
34 #include <set>
35 #include <string>
36 #include <vector>
37 #include <exception>
38 #include <mutex>
39 
40 namespace edm {
41 
42  class ExceptionToActionTable;
43  class BranchIDListHelper;
44  class ThinnedAssociationsHelper;
45  class EDLooperBase;
46  class HistoryAppender;
47  class ProcessDesc;
48  class SubProcess;
49  class WaitingTaskHolder;
50  class WaitingTask;
51 
52  namespace eventsetup {
53  class EventSetupProvider;
54  class EventSetupsController;
55  }
56 
58  public:
59 
60  // Status codes:
61  // 0 successful completion
62  // 1 exception of unknown type caught
63  // 2 everything else
64  // 3 signal received
65  // 4 input complete
66  // 5 call timed out
67  // 6 input count complete
68  enum StatusCode { epSuccess=0, epException=1, epOther=2, epSignal=3,
69  epInputComplete=4, epTimedOut=5, epCountComplete=6 };
70 
71  // The input string 'config' contains the entire contents of a configuration file.
72  // Also allows the attachement of pre-existing services specified by 'token', and
73  // the specification of services by name only (defaultServices and forcedServices).
74  // 'defaultServices' are overridden by 'config'.
75  // 'forcedServices' the 'config'.
76  explicit EventProcessor(std::string const& config,
77  ServiceToken const& token = ServiceToken(),
79  std::vector<std::string> const& defaultServices = std::vector<std::string>(),
80  std::vector<std::string> const& forcedServices = std::vector<std::string>());
81 
82  // Same as previous constructor, but without a 'token'. Token will be defaulted.
83 
84  EventProcessor(std::string const& config,
85  std::vector<std::string> const& defaultServices,
86  std::vector<std::string> const& forcedServices = std::vector<std::string>());
87 
88  EventProcessor(std::shared_ptr<ProcessDesc> processDesc,
89  ServiceToken const& token,
91 
93  EventProcessor(std::string const& config, bool isPython);
94 
95  ~EventProcessor();
96 
97  EventProcessor(EventProcessor const&) = delete; // Disallow copying and moving
98  EventProcessor& operator=(EventProcessor const&) = delete; // Disallow copying and moving
99 
104  void beginJob();
105 
109  void endJob();
110 
111  // -------------
112 
113  // Same as runToCompletion(false) but since it was used extensively
114  // outside of the framework (and is simpler) will keep
115  StatusCode run();
116 
119 
123 
124  std::vector<ModuleDescription const*>
125  getAllModuleDescriptions() const;
126 
127  ProcessConfiguration const& processConfiguration() const { return *processConfiguration_; }
128 
132  int totalEvents() const;
133 
136  int totalEventsPassed() const;
137 
140  int totalEventsFailed() const;
141 
144  void enableEndPaths(bool active);
145 
148  bool endPathsEnabled() const;
149 
152  void getTriggerReport(TriggerReport& rep) const;
153 
155  void clearCounters();
156 
157  // Really should not be public,
158  // but the EventFilter needs it for now.
160 
161  //------------------------------------------------------------------
162  //
163  // Nested classes and structs below.
164 
165  // The function "runToCompletion" will run until the job is "complete",
166  // which means:
167  // 1 - no more input data
168  // 2 - input maxEvents parameter limit reached
169  // 3 - output maxEvents parameter limit reached
170  // 4 - input maxLuminosityBlocks parameter limit reached
171  // 5 - looper directs processing to end
172  //
173  // The return values from the function are as follows:
174  // epSignal - processing terminated early, SIGUSR2 encountered
175  // epCountComplete - "runEventCount" processed the number of events
176  // requested by the argument
177  // epSuccess - all other cases
178  //
179  StatusCode runToCompletion();
180 
181  // The following functions are used by the code implementing
182  // transition handling.
183 
184  InputSource::ItemType nextTransitionType();
185  std::pair<edm::ProcessHistoryID, edm::RunNumber_t> nextRunID();
186  edm::LuminosityBlockNumber_t nextLuminosityBlockID();
187 
188  void readFile();
189  void closeInputFile(bool cleaningUpAfterException);
190  void openOutputFiles();
191  void closeOutputFiles();
192 
193  void respondToOpenInputFile();
194  void respondToCloseInputFile();
195 
196  void startingNewLoop();
197  bool endOfLoop();
198  void rewindInput();
199  void prepareForNextLoop();
200  bool shouldWeCloseOutput() const;
201 
202  void doErrorStuff();
203 
204  void beginRun(ProcessHistoryID const& phid, RunNumber_t run);
205  void endRun(ProcessHistoryID const& phid, RunNumber_t run, bool cleaningUpAfterException);
206 
207  void beginLumi(ProcessHistoryID const& phid, RunNumber_t run, LuminosityBlockNumber_t lumi);
208  void endLumi(ProcessHistoryID const& phid, RunNumber_t run, LuminosityBlockNumber_t lumi, bool cleaningUpAfterException);
209 
210  std::pair<ProcessHistoryID,RunNumber_t> readRun();
211  std::pair<ProcessHistoryID,RunNumber_t> readAndMergeRun();
212  int readLuminosityBlock();
213  int readAndMergeLumi();
214  void writeRun(ProcessHistoryID const& phid, RunNumber_t run);
215  void deleteRunFromCache(ProcessHistoryID const& phid, RunNumber_t run);
216  void writeLumi(ProcessHistoryID const& phid, RunNumber_t run, LuminosityBlockNumber_t lumi);
217  void deleteLumiFromCache(ProcessHistoryID const& phid, RunNumber_t run, LuminosityBlockNumber_t lumi);
218 
219  bool shouldWeStop() const;
220 
221  void setExceptionMessageFiles(std::string& message);
222  void setExceptionMessageRuns(std::string& message);
223  void setExceptionMessageLumis(std::string& message);
224 
225  bool setDeferredException(std::exception_ptr);
226 
227  InputSource::ItemType readAndProcessEvents();
228 
229  private:
230  //------------------------------------------------------------------
231  //
232  // Now private functions.
233  // init() is used by only by constructors
234  void init(std::shared_ptr<ProcessDesc>& processDesc,
235  ServiceToken const& token,
237 
238  bool readNextEventForStream(unsigned int iStreamIndex,
239  std::atomic<bool>* finishedProcessingEvents);
240 
241  void handleNextEventForStreamAsync(WaitingTask* iTask,
242  unsigned int iStreamIndex,
243  std::atomic<bool>* finishedProcessingEvents);
244 
245 
246  //read the next event using Stream iStreamIndex
247  void readEvent(unsigned int iStreamIndex);
248 
249  //process the already read event using Stream iStreamIndex
250  void processEventAsync(WaitingTaskHolder iHolder,
251  unsigned int iStreamIndex);
252 
253  //returns true if an asynchronous stop was requested
254  bool checkForAsyncStopRequest(StatusCode&);
255 
256  void processEventWithLooper(EventPrincipal&);
257 
258  std::shared_ptr<ProductRegistry const> preg() const {return get_underlying_safe(preg_);}
259  std::shared_ptr<ProductRegistry>& preg() {return get_underlying_safe(preg_);}
260  std::shared_ptr<BranchIDListHelper const> branchIDListHelper() const {return get_underlying_safe(branchIDListHelper_);}
261  std::shared_ptr<BranchIDListHelper>& branchIDListHelper() {return get_underlying_safe(branchIDListHelper_);}
262  std::shared_ptr<ThinnedAssociationsHelper const> thinnedAssociationsHelper() const {return get_underlying_safe(thinnedAssociationsHelper_);}
263  std::shared_ptr<ThinnedAssociationsHelper>& thinnedAssociationsHelper() {return get_underlying_safe(thinnedAssociationsHelper_);}
264  std::shared_ptr<EDLooperBase const> looper() const {return get_underlying_safe(looper_);}
265  std::shared_ptr<EDLooperBase>& looper() {return get_underlying_safe(looper_);}
266  //------------------------------------------------------------------
267  //
268  // Data members below.
269  // Are all these data members really needed? Some of them are used
270  // only during construction, and never again. If they aren't
271  // really needed, we should remove them.
272 
273  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
281  std::unique_ptr<ExceptionToActionTable const> act_table_;
282  std::shared_ptr<ProcessConfiguration const> processConfiguration_;
286  std::vector<SubProcess> subProcesses_;
288 
291 
292  //The atomic protects concurrent access of deferredExceptionPtr_
293  std::atomic<bool> deferredExceptionPtrIsSet_;
294  std::exception_ptr deferredExceptionPtr_;
295 
297  std::shared_ptr<std::recursive_mutex> sourceMutex_;
308 
310 
314  bool firstEventInBlock_=true;
315 
316  typedef std::set<std::pair<std::string, std::string> > ExcludedData;
317  typedef std::map<std::string, ExcludedData> ExcludedDataMap;
319 
320  bool printDependencies_ = false;
321  }; // class EventProcessor
322 
323  //--------------------------------------------------------------------
324 
325  inline
328  return runToCompletion();
329  }
330 }
331 #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_
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
ExcludedDataMap eventSetupDataToExcludeFromPrefetching_
InputSource::ItemType nextItemTypeFromProcessingEvents_
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()
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_
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_
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)