Skip to content

Commit 078d2cb

Browse files
committed
Added TestSourceProcessor testing helper
This is similar to TestProcessor but specialized for testing Sources.
1 parent 864c800 commit 078d2cb

File tree

8 files changed

+677
-1
lines changed

8 files changed

+677
-1
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
29+
// forward declarations
30+
31+
namespace edm {
32+
class EventFromSourcePrincipal;
33+
34+
namespace test {
35+
36+
class EventFromSource {
37+
public:
38+
EventFromSource(EventPrincipal const& iPrincipal) : principal_(&iPrincipal) {}
39+
40+
// ---------- const member functions ---------------------
41+
template <typename T>
42+
TestHandle<T> get(std::string const& iModule,
43+
std::string const& iInstanceLabel,
44+
std::string const& iProcess) const {
45+
auto h = principal_->getByLabel(
46+
edm::PRODUCT_TYPE, edm::TypeID(typeid(T)), iModule, iInstanceLabel, iProcess, nullptr, nullptr, nullptr);
47+
if (h.failedToGet()) {
48+
return TestHandle<T>(std::move(h.whyFailedFactory()));
49+
}
50+
void const* basicWrapper = h.wrapper();
51+
assert(basicWrapper);
52+
Wrapper<T> const* wrapper = static_cast<Wrapper<T> const*>(basicWrapper);
53+
return TestHandle<T>(wrapper->product());
54+
}
55+
56+
RunNumber_t run() const { return principal_->run(); }
57+
LuminosityBlockNumber_t luminosityBlock() const { return principal_->luminosityBlock(); }
58+
EventNumber_t event() const { return principal_->aux().event(); }
59+
EventAuxiliary const& aux() const { return principal_->aux(); }
60+
61+
private:
62+
// ---------- member data --------------------------------
63+
EventPrincipal const* principal_;
64+
};
65+
} // namespace test
66+
} // namespace edm
67+
68+
#endif
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
29+
// forward declarations
30+
31+
namespace edm {
32+
33+
namespace test {
34+
35+
class LuminosityBlockFromSource {
36+
public:
37+
LuminosityBlockFromSource(std::shared_ptr<LuminosityBlockPrincipal const> iPrincipal) : principal_(iPrincipal) {}
38+
39+
// ---------- const member functions ---------------------
40+
template <typename T>
41+
TestHandle<T> get(std::string const& iModule,
42+
std::string const& iInstanceLabel,
43+
std::string const& iProcess) const {
44+
auto h = principal_->getByLabel(
45+
edm::PRODUCT_TYPE, edm::TypeID(typeid(T)), iModule, iInstanceLabel, iProcess, nullptr, nullptr, nullptr);
46+
if (h.failedToGet()) {
47+
return TestHandle<T>(std::move(h.whyFailedFactory()));
48+
}
49+
void const* basicWrapper = h.wrapper();
50+
assert(basicWrapper);
51+
Wrapper<T> const* wrapper = static_cast<Wrapper<T> const*>(basicWrapper);
52+
return TestHandle<T>(wrapper->product());
53+
}
54+
55+
RunNumber_t run() const { return principal_->run(); }
56+
LuminosityBlockNumber_t luminosityBlock() const { return principal_->luminosityBlock(); }
57+
LuminosityBlockAuxiliary const& aux() const { return principal_->aux(); }
58+
59+
// ---------- static member functions --------------------
60+
61+
// ---------- member functions ---------------------------
62+
63+
private:
64+
// ---------- member data --------------------------------
65+
std::shared_ptr<LuminosityBlockPrincipal const> principal_;
66+
};
67+
} // namespace test
68+
} // namespace edm
69+
70+
#endif
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
29+
// forward declarations
30+
31+
namespace edm {
32+
33+
namespace test {
34+
35+
class RunFromSource {
36+
public:
37+
RunFromSource(std::shared_ptr<RunPrincipal const> iPrincipal) : principal_(iPrincipal) {}
38+
39+
// ---------- const member functions ---------------------
40+
template <typename T>
41+
TestHandle<T> get(std::string const& iModule,
42+
std::string const& iInstanceLabel,
43+
std::string const& iProcess) const {
44+
auto h = principal_->getByLabel(
45+
edm::PRODUCT_TYPE, edm::TypeID(typeid(T)), iModule, iInstanceLabel, iProcess, nullptr, nullptr, nullptr);
46+
if (h.failedToGet()) {
47+
return TestHandle<T>(std::move(h.whyFailedFactory()));
48+
}
49+
void const* basicWrapper = h.wrapper();
50+
assert(basicWrapper);
51+
Wrapper<T> const* wrapper = static_cast<Wrapper<T> const*>(basicWrapper);
52+
return TestHandle<T>(wrapper->product());
53+
}
54+
55+
RunNumber_t run() const { return principal_->run(); }
56+
RunAuxiliary const& aux() const { return principal_->aux(); }
57+
58+
private:
59+
// ---------- member data --------------------------------
60+
std::shared_ptr<RunPrincipal const> principal_;
61+
};
62+
} // namespace test
63+
} // namespace edm
64+
65+
#endif
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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/ServiceRegistry/interface/ActivityRegistry.h"
38+
#include "FWCore/ServiceRegistry/interface/ProcessContext.h"
39+
#include "FWCore/ServiceRegistry/interface/ServiceLegacy.h"
40+
#include "FWCore/ServiceRegistry/interface/ServiceToken.h"
41+
42+
#include "FWCore/TestProcessor/interface/EventFromSource.h"
43+
#include "FWCore/TestProcessor/interface/LuminosityBlockFromSource.h"
44+
#include "FWCore/TestProcessor/interface/ProcessBlock.h"
45+
#include "FWCore/TestProcessor/interface/RunFromSource.h"
46+
47+
namespace edm::test {
48+
49+
class TestSourceProcessor {
50+
public:
51+
TestSourceProcessor(std::string const& iConfig, ServiceToken iToken = ServiceToken());
52+
53+
InputSource::ItemTypeInfo findNextTransition();
54+
55+
std::shared_ptr<FileBlock> openFile();
56+
void closeFile(std::shared_ptr<FileBlock>);
57+
58+
edm::test::RunFromSource readRun();
59+
60+
edm::test::LuminosityBlockFromSource readLuminosityBlock();
61+
62+
edm::test::EventFromSource readEvent();
63+
64+
private:
65+
std::unique_ptr<edm::InputSource> source_;
66+
edm::InputSource::ItemTypeInfo lastTransition_;
67+
68+
oneapi::tbb::global_control globalControl_;
69+
oneapi::tbb::task_group taskGroup_;
70+
oneapi::tbb::task_arena arena_;
71+
std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
72+
std::shared_ptr<ProductRegistry> preg_;
73+
std::shared_ptr<BranchIDListHelper> branchIDListHelper_;
74+
std::shared_ptr<ProcessBlockHelper> processBlockHelper_;
75+
std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper_;
76+
ServiceToken serviceToken_;
77+
78+
std::shared_ptr<ProcessConfiguration const> processConfiguration_;
79+
ProcessContext processContext_;
80+
81+
ProcessHistoryRegistry processHistoryRegistry_;
82+
std::unique_ptr<HistoryAppender> historyAppender_;
83+
84+
PrincipalCache principalCache_;
85+
PreallocationConfiguration preallocations_;
86+
87+
std::shared_ptr<RunPrincipal> runPrincipal_;
88+
std::shared_ptr<LuminosityBlockPrincipal> lumiPrincipal_;
89+
90+
std::shared_ptr<FileBlock> fb_;
91+
};
92+
} // namespace edm::test
93+
94+
#endif
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)