-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45443 from Dr15Jones/testSourceProcessor
Added TestSourceProcessor helper
- Loading branch information
Showing
16 changed files
with
1,058 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#ifndef FWCore_TestProcessor_EventFromSource_h | ||
#define FWCore_TestProcessor_EventFromSource_h | ||
// -*- C++ -*- | ||
// | ||
// Package: FWCore/TestProcessor | ||
// Class : EventFromSource | ||
// | ||
/**\class EventFromSource EventFromSource.h "EventFromSource.h" | ||
Description: [one line class summary] | ||
Usage: | ||
<usage> | ||
*/ | ||
// | ||
// Original Author: Chris Jones | ||
// Created: Mon, 30 Apr 2018 18:51:27 GMT | ||
// | ||
|
||
// system include files | ||
#include <string> | ||
|
||
// user include files | ||
#include "FWCore/TestProcessor/interface/TestHandle.h" | ||
#include "FWCore/Framework/interface/EventPrincipal.h" | ||
#include "FWCore/Utilities/interface/TypeID.h" | ||
#include "FWCore/ServiceRegistry/interface/ServiceToken.h" | ||
#include "FWCore/ServiceRegistry/interface/ServiceRegistry.h" | ||
|
||
// forward declarations | ||
|
||
namespace edm { | ||
class EventFromSourcePrincipal; | ||
|
||
namespace test { | ||
|
||
class EventFromSource { | ||
public: | ||
EventFromSource(EventPrincipal const& iPrincipal, edm::ServiceToken iToken) | ||
: principal_(&iPrincipal), token_(iToken) {} | ||
|
||
// ---------- const member functions --------------------- | ||
template <typename T> | ||
TestHandle<T> get(std::string const& iModule, | ||
std::string const& iInstanceLabel, | ||
std::string const& iProcess) const { | ||
ServiceRegistry::Operate operate(token_); | ||
|
||
auto h = principal_->getByLabel( | ||
edm::PRODUCT_TYPE, edm::TypeID(typeid(T)), iModule, iInstanceLabel, iProcess, nullptr, nullptr, nullptr); | ||
if (h.failedToGet()) { | ||
return TestHandle<T>(std::move(h.whyFailedFactory())); | ||
} | ||
void const* basicWrapper = h.wrapper(); | ||
assert(basicWrapper); | ||
Wrapper<T> const* wrapper = static_cast<Wrapper<T> const*>(basicWrapper); | ||
return TestHandle<T>(wrapper->product()); | ||
} | ||
|
||
RunNumber_t run() const { return principal_->run(); } | ||
LuminosityBlockNumber_t luminosityBlock() const { return principal_->luminosityBlock(); } | ||
EventNumber_t event() const { return principal_->aux().event(); } | ||
EventAuxiliary const& aux() const { return principal_->aux(); } | ||
|
||
private: | ||
// ---------- member data -------------------------------- | ||
EventPrincipal const* principal_; | ||
edm::ServiceToken token_; | ||
}; | ||
} // namespace test | ||
} // namespace edm | ||
|
||
#endif |
76 changes: 76 additions & 0 deletions
76
FWCore/TestProcessor/interface/LuminosityBlockFromSource.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#ifndef FWCore_TestProcessor_LuminosityBlockFromSource_h | ||
#define FWCore_TestProcessor_LuminosityBlockFromSource_h | ||
// -*- C++ -*- | ||
// | ||
// Package: FWCore/TestProcessor | ||
// Class : LuminosityBlockFromSource | ||
// | ||
/**\class LuminosityBlockFromSource LuminosityBlockFromSource.h "LuminosityBlockFromSource.h" | ||
Description: [one line class summary] | ||
Usage: | ||
<usage> | ||
*/ | ||
// | ||
// Original Author: Chris Jones | ||
// Created: Mon, 30 Apr 2018 18:51:27 GMT | ||
// | ||
|
||
// system include files | ||
#include <string> | ||
|
||
// user include files | ||
#include "FWCore/TestProcessor/interface/TestHandle.h" | ||
#include "FWCore/Framework/interface/LuminosityBlockPrincipal.h" | ||
#include "FWCore/Utilities/interface/TypeID.h" | ||
#include "FWCore/ServiceRegistry/interface/ServiceToken.h" | ||
#include "FWCore/ServiceRegistry/interface/ServiceRegistry.h" | ||
|
||
// forward declarations | ||
|
||
namespace edm { | ||
|
||
namespace test { | ||
|
||
class LuminosityBlockFromSource { | ||
public: | ||
LuminosityBlockFromSource(std::shared_ptr<LuminosityBlockPrincipal const> iPrincipal, edm::ServiceToken iToken) | ||
: principal_(iPrincipal), token_(iToken) {} | ||
|
||
// ---------- const member functions --------------------- | ||
template <typename T> | ||
TestHandle<T> get(std::string const& iModule, | ||
std::string const& iInstanceLabel, | ||
std::string const& iProcess) const { | ||
ServiceRegistry::Operate operate(token_); | ||
|
||
auto h = principal_->getByLabel( | ||
edm::PRODUCT_TYPE, edm::TypeID(typeid(T)), iModule, iInstanceLabel, iProcess, nullptr, nullptr, nullptr); | ||
if (h.failedToGet()) { | ||
return TestHandle<T>(std::move(h.whyFailedFactory())); | ||
} | ||
void const* basicWrapper = h.wrapper(); | ||
assert(basicWrapper); | ||
Wrapper<T> const* wrapper = static_cast<Wrapper<T> const*>(basicWrapper); | ||
return TestHandle<T>(wrapper->product()); | ||
} | ||
|
||
RunNumber_t run() const { return principal_->run(); } | ||
LuminosityBlockNumber_t luminosityBlock() const { return principal_->luminosityBlock(); } | ||
LuminosityBlockAuxiliary const& aux() const { return principal_->aux(); } | ||
|
||
// ---------- static member functions -------------------- | ||
|
||
// ---------- member functions --------------------------- | ||
|
||
private: | ||
// ---------- member data -------------------------------- | ||
std::shared_ptr<LuminosityBlockPrincipal const> principal_; | ||
edm::ServiceToken token_; | ||
}; | ||
} // namespace test | ||
} // namespace edm | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#ifndef FWCore_TestProcessor_RunFromSource_h | ||
#define FWCore_TestProcessor_RunFromSource_h | ||
// -*- C++ -*- | ||
// | ||
// Package: FWCore/TestProcessor | ||
// Class : RunFromSource | ||
// | ||
/**\class RunFromSource RunFromSource.h "RunFromSource.h" | ||
Description: [one line class summary] | ||
Usage: | ||
<usage> | ||
*/ | ||
// | ||
// Original Author: Chris Jones | ||
// Created: Mon, 30 Apr 2018 18:51:27 GMT | ||
// | ||
|
||
// system include files | ||
#include <string> | ||
|
||
// user include files | ||
#include "FWCore/TestProcessor/interface/TestHandle.h" | ||
#include "FWCore/Framework/interface/RunPrincipal.h" | ||
#include "FWCore/Utilities/interface/TypeID.h" | ||
#include "FWCore/ServiceRegistry/interface/ServiceToken.h" | ||
#include "FWCore/ServiceRegistry/interface/ServiceRegistry.h" | ||
|
||
// forward declarations | ||
|
||
namespace edm { | ||
|
||
namespace test { | ||
|
||
class RunFromSource { | ||
public: | ||
RunFromSource(std::shared_ptr<RunPrincipal const> iPrincipal, edm::ServiceToken iToken) | ||
: principal_(iPrincipal), token_(iToken) {} | ||
|
||
// ---------- const member functions --------------------- | ||
template <typename T> | ||
TestHandle<T> get(std::string const& iModule, | ||
std::string const& iInstanceLabel, | ||
std::string const& iProcess) const { | ||
ServiceRegistry::Operate operate(token_); | ||
|
||
auto h = principal_->getByLabel( | ||
edm::PRODUCT_TYPE, edm::TypeID(typeid(T)), iModule, iInstanceLabel, iProcess, nullptr, nullptr, nullptr); | ||
if (h.failedToGet()) { | ||
return TestHandle<T>(std::move(h.whyFailedFactory())); | ||
} | ||
void const* basicWrapper = h.wrapper(); | ||
assert(basicWrapper); | ||
Wrapper<T> const* wrapper = static_cast<Wrapper<T> const*>(basicWrapper); | ||
return TestHandle<T>(wrapper->product()); | ||
} | ||
|
||
RunNumber_t run() const { return principal_->run(); } | ||
RunAuxiliary const& aux() const { return principal_->aux(); } | ||
|
||
private: | ||
// ---------- member data -------------------------------- | ||
std::shared_ptr<RunPrincipal const> principal_; | ||
edm::ServiceToken token_; | ||
}; | ||
} // namespace test | ||
} // namespace edm | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#ifndef FWCore_TestProcessor_TestSourceProcessor_h | ||
#define FWCore_TestProcessor_TestSourceProcessor_h | ||
// -*- C++ -*- | ||
// | ||
// Package: FWCore/TestProcessor | ||
// Class : TestSourceProcessor | ||
// | ||
/**\class TestSourceProcessor TestSourceProcessor.h "TestSourceProcessor.h" | ||
Description: Used for testing InputSources | ||
Usage: | ||
<usage> | ||
*/ | ||
// | ||
// Original Author: Chris Jones | ||
// Created: Mon, 30 Apr 2018 18:51:00 GMT | ||
// | ||
#include <string> | ||
#include <utility> | ||
#include <memory> | ||
#include "oneapi/tbb/global_control.h" | ||
#include "oneapi/tbb/task_arena.h" | ||
#include "oneapi/tbb/task_group.h" | ||
|
||
#include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h" | ||
|
||
#include "FWCore/Common/interface/FWCoreCommonFwd.h" | ||
|
||
#include "FWCore/Framework/interface/HistoryAppender.h" | ||
#include "FWCore/Framework/interface/InputSource.h" | ||
#include "FWCore/Framework/interface/SharedResourcesAcquirer.h" | ||
#include "FWCore/Framework/interface/PrincipalCache.h" | ||
#include "FWCore/Framework/interface/SignallingProductRegistry.h" | ||
#include "FWCore/Framework/interface/PreallocationConfiguration.h" | ||
#include "FWCore/Framework/interface/MergeableRunProductProcesses.h" | ||
|
||
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h" | ||
#include "FWCore/ServiceRegistry/interface/ProcessContext.h" | ||
#include "FWCore/ServiceRegistry/interface/ServiceLegacy.h" | ||
#include "FWCore/ServiceRegistry/interface/ServiceToken.h" | ||
|
||
#include "FWCore/TestProcessor/interface/EventFromSource.h" | ||
#include "FWCore/TestProcessor/interface/LuminosityBlockFromSource.h" | ||
#include "FWCore/TestProcessor/interface/ProcessBlock.h" | ||
#include "FWCore/TestProcessor/interface/RunFromSource.h" | ||
|
||
namespace edm::test { | ||
|
||
class TestSourceProcessor { | ||
public: | ||
TestSourceProcessor(std::string const& iConfig, ServiceToken iToken = ServiceToken()); | ||
~TestSourceProcessor(); | ||
|
||
InputSource::ItemTypeInfo findNextTransition(); | ||
|
||
std::shared_ptr<FileBlock> openFile(); | ||
void closeFile(std::shared_ptr<FileBlock>); | ||
|
||
edm::test::RunFromSource readRun(); | ||
|
||
edm::test::LuminosityBlockFromSource readLuminosityBlock(); | ||
|
||
edm::test::EventFromSource readEvent(); | ||
|
||
private: | ||
edm::InputSource::ItemTypeInfo lastTransition_; | ||
|
||
oneapi::tbb::global_control globalControl_; | ||
oneapi::tbb::task_group taskGroup_; | ||
oneapi::tbb::task_arena arena_; | ||
std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable. | ||
std::shared_ptr<ProductRegistry> preg_; | ||
std::shared_ptr<BranchIDListHelper> branchIDListHelper_; | ||
std::shared_ptr<ProcessBlockHelper> processBlockHelper_; | ||
std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper_; | ||
ServiceToken serviceToken_; | ||
|
||
std::shared_ptr<ProcessConfiguration const> processConfiguration_; | ||
ProcessContext processContext_; | ||
MergeableRunProductProcesses mergeableRunProductProcesses_; | ||
|
||
ProcessHistoryRegistry processHistoryRegistry_; | ||
std::unique_ptr<HistoryAppender> historyAppender_; | ||
|
||
PrincipalCache principalCache_; | ||
PreallocationConfiguration preallocations_; | ||
|
||
std::unique_ptr<edm::InputSource> source_; | ||
|
||
std::shared_ptr<RunPrincipal> runPrincipal_; | ||
std::shared_ptr<LuminosityBlockPrincipal> lumiPrincipal_; | ||
|
||
std::shared_ptr<FileBlock> fb_; | ||
}; | ||
} // namespace edm::test | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
|
||
class TestSourceProcess(cms.Process): | ||
def __init__(self,name="TEST",*modifiers): | ||
super(TestSourceProcess,self).__init__(name,*modifiers) | ||
def fillProcessDesc(self, processPSet): | ||
if not hasattr(self,"options"): | ||
self.options = cms.untracked.PSet() | ||
cms.Process.fillProcessDesc(self,processPSet) |
Oops, something went wrong.