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 
38 namespace statemachine {
39  class Machine;
40  class Run;
41 }
42 
43 namespace edm {
44 
45  class ExceptionToActionTable;
46  class BranchIDListHelper;
47  class EDLooperBase;
48  class HistoryAppender;
49  class ProcessDesc;
50  class SubProcess;
51  namespace eventsetup {
52  class EventSetupProvider;
53  class EventSetupsController;
54  }
55 
57  public:
58 
59  // The input string 'config' contains the entire contents of a configuration file.
60  // Also allows the attachement of pre-existing services specified by 'token', and
61  // the specification of services by name only (defaultServices and forcedServices).
62  // 'defaultServices' are overridden by 'config'.
63  // 'forcedServices' override the 'config'.
64  explicit EventProcessor(std::string const& config,
65  ServiceToken const& token = ServiceToken(),
67  std::vector<std::string> const& defaultServices = std::vector<std::string>(),
68  std::vector<std::string> const& forcedServices = std::vector<std::string>());
69 
70  // Same as previous constructor, but without a 'token'. Token will be defaulted.
71 
72  EventProcessor(std::string const& config,
73  std::vector<std::string> const& defaultServices,
74  std::vector<std::string> const& forcedServices = std::vector<std::string>());
75 
76  EventProcessor(boost::shared_ptr<ProcessDesc>& processDesc,
77  ServiceToken const& token,
79 
81  EventProcessor(std::string const& config, bool isPython);
82 
84 
85  EventProcessor(EventProcessor const&) = delete; // Disallow copying and moving
86  EventProcessor& operator=(EventProcessor const&) = delete; // Disallow copying and moving
87 
92  void beginJob();
93 
97  void endJob();
98 
99  // -------------
100 
101  // Same as runToCompletion(false) but since it was used extensively
102  // outside of the framework (and is simpler) will keep
103  StatusCode run();
104 
107 
111 
112  std::vector<ModuleDescription const*>
113  getAllModuleDescriptions() const;
114 
118  int totalEvents() const;
119 
122  int totalEventsPassed() const;
123 
126  int totalEventsFailed() const;
127 
130  void enableEndPaths(bool active);
131 
134  bool endPathsEnabled() const;
135 
138  void getTriggerReport(TriggerReport& rep) const;
139 
141  void clearCounters();
142 
143  // Really should not be public,
144  // but the EventFilter needs it for now.
146 
147  //------------------------------------------------------------------
148  //
149  // Nested classes and structs below.
150 
151  // The function "runToCompletion" will run until the job is "complete",
152  // which means:
153  // 1 - no more input data
154  // 2 - input maxEvents parameter limit reached
155  // 3 - output maxEvents parameter limit reached
156  // 4 - input maxLuminosityBlocks parameter limit reached
157  // 5 - looper directs processing to end
158  //
159  // The return values from the function are as follows:
160  // epSignal - processing terminated early, SIGUSR2 encountered
161  // epCountComplete - "runEventCount" processed the number of events
162  // requested by the argument
163  // epSuccess - all other cases
164  //
165  virtual StatusCode runToCompletion();
166 
167  // The following functions are used by the code implementing our
168  // boost statemachine
169 
170  virtual void readFile();
171  virtual void closeInputFile(bool cleaningUpAfterException);
172  virtual void openOutputFiles();
173  virtual void closeOutputFiles();
174 
175  virtual void respondToOpenInputFile();
176  virtual void respondToCloseInputFile();
177 
178  virtual void startingNewLoop();
179  virtual bool endOfLoop();
180  virtual void rewindInput();
181  virtual void prepareForNextLoop();
182  virtual bool shouldWeCloseOutput() const;
183 
184  virtual void doErrorStuff();
185 
186  virtual void beginRun(statemachine::Run const& run);
187  virtual void endRun(statemachine::Run const& run, bool cleaningUpAfterException);
188 
189  virtual void beginLumi(ProcessHistoryID const& phid, RunNumber_t run, LuminosityBlockNumber_t lumi);
190  virtual void endLumi(ProcessHistoryID const& phid, RunNumber_t run, LuminosityBlockNumber_t lumi, bool cleaningUpAfterException);
191 
192  virtual statemachine::Run readRun();
194  virtual int readLuminosityBlock();
195  virtual int readAndMergeLumi();
196  virtual void writeRun(statemachine::Run const& run);
197  virtual void deleteRunFromCache(statemachine::Run const& run);
198  virtual void writeLumi(ProcessHistoryID const& phid, RunNumber_t run, LuminosityBlockNumber_t lumi);
199  virtual void deleteLumiFromCache(ProcessHistoryID const& phid, RunNumber_t run, LuminosityBlockNumber_t lumi);
200 
201  virtual void readAndProcessEvent();
202  virtual bool shouldWeStop() const;
203 
205  virtual void setExceptionMessageRuns(std::string& message);
206  virtual void setExceptionMessageLumis(std::string& message);
207 
208  virtual bool alreadyHandlingException() const;
209 
210  //returns 'true' if this was a child and we should continue processing
211  bool forkProcess(std::string const& jobReportFile);
212 
213  private:
214  //------------------------------------------------------------------
215  //
216  // Now private functions.
217  // init() is used by only by constructors
218  void init(boost::shared_ptr<ProcessDesc>& processDesc,
219  ServiceToken const& token,
221 
222  void terminateMachine(std::auto_ptr<statemachine::Machine>&);
223  std::auto_ptr<statemachine::Machine> createStateMachine();
224 
225  void setupSignal();
226 
227  bool hasSubProcess() const {
228  return subProcess_.get() != 0;
229  }
230 
232 
233  //read the next event using Stream iStreamIndex
234  void readEvent(unsigned int iStreamIndex);
235 
236  //process the already read event using Stream iStreamIndex
237  void processEvent(unsigned int iStreamIndex);
238 
239  //returns true if an asynchronous stop was requested
241  //------------------------------------------------------------------
242  //
243  // Data members below.
244  // Are all these data members really needed? Some of them are used
245  // only during construction, and never again. If they aren't
246  // really needed, we should remove them.
247 
248  boost::shared_ptr<ActivityRegistry> actReg_;
249  boost::shared_ptr<ProductRegistry const> preg_;
250  boost::shared_ptr<BranchIDListHelper> branchIDListHelper_;
252  std::unique_ptr<InputSource> input_;
253  std::unique_ptr<eventsetup::EventSetupsController> espController_;
254  boost::shared_ptr<eventsetup::EventSetupProvider> esp_;
255  std::unique_ptr<ExceptionToActionTable const> act_table_;
256  boost::shared_ptr<ProcessConfiguration const> processConfiguration_;
258  std::auto_ptr<Schedule> schedule_;
259  std::auto_ptr<SubProcess> subProcess_;
260  std::unique_ptr<HistoryAppender> historyAppender_;
261 
262  std::unique_ptr<FileBlock> fb_;
263  boost::shared_ptr<EDLooperBase> looper_;
264 
278 
283 
285 
289 
290  typedef std::set<std::pair<std::string, std::string> > ExcludedData;
291  typedef std::map<std::string, ExcludedData> ExcludedDataMap;
293  }; // class EventProcessor
294 
295  //--------------------------------------------------------------------
296 
297  inline
300  return runToCompletion();
301  }
302 }
303 #endif
std::string emptyRunLumiMode_
unsigned int numberOfSequentialEventsPerChild_
void readEvent(unsigned int iStreamIndex)
string rep
Definition: cuy.py:1188
ProcessContext processContext_
virtual void closeOutputFiles()
std::unique_ptr< ExceptionToActionTable const > act_table_
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 &)
boost::shared_ptr< ActivityRegistry > actReg_
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_
PreallocationConfiguration preallocations_
unsigned int LuminosityBlockNumber_t
Definition: EventID.h:31
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
virtual bool alreadyHandlingException() const
std::string exceptionMessageLumis_
virtual void setExceptionMessageLumis(std::string &message)
boost::shared_ptr< ProcessConfiguration const > processConfiguration_
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
int totalEvents() const
std::auto_ptr< Schedule > schedule_
std::string exceptionMessageFiles_
boost::shared_ptr< ProductRegistry const > preg_
virtual statemachine::Run readAndMergeRun()
virtual int readLuminosityBlock()
virtual void respondToCloseInputFile()
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()
void init(boost::shared_ptr< ProcessDesc > &processDesc, ServiceToken const &token, serviceregistry::ServiceLegacy)
virtual void deleteLumiFromCache(ProcessHistoryID const &phid, RunNumber_t run, LuminosityBlockNumber_t lumi)
virtual void closeInputFile(bool cleaningUpAfterException)
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
Definition: EventRange.h:32
bool asyncStopRequestedWhileProcessingEvents_
std::vector< ModuleDescription const * > getAllModuleDescriptions() const
std::unique_ptr< eventsetup::EventSetupsController > espController_
int totalEventsPassed() const
virtual int readAndMergeLumi()
boost::shared_ptr< BranchIDListHelper > branchIDListHelper_
PrincipalCache principalCache_
bool hasSubProcess() const
virtual bool shouldWeStop() const
void enableEndPaths(bool active)
void getTriggerReport(TriggerReport &rep) const