Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-23 00:28:19

0001 #ifndef FWCore_Framework_MockEventProcessor_h
0002 #define FWCore_Framework_MockEventProcessor_h
0003 
0004 /*
0005 Version of the Event Processor used for tests of
0006 the state machine and other tests.
0007 
0008 Original Authors: W. David Dagenhart, Marc Paterno
0009 */
0010 
0011 #include "DataFormats/Provenance/interface/ProcessHistoryID.h"
0012 #include "FWCore/Framework/interface/InputSource.h"
0013 
0014 #include <iostream>
0015 #include <string>
0016 #include <sstream>
0017 #include <exception>
0018 
0019 namespace edm {
0020   class LuminosityBlockProcessingStatus;
0021 
0022   class MockEventProcessor {
0023   public:
0024     class TestException : public std::exception {
0025     public:
0026       TestException() noexcept : std::exception() {}
0027     };
0028 
0029     MockEventProcessor(std::string const& mockData, std::ostream& output, bool iDoNotMerge);
0030 
0031     void runToCompletion();
0032 
0033     InputSource::ItemType nextTransitionType();
0034     InputSource::ItemType lastTransitionType() const;
0035     std::pair<edm::ProcessHistoryID, edm::RunNumber_t> nextRunID();
0036     edm::LuminosityBlockNumber_t nextLuminosityBlockID();
0037 
0038     void readFile();
0039     bool fileBlockValid() { return true; }
0040     void closeInputFile(bool cleaningUpAfterException);
0041     void openOutputFiles();
0042     void closeOutputFiles();
0043 
0044     void respondToOpenInputFile();
0045     void respondToCloseInputFile();
0046 
0047     void startingNewLoop();
0048     bool endOfLoop();
0049     void rewindInput();
0050     void prepareForNextLoop();
0051     bool shouldWeCloseOutput() const;
0052 
0053     void doErrorStuff();
0054 
0055     void beginProcessBlock(bool& beginProcessBlockSucceeded);
0056     void inputProcessBlocks();
0057     void endProcessBlock(bool cleaningUpAfterException, bool beginProcessBlockSucceeded);
0058 
0059     void beginRun(ProcessHistoryID const& phid,
0060                   RunNumber_t run,
0061                   bool& globalTransitionSucceeded,
0062                   bool& eventSetupForInstanceSucceeded);
0063     void endUnfinishedRun(ProcessHistoryID const& phid,
0064                           RunNumber_t run,
0065                           bool globalTranstitionSucceeded,
0066                           bool cleaningUpAfterException,
0067                           bool eventSetupForInstanceSucceeded);
0068 
0069     void endRun(ProcessHistoryID const& phid,
0070                 RunNumber_t run,
0071                 bool globalTranstitionSucceeded,
0072                 bool cleaningUpAfterException);
0073 
0074     InputSource::ItemType processLumis(std::shared_ptr<void>);
0075     void endUnfinishedLumi();
0076 
0077     std::pair<ProcessHistoryID, RunNumber_t> readRun();
0078     std::pair<ProcessHistoryID, RunNumber_t> readAndMergeRun();
0079     int readLuminosityBlock(LuminosityBlockProcessingStatus&);
0080     int readAndMergeLumi(LuminosityBlockProcessingStatus&);
0081     void writeRun(ProcessHistoryID const& phid, RunNumber_t run);
0082     void deleteRunFromCache(ProcessHistoryID const& phid, RunNumber_t run);
0083     void writeLumi(LuminosityBlockProcessingStatus&);
0084     void deleteLumiFromCache(LuminosityBlockProcessingStatus&);
0085 
0086     bool shouldWeStop() const;
0087 
0088     void setExceptionMessageFiles(std::string& message);
0089     void setExceptionMessageRuns();
0090     void setExceptionMessageLumis();
0091 
0092     bool setDeferredException(std::exception_ptr);
0093 
0094   private:
0095     InputSource::ItemType readAndProcessEvents();
0096     void readAndProcessEvent();
0097     void throwIfNeeded();
0098     void endLumi();
0099 
0100     std::string mockData_;
0101     std::ostream& output_;
0102     std::istringstream input_;
0103 
0104     std::shared_ptr<LuminosityBlockProcessingStatus> lumiStatus_;
0105     InputSource::ItemType lastTransition_;
0106 
0107     int run_;
0108     int lumi_;
0109 
0110     bool doNotMerge_;
0111     bool shouldWeCloseOutput_;
0112     bool shouldWeEndLoop_;
0113     bool shouldWeStop_;
0114     bool eventProcessed_;
0115     bool reachedEndOfInput_;
0116     bool shouldThrow_;
0117   };
0118 }  // namespace edm
0119 
0120 #endif