CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
30 #include "boost/shared_ptr.hpp"
31 #include "boost/thread/condition.hpp"
32 
33 #include <map>
34 #include <memory>
35 #include <set>
36 #include <string>
37 #include <vector>
38 #include <mutex>
39 #include <exception>
40 
41 namespace statemachine {
42  class Machine;
43  class Run;
44 }
45 
46 namespace edm {
47 
48  class ExceptionToActionTable;
49  class BranchIDListHelper;
50  class ThinnedAssociationsHelper;
51  class EDLooperBase;
52  class HistoryAppender;
53  class ProcessDesc;
54  class SubProcess;
55  namespace eventsetup {
56  class EventSetupProvider;
57  class EventSetupsController;
58  }
59 
61  public:
62 
63  // The input string 'config' contains the entire contents of a configuration file.
64  // Also allows the attachement of pre-existing services specified by 'token', and
65  // the specification of services by name only (defaultServices and forcedServices).
66  // 'defaultServices' are overridden by 'config'.
67  // 'forcedServices' override the 'config'.
68  explicit EventProcessor(std::string const& config,
69  ServiceToken const& token = ServiceToken(),
71  std::vector<std::string> const& defaultServices = std::vector<std::string>(),
72  std::vector<std::string> const& forcedServices = std::vector<std::string>());
73 
74  // Same as previous constructor, but without a 'token'. Token will be defaulted.
75 
76  EventProcessor(std::string const& config,
77  std::vector<std::string> const& defaultServices,
78  std::vector<std::string> const& forcedServices = std::vector<std::string>());
79 
80  EventProcessor(std::shared_ptr<ProcessDesc>& processDesc,
81  ServiceToken const& token,
83 
85  EventProcessor(std::string const& config, bool isPython);
86 
88 
89  EventProcessor(EventProcessor const&) = delete; // Disallow copying and moving
90  EventProcessor& operator=(EventProcessor const&) = delete; // Disallow copying and moving
91 
96  void beginJob();
97 
101  void endJob();
102 
103  // -------------
104 
105  // Same as runToCompletion(false) but since it was used extensively
106  // outside of the framework (and is simpler) will keep
107  StatusCode run();
108 
111 
115 
116  std::vector<ModuleDescription const*>
117  getAllModuleDescriptions() const;
118 
122  int totalEvents() const;
123 
126  int totalEventsPassed() const;
127 
130  int totalEventsFailed() const;
131 
134  void enableEndPaths(bool active);
135 
138  bool endPathsEnabled() const;
139 
142  void getTriggerReport(TriggerReport& rep) const;
143 
145  void clearCounters();
146 
147  // Really should not be public,
148  // but the EventFilter needs it for now.
150 
151  //------------------------------------------------------------------
152  //
153  // Nested classes and structs below.
154 
155  // The function "runToCompletion" will run until the job is "complete",
156  // which means:
157  // 1 - no more input data
158  // 2 - input maxEvents parameter limit reached
159  // 3 - output maxEvents parameter limit reached
160  // 4 - input maxLuminosityBlocks parameter limit reached
161  // 5 - looper directs processing to end
162  //
163  // The return values from the function are as follows:
164  // epSignal - processing terminated early, SIGUSR2 encountered
165  // epCountComplete - "runEventCount" processed the number of events
166  // requested by the argument
167  // epSuccess - all other cases
168  //
169  virtual StatusCode runToCompletion();
170 
171  // The following functions are used by the code implementing our
172  // boost statemachine
173 
174  virtual void readFile();
175  virtual void closeInputFile(bool cleaningUpAfterException);
176  virtual void openOutputFiles();
177  virtual void closeOutputFiles();
178 
179  virtual void respondToOpenInputFile();
180  virtual void respondToCloseInputFile();
181 
182  virtual void startingNewLoop();
183  virtual bool endOfLoop();
184  virtual void rewindInput();
185  virtual void prepareForNextLoop();
186  virtual bool shouldWeCloseOutput() const;
187 
188  virtual void doErrorStuff();
189 
190  virtual void beginRun(statemachine::Run const& run);
191  virtual void endRun(statemachine::Run const& run, bool cleaningUpAfterException);
192 
193  virtual void beginLumi(ProcessHistoryID const& phid, RunNumber_t run, LuminosityBlockNumber_t lumi);
194  virtual void endLumi(ProcessHistoryID const& phid, RunNumber_t run, LuminosityBlockNumber_t lumi, bool cleaningUpAfterException);
195 
196  virtual statemachine::Run readRun();
198  virtual int readLuminosityBlock();
199  virtual int readAndMergeLumi();
200  virtual void writeRun(statemachine::Run const& run);
201  virtual void deleteRunFromCache(statemachine::Run const& run);
202  virtual void writeLumi(ProcessHistoryID const& phid, RunNumber_t run, LuminosityBlockNumber_t lumi);
203  virtual void deleteLumiFromCache(ProcessHistoryID const& phid, RunNumber_t run, LuminosityBlockNumber_t lumi);
204 
205  virtual void readAndProcessEvent();
206  virtual bool shouldWeStop() const;
207 
209  virtual void setExceptionMessageRuns(std::string& message);
210  virtual void setExceptionMessageLumis(std::string& message);
211 
212  virtual bool alreadyHandlingException() const;
213 
214  //returns 'true' if this was a child and we should continue processing
215  bool forkProcess(std::string const& jobReportFile);
216 
217  private:
218  //------------------------------------------------------------------
219  //
220  // Now private functions.
221  // init() is used by only by constructors
222  void init(std::shared_ptr<ProcessDesc>& processDesc,
223  ServiceToken const& token,
225 
226  void terminateMachine(std::auto_ptr<statemachine::Machine>&);
227  std::auto_ptr<statemachine::Machine> createStateMachine();
228 
229  void setupSignal();
230 
231  bool hasSubProcess() const {
232  return subProcess_.get() != 0;
233  }
234 
236 
237  friend class StreamProcessingTask;
238  void processEventsForStreamAsync(unsigned int iStreamIndex,
239  std::atomic<bool>* finishedProcessingEvents);
240 
241 
242  //read the next event using Stream iStreamIndex
243  void readEvent(unsigned int iStreamIndex);
244 
245  //process the already read event using Stream iStreamIndex
246  void processEvent(unsigned int iStreamIndex);
247 
248  //returns true if an asynchronous stop was requested
250  //------------------------------------------------------------------
251  //
252  // Data members below.
253  // Are all these data members really needed? Some of them are used
254  // only during construction, and never again. If they aren't
255  // really needed, we should remove them.
256 
257  std::shared_ptr<ActivityRegistry> actReg_;
258  std::shared_ptr<ProductRegistry const> preg_;
259  std::shared_ptr<BranchIDListHelper> branchIDListHelper_;
260  std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper_;
262  std::unique_ptr<InputSource> input_;
263  std::unique_ptr<eventsetup::EventSetupsController> espController_;
264  boost::shared_ptr<eventsetup::EventSetupProvider> esp_;
265  std::unique_ptr<ExceptionToActionTable const> act_table_;
266  std::shared_ptr<ProcessConfiguration const> processConfiguration_;
269  std::auto_ptr<Schedule> schedule_;
270  std::auto_ptr<SubProcess> subProcess_;
271  std::unique_ptr<HistoryAppender> historyAppender_;
272 
273  std::unique_ptr<FileBlock> fb_;
274  boost::shared_ptr<EDLooperBase> looper_;
275 
276  //The atomic protects concurrent access of deferredExceptionPtr_
277  std::atomic<bool> deferredExceptionPtrIsSet_;
278  std::exception_ptr deferredExceptionPtr_;
279 
294 
299 
301 
305 
306  typedef std::set<std::pair<std::string, std::string> > ExcludedData;
307  typedef std::map<std::string, ExcludedData> ExcludedDataMap;
309  }; // class EventProcessor
310 
311  //--------------------------------------------------------------------
312 
313  inline
316  return runToCompletion();
317  }
318 }
319 #endif
std::string emptyRunLumiMode_
unsigned int numberOfSequentialEventsPerChild_
void readEvent(unsigned int iStreamIndex)
string rep
Definition: cuy.py:1188
ProcessContext processContext_
void init(std::shared_ptr< ProcessDesc > &processDesc, ServiceToken const &token, serviceregistry::ServiceLegacy)
virtual void closeOutputFiles()
std::unique_ptr< ExceptionToActionTable const > act_table_
static boost::mutex mutex
Definition: LHEProxy.cc:11
virtual void beginLumi(ProcessHistoryID const &phid, RunNumber_t run, LuminosityBlockNumber_t lumi)
boost::shared_ptr< EDLooperBase > looper_
virtual void setExceptionMessageFiles(std::string &message)
void possiblyContinueAfterForkChildFailure()
tuple lumi
Definition: fjr2json.py:35
virtual statemachine::Run readRun()
virtual void writeLumi(ProcessHistoryID const &phid, RunNumber_t run, LuminosityBlockNumber_t lumi)
void clearCounters()
Clears counters used by trigger report.
bool checkForAsyncStopRequest(StatusCode &)
virtual void deleteRunFromCache(statemachine::Run const &run)
virtual void rewindInput()
std::set< std::pair< std::string, std::string > > ExcludedData
std::auto_ptr< statemachine::Machine > createStateMachine()
std::string exceptionMessageRuns_
std::shared_ptr< BranchIDListHelper > branchIDListHelper_
PreallocationConfiguration preallocations_
unsigned int LuminosityBlockNumber_t
EventProcessor(std::string const &config, 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 >())
bool forkProcess(std::string const &jobReportFile)
virtual void beginRun(statemachine::Run const &run)
boost::shared_ptr< eventsetup::EventSetupProvider > esp_
virtual void readFile()
void terminateMachine(std::auto_ptr< statemachine::Machine > &)
ServiceToken serviceToken_
bool endPathsEnabled() const
std::atomic< bool > deferredExceptionPtrIsSet_
virtual bool alreadyHandlingException() const
std::string exceptionMessageLumis_
virtual void setExceptionMessageLumis(std::string &message)
virtual void setExceptionMessageRuns(std::string &message)
std::unique_ptr< HistoryAppender > historyAppender_
std::unique_ptr< FileBlock > fb_
ExcludedDataMap eventSetupDataToExcludeFromPrefetching_
InputSource::ItemType nextItemTypeFromProcessingEvents_
virtual void readAndProcessEvent()
void processEvent(unsigned int iStreamIndex)
virtual StatusCode runToCompletion()
EventProcessor & operator=(EventProcessor const &)=delete
std::shared_ptr< ProcessConfiguration const > processConfiguration_
int totalEvents() const
std::auto_ptr< Schedule > schedule_
std::string exceptionMessageFiles_
virtual statemachine::Run readAndMergeRun()
virtual int readLuminosityBlock()
virtual void respondToCloseInputFile()
std::shared_ptr< ProductRegistry const > preg_
virtual void writeRun(statemachine::Run const &run)
StatusCode asyncStopStatusCodeFromProcessingEvents_
virtual void respondToOpenInputFile()
virtual bool shouldWeCloseOutput() const
virtual void doErrorStuff()
virtual void endLumi(ProcessHistoryID const &phid, RunNumber_t run, LuminosityBlockNumber_t lumi, bool cleaningUpAfterException)
std::unique_ptr< InputSource > input_
std::map< std::string, ExcludedData > ExcludedDataMap
ServiceToken getToken()
virtual void openOutputFiles()
virtual void deleteLumiFromCache(ProcessHistoryID const &phid, RunNumber_t run, LuminosityBlockNumber_t lumi)
virtual void closeInputFile(bool cleaningUpAfterException)
std::exception_ptr deferredExceptionPtr_
int totalEventsFailed() const
virtual bool endOfLoop()
PathsAndConsumesOfModules pathsAndConsumesOfModules_
virtual void prepareForNextLoop()
virtual void endRun(statemachine::Run const &run, bool cleaningUpAfterException)
std::auto_ptr< SubProcess > subProcess_
virtual void startingNewLoop()
unsigned int RunNumber_t
bool asyncStopRequestedWhileProcessingEvents_
std::shared_ptr< ActivityRegistry > actReg_
std::mutex nextTransitionMutex_
void processEventsForStreamAsync(unsigned int iStreamIndex, std::atomic< bool > *finishedProcessingEvents)
std::vector< ModuleDescription const * > getAllModuleDescriptions() const
std::unique_ptr< eventsetup::EventSetupsController > espController_
int totalEventsPassed() const
virtual int readAndMergeLumi()
PrincipalCache principalCache_
bool hasSubProcess() const
virtual bool shouldWeStop() const
void enableEndPaths(bool active)
void getTriggerReport(TriggerReport &rep) const
std::shared_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper_