Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:28

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 TransitionProcessors.icc.
0007 
0008 The tests that use this class are less useful than they used
0009 to be. MockEventProcessor is mainly used to test the code in
0010 TransitionProcessors.icc (historical sidenote: at the time
0011 MockEventProcessor was originally created a long time ago,
0012 the functionality in TransitionProcessors.icc was
0013 implemented using a boost state machine and MockEventProcessor
0014 was originally designed to test that).  When
0015 concurrent runs and concurrent lumis were implemented,
0016 a lot of functionality was moved from TransitionProcessors.icc
0017 into EventProcessors.cc. In the tests, MockEventProcessor
0018 replaces EventProcessor and therefore it cannot be used
0019 to test code in EventProcessor. Originally, this tested
0020 the loops over runs, lumis, and events in addition to the
0021 loops over files. At this point, it is really
0022 testing only the code related to the loop over files in
0023 TransitionProcessors.icc and we could clean things up by
0024 removing the code and parts of the tests that are intended to
0025 test runs, lumis, and events. That part of the code is not
0026 serving any purpose anymore. This cleanup would be a lot
0027 of tedious work for very little practical gain though...
0028 It might never happen.
0029 
0030 Original Authors: W. David Dagenhart, Marc Paterno
0031 */
0032 
0033 #include "DataFormats/Provenance/interface/RunLumiEventNumber.h"
0034 #include "FWCore/Framework/interface/InputSource.h"
0035 
0036 #include <exception>
0037 #include <ostream>
0038 #include <memory>
0039 #include <sstream>
0040 #include <string>
0041 
0042 namespace edm {
0043 
0044   class MockEventProcessor {
0045   public:
0046     class TestException : public std::exception {
0047     public:
0048       TestException() noexcept : std::exception() {}
0049     };
0050 
0051     MockEventProcessor(std::string const& mockData, std::ostream& output, bool iDoNotMerge);
0052 
0053     void runToCompletion();
0054 
0055     InputSource::ItemType nextTransitionType();
0056     InputSource::ItemType lastTransitionType() const;
0057 
0058     void readFile();
0059     bool fileBlockValid() { return true; }
0060     void closeInputFile(bool cleaningUpAfterException);
0061     void openOutputFiles();
0062     void closeOutputFiles();
0063 
0064     void respondToOpenInputFile();
0065     void respondToCloseInputFile();
0066 
0067     void startingNewLoop();
0068     bool endOfLoop();
0069     void rewindInput();
0070     void prepareForNextLoop();
0071     bool shouldWeCloseOutput() const;
0072 
0073     void doErrorStuff();
0074 
0075     void beginProcessBlock(bool& beginProcessBlockSucceeded);
0076     void inputProcessBlocks();
0077     void endProcessBlock(bool cleaningUpAfterException, bool beginProcessBlockSucceeded);
0078 
0079     InputSource::ItemType processRuns();
0080     void processRun();
0081     InputSource::ItemType processLumis();
0082 
0083     void beginRun(RunNumber_t run);
0084 
0085     void endUnfinishedRun(bool);
0086 
0087     void endRun();
0088 
0089     void endUnfinishedLumi(bool);
0090 
0091     void readRun();
0092     void readAndMergeRun();
0093     LuminosityBlockNumber_t readLuminosityBlock();
0094     LuminosityBlockNumber_t readAndMergeLumi();
0095     void writeRun();
0096     void clearRunPrincipal();
0097     void writeLumi();
0098     void clearLumiPrincipal();
0099 
0100     bool shouldWeStop() const;
0101 
0102     void setExceptionMessageFiles(std::string& message);
0103     void setExceptionMessageRuns();
0104     void setExceptionMessageLumis();
0105 
0106     bool setDeferredException(std::exception_ptr);
0107 
0108   private:
0109     InputSource::ItemType readAndProcessEvents();
0110     void readAndProcessEvent();
0111     void throwIfNeeded();
0112     void endLumi();
0113 
0114     std::string mockData_;
0115     std::ostream& output_;
0116     std::istringstream input_;
0117 
0118     bool lumiStatus_ = false;
0119     LuminosityBlockNumber_t currentLumiNumber_ = 0;
0120     bool didGlobalBeginLumiSucceed_ = false;
0121     InputSource::ItemType lastTransition_ = InputSource::ItemType::IsInvalid;
0122 
0123     bool currentRun_ = false;
0124     RunNumber_t currentRunNumber_ = 0;
0125     bool didGlobalBeginRunSucceed_ = false;
0126 
0127     RunNumber_t nextRun_;
0128     LuminosityBlockNumber_t nextLumi_;
0129 
0130     bool doNotMerge_;
0131     bool shouldWeCloseOutput_;
0132     bool shouldWeEndLoop_;
0133     bool shouldWeStop_;
0134     bool eventProcessed_;
0135     bool reachedEndOfInput_;
0136     bool shouldThrow_;
0137   };
0138 }  // namespace edm
0139 
0140 #endif