CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
testinter::StreamCache Struct Reference

Public Member Functions

edmtest::ThingCollection beginLumiProduce (unsigned long long iTransitionID)
 
ReturnedType beginLumiProduce (edm::RandomNumberGeneratorState const &iState, unsigned long long iTransitionID, edm::LuminosityBlockIndex iLumi)
 
edmtest::ThingCollection beginRunProduce (unsigned long long iTransitionID)
 
template<typename SERIAL >
auto doTransition (SERIAL &iDeserializer, edm::Transition iTrans, unsigned long long iTransitionID) -> decltype(iDeserializer.deserialize())
 
template<typename SERIAL >
auto doTransition (SERIAL &iDeserializer, edm::Transition iTrans, unsigned long long iTransitionID) -> decltype(iDeserializer.deserialize())
 
edmtest::ThingCollection endLumiProduce (unsigned long long iTransitionID)
 
edmtest::ThingCollection endRunProduce (unsigned long long iTransitionID)
 
edmtest::ThingCollection produce (unsigned long long iTransitionID)
 
edmtest::IntProduct produce (unsigned long long iTransitionID, edm::StreamID iStream)
 
 StreamCache (const std::string &iConfig, int id)
 
 StreamCache (const std::string &iConfig, int id)
 
 ~StreamCache ()
 
 ~StreamCache ()
 

Private Types

using TCDeserializer = ROOTDeserializer< edmtest::ThingCollection, ReadBuffer >
 
using TCDeserializer = ROOTDeserializer< ReturnedType, ReadBuffer >
 
using TCSerializer = ROOTSerializer< edm::RandomNumberGeneratorState, WriteBuffer >
 

Private Member Functions

std::string unique_name (std::string iBase)
 
std::string unique_name (std::string iBase)
 

Private Attributes

TCDeserializer bl_deserializer_
 
TCDeserializer br_deserializer_
 
ControllerChannel channel_
 
TCDeserializer deserializer_
 
TCDeserializer el_deserializer_
 
TCDeserializer er_deserializer_
 
bool externalFailed_ = false
 
int id_
 
FILE * pipe_
 
TCSerializer randSerializer_
 
ReadBuffer readBuffer_
 
WriteBuffer writeBuffer_
 

Detailed Description

Definition at line 19 of file TestInterProcessProd.cc.

Member Typedef Documentation

◆ TCDeserializer [1/2]

using testinter::StreamCache::TCDeserializer = ROOTDeserializer<edmtest::ThingCollection, ReadBuffer>
private

Definition at line 117 of file TestInterProcessProd.cc.

◆ TCDeserializer [2/2]

Definition at line 126 of file TestInterProcessRandomProd.cc.

◆ TCSerializer

Definition at line 129 of file TestInterProcessRandomProd.cc.

Constructor & Destructor Documentation

◆ StreamCache() [1/2]

testinter::StreamCache::StreamCache ( const std::string &  iConfig,
int  id 
)
inline

Definition at line 20 of file TestInterProcessProd.cc.

21  : id_{id},
22  channel_("testProd", id_, 60),
29  //make sure output is flushed before popen does any writing
30  fflush(stdout);
31  fflush(stderr);
32 
33  channel_.setupWorker([&]() {
34  using namespace std::string_literals;
35  std::cout << id_ << " starting external process" << std::endl;
36  pipe_ = popen(("cmsTestInterProcess "s + channel_.sharedMemoryName() + " " + channel_.uniqueID()).c_str(), "w");
37 
38  if (nullptr == pipe_) {
39  abort();
40  }
41 
42  {
43  auto nlines = std::to_string(std::count(iConfig.begin(), iConfig.end(), '\n'));
44  auto result = fwrite(nlines.data(), sizeof(char), nlines.size(), pipe_);
45  assert(result == nlines.size());
46  result = fwrite(iConfig.data(), sizeof(char), iConfig.size(), pipe_);
47  assert(result == iConfig.size());
48  fflush(pipe_);
49  }
50  });
51  }
std::string const & sharedMemoryName() const
BufferInfo * fromWorkerBufferInfo()
This can be used with ReadBuffer to keep Controller and Worker in sync.
assert(be >=bs)
static std::string to_string(const XMLCh *ch)

◆ ~StreamCache() [1/2]

testinter::StreamCache::~StreamCache ( )
inline

Definition at line 97 of file TestInterProcessProd.cc.

References sistrip::pipe_.

◆ StreamCache() [2/2]

testinter::StreamCache::StreamCache ( const std::string &  iConfig,
int  id 
)
inline

Definition at line 32 of file TestInterProcessRandomProd.cc.

