Skip to content

Commit a513adf

Browse files
authored
Merge pull request #45443 from Dr15Jones/testSourceProcessor
Added TestSourceProcessor helper
2 parents a0e108b + 9bbc86a commit a513adf

16 files changed

+1058
-40
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#ifndef FWCore_TestProcessor_EventFromSource_h
2+
#define FWCore_TestProcessor_EventFromSource_h
3+
// -*- C++ -*-
4+
//
5+
// Package: FWCore/TestProcessor
6+
// Class : EventFromSource
7+
//
8+
/**\class EventFromSource EventFromSource.h "EventFromSource.h"
9+
10+
Description: [one line class summary]
11+
12+
Usage:
13+
<usage>
14+
15+
*/
16+
//
17+
// Original Author: Chris Jones
18+
// Created: Mon, 30 Apr 2018 18:51:27 GMT
19+
//
20+
21+
// system include files
22+
#include <string>
23+
24+
// user include files
25+
#include "FWCore/TestProcessor/interface/TestHandle.h"
26+
#include "FWCore/Framework/interface/EventPrincipal.h"
27+
#include "FWCore/Utilities/interface/TypeID.h"
28+
#include "FWCore/ServiceRegistry/interface/ServiceToken.h"
29+
#include "FWCore/ServiceRegistry/interface/ServiceRegistry.h"
30+
31+
// forward declarations
32+
33+
namespace edm {
34+
class EventFromSourcePrincipal;
35+
36+
namespace test {
37+
38+
class EventFromSource {
39+
public:
40+
EventFromSource(EventPrincipal const& iPrincipal, edm::ServiceToken iToken)
41+
: principal_(&iPrincipal), token_(iToken) {}
42+
43+
// ---------- const member functions ---------------------
44+
template <typename T>
45+
TestHandle<T> get(std::string const& iModule,
46+
std::string const& iInstanceLabel,
47+
std::string const& iProcess) const {
48+
ServiceRegistry::Operate operate(token_);
49+
50+
auto h = principal_->getByLabel(
51+
edm::PRODUCT_TYPE, edm::TypeID(typeid(T)), iModule, iInstanceLabel, iProcess, nullptr, nullptr, nullptr);
52+
if (h.failedToGet()) {
53+
return TestHandle<T>(std::move(h.whyFailedFactory()));
54+
}
55+
void const* basicWrapper = h.wrapper();
56+
assert(basicWrapper);
57+
Wrapper<T> const* wrapper = static_cast<Wrapper<T> const*>(basicWrapper);
58+
return TestHandle<T>(wrapper->product());
59+
}
60+
61+
RunNumber_t run() const { return principal_->run(); }
62+
LuminosityBlockNumber_t luminosityBlock() const { return principal_->luminosityBlock(); }
63+
EventNumber_t event() const { return principal_->aux().event(); }
64+
EventAuxiliary const& aux() const { return principal_->aux(); }
65+
66+
private:
67+
// ---------- member data --------------------------------
68+
EventPrincipal const* principal_;
69+
edm::ServiceToken token_;
70+
};
71+
} // namespace test
72+
} // namespace edm
73+
74+
#endif
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#ifndef FWCore_TestProcessor_LuminosityBlockFromSource_h
2+
#define FWCore_TestProcessor_LuminosityBlockFromSource_h
3+
// -*- C++ -*-
4+
//
5+
// Package: FWCore/TestProcessor
6+
// Class : LuminosityBlockFromSource
7+
//
8+
/**\class LuminosityBlockFromSource LuminosityBlockFromSource.h "LuminosityBlockFromSource.h"
9+
10+
Description: [one line class summary]
11+
12+
Usage:
13+
<usage>
14+
15+
*/
16+
//
17+
// Original Author: Chris Jones
18+
// Created: Mon, 30 Apr 2018 18:51:27 GMT
19+
//
20+
21+
// system include files
22+
#include <string>
23+
24+
// user include files
25+
#include "FWCore/TestProcessor/interface/TestHandle.h"
26+
#include "FWCore/Framework/interface/LuminosityBlockPrincipal.h"
27+
#include "FWCore/Utilities/interface/TypeID.h"
28+
#include "FWCore/ServiceRegistry/interface/ServiceToken.h"
29+
#include "FWCore/ServiceRegistry/interface/ServiceRegistry.h"
30+
31+
// forward declarations
32+
33+
namespace edm {
34+
35+
namespace test {
36+
37+
class LuminosityBlockFromSource {
38+
public:
39+
LuminosityBlockFromSource(std::shared_ptr<LuminosityBlockPrincipal const> iPrincipal, edm::ServiceToken iToken)
40+
: principal_(iPrincipal), token_(iToken) {}
41+
42+
// ---------- const member functions ---------------------
43+
template <typename T>
44+
TestHandle<T> get(std::string const& iModule,
45+
std::string const& iInstanceLabel,
46+
std::string const& iProcess) const {
47+
ServiceRegistry::Operate operate(token_);
48+
49+
auto h = principal_->getByLabel(
50+
edm::PRODUCT_TYPE, edm::TypeID(typeid(T)), iModule, iInstanceLabel, iProcess, nullptr, nullptr, nullptr);
51+
if (h.failedToGet()) {
52+
return TestHandle<T>(std::move(h.whyFailedFactory()));
53+
}
54+
void const* basicWrapper = h.wrapper();
55+
assert(basicWrapper);
56+
Wrapper<T> const* wrapper = static_cast<Wrapper<T> const*>(basicWrapper);
57+
return TestHandle<T>(wrapper->product());
58+
}
59+
60+
RunNumber_t run() const { return principal_->run(); }
61+
LuminosityBlockNumber_t luminosityBlock() const { return principal_->luminosityBlock(); }
62+
LuminosityBlockAuxiliary const& aux() const { return principal_->aux(); }
63+
64+
// ---------- static member functions --------------------
65+
66+
// ---------- member functions ---------------------------
67+
68+
private:
69+
// ---------- member data --------------------------------
70+
std::shared_ptr<LuminosityBlockPrincipal const> principal_;
71+
edm::ServiceToken token_;
72+
};
73+
} // namespace test
74+
} // namespace edm
75+
76+
#endif
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#ifndef FWCore_TestProcessor_RunFromSource_h
2+
#define FWCore_TestProcessor_RunFromSource_h
3+
// -*- C++ -*-
4+
//
5+
// Package: FWCore/TestProcessor
6+
// Class : RunFromSource
7+
//
8+
/**\class RunFromSource RunFromSource.h "RunFromSource.h"
9+
10+
Description: [one line class summary]
11+
12+
Usage:
13+
<usage>
14+
15+
*/
16+
//
17+
// Original Author: Chris Jones
18+
// Created: Mon, 30 Apr 2018 18:51:27 GMT
19+
//
20+
21+
// system include files
22+
#include <string>
23+
24+
// user include files
25+
#include "FWCore/TestProcessor/interface/TestHandle.h"
26+
#include "FWCore/Framework/interface/RunPrincipal.h"
27+
#include "FWCore/Utilities/interface/TypeID.h"
28+
#include "FWCore/ServiceRegistry/interface/ServiceToken.h"
29+
#include "FWCore/ServiceRegistry/interface/ServiceRegistry.h"
30+
31+
// forward declarations
32+
33+
namespace edm {
34+
35+
namespace test {
36+
37+
class RunFromSource {
38+
public:
39+
RunFromSource(std::shared_ptr<RunPrincipal const> iPrincipal, edm::ServiceToken iToken)
40+
: principal_(iPrincipal), token_(iToken) {}
41+
42+
// ---------- const member functions ---------------------
43+
template <typename T>
44+
TestHandle<T> get(std::string const& iModule,
45+
std::string const& iInstanceLabel,
46+
std::string const& iProcess) const {
47+
ServiceRegistry::Operate operate(token_);
48+
49+
auto h = principal_->getByLabel(
50+
edm::PRODUCT_TYPE, edm::TypeID(typeid(T)), iModule, iInstanceLabel, iProcess, nullptr, nullptr, nullptr);
51+
if (h.failedToGet()) {
52+
return TestHandle<T>(std::move(h.whyFailedFactory()));
53+
}
54+
void const* basicWrapper = h.wrapper();
55+
assert(basicWrapper);
56+
Wrapper<T> const* wrapper = static_cast<Wrapper<T> const*>(basicWrapper);
57+
return TestHandle<T>(wrapper->product());
58+
}
59+
60+
RunNumber_t run() const { return principal_->run(); }
61+
RunAuxiliary const& aux() const { return principal_->aux(); }
62+
63+
private:
64+
// ---------- member data --------------------------------
65+
std::shared_ptr<RunPrincipal const> principal_;
66+
edm::ServiceToken token_;
67+
};
68+
} // namespace test
69+
} // namespace edm
70+
71+
#endif

