Skip to content

Commit

Permalink
Merge pull request #32217 from makortel/fixEsConsumesCurrentProcess
Browse files Browse the repository at this point in the history
Fix esConsumes() for an EDModule that consumes EDProduct with @currentProcess
  • Loading branch information
cmsbuild committed Nov 24, 2020
2 parents 044c077 + c2c4015 commit c608f97
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 34 deletions.
2 changes: 1 addition & 1 deletion FWCore/Framework/interface/EDConsumerBase.h
Expand Up @@ -69,7 +69,7 @@ namespace edm {

class EDConsumerBase {
public:
EDConsumerBase() : m_tokenLabels{'\0'}, frozen_(false), containsCurrentProcessAlias_(false) {}
EDConsumerBase();
virtual ~EDConsumerBase() noexcept(false);

// disallow copying
Expand Down
41 changes: 8 additions & 33 deletions FWCore/Framework/src/EDConsumerBase.cc
Expand Up @@ -31,40 +31,15 @@

using namespace edm;

//
// constants, enums and typedefs
//

//
// static data member definitions
//

//
// constructors and destructor
//
//EDConsumerBase::EDConsumerBase()
//{
//}
namespace {
std::vector<char> makeEmptyTokenLabels() { return std::vector<char>{'\0'}; }
} // namespace

// EDConsumerBase::EDConsumerBase(const EDConsumerBase& rhs)
// {
// // do actual copying here;
// }
EDConsumerBase::EDConsumerBase()
: m_tokenLabels{makeEmptyTokenLabels()}, frozen_(false), containsCurrentProcessAlias_(false) {}

EDConsumerBase::~EDConsumerBase() noexcept(false) {}

//
// assignment operators
//
// const EDConsumerBase& EDConsumerBase::operator=(const EDConsumerBase& rhs)
// {
// //An exception safe implementation is
// EDConsumerBase temp(rhs);
// swap(rhs);
//
// return *this;
// }

//
// member functions
//
Expand Down Expand Up @@ -549,10 +524,10 @@ void EDConsumerBase::convertCurrentProcessAlias(std::string const& processName)
if (containsCurrentProcessAlias_) {
containsCurrentProcessAlias_ = false;

std::vector<char> newTokenLabels;
auto newTokenLabels = makeEmptyTokenLabels();

// first calculate the size of the new vector and reserve memory for it
std::vector<char>::size_type newSize = 0;
std::vector<char>::size_type newSize = newTokenLabels.size();
std::string newProcessName;
for (auto iter = m_tokenInfo.begin<kLabels>(), itEnd = m_tokenInfo.end<kLabels>(); iter != itEnd; ++iter) {
newProcessName = &m_tokenLabels[iter->m_startOfModuleLabel + iter->m_deltaToProcessName];
Expand All @@ -563,7 +538,7 @@ void EDConsumerBase::convertCurrentProcessAlias(std::string const& processName)
}
newTokenLabels.reserve(newSize);

unsigned int newStartOfModuleLabel = 0;
unsigned int newStartOfModuleLabel = newTokenLabels.size();
for (auto iter = m_tokenInfo.begin<kLabels>(), itEnd = m_tokenInfo.end<kLabels>(); iter != itEnd; ++iter) {
unsigned int startOfModuleLabel = iter->m_startOfModuleLabel;
unsigned short deltaToProcessName = iter->m_deltaToProcessName;
Expand Down
20 changes: 20 additions & 0 deletions FWCore/Integration/test/ESTestAnalyzers.cc
@@ -1,6 +1,7 @@
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/stream/EDAnalyzer.h"
#include "DataFormats/Provenance/interface/ModuleDescription.h"
#include "DataFormats/TestObjects/interface/ToyProducts.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
Expand Down Expand Up @@ -213,10 +214,29 @@ namespace edmtest {
<< ": Data values = " << dataJ->value();
}

class ESTestAnalyzerL : public edm::stream::EDAnalyzer<> {
public:
explicit ESTestAnalyzerL(edm::ParameterSet const& iConfig)
: edToken_(consumes(iConfig.getParameter<edm::InputTag>("src"))), esToken_(esConsumes()) {}
void analyze(const edm::Event&, const edm::EventSetup&) override;

private:
edm::EDGetTokenT<IntProduct> edToken_;
edm::ESGetToken<ESTestDataJ, ESTestRecordJ> esToken_;
};

void ESTestAnalyzerL::analyze(edm::Event const& ev, edm::EventSetup const& es) {
auto const& intData = ev.get(edToken_);
auto const& dataJ = es.getData(esToken_);
edm::LogAbsolute("ESTestAnalyzerJ") << "ESTestAnalyzerL: process = " << moduleDescription().processName()
<< ": ED value " << intData.value << ": ES value = " << dataJ.value();
}

} // namespace edmtest
using namespace edmtest;
DEFINE_FWK_MODULE(ESTestAnalyzerA);
DEFINE_FWK_MODULE(ESTestAnalyzerB);
DEFINE_FWK_MODULE(ESTestAnalyzerK);
DEFINE_FWK_MODULE(ESTestAnalyzerAZ);
DEFINE_FWK_MODULE(ESTestAnalyzerJ);
DEFINE_FWK_MODULE(ESTestAnalyzerL);
42 changes: 42 additions & 0 deletions FWCore/Integration/test/EventSetupTestCurrentProcess_cfg.py
@@ -0,0 +1,42 @@
import FWCore.ParameterSet.Config as cms

process = cms.Process("TEST")

process.load("FWCore.Framework.test.cmsExceptionsFatal_cff")

process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(3)
)

process.source = cms.Source("EmptySource",
numberEventsInRun = cms.untracked.uint32(3)
)

process.WhatsItESProducer = cms.ESProducer("WhatsItESProducer")

process.DoodadESSource = cms.ESSource("DoodadESSource")

process.emptyESSourceK = cms.ESSource("EmptyESSource",
recordName = cms.string("ESTestRecordK"),
firstValid = cms.vuint32(1,2,3),
iovIsRunNotTime = cms.bool(True)
)

process.testDataProxyProviderJ = cms.ESProducer("ESTestDataProxyProviderJ",
expectedCacheIds = cms.untracked.vuint32(2, 3, 4)
)

process.intProducer = cms.EDProducer("IntProducer", ivalue = cms.int32(1))

process.esAnalyzerL1 = cms.EDAnalyzer("ESTestAnalyzerL",
src = cms.InputTag("intProducer")
)
process.esAnalyzerL2 = cms.EDAnalyzer("ESTestAnalyzerL",
src = cms.InputTag("intProducer", "", cms.InputTag.currentProcess())
)

process.p = cms.Path(
process.intProducer+
process.esAnalyzerL1+
process.esAnalyzerL2
)
3 changes: 3 additions & 0 deletions FWCore/Integration/test/eventSetupTest.sh
Expand Up @@ -30,4 +30,7 @@ cmsRun --parameter-set ${LOCAL_TEST_DIR}/testEventSetupRunLumi_cfg.py || die 'Fa
echo testConcurrentIOVsESSource_cfg.py
cmsRun --parameter-set ${LOCAL_TEST_DIR}/testConcurrentIOVsESSource_cfg.py || die 'Failed in testConcurrentIOVsESSource_cfg.py' $?

echo EventSetupTestCurrentProcess_cfg.py
cmsRun ${LOCAL_TEST_DIR}/EventSetupTestCurrentProcess_cfg.py || die 'Failed in EventSetupTestCurrentProcess_cfg.py' $?

popd

0 comments on commit c608f97

Please sign in to comment.