-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement EventIDProducer and EventIDValidator
EventIDProducer reads the EventID from the current event and copies it into the Event as a data product. EventIDValidator reads the EventID from the current event and compares it to a data product read from the Event. They can be used to validate that an object produced in a given event is being read back in the same event.
- Loading branch information
Showing
6 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
<use name="DataFormats/Provenance"/> | ||
<use name="FWCore/Framework"/> | ||
<use name="FWCore/ParameterSet"/> | ||
<use name="FWCore/PluginManager"/> | ||
<use name="FWCore/Utilities"/> | ||
<library file="*.cc" name="FWCoreTestModulesPlugins"> | ||
<flags EDM_PLUGIN="1"/> | ||
</library> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// CMSSW include files | ||
#include "DataFormats/Provenance/interface/EventID.h" | ||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/Framework/interface/global/EDProducer.h" | ||
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" | ||
#include "FWCore/Utilities/interface/EDPutToken.h" | ||
|
||
namespace edmtest { | ||
|
||
class EventIDProducer : public edm::global::EDProducer<> { | ||
public: | ||
EventIDProducer(edm::ParameterSet const& config) : token_(produces()) {} | ||
|
||
void produce(edm::StreamID, edm::Event& event, edm::EventSetup const&) const final { | ||
event.emplace(token_, event.id()); | ||
} | ||
|
||
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { | ||
edm::ParameterSetDescription desc; | ||
descriptions.addWithDefaultLabel(desc); | ||
} | ||
|
||
private: | ||
edm::EDPutTokenT<edm::EventID> token_; | ||
}; | ||
|
||
} // namespace edmtest | ||
|
||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
DEFINE_FWK_MODULE(edmtest::EventIDProducer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// C++ include files | ||
#include <sstream> | ||
#include <stdexcept> | ||
|
||
// CMSSW include files | ||
#include "DataFormats/Provenance/interface/EventID.h" | ||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/Framework/interface/global/EDAnalyzer.h" | ||
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" | ||
#include "FWCore/Utilities/interface/EDGetToken.h" | ||
|
||
namespace edmtest { | ||
|
||
class EventIDValidator : public edm::global::EDAnalyzer<> { | ||
public: | ||
EventIDValidator(edm::ParameterSet const& config) | ||
: token_(consumes(config.getUntrackedParameter<edm::InputTag>("source"))) {} | ||
|
||
void analyze(edm::StreamID, edm::Event const& event, edm::EventSetup const&) const final { | ||
auto const& id = event.get(token_); | ||
if (id != event.id()) { | ||
std::ostringstream msg; | ||
msg << "EventIDValidator: found invalid input value\n" << id << "\nwhile expecting\n" << event.id(); | ||
throw std::logic_error(msg.str()); | ||
} | ||
} | ||
|
||
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { | ||
edm::ParameterSetDescription desc; | ||
desc.addUntracked("source", edm::InputTag{"eventIDProducer", ""}) | ||
->setComment("EventID product to read from the event"); | ||
descriptions.addWithDefaultLabel(desc); | ||
} | ||
|
||
private: | ||
edm::EDGetTokenT<edm::EventID> token_; | ||
}; | ||
|
||
} // namespace edmtest | ||
|
||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
DEFINE_FWK_MODULE(edmtest::EventIDValidator); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<test name="TestFWCoreModulesEventIDValidator" command="cmsRun ${LOCALTOP}/src/FWCore/TestModules/test/testEventIDValidator_cfg.py"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
|
||
process = cms.Process("TEST") | ||
|
||
process.options.numberOfThreads = 4 | ||
process.options.numberOfStreams = 4 | ||
|
||
process.source = cms.Source("EmptySource") | ||
|
||
process.maxEvents.input = 100 | ||
|
||
process.eventIds = cms.EDProducer("EventIDProducer") | ||
|
||
process.eventValidator = cms.EDAnalyzer("EventIDValidator", | ||
source = cms.untracked.InputTag('eventIds') | ||
) | ||
|
||
process.path = cms.Path(process.eventIds + process.eventValidator) |