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