6 #include "DataFormats/TestObjects/interface/ToyProducts.h" 7 #include "DataFormats/TestObjects/interface/ThingCollection.h" 22 #include "CLHEP/Random/RandomEngine.h" 23 #include "CLHEP/Random/engineIDulong.h" 24 #include "CLHEP/Random/RanecuEngine.h" 29 using ReturnedType = std::pair<edmtest::IntProduct, edm::RandomNumberGeneratorState>;
34 channel_(
"testProd", id_, 60),
35 readBuffer_{channel_.sharedMemoryName(), channel_.fromWorkerBufferInfo()},
36 writeBuffer_{
std::string(
"Rand") + channel_.sharedMemoryName(), channel_.toWorkerBufferInfo()},
37 deserializer_{readBuffer_},
38 bl_deserializer_{readBuffer_},
39 randSerializer_{writeBuffer_} {
44 channel_.setupWorker([&]() {
46 std::cout << id_ <<
" starting external process" << std::endl;
47 pipe_ = popen((
"cmsTestInterProcessRandom "s + channel_.sharedMemoryName() +
" " + channel_.uniqueID()).c_str(),
50 if (
nullptr ==
pipe_) {
56 auto result = fwrite(nlines.data(),
sizeof(char), nlines.size(),
pipe_);
58 result = fwrite(iConfig.data(),
sizeof(char), iConfig.size(),
pipe_);
65 template <
typename SERIAL>
67 -> decltype(iDeserializer.deserialize()) {
68 decltype(iDeserializer.deserialize())
value;
69 if (not channel_.doTransition(
71 value = deserializer_.deserialize();
72 std::cout << id_ <<
" from shared memory " << value.first.value << std::endl;
76 std::cout << id_ <<
" FAILED waiting for external process" << std::endl;
77 externalFailed_ =
true;
84 auto& engine =
gen->getEngine(iStream);
86 randSerializer_.serialize(
state);
88 if (
v.second.state_[0] != CLHEP::engineIDulong<CLHEP::RanecuEngine>()) {
89 engine.setSeed(
v.second.seed_, 0);
91 engine.get(
v.second.state_);
96 unsigned long long iTransitionID,
100 randSerializer_.serialize(const_cast<edm::RandomNumberGeneratorState&>(iState));
105 channel_.stopWorker();
131 bool externalFailed_ =
false;
138 edm::LuminosityBlockCache<edm::RandomNumberGeneratorState>,
139 edm::BeginLuminosityBlockProducer> {
143 std::unique_ptr<testinter::StreamCache> beginStream(
edm::StreamID)
const final;
149 std::shared_ptr<edm::RandomNumberGeneratorState> globalBeginLuminosityBlock(
edm::LuminosityBlock const&,
171 mutable std::atomic<unsigned int> lastLumiIndex_ = 0;
175 : token_{produces<edmtest::IntProduct>()},
176 blToken_{produces<edmtest::IntProduct, edm::Transition::BeginLuminosityBlock>(
"lumi")},
177 config_{iPSet.getUntrackedParameter<
std::string>(
"@python_config")} {}
185 process = TestProcess() 188 config +=
"process.moduleToTest(process."s +
label +
")\n";
190 process.add_(cms.Service("InitRootHandlers", UnloadRootSigHandler=cms.untracked.bool(True))) 194 if (iID.
value() == 0) {
204 auto value = streamCache(iID)->produce(
iEvent.id().event(), iID);
211 auto& engine =
gen->getEngine(iLumi.
index());
212 return std::make_shared<edm::RandomNumberGeneratorState>(engine.put(), engine.getSeed());
223 auto& engine =
gen->getEngine(iLuminosityBlock.
index());
224 if (
v.second.state_[0] != CLHEP::engineIDulong<CLHEP::RanecuEngine>()) {
225 engine.setSeed(
v.second.seed_, 0);
227 engine.get(
v.second.state_);
237 auto cache = streamCache(iID);
void streamEndRun(edm::StreamID, edm::Run const &, edm::EventSetup const &) const final
testinter::StreamCache * stream0Cache_
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const final
std::atomic< unsigned int > lastLumiIndex_
void globalBeginLuminosityBlockProduce(edm::LuminosityBlock &, edm::EventSetup const &) const final
std::atomic< testinter::StreamCache * > availableForBeginLumi_
edm::EDPutTokenT< edmtest::IntProduct > const token_
void globalEndLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const final
void streamBeginLuminosityBlock(edm::StreamID, edm::LuminosityBlock const &, edm::EventSetup const &) const final
TestInterProcessRandomProd(edm::ParameterSet const &)
std::shared_ptr< edm::RandomNumberGeneratorState > globalBeginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const final
ReturnedType beginLumiProduce(edm::RandomNumberGeneratorState const &iState, unsigned long long iTransitionID, edm::LuminosityBlockIndex iLumi)
void streamBeginRun(edm::StreamID, edm::Run const &, edm::EventSetup const &) const final
static std::string to_string(const XMLCh *ch)
TEMPL(T2) struct Divides void
auto doTransition(SERIAL &iDeserializer, edm::Transition iTrans, unsigned long long iTransitionID) -> decltype(iDeserializer.deserialize())
edmtest::IntProduct produce(unsigned long long iTransitionID, edm::StreamID iStream)
ModuleDescription const & moduleDescription() const
#define DEFINE_FWK_MODULE(type)
std::unique_ptr< testinter::StreamCache > beginStream(edm::StreamID) const final
def gen(fragment, howMuch)
Event to runs.
edm::EDPutTokenT< edmtest::IntProduct > const blToken_
void emplace(EDPutTokenT< PROD > token, Args &&... args)
puts a new product
std::string unique_name(std::string iBase)
static const char pipe_[]
LuminosityBlockIndex index() const
std::pair< edmtest::IntProduct, edm::RandomNumberGeneratorState > ReturnedType
StreamCache(const std::string &iConfig, int id)
dictionary config
Read in AllInOne config in JSON format.
TCSerializer randSerializer_
unsigned int value() const
LuminosityBlockNumber_t luminosityBlock() const
std::string const & moduleLabel() const
void streamEndLuminosityBlock(edm::StreamID, edm::LuminosityBlock const &, edm::EventSetup const &) const final