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 116 of file TestInterProcessProd.cc.

◆ TCDeserializer [2/2]

Definition at line 125 of file TestInterProcessRandomProd.cc.

◆ TCSerializer

Definition at line 128 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 to_string(const V &value)
Definition: OMSAccess.h:71
std::string const & sharedMemoryName() const
BufferInfo * fromWorkerBufferInfo()
This can be used with ReadBuffer to keep Controller and Worker in sync.
assert(be >=bs)

◆ ~StreamCache() [1/2]

testinter::StreamCache::~StreamCache ( )
inline

Definition at line 96 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 to_string(const V &value)
Definition: OMSAccess.h:71
std::string const & sharedMemoryName() const
BufferInfo * fromWorkerBufferInfo()
This can be used with ReadBuffer to keep Controller and Worker in sync.
assert(be >=bs)

◆ ~StreamCache() [2/2]

testinter::StreamCache::~StreamCache ( )
inline

Definition at line 104 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 85 of file TestInterProcessProd.cc.

References edm::BeginLuminosityBlock.

85  {
87  }
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 95 of file TestInterProcessRandomProd.cc.

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

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

◆ beginRunProduce()

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

Definition at line 74 of file TestInterProcessProd.cc.

References edm::BeginRun.

Referenced by TestInterProcessProd::globalBeginRunProduce().

74  {
76  }
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.

55  {
56  decltype(iDeserializer.deserialize()) value;
57  if (not channel_.doTransition(
58  [&value, this]() {
59  value = deserializer_.deserialize();
60  std::cout << id_ << " from shared memory " << value.size() << std::endl;
61  },
62  iTrans,
63  iTransitionID)) {
64  std::cout << id_ << " FAILED waiting for external process" << std::endl;
65  externalFailed_ = true;
67  }
68  return value;
69  }
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.

67  {
68  decltype(iDeserializer.deserialize()) value;
69  if (not channel_.doTransition(
70  [&value, this]() {
71  value = deserializer_.deserialize();
72  std::cout << id_ << " from shared memory " << value.first.value << std::endl;
73  },
74  iTrans,
75  iTransitionID)) {
76  std::cout << id_ << " FAILED waiting for external process" << std::endl;
77  externalFailed_ = true;
79  }
80  return value;
81  }
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 89 of file TestInterProcessProd.cc.

References edm::EndLuminosityBlock.

89  {
90  if (not externalFailed_) {
92  }
93  return edmtest::ThingCollection();
94  }
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 78 of file TestInterProcessProd.cc.

References edm::EndRun.

78  {
79  if (not externalFailed_) {
81  }
82  return edmtest::ThingCollection();
83  }
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 70 of file TestInterProcessProd.cc.

References edm::Event.

70  {
71  return doTransition(deserializer_, edm::Transition::Event, iTransitionID);
72  }
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 82 of file TestInterProcessRandomProd.cc.

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

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

◆ unique_name() [1/2]

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

Definition at line 102 of file TestInterProcessProd.cc.

References cond::impl::to_string().

102  {
103  auto pid = getpid();
104  iBase += std::to_string(pid);
105  iBase += "_";
106  iBase += std::to_string(id_);
107 
108  return iBase;
109  }
std::string to_string(const V &value)
Definition: OMSAccess.h:71

◆ unique_name() [2/2]

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

Definition at line 110 of file TestInterProcessRandomProd.cc.

References cond::impl::to_string().

110  {
111  auto pid = getpid();
112  iBase += std::to_string(pid);
113  iBase += "_";
114  iBase += std::to_string(id_);
115 
116  return iBase;
117  }
std::string to_string(const V &value)
Definition: OMSAccess.h:71

Member Data Documentation

◆ bl_deserializer_

TCDeserializer testinter::StreamCache::bl_deserializer_
private

Definition at line 120 of file TestInterProcessProd.cc.

◆ br_deserializer_

TCDeserializer testinter::StreamCache::br_deserializer_
private

Definition at line 118 of file TestInterProcessProd.cc.

◆ channel_

ControllerChannel testinter::StreamCache::channel_
private

Definition at line 113 of file TestInterProcessProd.cc.

◆ deserializer_

TCDeserializer testinter::StreamCache::deserializer_
private

Definition at line 117 of file TestInterProcessProd.cc.

◆ el_deserializer_

TCDeserializer testinter::StreamCache::el_deserializer_
private

Definition at line 121 of file TestInterProcessProd.cc.

◆ er_deserializer_

TCDeserializer testinter::StreamCache::er_deserializer_
private

Definition at line 119 of file TestInterProcessProd.cc.

◆ externalFailed_

bool testinter::StreamCache::externalFailed_ = false
private

Definition at line 122 of file TestInterProcessProd.cc.

◆ id_

int testinter::StreamCache::id_
private

Definition at line 111 of file TestInterProcessProd.cc.

◆ pipe_

FILE * testinter::StreamCache::pipe_
private

Definition at line 112 of file TestInterProcessProd.cc.

◆ randSerializer_

TCSerializer testinter::StreamCache::randSerializer_
private

Definition at line 129 of file TestInterProcessRandomProd.cc.

◆ readBuffer_

ReadBuffer testinter::StreamCache::readBuffer_
private

Definition at line 114 of file TestInterProcessProd.cc.

◆ writeBuffer_

WriteBuffer testinter::StreamCache::writeBuffer_
private

Definition at line 123 of file TestInterProcessRandomProd.cc.