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 all 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
74 changes: 74 additions & 0 deletions FWCore/TestProcessor/interface/EventFromSource.h
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 FWCore/TestProcessor/interface/LuminosityBlockFromSource.h
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
71 changes: 71 additions & 0 deletions FWCore/TestProcessor/interface/RunFromSource.h
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
11 changes: 11 additions & 0 deletions FWCore/TestProcessor/interface/TestProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include "FWCore/Framework/interface/Schedule.h"
#include "FWCore/Framework/interface/EventSetupRecordKey.h"
#include "FWCore/Framework/interface/DataKey.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"
Expand Down Expand Up @@ -317,13 +319,17 @@ This simulates a problem happening early in the job which causes processing not
void teardownProcessing();

void beginJob();
void respondToOpenInputFile();
void openOutputFiles();
void beginProcessBlock();
void beginRun();
void beginLuminosityBlock();
void event();
std::shared_ptr<LuminosityBlockPrincipal> endLuminosityBlock();
std::shared_ptr<RunPrincipal> endRun();
void respondToCloseInputFile();
ProcessBlockPrincipal const* endProcessBlock();
void closeOutputFiles();
void endJob();

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

MergeableRunProductProcesses mergeableRunProductProcesses_;

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

PrincipalCache principalCache_;
Expand All @@ -363,9 +372,11 @@ This simulates a problem happening early in the job which causes processing not
LuminosityBlockNumber_t lumiNumber_ = 1;
EventNumber_t eventNumber_ = 1;
bool beginJobCalled_ = false;
bool respondToOpenInputFileCalled_ = false;
bool beginProcessBlockCalled_ = false;
bool beginRunCalled_ = false;
bool beginLumiCalled_ = false;
bool openOutputFilesCalled_ = false;
};
} // namespace test
} // namespace edm
Expand Down
99 changes: 99 additions & 0 deletions FWCore/TestProcessor/interface/TestSourceProcessor.h
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
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)
Loading