00001 #ifndef FWCore_Framework_EventProcessor_h
00002 #define FWCore_Framework_EventProcessor_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <string>
00014 #include <vector>
00015 #include <memory>
00016
00017 #include "boost/shared_ptr.hpp"
00018 #include "boost/thread/thread.hpp"
00019 #include "boost/utility.hpp"
00020
00021 #include "FWCore/Framework/interface/IEventProcessor.h"
00022 #include "FWCore/Framework/interface/InputSource.h"
00023 #include "FWCore/ServiceRegistry/interface/ServiceLegacy.h"
00024 #include "FWCore/ServiceRegistry/interface/ServiceToken.h"
00025 #include "FWCore/Framework/src/WorkerRegistry.h"
00026 #include "FWCore/Framework/src/SignallingProductRegistry.h"
00027 #include "FWCore/Framework/interface/Actions.h"
00028 #include "DataFormats/Provenance/interface/PassID.h"
00029 #include "DataFormats/Provenance/interface/ReleaseVersion.h"
00030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00031 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
00032
00033 #include "FWCore/Framework/interface/Frameworkfwd.h"
00034 #include "FWCore/Framework/src/PrincipalCache.h"
00035
00036 namespace statemachine {
00037 class Machine;
00038 }
00039
00040 namespace edm {
00041
00042 class ProcessDesc;
00043 namespace eventsetup {
00044 class EventSetupProvider;
00045 }
00046
00047 namespace event_processor
00048 {
00049
00050
00051
00052
00053
00054 enum State { sInit=0,sJobReady,sRunGiven,sRunning,sStopping,
00055 sShuttingDown,sDone,sJobEnded,sError,sErrorEnded,sEnd,sInvalid };
00056
00057 enum Msg { mSetRun=0, mSkip, mRunAsync, mRunID, mRunCount, mBeginJob,
00058 mStopAsync, mShutdownAsync, mEndJob, mCountComplete,
00059 mInputExhausted, mStopSignal, mShutdownSignal, mFinished,
00060 mAny, mDtor, mException, mInputRewind };
00061
00062 class StateSentry;
00063 }
00064
00065 class EventProcessor : public IEventProcessor, private boost::noncopyable
00066 {
00067 public:
00068
00069
00070
00071
00072
00073
00074 explicit EventProcessor(std::string const& config,
00075 ServiceToken const& token = ServiceToken(),
00076 serviceregistry::ServiceLegacy =
00077 serviceregistry::kOverlapIsError,
00078 std::vector<std::string> const& defaultServices =
00079 std::vector<std::string>(),
00080 std::vector<std::string> const& forcedServices =
00081 std::vector<std::string>());
00082
00083
00084
00085 EventProcessor(std::string const& config,
00086 std::vector<std::string> const& defaultServices,
00087 std::vector<std::string> const& forcedServices =
00088 std::vector<std::string>());
00089
00090
00091 EventProcessor(boost::shared_ptr<edm::ProcessDesc> & processDesc,
00092 ServiceToken const& token,
00093 serviceregistry::ServiceLegacy legacy);
00094
00096 EventProcessor(std::string const& config, bool isPython);
00097
00098 ~EventProcessor();
00099
00104 void beginJob();
00105
00109 void endJob();
00110
00114 char const* currentStateName() const;
00115 char const* stateName(event_processor::State s) const;
00116 char const* msgName(event_processor::Msg m) const;
00117 event_processor::State getState() const;
00118 void runAsync();
00119 StatusCode statusAsync() const;
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 StatusCode stopAsync(unsigned int timeout_secs=60*2);
00135
00136
00137 StatusCode shutdownAsync(unsigned int timeout_secs=60*2);
00138
00139
00140
00141 StatusCode waitTillDoneAsync(unsigned int timeout_seconds=0);
00142
00143
00144
00145
00146
00147 void setRunNumber(RunNumber_t runNumber);
00148 void declareRunNumber(RunNumber_t runNumber);
00149
00150
00151
00152
00153
00154
00155
00156 StatusCode run(int numberEventsToProcess, bool repeatable = true);
00157 StatusCode run();
00158
00159
00160 StatusCode run(EventID const& id);
00161
00162
00163
00164 StatusCode skip(int numberToSkip);
00165
00166
00167 void rewind();
00168
00171
00175
00176 std::vector<ModuleDescription const*>
00177 getAllModuleDescriptions() const;
00178
00182 int totalEvents() const;
00183
00186 int totalEventsPassed() const;
00187
00190 int totalEventsFailed() const;
00191
00194 void enableEndPaths(bool active);
00195
00198 bool endPathsEnabled() const;
00199
00202 void getTriggerReport(TriggerReport& rep) const;
00203
00205 void clearCounters();
00206
00207
00208
00209 ServiceToken getToken();
00210
00213 ActivityRegistry::PreProcessEvent &
00214 preProcessEventSignal() {return preProcessEventSignal_;}
00215
00218 ActivityRegistry::PostProcessEvent &
00219 postProcessEventSignal() {return postProcessEventSignal_;}
00220
00221
00222
00223
00224
00225 struct CommonParams
00226 {
00227 CommonParams():
00228 processName_(),
00229 releaseVersion_(),
00230 passID_(),
00231 maxEventsInput_(),
00232 maxLumisInput_()
00233 { }
00234
00235 CommonParams(std::string const& processName,
00236 ReleaseVersion const& releaseVersion,
00237 PassID const& passID,
00238 int maxEvents,
00239 int maxLumis):
00240 processName_(processName),
00241 releaseVersion_(releaseVersion),
00242 passID_(passID),
00243 maxEventsInput_(maxEvents),
00244 maxLumisInput_(maxLumis)
00245 { }
00246
00247 std::string processName_;
00248 ReleaseVersion releaseVersion_;
00249 PassID passID_;
00250 int maxEventsInput_;
00251 int maxLumisInput_;
00252 };
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297 virtual StatusCode runToCompletion(bool onlineStateTransitions);
00298 virtual StatusCode runEventCount(int numberOfEventsToProcess);
00299
00300
00301
00302
00303 virtual void readFile();
00304 virtual void closeInputFile();
00305 virtual void openOutputFiles();
00306 virtual void closeOutputFiles();
00307
00308 virtual void respondToOpenInputFile();
00309 virtual void respondToCloseInputFile();
00310 virtual void respondToOpenOutputFiles();
00311 virtual void respondToCloseOutputFiles();
00312
00313 virtual void startingNewLoop();
00314 virtual bool endOfLoop();
00315 virtual void rewindInput();
00316 virtual void prepareForNextLoop();
00317 virtual void writeLumiCache();
00318 virtual void writeRunCache();
00319 virtual bool shouldWeCloseOutput() const;
00320
00321 virtual void doErrorStuff();
00322
00323 virtual void beginRun(int run);
00324 virtual void endRun(int run);
00325
00326 virtual void beginLumi(int run, int lumi);
00327 virtual void endLumi(int run, int lumi);
00328
00329 virtual int readAndCacheRun();
00330 virtual int readAndCacheLumi();
00331 virtual void writeRun(int run);
00332 virtual void deleteRunFromCache(int run);
00333 virtual void writeLumi(int run, int lumi);
00334 virtual void deleteLumiFromCache(int run, int lumi);
00335
00336 virtual void readEvent();
00337 virtual void processEvent();
00338 virtual bool shouldWeStop() const;
00339
00340 virtual void setExceptionMessageFiles(std::string& message);
00341 virtual void setExceptionMessageRuns(std::string& message);
00342 virtual void setExceptionMessageLumis(std::string& message);
00343
00344 virtual bool alreadyHandlingException() const;
00345
00346 private:
00347
00348
00349
00350
00351 void init(boost::shared_ptr<edm::ProcessDesc> & processDesc,
00352 ServiceToken const& token,
00353 serviceregistry::ServiceLegacy);
00354
00355
00356
00357 StatusCode runCommon(bool onlineStateTransitions, int numberOfEventsToProcess);
00358 void terminateMachine();
00359
00360 StatusCode doneAsync(event_processor::Msg m);
00361
00362 std::auto_ptr<EventPrincipal> doOneEvent(EventID const& id);
00363 void procOneEvent(EventPrincipal *pep);
00364
00365 StatusCode waitForAsyncCompletion(unsigned int timeout_seconds);
00366
00367 void connectSigs(EventProcessor * ep);
00368
00369 void changeState(event_processor::Msg);
00370 void errorState();
00371 void setupSignal();
00372
00373 static void asyncRun(EventProcessor *);
00374
00375
00376
00377
00378
00379
00380
00381
00382 ActivityRegistry::PreProcessEvent preProcessEventSignal_;
00383 ActivityRegistry::PostProcessEvent postProcessEventSignal_;
00384 ParameterSet maxEventsPset_;
00385 ParameterSet maxLumisPset_;
00386 boost::shared_ptr<ActivityRegistry> actReg_;
00387 WorkerRegistry wreg_;
00388 SignallingProductRegistry preg_;
00389 ServiceToken serviceToken_;
00390 boost::shared_ptr<InputSource> input_;
00391 std::auto_ptr<Schedule> schedule_;
00392 std::auto_ptr<eventsetup::EventSetupProvider> esp_;
00393 ActionTable act_table_;
00394
00395 volatile event_processor::State state_;
00396 boost::shared_ptr<boost::thread> event_loop_;
00397
00398 boost::mutex state_lock_;
00399 boost::mutex stop_lock_;
00400 boost::condition stopper_;
00401 boost::condition starter_;
00402 volatile int stop_count_;
00403 volatile Status last_rc_;
00404 std::string last_error_text_;
00405 volatile bool id_set_;
00406 volatile pthread_t event_loop_id_;
00407 int my_sig_num_;
00408 boost::shared_ptr<FileBlock> fb_;
00409 boost::shared_ptr<EDLooper> looper_;
00410
00411 std::auto_ptr<statemachine::Machine> machine_;
00412 PrincipalCache principalCache_;
00413 std::auto_ptr<EventPrincipal> sm_evp_;
00414 bool shouldWeStop_;
00415 bool stateMachineWasInErrorState_;
00416 std::string fileMode_;
00417 bool handleEmptyRuns_;
00418 bool handleEmptyLumis_;
00419 std::string exceptionMessageFiles_;
00420 std::string exceptionMessageRuns_;
00421 std::string exceptionMessageLumis_;
00422 bool alreadyHandlingException_;
00423 bool forceLooperToEnd_;
00424
00425 friend class event_processor::StateSentry;
00426 };
00427
00428
00429
00430 inline
00431 EventProcessor::StatusCode
00432 EventProcessor::run() {
00433 return run(-1, false);
00434 }
00435 }
00436 #endif