6 #include "DataFormats/TestObjects/interface/ToyProducts.h" 7 #include "DataFormats/TestObjects/interface/ThingCollection.h" 22 channel_(
"testProd", id_, 60),
23 readBuffer_{channel_.sharedMemoryName(), channel_.fromWorkerBufferInfo()},
24 deserializer_{readBuffer_},
25 br_deserializer_{readBuffer_},
26 er_deserializer_{readBuffer_},
27 bl_deserializer_{readBuffer_},
28 el_deserializer_(readBuffer_) {
33 channel_.setupWorker([&]() {
35 std::cout << id_ <<
" starting external process" << std::endl;
36 pipe_ = popen((
"cmsTestInterProcess "s + channel_.sharedMemoryName() +
" " + channel_.uniqueID()).c_str(),
"w");
38 if (
nullptr ==
pipe_) {
44 auto result = fwrite(nlines.data(),
sizeof(char), nlines.size(),
pipe_);
46 result = fwrite(iConfig.data(),
sizeof(char), iConfig.size(),
pipe_);
53 template <
typename SERIAL>
55 -> decltype(iDeserializer.deserialize()) {
56 decltype(iDeserializer.deserialize())
value;
57 if (not channel_.doTransition(
59 value = deserializer_.deserialize();
60 std::cout << id_ <<
" from shared memory " << value.size() << std::endl;
64 std::cout << id_ <<
" FAILED waiting for external process" << std::endl;
65 externalFailed_ =
true;
70 edmtest::ThingCollection
produce(
unsigned long long iTransitionID) {
78 edmtest::ThingCollection
endRunProduce(
unsigned long long iTransitionID) {
79 if (not externalFailed_) {
82 return edmtest::ThingCollection();
90 if (not externalFailed_) {
93 return edmtest::ThingCollection();
97 channel_.stopWorker();
122 bool externalFailed_ =
false;
138 edm::RunCache<testinter::RunCache>,
139 edm::BeginRunProducer,
141 edm::LuminosityBlockCache<testinter::LumiCache>,
142 edm::BeginLuminosityBlockProducer,
143 edm::EndLuminosityBlockProducer> {
147 std::unique_ptr<testinter::StreamCache> beginStream(
edm::StreamID)
const final;
182 mutable std::atomic<unsigned int> lastLumiIndex_ = 0;
186 : token_{produces<edmtest::ThingCollection>()},
187 brToken_{produces<edmtest::ThingCollection, edm::Transition::BeginRun>(
"beginRun")},
188 erToken_{produces<edmtest::ThingCollection, edm::Transition::EndRun>(
"endRun")},
189 blToken_{produces<edmtest::ThingCollection, edm::Transition::BeginLuminosityBlock>(
"beginLumi")},
190 elToken_{produces<edmtest::ThingCollection, edm::Transition::EndLuminosityBlock>(
"endLumi")},
191 config_{iPSet.getUntrackedParameter<
std::string>(
"@python_config")} {}
199 process = TestProcess() 202 config +=
"process.moduleToTest(process."s +
label +
")\n";
204 process.add_(cms.Service("InitRootHandlers", UnloadRootSigHandler=cms.untracked.bool(True))) 208 if (iID.
value() == 0) {
218 auto value = streamCache(iID)->produce(
iEvent.id().event());
228 return std::make_shared<testinter::RunCache>();
232 if (iID.
value() != 0) {
233 (
void)streamCache(iID)->beginRunProduce(iRun.
run());
237 if (iID.
value() == 0) {
238 runCache(iRun.
index())->thingCollection_ = streamCache(iID)->endRunProduce(iRun.
run());
240 (
void)streamCache(iID)->endRunProduce(iRun.
run());
260 return std::make_shared<testinter::LumiCache>();
266 auto cache = streamCache(iID);
277 if (iID.
value() == 0) {
278 luminosityBlockCache(iLuminosityBlock.
index())->thingCollection_ =
279 streamCache(iID)->endLumiProduce(iLuminosityBlock.
run());
281 (
void)streamCache(iID)->endLumiProduce(iLuminosityBlock.
run());
void globalBeginRunProduce(edm::Run &, edm::EventSetup const &) const final
edmtest::ThingCollection beginRunProduce(unsigned long long iTransitionID)
testinter::StreamCache * stream0Cache_
void streamEndLuminosityBlock(edm::StreamID, edm::LuminosityBlock const &, edm::EventSetup const &) const final
TCDeserializer deserializer_
TCDeserializer er_deserializer_
void globalEndRun(edm::Run const &, edm::EventSetup const &) const final
dictionary config
Read in AllInOne config in JSON format.
void emplace(EDPutTokenT< PROD > token, Args &&... args)
puts a new product
TCDeserializer bl_deserializer_
edm::EDPutTokenT< edmtest::ThingCollection > const blToken_
void globalEndLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const final
static std::string to_string(const XMLCh *ch)
TEMPL(T2) struct Divides void
edmtest::ThingCollection thingCollection_
auto doTransition(SERIAL &iDeserializer, edm::Transition iTrans, unsigned long long iTransitionID) -> decltype(iDeserializer.deserialize())
edmtest::ThingCollection beginLumiProduce(unsigned long long iTransitionID)
edmtest::ThingCollection produce(unsigned long long iTransitionID)
void streamBeginRun(edm::StreamID, edm::Run const &, edm::EventSetup const &) const final
edm::EDPutTokenT< edmtest::ThingCollection > const elToken_
ModuleDescription const & moduleDescription() const
edm::EDPutTokenT< edmtest::ThingCollection > const token_
#define DEFINE_FWK_MODULE(type)
edmtest::ThingCollection thingCollection_
std::atomic< unsigned int > lastLumiIndex_
std::unique_ptr< testinter::StreamCache > beginStream(edm::StreamID) const final
std::atomic< testinter::StreamCache * > availableForBeginLumi_
edmtest::ThingCollection endRunProduce(unsigned long long iTransitionID)
void emplace(EDPutTokenT< PROD > token, Args &&... args)
puts a new product
std::string unique_name(std::string iBase)
ControllerChannel channel_
static const char pipe_[]
edm::EDPutTokenT< edmtest::ThingCollection > const erToken_
edm::EDPutTokenT< edmtest::ThingCollection > const brToken_
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const final
std::shared_ptr< testinter::RunCache > globalBeginRun(edm::Run const &, edm::EventSetup const &) const final
void globalBeginLuminosityBlockProduce(edm::LuminosityBlock &, edm::EventSetup const &) const final
edmtest::ThingCollection endLumiProduce(unsigned long long iTransitionID)
TestInterProcessProd(edm::ParameterSet const &)
LuminosityBlockIndex index() const
std::shared_ptr< testinter::LumiCache > globalBeginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const final
void streamEndRun(edm::StreamID, edm::Run const &, edm::EventSetup const &) const final
void globalEndRunProduce(edm::Run &, edm::EventSetup const &) const final
StreamCache(const std::string &iConfig, int id)
TCDeserializer br_deserializer_
unsigned int value() const
void globalEndLuminosityBlockProduce(edm::LuminosityBlock &, edm::EventSetup const &) const final
std::string const & moduleLabel() const
void streamBeginLuminosityBlock(edm::StreamID, edm::LuminosityBlock const &, edm::EventSetup const &) const final
TCDeserializer el_deserializer_