Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added TestSourceProcessor helper #45443

Merged
merged 7 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions FWCore/TestProcessor/interface/EventFromSource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#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"

// forward declarations

namespace edm {
class EventFromSourcePrincipal;

namespace test {

class EventFromSource {
public:
EventFromSource(EventPrincipal const& iPrincipal) : principal_(&iPrincipal) {}

// ---------- const member functions ---------------------
template <typename T>
TestHandle<T> get(std::string const& iModule,
std::string const& iInstanceLabel,
std::string const& iProcess) const {
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_;
};
} // namespace test
} // namespace edm

#endif
70 changes: 70 additions & 0 deletions FWCore/TestProcessor/interface/LuminosityBlockFromSource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#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"

// forward declarations

namespace edm {

namespace test {

class LuminosityBlockFromSource {
public:
LuminosityBlockFromSource(std::shared_ptr<LuminosityBlockPrincipal const> iPrincipal) : principal_(iPrincipal) {}

// ---------- const member functions ---------------------
template <typename T>
TestHandle<T> get(std::string const& iModule,
std::string const& iInstanceLabel,
std::string const& iProcess) const {
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_;
};
} // namespace test
} // namespace edm

#endif
65 changes: 65 additions & 0 deletions FWCore/TestProcessor/interface/RunFromSource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#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"

// forward declarations

namespace edm {

namespace test {

class RunFromSource {
public:
RunFromSource(std::shared_ptr<RunPrincipal const> iPrincipal) : principal_(iPrincipal) {}

// ---------- const member functions ---------------------
template <typename T>
TestHandle<T> get(std::string const& iModule,
std::string const& iInstanceLabel,
std::string const& iProcess) const {
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_;
};
} // namespace test
} // namespace edm

#endif
94 changes: 94 additions & 0 deletions FWCore/TestProcessor/interface/TestSourceProcessor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#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/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());

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:
std::unique_ptr<edm::InputSource> source_;
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_;

ProcessHistoryRegistry processHistoryRegistry_;
std::unique_ptr<HistoryAppender> historyAppender_;

PrincipalCache principalCache_;
PreallocationConfiguration preallocations_;

std::shared_ptr<RunPrincipal> runPrincipal_;
std::shared_ptr<LuminosityBlockPrincipal> lumiPrincipal_;

std::shared_ptr<FileBlock> fb_;
};
} // namespace edm::test

#endif
2 changes: 1 addition & 1 deletion FWCore/TestProcessor/python/TestProcess.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def moduleToTest(self,mod,task=cms.Task()):
self._test_endpath = cms.EndPath(mod,task)
def fillProcessDesc(self, processPSet):
if self.__dict__["_TestProcess__moduleToTest"] is None:
raise LogicError("moduleToTest was not called")
raise RuntimeError("moduleToTest was not called")
for p in self.paths.iterkeys():
if p != "_test_path":
delattr(self,p)
Expand Down
9 changes: 9 additions & 0 deletions FWCore/TestProcessor/python/TestSourceProcess.py
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)
29 changes: 2 additions & 27 deletions FWCore/TestProcessor/src/TestProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,47 +38,22 @@
#include "FWCore/ServiceRegistry/interface/ServiceRegistry.h"
#include "FWCore/ServiceRegistry/interface/SystemBounds.h"

#include "FWCore/PluginManager/interface/PluginManager.h"
#include "FWCore/PluginManager/interface/standard.h"

#include "FWCore/ParameterSetReader/interface/ProcessDescImpl.h"
#include "FWCore/ParameterSet/interface/ProcessDesc.h"
#include "FWCore/ParameterSet/interface/validateTopLevelParameterSets.h"

#include "FWCore/Utilities/interface/ExceptionCollector.h"

#include "FWCore/Concurrency/interface/ThreadsController.h"
#include "FWCore/Concurrency/interface/FinalWaitingTask.h"

#include "DataFormats/Provenance/interface/ParentageRegistry.h"
#include "oneTimeInitialization.h"

#define xstr(s) str(s)
#define str(s) #s

namespace edm {
namespace test {

namespace {

bool oneTimeInitializationImpl() {
edmplugin::PluginManager::configure(edmplugin::standard::config());

static std::unique_ptr<edm::ThreadsController> tsiPtr = std::make_unique<edm::ThreadsController>(1);

// register the empty parentage vector , once and for all
ParentageRegistry::instance()->insertMapped(Parentage());

// register the empty parameter set, once and for all.
ParameterSet().registerIt();
return true;
}

bool oneTimeInitialization() {
static const bool s_init{oneTimeInitializationImpl()};
return s_init;
}
} // namespace

//
// constructors and destructor
//
Expand All @@ -88,7 +63,7 @@ namespace edm {
historyAppender_(std::make_unique<HistoryAppender>()),
moduleRegistry_(std::make_shared<ModuleRegistry>()) {
//Setup various singletons
(void)oneTimeInitialization();
(void)testprocessor::oneTimeInitialization();

ProcessDescImpl desc(iConfig.pythonConfiguration(), false);

Expand Down
Loading