FWCore/TestProcessor/interface/TestProcessor.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include "FWCore/Framework/interface/Schedule.h"
3737
#include "FWCore/Framework/interface/EventSetupRecordKey.h"
3838
#include "FWCore/Framework/interface/DataKey.h"
39+
#include "FWCore/Framework/interface/MergeableRunProductProcesses.h"
40+
3941
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
4042
#include "FWCore/ServiceRegistry/interface/ProcessContext.h"
4143
#include "FWCore/ServiceRegistry/interface/ServiceLegacy.h"
@@ -317,13 +319,17 @@ This simulates a problem happening early in the job which causes processing not
317319
void teardownProcessing();
318320

319321
void beginJob();
322+
void respondToOpenInputFile();
323+
void openOutputFiles();
320324
void beginProcessBlock();
321325
void beginRun();
322326
void beginLuminosityBlock();
323327
void event();
324328
std::shared_ptr<LuminosityBlockPrincipal> endLuminosityBlock();
325329
std::shared_ptr<RunPrincipal> endRun();
330+
void respondToCloseInputFile();
326331
ProcessBlockPrincipal const* endProcessBlock();
332+
void closeOutputFiles();
327333
void endJob();
328334

329335
// ---------- member data --------------------------------
@@ -346,7 +352,10 @@ This simulates a problem happening early in the job which causes processing not
346352
std::shared_ptr<ProcessConfiguration const> processConfiguration_;
347353
ProcessContext processContext_;
348354

