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