33  : id_{id},
34  channel_("testProd", id_, 60),
40  //make sure output is flushed before popen does any writing
41  fflush(stdout);
42  fflush(stderr);
43 
44  channel_.setupWorker([&]() {
45  using namespace std::string_literals;
46  std::cout << id_ << " starting external process" << std::endl;
47  pipe_ = popen(("cmsTestInterProcessRandom "s + channel_.sharedMemoryName() + " " + channel_.uniqueID()).c_str(),
48  "w");
49 
50  if (nullptr == pipe_) {
51  abort();
52  }
53 
54  {
55  auto nlines = std::to_string(std::count(iConfig.begin(), iConfig.end(), '\n'));
56  auto result = fwrite(nlines.data(), sizeof(char), nlines.size(), pipe_);
57  assert(result == nlines.size());
58  result = fwrite(iConfig.data(), sizeof(char), iConfig.size(), pipe_);
59  assert(result == iConfig.size());
60  fflush(pipe_);
61  }
62  });
63  }
BufferInfo * toWorkerBufferInfo()
This can be used with WriteBuffer to keep Controller and Worker in sync.
std::string const & sharedMemoryName() const
BufferInfo * fromWorkerBufferInfo()
This can be used with ReadBuffer to keep Controller and Worker in sync.
assert(be >=bs)
static std::string to_string(const XMLCh *ch)

◆ ~StreamCache() [2/2]

testinter::StreamCache::~StreamCache ( )
inline

Definition at line 105 of file TestInterProcessRandomProd.cc.

References sistrip::pipe_.

Member Function Documentation

◆ beginLumiProduce() [1/2]

edmtest::ThingCollection testinter::StreamCache::beginLumiProduce ( unsigned long long  iTransitionID)
inline

Definition at line 86 of file TestInterProcessProd.cc.

References edm::BeginLuminosityBlock.

86  {
88  }
auto doTransition(SERIAL &iDeserializer, edm::Transition iTrans, unsigned long long iTransitionID) -> decltype(iDeserializer.deserialize())

◆ beginLumiProduce() [2/2]

ReturnedType testinter::StreamCache::beginLumiProduce ( edm::RandomNumberGeneratorState const &  iState,
unsigned long long  iTransitionID,
edm::LuminosityBlockIndex  iLumi 
)
inline

Definition at line 96 of file TestInterProcessRandomProd.cc.

References edm::BeginLuminosityBlock, and relval_steps::gen().

98  {
100  //NOTE: root serialize requires a `void*` not a `void const*` even though it doesn't modify the object
101  randSerializer_.serialize(const_cast<edm::RandomNumberGeneratorState&>(iState));
103  }
auto doTransition(SERIAL &iDeserializer, edm::Transition iTrans, unsigned long long iTransitionID) -> decltype(iDeserializer.deserialize())
def gen(fragment, howMuch)
Tau Embedding 2016 HIPM ###.

◆ beginRunProduce()

edmtest::ThingCollection testinter::StreamCache::beginRunProduce ( unsigned long long  iTransitionID)
inline

Definition at line 75 of file TestInterProcessProd.cc.

References edm::BeginRun.

Referenced by TestInterProcessProd::globalBeginRunProduce().

75  {
77  }
auto doTransition(SERIAL &iDeserializer, edm::Transition iTrans, unsigned long long iTransitionID) -> decltype(iDeserializer.deserialize())

◆ doTransition() [1/2]

template<typename SERIAL >
auto testinter::StreamCache::doTransition ( SERIAL &  iDeserializer,
edm::Transition  iTrans,
unsigned long long  iTransitionID 
) -> decltype(iDeserializer.deserialize())
inline

Definition at line 54 of file TestInterProcessProd.cc.

References gather_cfg::cout, Exception, edm::errors::ExternalFailure, and relativeConstraints::value.

56  {
57  decltype(iDeserializer.deserialize()) value;
58  if (not channel_.doTransition(
59  [&value, this]() {
60  value = deserializer_.deserialize();
61  std::cout << id_ << " from shared memory " << value.size() << std::endl;
62  },
63  iTrans,
64  iTransitionID)) {
65  std::cout << id_ << " FAILED waiting for external process" << std::endl;
66  externalFailed_ = true;
68  }
69  return value;
70  }
Definition: value.py:1
bool doTransition(F &&iF, edm::Transition iTrans, unsigned long long iTransitionID)

◆ doTransition() [2/2]

template<typename SERIAL >
auto testinter::StreamCache::doTransition ( SERIAL &  iDeserializer,
edm::Transition  iTrans,
unsigned long long  iTransitionID 
) -> decltype(iDeserializer.deserialize())
inline

Definition at line 66 of file TestInterProcessRandomProd.cc.

References gather_cfg::cout, Exception, edm::errors::ExternalFailure, and relativeConstraints::value.

68  {
69  decltype(iDeserializer.deserialize()) value;
70  if (not channel_.doTransition(
71  [&value, this]() {
72  value = deserializer_.deserialize();
73  std::cout << id_ << " from shared memory " << value.first.value << std::endl;
74  },
75  iTrans,
76  iTransitionID)) {
77  std::cout << id_ << " FAILED waiting for external process" << std::endl;
78  externalFailed_ = true;
80  }
81  return value;
82  }
Definition: value.py:1
bool doTransition(F &&iF, edm::Transition iTrans, unsigned long long iTransitionID)

◆ endLumiProduce()

edmtest::ThingCollection testinter::StreamCache::endLumiProduce ( unsigned long long  iTransitionID)
inline

