Skip to content

Commit

Permalink
Implement edmtest::EventIDProducer and edmtest::EventIDValidator
Browse files Browse the repository at this point in the history
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
fwyzard committed Nov 26, 2024
1 parent 3e100f9 commit b73d08a
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 0 deletions.
17 changes: 17 additions & 0 deletions FWCore/TestModules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ This package contains modules that are used in framework tests, but
are generic-enough to be usable outside of the framework as well.
Their interfaces are intended to be relatively stable.


## `edmtest::StreamIDFilter`

This module can be used to reject all events in specific streams.


## `edmtest::EventIDProducer`

This module reads the `EventID` from the current event and copies it as a data
product into the `Event`.


## `edmtest::EventIDValidator`

This module reads the `EventID` from the current event and compares it to a data
product read from the `Event`.

Together `edmtest::EventIDProducer` and `edmtest::EventIDValidator` can be used
to validate that an object produced in a given event is being read back in the
same event.
3 changes: 3 additions & 0 deletions FWCore/TestModules/plugins/BuildFile.xml
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>
31 changes: 31 additions & 0 deletions FWCore/TestModules/plugins/EventIDProducer.cc
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);
40 changes: 40 additions & 0 deletions FWCore/TestModules/plugins/EventIDValidator.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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"
#include "FWCore/Utilities/interface/Exception.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()) {
throw cms::Exception("InvalidValue") << "EventIDValidator: found invalid input value\n"
<< id << "\nwhile expecting\n"
<< event.id();
}
}

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);
1 change: 1 addition & 0 deletions FWCore/TestModules/test/BuildFile.xml
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"/>
17 changes: 17 additions & 0 deletions FWCore/TestModules/test/testEventIDValidator_cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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 = 10

process.eventIds = cms.EDProducer("edmtest::EventIDProducer")

process.eventValidator = cms.EDAnalyzer("edmtest::EventIDValidator",
source = cms.untracked.InputTag('eventIds')
)

process.path = cms.Path(process.eventIds + process.eventValidator)

0 comments on commit b73d08a

Please sign in to comment.