Skip to content

Commit 87efee3

Browse files
committed
Fix meta-data and Service issues in TestSourceProcessor
Testing using PoolSource uncovered these issues.
1 parent ff4d600 commit 87efee3

File tree

5 files changed

+62
-8
lines changed

5 files changed

+62
-8
lines changed

FWCore/TestProcessor/interface/EventFromSource.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "FWCore/TestProcessor/interface/TestHandle.h"
2626
#include "FWCore/Framework/interface/EventPrincipal.h"
2727
#include "FWCore/Utilities/interface/TypeID.h"
28+
#include "FWCore/ServiceRegistry/interface/ServiceToken.h"
29+
#include "FWCore/ServiceRegistry/interface/ServiceRegistry.h"
2830

2931
// forward declarations
3032

@@ -35,13 +37,16 @@ namespace edm {
3537

3638
class EventFromSource {
3739
public:
38-
EventFromSource(EventPrincipal const& iPrincipal) : principal_(&iPrincipal) {}
40+
EventFromSource(EventPrincipal const& iPrincipal, edm::ServiceToken iToken)
41+
: principal_(&iPrincipal), token_(iToken) {}
3942

4043
// ---------- const member functions ---------------------
4144
template <typename T>
4245
TestHandle<T> get(std::string const& iModule,
4346
std::string const& iInstanceLabel,
4447
std::string const& iProcess) const {
48+
ServiceRegistry::Operate operate(token_);
49+
4550
auto h = principal_->getByLabel(
4651
edm::PRODUCT_TYPE, edm::TypeID(typeid(T)), iModule, iInstanceLabel, iProcess, nullptr, nullptr, nullptr);
4752
if (h.failedToGet()) {
@@ -61,6 +66,7 @@ namespace edm {
6166
private:
6267
// ---------- member data --------------------------------
6368
EventPrincipal const* principal_;
69+
edm::ServiceToken token_;
6470
};
6571
} // namespace test
6672
} // namespace edm

FWCore/TestProcessor/interface/LuminosityBlockFromSource.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "FWCore/TestProcessor/interface/TestHandle.h"
2626
#include "FWCore/Framework/interface/LuminosityBlockPrincipal.h"
2727
#include "FWCore/Utilities/interface/TypeID.h"
28+
#include "FWCore/ServiceRegistry/interface/ServiceToken.h"
29+
#include "FWCore/ServiceRegistry/interface/ServiceRegistry.h"
2830

2931
// forward declarations
3032

@@ -34,13 +36,16 @@ namespace edm {
3436

3537
class LuminosityBlockFromSource {
3638
public:
37-
LuminosityBlockFromSource(std::shared_ptr<LuminosityBlockPrincipal const> iPrincipal) : principal_(iPrincipal) {}
39+
LuminosityBlockFromSource(std::shared_ptr<LuminosityBlockPrincipal const> iPrincipal, edm::ServiceToken iToken)
40+
: principal_(iPrincipal), token_(iToken) {}
3841

3942
// ---------- const member functions ---------------------
4043
template <typename T>
4144
TestHandle<T> get(std::string const& iModule,
4245
std::string const& iInstanceLabel,
4346
std::string const& iProcess) const {
47+
ServiceRegistry::Operate operate(token_);
48+
4449
auto h = principal_->getByLabel(
4550
edm::PRODUCT_TYPE, edm::TypeID(typeid(T)), iModule, iInstanceLabel, iProcess, nullptr, nullptr, nullptr);
4651
if (h.failedToGet()) {
@@ -63,6 +68,7 @@ namespace edm {
6368
private:
6469
// ---------- member data --------------------------------
6570
std::shared_ptr<LuminosityBlockPrincipal const> principal_;
71+
edm::ServiceToken token_;
6672
};
6773
} // namespace test
6874
} // namespace edm

FWCore/TestProcessor/interface/RunFromSource.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "FWCore/TestProcessor/interface/TestHandle.h"
2626
#include "FWCore/Framework/interface/RunPrincipal.h"
2727
#include "FWCore/Utilities/interface/TypeID.h"
28+
#include "FWCore/ServiceRegistry/interface/ServiceToken.h"
29+
#include "FWCore/ServiceRegistry/interface/ServiceRegistry.h"
2830

2931
// forward declarations
3032

@@ -34,13 +36,16 @@ namespace edm {
3436

3537
class RunFromSource {
3638
public:
37-
RunFromSource(std::shared_ptr<RunPrincipal const> iPrincipal) : principal_(iPrincipal) {}
39+
RunFromSource(std::shared_ptr<RunPrincipal const> iPrincipal, edm::ServiceToken iToken)
40+
: principal_(iPrincipal), token_(iToken) {}
3841

3942
// ---------- const member functions ---------------------
4043
template <typename T>
4144
TestHandle<T> get(std::string const& iModule,
4245
std::string const& iInstanceLabel,
4346
std::string const& iProcess) const {
47+
ServiceRegistry::Operate operate(token_);
48+
4449
auto h = principal_->getByLabel(
4550
edm::PRODUCT_TYPE, edm::TypeID(typeid(T)), iModule, iInstanceLabel, iProcess, nullptr, nullptr, nullptr);
4651
if (h.failedToGet()) {
@@ -58,6 +63,7 @@ namespace edm {
5863
private:
5964
// ---------- member data --------------------------------
6065
std::shared_ptr<RunPrincipal const> principal_;
66+
edm::ServiceToken token_;
6167
};
6268
} // namespace test
6369
} // namespace edm

FWCore/TestProcessor/interface/TestSourceProcessor.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include "FWCore/Framework/interface/PrincipalCache.h"
3535
#include "FWCore/Framework/interface/SignallingProductRegistry.h"
3636
#include "FWCore/Framework/interface/PreallocationConfiguration.h"
37+
#include "FWCore/Framework/interface/MergeableRunProductProcesses.h"
38+
3739
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
3840
#include "FWCore/ServiceRegistry/interface/ProcessContext.h"
3941
#include "FWCore/ServiceRegistry/interface/ServiceLegacy.h"
@@ -49,6 +51,7 @@ namespace edm::test {
4951
class TestSourceProcessor {
5052
public:
5153
TestSourceProcessor(std::string const& iConfig, ServiceToken iToken = ServiceToken());
54+
~TestSourceProcessor();
5255

5356
InputSource::ItemTypeInfo findNextTransition();
5457

@@ -62,7 +65,6 @@ namespace edm::test {
6265
edm::test::EventFromSource readEvent();
6366

6467
private:
65-
std::unique_ptr<edm::InputSource> source_;
6668
edm::InputSource::ItemTypeInfo lastTransition_;
6769

6870
oneapi::tbb::global_control globalControl_;
@@ -77,13 +79,16 @@ namespace edm::test {
7779

7880
std::shared_ptr<ProcessConfiguration const> processConfiguration_;
7981
ProcessContext processContext_;
82+
MergeableRunProductProcesses mergeableRunProductProcesses_;
8083

8184
ProcessHistoryRegistry processHistoryRegistry_;
8285
std::unique_ptr<HistoryAppender> historyAppender_;
8386

8487
PrincipalCache principalCache_;
8588
PreallocationConfiguration preallocations_;
8689

90+
std::unique_ptr<edm::InputSource> source_;
91+
8792
std::shared_ptr<RunPrincipal> runPrincipal_;
8893
std::shared_ptr<LuminosityBlockPrincipal> lumiPrincipal_;
8994

FWCore/TestProcessor/src/TestSourceProcessor.cc

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,14 @@ namespace edm::test {
161161
actReg_ = items.actReg_;
162162
branchIDListHelper_ = items.branchIDListHelper();
163163
thinnedAssociationsHelper_ = items.thinnedAssociationsHelper();
164+
processConfiguration_ = items.processConfiguration();
165+
164166
processContext_.setProcessConfiguration(processConfiguration_.get());
165167
preg_ = items.preg();
166168
principalCache_.setNumberOfConcurrentPrincipals(preallocations_);
167169

168170
preg_->setFrozen();
171+
mergeableRunProductProcesses_.setProcessesWithMergeableRunProducts(*preg_);
169172

170173
for (unsigned int index = 0; index < preallocations_.numberOfStreams(); ++index) {
171174
// Reusable event principal
@@ -174,7 +177,8 @@ namespace edm::test {
174177
principalCache_.insert(std::move(ep));
175178
}
176179
for (unsigned int index = 0; index < preallocations_.numberOfRuns(); ++index) {
177-
auto rp = std::make_unique<RunPrincipal>(preg_, *processConfiguration_, historyAppender_.get(), index);
180+
auto rp = std::make_unique<RunPrincipal>(
181+
preg_, *processConfiguration_, historyAppender_.get(), index, true, &mergeableRunProductProcesses_);
178182
principalCache_.insert(std::move(rp));
179183
}
180184
for (unsigned int index = 0; index < preallocations_.numberOfLuminosityBlocks(); ++index) {
@@ -190,12 +194,28 @@ namespace edm::test {
190194
source_->doBeginJob();
191195
}
192196

197+
TestSourceProcessor::~TestSourceProcessor() {
198+
//make the services available
199+
ServiceRegistry::Operate operate(serviceToken_);
200+
try {
201+
source_.reset();
202+
} catch (std::exception const& iExcept) {
203+
std::cerr << " caught exception while destroying TestSourceProcessor\n" << iExcept.what();
204+
}
205+
}
206+
193207
edm::InputSource::ItemTypeInfo TestSourceProcessor::findNextTransition() {
208+
//make the services available
209+
ServiceRegistry::Operate operate(serviceToken_);
210+
194211
lastTransition_ = source_->nextItemType();
195212
return lastTransition_;
196213
}
197214

198215
std::shared_ptr<FileBlock> TestSourceProcessor::openFile() {
216+
//make the services available
217+
ServiceRegistry::Operate operate(serviceToken_);
218+
199219
size_t size = preg_->size();
200220
fb_ = source_->readFile();
201221
if (size < preg_->size()) {
@@ -217,6 +237,9 @@ namespace edm::test {
217237
<< "closeFile given a FileBlock that does not correspond to the one returned by openFile";
218238
}
219239
if (fb_) {
240+
//make the services available
241+
ServiceRegistry::Operate operate(serviceToken_);
242+
220243
source_->closeFile(fb_.get(), false);
221244
}
222245
}
@@ -225,12 +248,15 @@ namespace edm::test {
225248
if (lastTransition_.itemType() != edm::InputSource::ItemType::IsRun) {
226249
throw cms::Exception("NotARun") << "The last transition is " << name(lastTransition_.itemType()) << " not a Run";
227250
}
251+
//make the services available
252+
ServiceRegistry::Operate operate(serviceToken_);
253+
228254
//NOTE: should probably handle merging as well
229255
runPrincipal_ = principalCache_.getAvailableRunPrincipalPtr();
230256
runPrincipal_->setAux(*source_->runAuxiliary());
231257
source_->readRun(*runPrincipal_, *historyAppender_);
232258

233-
return edm::test::RunFromSource(runPrincipal_);
259+
return edm::test::RunFromSource(runPrincipal_, serviceToken_);
234260
}
235261

236262
edm::test::LuminosityBlockFromSource TestSourceProcessor::readLuminosityBlock() {
@@ -239,25 +265,30 @@ namespace edm::test {
239265
<< "The last transition is " << name(lastTransition_.itemType()) << " not a LuminosityBlock";
240266
}
241267

268+
//make the services available
269+
ServiceRegistry::Operate operate(serviceToken_);
270+
242271
lumiPrincipal_ = principalCache_.getAvailableLumiPrincipalPtr();
243272
assert(lumiPrincipal_);
244273
lumiPrincipal_->setAux(*source_->luminosityBlockAuxiliary());
245274
source_->readLuminosityBlock(*lumiPrincipal_, *historyAppender_);
246275

247-
return edm::test::LuminosityBlockFromSource(lumiPrincipal_);
276+
return edm::test::LuminosityBlockFromSource(lumiPrincipal_, serviceToken_);
248277
}
249278

250279
edm::test::EventFromSource TestSourceProcessor::readEvent() {
251280
if (lastTransition_.itemType() != edm::InputSource::ItemType::IsEvent) {
252281
throw cms::Exception("NotAnEvent") << "The last transition is " << name(lastTransition_.itemType())
253282
<< " not a Event";
254283
}
284+
//make the services available
285+
ServiceRegistry::Operate operate(serviceToken_);
255286

256287
auto& event = principalCache_.eventPrincipal(0);
257288
StreamContext streamContext(event.streamID(), &processContext_);
258289

259290
source_->readEvent(event, streamContext);
260291

261-
return edm::test::EventFromSource(event);
292+
return edm::test::EventFromSource(event, serviceToken_);
262293
}
263294
} // namespace edm::test

0 commit comments

Comments
 (0)