Definition at line 90 of file TestInterProcessProd.cc.

References edm::EndLuminosityBlock.

90  {
91  if (not externalFailed_) {
93  }
94  return edmtest::ThingCollection();
95  }
auto doTransition(SERIAL &iDeserializer, edm::Transition iTrans, unsigned long long iTransitionID) -> decltype(iDeserializer.deserialize())

◆ endRunProduce()

edmtest::ThingCollection testinter::StreamCache::endRunProduce ( unsigned long long  iTransitionID)
inline

Definition at line 79 of file TestInterProcessProd.cc.

References edm::EndRun.

79  {
80  if (not externalFailed_) {
82  }
83  return edmtest::ThingCollection();
84  }
auto doTransition(SERIAL &iDeserializer, edm::Transition iTrans, unsigned long long iTransitionID) -> decltype(iDeserializer.deserialize())

◆ produce() [1/2]

edmtest::ThingCollection testinter::StreamCache::produce ( unsigned long long  iTransitionID)
inline

Definition at line 71 of file TestInterProcessProd.cc.

References edm::Event.

71  {
72  return doTransition(deserializer_, edm::Transition::Event, iTransitionID);
73  }
auto doTransition(SERIAL &iDeserializer, edm::Transition iTrans, unsigned long long iTransitionID) -> decltype(iDeserializer.deserialize())

◆ produce() [2/2]

edmtest::IntProduct testinter::StreamCache::produce ( unsigned long long  iTransitionID,
edm::StreamID  iStream 
)
inline

Definition at line 83 of file TestInterProcessRandomProd.cc.

References edm::Event, relval_steps::gen(), and findQualityFiles::v.

83  {
85  auto& engine = gen->getEngine(iStream);
86  edm::RandomNumberGeneratorState state{engine.put(), engine.getSeed()};
88  auto v = doTransition(deserializer_, edm::Transition::Event, iTransitionID);
89  if (v.second.state_[0] != CLHEP::engineIDulong<CLHEP::RanecuEngine>()) {
90  engine.setSeed(v.second.seed_, 0);
91  }
92  engine.get(v.second.state_);
93  return v.first;
94  }
auto doTransition(SERIAL &iDeserializer, edm::Transition iTrans, unsigned long long iTransitionID) -> decltype(iDeserializer.deserialize())
def gen(fragment, howMuch)
Tau Embedding 2016 HIPM ###.

◆ unique_name() [1/2]

std::string testinter::StreamCache::unique_name ( std::string  iBase)
inlineprivate

Definition at line 103 of file TestInterProcessProd.cc.

References to_string().

103  {
104  auto pid = getpid();
105  iBase += std::to_string(pid);
106  iBase += "_";
107  iBase += std::to_string(id_);
108 
109  return iBase;
110  }
static std::string to_string(const XMLCh *ch)

◆ unique_name() [2/2]

std::string testinter::StreamCache::unique_name ( std::string  iBase)
inlineprivate

Definition at line 111 of file TestInterProcessRandomProd.cc.

References to_string().

111  {
112  auto pid = getpid();
113  iBase += std::to_string(pid);
114  iBase += "_";
115  iBase += std::to_string(id_);
116 
117  return iBase;
118  }
static std::string to_string(const XMLCh *ch)

Member Data Documentation

◆ bl_deserializer_

TCDeserializer testinter::StreamCache::bl_deserializer_
private

Definition at line 121 of file TestInterProcessProd.cc.

◆ br_deserializer_

TCDeserializer testinter::StreamCache::br_deserializer_
private

Definition at line 119 of file TestInterProcessProd.cc.

◆ channel_

ControllerChannel testinter::StreamCache::channel_
private

Definition at line 114 of file TestInterProcessProd.cc.

◆ deserializer_

TCDeserializer testinter::StreamCache::deserializer_
private

Definition at line 118 of file TestInterProcessProd.cc.

◆ el_deserializer_

TCDeserializer testinter::StreamCache::el_deserializer_
private

Definition at line 122 of file TestInterProcessProd.cc.

◆ er_deserializer_

TCDeserializer testinter::StreamCache::er_deserializer_
private

Definition at line 120 of file TestInterProcessProd.cc.

◆ externalFailed_

bool testinter::StreamCache::externalFailed_ = false
private

Definition at line 123 of file TestInterProcessProd.cc.

◆ id_

int testinter::StreamCache::id_
private

Definition at line 112 of file TestInterProcessProd.cc.

◆ pipe_

FILE * testinter::StreamCache::pipe_
private

Definition at line 113 of file TestInterProcessProd.cc.

◆ randSerializer_

TCSerializer testinter::StreamCache::randSerializer_
private

Definition at line 130 of file TestInterProcessRandomProd.cc.

◆ readBuffer_

ReadBuffer testinter::StreamCache::readBuffer_
private

Definition at line 115 of file TestInterProcessProd.cc.

◆ writeBuffer_

WriteBuffer testinter::StreamCache::writeBuffer_
private

Definition at line 124 of file TestInterProcessRandomProd.cc.