355+
MergeableRunProductProcesses mergeableRunProductProcesses_;
356+
349357
ProcessHistoryRegistry processHistoryRegistry_;
358+
ProcessHistory processHistory_;
350359
std::unique_ptr<HistoryAppender> historyAppender_;
351360

352361
PrincipalCache principalCache_;
@@ -363,9 +372,11 @@ This simulates a problem happening early in the job which causes processing not
363372
LuminosityBlockNumber_t lumiNumber_ = 1;
364373
EventNumber_t eventNumber_ = 1;
365374
bool beginJobCalled_ = false;
375+
bool respondToOpenInputFileCalled_ = false;
366376
bool beginProcessBlockCalled_ = false;
367377
bool beginRunCalled_ = false;
368378
bool beginLumiCalled_ = false;
379+
bool openOutputFilesCalled_ = false;
369380
};
370381
} // namespace test
371382
} // namespace edm
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#ifndef FWCore_TestProcessor_TestSourceProcessor_h
2+
#define FWCore_TestProcessor_TestSourceProcessor_h
3+
// -*- C++ -*-
4+
//
5+
// Package: FWCore/TestProcessor
6+
// Class : TestSourceProcessor
7+
//
8+
/**\class TestSourceProcessor TestSourceProcessor.h "TestSourceProcessor.h"
9+
10+
Description: Used for testing InputSources
11+
12+
Usage:
13+
<usage>
14+
15+
*/
16+
//
17+
// Original Author: Chris Jones
18+
// Created: Mon, 30 Apr 2018 18:51:00 GMT
19+
//
20+
#include <string>
21+
#include <utility>
22+
#include <memory>
23+
#include "oneapi/tbb/global_control.h"
24+
#include "oneapi/tbb/task_arena.h"
25+
#include "oneapi/tbb/task_group.h"
26+
27+
#include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h"
28+
29+
#include "FWCore/Common/interface/FWCoreCommonFwd.h"
30+
31+
#include "FWCore/Framework/interface/HistoryAppender.h"
32+
#include "FWCore/Framework/interface/InputSource.h"
33+
#include "FWCore/Framework/interface/SharedResourcesAcquirer.h"
34+
#include "FWCore/Framework/interface/PrincipalCache.h"
35+
#include "FWCore/Framework/interface/SignallingProductRegistry.h"
36+
#include "FWCore/Framework/interface/PreallocationConfiguration.h"
37+
#include "FWCore/Framework/interface/MergeableRunProductProcesses.h"
38+
39+
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
40+
#include "FWCore/ServiceRegistry/interface/ProcessContext.h"
41+
#include "FWCore/ServiceRegistry/interface/ServiceLegacy.h"
42+
#include "FWCore/ServiceRegistry/interface/ServiceToken.h"
43+
44+
#include "FWCore/TestProcessor/interface/EventFromSource.h"
45+
#include "FWCore/TestProcessor/interface/LuminosityBlockFromSource.h"
46+
#include "FWCore/TestProcessor/interface/ProcessBlock.h"
47+
#include "FWCore/TestProcessor/interface/RunFromSource.h"
48+
49+
namespace edm::test {
50+
51+
class TestSourceProcessor {
52+
public:
53+
TestSourceProcessor(std::string const& iConfig, ServiceToken iToken = ServiceToken());
54+
~TestSourceProcessor();
55+
56+
InputSource::ItemTypeInfo findNextTransition();
57+
58+
std::shared_ptr<FileBlock> openFile();
59+
void closeFile(std::shared_ptr<FileBlock>);
60+
61+
edm::test::RunFromSource readRun();
62+
63+
edm::test::LuminosityBlockFromSource readLuminosityBlock();
64+
65+
edm::test::EventFromSource readEvent();
66+
67+
private:
68+
edm::InputSource::ItemTypeInfo lastTransition_;
69+
70+
oneapi::tbb::global_control globalControl_;
71+
oneapi::tbb::task_group taskGroup_;
72+
oneapi::tbb::task_arena arena_;
73+
std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
74+
std::shared_ptr<ProductRegistry> preg_;
75+
std::shared_ptr<BranchIDListHelper> branchIDListHelper_;
76+
std::shared_ptr<ProcessBlockHelper> processBlockHelper_;
77+
std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper_;
78+
ServiceToken serviceToken_;
79+
80+
std::shared_ptr<ProcessConfiguration const> processConfiguration_;
81+
ProcessContext processContext_;
82+
MergeableRunProductProcesses mergeableRunProductProcesses_;
83+
84+
ProcessHistoryRegistry processHistoryRegistry_;
85+
std::unique_ptr<HistoryAppender> historyAppender_;
86+
87+
PrincipalCache principalCache_;
88+
PreallocationConfiguration preallocations_;
89+
90+
std::unique_ptr<edm::InputSource> source_;
91+
92+
std::shared_ptr<RunPrincipal> runPrincipal_;
93+
std::shared_ptr<LuminosityBlockPrincipal> lumiPrincipal_;
94+
95+
std::shared_ptr<FileBlock> fb_;
96+
};
97+
} // namespace edm::test
98+
99+
#endif

FWCore/TestProcessor/python/TestProcess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def moduleToTest(self,mod,task=cms.Task()):
1212
self._test_endpath = cms.EndPath(mod,task)
1313
def fillProcessDesc(self, processPSet):
1414
if self.__dict__["_TestProcess__moduleToTest"] is None:
15-
raise LogicError("moduleToTest was not called")
15+
raise RuntimeError("moduleToTest was not called")
1616
for p in self.paths.iterkeys():
1717
if p != "_test_path":
1818
delattr(self,p)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import FWCore.ParameterSet.Config as cms
2+
3+
class TestSourceProcess(cms.Process):
4+
def __init__(self,name="TEST",*modifiers):
5+
super(TestSourceProcess,self).__init__(name,*modifiers)
6+
def fillProcessDesc(self, processPSet):
7+
if not hasattr(self,"options"):
8+
self.options = cms.untracked.PSet()
9+
cms.Process.fillProcessDesc(self,processPSet)

0 commit comments

Comments
 (0)