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>
56 unsigned long long iTransitionID) -> decltype(iDeserializer.deserialize()) {
57 decltype(iDeserializer.deserialize())
value;
58 if (not channel_.doTransition(
60 value = deserializer_.deserialize();
61 std::cout << id_ <<
" from shared memory " << value.size() << std::endl;
65 std::cout << id_ <<
" FAILED waiting for external process" << std::endl;
66 externalFailed_ =
true;
71 edmtest::ThingCollection
produce(
unsigned long long iTransitionID) {
79 edmtest::ThingCollection
endRunProduce(
unsigned long long iTransitionID) {
80 if (not externalFailed_) {
83 return edmtest::ThingCollection();
91 if (not externalFailed_) {
94 return edmtest::ThingCollection();
98 channel_.stopWorker();
123 bool externalFailed_ =
false;
139 edm::RunCache<testinter::RunCache>,
140 edm::BeginRunProducer,
142 edm::LuminosityBlockCache<testinter::LumiCache>,
143 edm::BeginLuminosityBlockProducer,
144 edm::EndLuminosityBlockProducer> {
148 std::unique_ptr<testinter::StreamCache> beginStream(
edm::StreamID)
const final;
183 mutable std::atomic<unsigned int> lastLumiIndex_ = 0;
187 : token_{produces<edmtest::ThingCollection>()},
188 brToken_{produces<edmtest::ThingCollection, edm::Transition::BeginRun>(
"beginRun")},
189 erToken_{produces<edmtest::ThingCollection, edm::Transition::EndRun>(
"endRun")},
190 blToken_{produces<edmtest::ThingCollection, edm::Transition::BeginLuminosityBlock>(
"beginLumi")},
191 elToken_{produces<edmtest::ThingCollection, edm::Transition::EndLuminosityBlock>(
"endLumi")},
192 config_{iPSet.getUntrackedParameter<
std::string>(
"@python_config")} {}
200 process = TestProcess() 203 config +=
"process.moduleToTest(process."s +
label +
")\n";
205 process.add_(cms.Service("InitRootHandlers", UnloadRootSigHandler=cms.untracked.bool(True))) 209 if (iID.
value() == 0) {
219 auto value = streamCache(iID)->produce(
iEvent.id().event());
229 return std::make_shared<testinter::RunCache>();
233 if (iID.
value() != 0) {
234 (
void)streamCache(iID)->beginRunProduce(iRun.
run());
238 if (iID.
value() == 0) {
239 runCache(iRun.
index())->thingCollection_ = streamCache(iID)->endRunProduce(iRun.
run());
241 (
void)streamCache(iID)->endRunProduce(iRun.
run());
261 return std::make_shared<testinter::LumiCache>();
267 auto cache = streamCache(iID);
278 if (iID.
value() == 0) {
279 luminosityBlockCache(iLuminosityBlock.
index())->thingCollection_ =
280 streamCache(iID)->endLumiProduce(iLuminosityBlock.
run());
282 (
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
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)
dictionary config
Read in AllInOne config in JSON format.
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_