diff --git a/FWCore/Integration/test/BuildFile.xml b/FWCore/Integration/test/BuildFile.xml index db12dada405cc..fd634d642aed9 100644 --- a/FWCore/Integration/test/BuildFile.xml +++ b/FWCore/Integration/test/BuildFile.xml @@ -120,11 +120,11 @@ - + - + diff --git a/FWCore/Integration/test/CatchCmsExceptionFromSource_cfg.py b/FWCore/Integration/test/CatchCmsExceptionFromSource_cfg.py index 21939a17bf490..300eaf00cf810 100644 --- a/FWCore/Integration/test/CatchCmsExceptionFromSource_cfg.py +++ b/FWCore/Integration/test/CatchCmsExceptionFromSource_cfg.py @@ -2,13 +2,4 @@ process = cms.Process("TEST") -process.source = cms.Source("TestRunLumiSource", - runLumiEvent = cms.untracked.vint32(1, 0, 0, - 1, 1, 0, - 1, 1, 1, - 1, 1, 2, - 1, 1, 0, - 1, 0, 0 - ), - whenToThrow = cms.untracked.int32(3) -) +process.source = cms.Source("ThrowingSource", whenToThrow = cms.untracked.int32(3)) diff --git a/FWCore/Integration/test/TestRunLumiSource.cc b/FWCore/Integration/test/TestRunLumiSource.cc deleted file mode 100644 index 2310fe327d345..0000000000000 --- a/FWCore/Integration/test/TestRunLumiSource.cc +++ /dev/null @@ -1,156 +0,0 @@ -/*---------------------------------------------------------------------- -----------------------------------------------------------------------*/ - -#include "FWCore/Integration/test/TestRunLumiSource.h" -#include "DataFormats/Provenance/interface/BranchIDListHelper.h" -#include "DataFormats/Provenance/interface/EventID.h" -#include "DataFormats/Provenance/interface/EventAuxiliary.h" -#include "DataFormats/Provenance/interface/LuminosityBlockAuxiliary.h" -#include "DataFormats/Provenance/interface/RunAuxiliary.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/Framework/interface/EventPrincipal.h" -#include "FWCore/Framework/interface/LuminosityBlockPrincipal.h" -#include "FWCore/Framework/interface/RunPrincipal.h" -#include "DataFormats/Provenance/interface/Timestamp.h" -#include "FWCore/Framework/interface/InputSourceMacros.h" -#include "FWCore/Utilities/interface/Exception.h" -#include "FWCore/Framework/interface/FileBlock.h" - -namespace edm { - - TestRunLumiSource::TestRunLumiSource(ParameterSet const& pset, - InputSourceDescription const& desc) : - InputSource(pset, desc), - runLumiEvent_(pset.getUntrackedParameter >("runLumiEvent", std::vector())), - currentIndex_(0), - firstTime_(true), - whenToThrow_(pset.getUntrackedParameter("whenToThrow", kDoNotThrow)) { - - if (whenToThrow_ == kConstructor) throw cms::Exception("TestThrow") << "TestRunLumiSource constructor"; - } - - TestRunLumiSource::~TestRunLumiSource() { - if (whenToThrow_ == kDestructor) throw cms::Exception("TestThrow") << "TestRunLumiSource destructor"; - } - - void - TestRunLumiSource::beginJob() { - if (whenToThrow_ == kBeginJob) throw cms::Exception("TestThrow") << "TestRunLumiSource::beginJob"; - } - - void - TestRunLumiSource::endJob() { - if (whenToThrow_ == kEndJob) throw cms::Exception("TestThrow") << "TestRunLumiSource::endJob"; - } - - void - TestRunLumiSource::beginLuminosityBlock(LuminosityBlock&) { - if (whenToThrow_ == kBeginLumi) throw cms::Exception("TestThrow") << "TestRunLumiSource::beginLuminosityBlock"; - } - - void - TestRunLumiSource::endLuminosityBlock(LuminosityBlock&) { - if (whenToThrow_ == kEndLumi) throw cms::Exception("TestThrow") << "TestRunLumiSource::endLuminosityBlock"; - } - - void - TestRunLumiSource::beginRun(Run&) { - if (whenToThrow_ == kBeginRun) throw cms::Exception("TestThrow") << "TestRunLumiSource::beginRun"; - } - - void - TestRunLumiSource::endRun(Run&) { - if (whenToThrow_ == kEndRun) throw cms::Exception("TestThrow") << "TestRunLumiSource::endRun"; - } - - std::unique_ptr - TestRunLumiSource::readFile_() { - if (whenToThrow_ == kReadFile) throw cms::Exception("TestThrow") << "TestRunLumiSource::readFile_"; - return std::unique_ptr(new FileBlock); - } - - void - TestRunLumiSource::closeFile_() { - if (whenToThrow_ == kCloseFile) throw cms::Exception("TestThrow") << "TestRunLumiSource::closeFile_"; - } - - boost::shared_ptr - TestRunLumiSource::readRunAuxiliary_() { - if (whenToThrow_ == kReadRunAuxiliary) throw cms::Exception("TestThrow") << "TestRunLumiSource::readRunAuxiliary_"; - - unsigned int run = runLumiEvent_[currentIndex_]; - Timestamp ts = Timestamp(1); // 1 is just a meaningless number to make it compile for the test - currentIndex_ += 3; - return boost::shared_ptr(new RunAuxiliary(run, ts, Timestamp::invalidTimestamp())); - } - - boost::shared_ptr - TestRunLumiSource::readLuminosityBlockAuxiliary_() { - if (whenToThrow_ == kReadLuminosityBlockAuxiliary) throw cms::Exception("TestThrow") << "TestRunLumiSource::readLuminosityBlockAuxiliary_"; - - unsigned int run = runLumiEvent_[currentIndex_]; - unsigned int lumi = runLumiEvent_[currentIndex_ + 1]; - Timestamp ts = Timestamp(1); - currentIndex_ += 3; - return boost::shared_ptr(new LuminosityBlockAuxiliary(run, lumi, ts, Timestamp::invalidTimestamp())); - } - - EventPrincipal* - TestRunLumiSource::readEvent_(EventPrincipal& eventPrincipal) { - if (whenToThrow_ == kReadEvent) throw cms::Exception("TestThrow") << "TestRunLumiSource::readEvent_"; - - EventSourceSentry sentry{*this}; - unsigned int run = runLumiEvent_[currentIndex_]; - unsigned int lumi = runLumiEvent_[currentIndex_ + 1]; - unsigned int event = runLumiEvent_[currentIndex_ + 2]; - Timestamp ts = Timestamp(1); - - boost::shared_ptr runAux(new RunAuxiliary(run, ts, Timestamp::invalidTimestamp())); - boost::shared_ptr rp2( - new RunPrincipal(runAux, productRegistry(), processConfiguration(), &historyAppender_,0)); - - boost::shared_ptr lumiAux( - new LuminosityBlockAuxiliary(rp2->run(), lumi, ts, Timestamp::invalidTimestamp())); - boost::shared_ptr lbp2( - new LuminosityBlockPrincipal(lumiAux, productRegistry(), processConfiguration(), &historyAppender_,0)); - lbp2->setRunPrincipal(rp2); - - EventID id(run, lbp2->luminosityBlock(), event); - currentIndex_ += 3; - EventAuxiliary eventAux(id, processGUID(), ts, false); - boost::shared_ptr branchIDListHelper(new BranchIDListHelper()); - EventPrincipal* result(new EventPrincipal(productRegistry(), branchIDListHelper, processConfiguration(), &historyAppender_,eventPrincipal.streamID())); - result->fillEventPrincipal(eventAux); - result->setLuminosityBlockPrincipal(lbp2); - return result; - } - - InputSource::ItemType - TestRunLumiSource::getNextItemType() { - if (whenToThrow_ == kGetNextItemType ) throw cms::Exception("TestThrow") << "TestRunLumiSource::getNextItemType"; - - if (firstTime_) { - firstTime_ = false; - return InputSource::IsFile; - } - if (currentIndex_ + 2 >= runLumiEvent_.size()) { - return InputSource::IsStop; - } - if (runLumiEvent_[currentIndex_] == 0) { - return InputSource::IsStop; - } - ItemType oldState = state(); - if (oldState == IsInvalid) return InputSource::IsFile; - if (runLumiEvent_[currentIndex_ + 1] == 0) { - return InputSource::IsRun; - } - if (runLumiEvent_[currentIndex_ + 2] == 0) { - return InputSource::IsLumi; - } - return InputSource::IsEvent; - } -} - -using edm::TestRunLumiSource; -DEFINE_FWK_INPUT_SOURCE(TestRunLumiSource); - diff --git a/FWCore/Integration/test/TestRunLumiSource.h b/FWCore/Integration/test/TestRunLumiSource.h deleted file mode 100644 index 3b77b2e5dc565..0000000000000 --- a/FWCore/Integration/test/TestRunLumiSource.h +++ /dev/null @@ -1,120 +0,0 @@ -#ifndef FWCore_Framework_TestRunLumiSource_h -#define FWCore_Framework_TestRunLumiSource_h - -/*---------------------------------------------------------------------- -This source is intended only for test purposes. With it one can -create data files with arbitrary sequences of run number, lumi -number, and event number in the auxiliary objects in the run tree, -lumi tree, and event tree. It is quite possible to create an illegal -format that cannot be read with any input module using this source. - -The output files of jobs using this source will be used in tests of -input modules to verify they are behaving properly. - -The configuration looks as follows - - source = TestRunLumiSource { - untracked vint32 runLumiEvent = { 1, 1, 1, # run - 1, 1, 1, # lumi - 1, 1, 1, # event - 1, 1, 2, # event - 0, 0, 0, # causes end lumi - 0, 0, 0 # causes end run - } - } - -Each line contains 3 values: run, lumi, and event. These lines -are used in order, one line per each call to readRun_, -readLuminosityBlock_, and readEvent, in the order called by the -event processor. Note that when readRun_ is called only the run -number is used and the other two values are extraneous. When -readLuminosityBlock is called only the first two values are used. -(0, 0, 0) will trigger the end of the current luminosity block, -run, or job as appropriate for when it appears. Running off the -bottom list is also equivalent to (0,0,0). What is shown above -is the typical sequence one would expect for two events, but this -source is capable of handling arbitrary sequences of run numbers, -lumi block number, and events. For test purposes one can even -include sequences that make no sense and the entries will get -written to the output file anyway. - -----------------------------------------------------------------------*/ - -#include "FWCore/Framework/interface/InputSource.h" -#include "FWCore/Framework/interface/HistoryAppender.h" - -#include "boost/shared_ptr.hpp" - -#include -#include - -namespace edm { - - class EventPrincipal; - class FileBlock; - struct InputSourceDescription; - class LuminosityBlock; - class LuminosityBlockPrincipal; - class ParameterSet; - class Run; - class RunPrincipal; - - class TestRunLumiSource : public InputSource { - public: - explicit TestRunLumiSource(ParameterSet const& pset, InputSourceDescription const& desc); - virtual ~TestRunLumiSource(); - - private: - - enum { - kDoNotThrow = 0, - kConstructor = 1, - kBeginJob = 2, - kBeginRun = 3, - kBeginLumi = 4, - kEndLumi = 5, - kEndRun = 6, - kEndJob = 7, - kGetNextItemType = 8, - kReadEvent = 9, - kReadLuminosityBlockAuxiliary = 10, - kReadRunAuxiliary = 11, - kReadFile = 12, - kCloseFile = 13, - kDestructor = 14 - }; - - virtual void beginJob(); - virtual void endJob(); - virtual void beginLuminosityBlock(LuminosityBlock&); - virtual void endLuminosityBlock(LuminosityBlock&); - virtual void beginRun(Run&); - virtual void endRun(Run&); - virtual std::unique_ptr readFile_(); - virtual void closeFile_(); - - virtual ItemType getNextItemType(); - virtual EventPrincipal* readEvent_(EventPrincipal& eventPrincipal); - virtual boost::shared_ptr readLuminosityBlockAuxiliary_(); - virtual boost::shared_ptr readRunAuxiliary_(); - - // This vector holds 3 values representing (run, lumi, event) - // repeated over and over again, in one vector. - // Each set of 3 values is placed in the the auxiliary - // object of the principal returned by a call - // to readEvent_, readLuminosityBlock_, or readRun_. - // Each set of 3 values is used in the order it appears in the vector. - // (0, 0, 0) is a special value indicating the read - // function should return a NULL value indicating last event, - // last lumi, or last run. - std::vector runLumiEvent_; - std::vector::size_type currentIndex_; - bool firstTime_; - - // To test exception throws from sources - int whenToThrow_; - - HistoryAppender historyAppender_; - }; -} -#endif diff --git a/FWCore/Integration/test/ThrowingSource.cc b/FWCore/Integration/test/ThrowingSource.cc new file mode 100644 index 0000000000000..b9139b2cc567d --- /dev/null +++ b/FWCore/Integration/test/ThrowingSource.cc @@ -0,0 +1,142 @@ +#include "FWCore/Framework/interface/FileBlock.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/EventPrincipal.h" +#include "FWCore/Framework/interface/InputSourceMacros.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Sources/interface/ProducerSourceBase.h" +#include "FWCore/Utilities/interface/Exception.h" + +namespace edm { + class ThrowingSource : public ProducerSourceBase { + public: + explicit ThrowingSource(ParameterSet const&, InputSourceDescription const&); + ~ThrowingSource(); + + virtual void beginJob(); + virtual void endJob(); + virtual void beginLuminosityBlock(edm::LuminosityBlock&); + virtual void endLuminosityBlock(edm::LuminosityBlock&); + virtual void beginRun(edm::Run&); + virtual void endRun(edm::Run&); + virtual std::unique_ptr readFile_(); + virtual void closeFile_(); + virtual boost::shared_ptr readRunAuxiliary_(); + virtual boost::shared_ptr readLuminosityBlockAuxiliary_(); + virtual edm::EventPrincipal* readEvent_(edm::EventPrincipal&); + private: + enum { + kDoNotThrow = 0, + kConstructor = 1, + kBeginJob = 2, + kBeginRun = 3, + kBeginLumi = 4, + kEndLumi = 5, + kEndRun = 6, + kEndJob = 7, + kGetNextItemType = 8, + kReadEvent = 9, + kReadLuminosityBlockAuxiliary = 10, + kReadRunAuxiliary = 11, + kReadFile = 12, + kCloseFile = 13, + kDestructor = 14 + }; + virtual bool setRunAndEventInfo(EventID& id, TimeValue_t& time); + virtual void produce(Event &); + + // To test exception throws from sources + int whenToThrow_; + }; + + ThrowingSource::ThrowingSource(ParameterSet const& pset, + InputSourceDescription const& desc) : + ProducerSourceBase(pset, desc, false), whenToThrow_(pset.getUntrackedParameter("whenToThrow", kDoNotThrow)) { + if (whenToThrow_ == kConstructor) throw cms::Exception("TestThrow") << "ThrowingSource constructor"; + + } + + ThrowingSource::~ThrowingSource() { + if (whenToThrow_ == kDestructor) throw cms::Exception("TestThrow") << "ThrowingSource destructor"; + } + + bool + ThrowingSource::setRunAndEventInfo(EventID&, TimeValue_t&) { + return true; + } + + void + ThrowingSource::produce(edm::Event&) { + } + + void + ThrowingSource::beginJob() { + if (whenToThrow_ == kBeginJob) throw cms::Exception("TestThrow") << "ThrowingSource::beginJob"; + } + + void + ThrowingSource::endJob() { + if (whenToThrow_ == kEndJob) throw cms::Exception("TestThrow") << "ThrowingSource::endJob"; + } + + void + ThrowingSource::beginLuminosityBlock(LuminosityBlock& lb) { + if (whenToThrow_ == kBeginLumi) throw cms::Exception("TestThrow") << "ThrowingSource::beginLuminosityBlock"; + } + + void + ThrowingSource::endLuminosityBlock(LuminosityBlock& lb) { + if (whenToThrow_ == kEndLumi) throw cms::Exception("TestThrow") << "ThrowingSource::endLuminosityBlock"; + } + + void + ThrowingSource::beginRun(Run& run) { + if (whenToThrow_ == kBeginRun) throw cms::Exception("TestThrow") << "ThrowingSource::beginRun"; + } + + void + ThrowingSource::endRun(Run& run) { + if (whenToThrow_ == kEndRun) throw cms::Exception("TestThrow") << "ThrowingSource::endRun"; + } + + std::unique_ptr + ThrowingSource::readFile_() { + if (whenToThrow_ == kReadFile) throw cms::Exception("TestThrow") << "ThrowingSource::readFile_"; + return std::unique_ptr(new FileBlock); + } + + void + ThrowingSource::closeFile_() { + if (whenToThrow_ == kCloseFile) throw cms::Exception("TestThrow") << "ThrowingSource::closeFile_"; + } + + boost::shared_ptr + ThrowingSource::readRunAuxiliary_() { + if (whenToThrow_ == kReadRunAuxiliary) throw cms::Exception("TestThrow") << "ThrowingSource::readRunAuxiliary_"; + Timestamp ts = Timestamp(presentTime()); + resetNewRun(); + return boost::shared_ptr(new RunAuxiliary(eventID().run(), ts, Timestamp::invalidTimestamp())); + } + + boost::shared_ptr + ThrowingSource::readLuminosityBlockAuxiliary_() { + if (whenToThrow_ == kReadLuminosityBlockAuxiliary) throw cms::Exception("TestThrow") << "ThrowingSource::readLuminosityBlockAuxiliary_"; + if (processingMode() == Runs) return boost::shared_ptr(); + Timestamp ts = Timestamp(presentTime()); + resetNewLumi(); + return boost::shared_ptr(new LuminosityBlockAuxiliary(eventID().run(), eventID().luminosityBlock(), ts, Timestamp::invalidTimestamp())); + } + + EventPrincipal* + ThrowingSource::readEvent_(EventPrincipal& eventPrincipal) { + if (whenToThrow_ == kReadEvent) throw cms::Exception("TestThrow") << "ThrowingSource::readEvent_"; + assert(eventCached() || processingMode() != RunsLumisAndEvents); + EventSourceSentry sentry(*this); + EventAuxiliary aux(eventID(), processGUID(), Timestamp(presentTime()), false, EventAuxiliary::Undefined); + eventPrincipal.fillEventPrincipal(aux); + return &eventPrincipal; + } +} + +using edm::ThrowingSource; +DEFINE_FWK_INPUT_SOURCE(ThrowingSource); + diff --git a/IOPool/Input/test/PoolEmptyTest_cfg.py b/IOPool/Input/test/PoolEmptyTest_cfg.py index 73164180cccc5..02d38ab8094ac 100644 --- a/IOPool/Input/test/PoolEmptyTest_cfg.py +++ b/IOPool/Input/test/PoolEmptyTest_cfg.py @@ -8,7 +8,7 @@ process.load("FWCore.Framework.test.cmsExceptionsFatal_cff") process.maxEvents = cms.untracked.PSet( - input = cms.untracked.int32(-1) + input = cms.untracked.int32(0) ) process.Thing = cms.EDProducer("ThingProducer") @@ -16,9 +16,7 @@ fileName = cms.untracked.string('PoolEmptyTest.root') ) -process.source = cms.Source("TestRunLumiSource", - runLumiEvent = cms.untracked.vint32(0, 0, 0) -) +process.source = cms.Source("EmptySource") process.p = cms.Path(process.Thing) process.ep = cms.EndPath(process.output)