CMS 3D CMS Logo

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

Public Member Functions

ExternalGeneratorLumiInfo beginLumiProduce (unsigned long long iTransitionID, edm::RandomNumberGeneratorState const &iState)
 
template<typename SERIAL >
auto doTransition (SERIAL &iDeserializer, edm::Transition iTrans, unsigned long long iTransitionID) -> decltype(iDeserializer.deserialize())
 
std::optional< GenLumiInfoProductendLumiProduce (unsigned long long iTransitionID)
 
std::optional< GenRunInfoProductendRunProduce (unsigned long long iTransitionID)
 
ExternalGeneratorEventInfo produce (edm::StreamID iStream, unsigned long long iTransitionID)
 
 StreamCache (const std::string &iConfig, int id, bool verbose, unsigned int waitTime)
 
 ~StreamCache ()
 

Private Types

template<typename T >
using Deserializer = ROOTDeserializer< T, ReadBuffer >
 

Private Member Functions

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

Private Attributes

Deserializer< ExternalGeneratorLumiInfobl_deserializer_
 
ControllerChannel channel_
 
Deserializer< ExternalGeneratorEventInfodeserializer_
 
Deserializer< GenLumiInfoProductel_deserializer_
 
Deserializer< GenRunInfoProducter_deserializer_
 
bool externalFailed_ = false
 
int id_
 
FILE * pipe_
 
ROOTSerializer< edm::RandomNumberGeneratorState, WriteBufferrandSerializer_
 
ReadBuffer readBuffer_
 
WriteBuffer writeBuffer_
 

Detailed Description

Definition at line 32 of file ExternalGeneratorFilter.cc.

Member Typedef Documentation

◆ Deserializer

template<typename T >
using externalgen::StreamCache::Deserializer = ROOTDeserializer<T, ReadBuffer>
private

Definition at line 138 of file ExternalGeneratorFilter.cc.

Constructor & Destructor Documentation

◆ StreamCache()

externalgen::StreamCache::StreamCache ( const std::string &  iConfig,
int  id,
bool  verbose,
unsigned int  waitTime 
)
inline

Definition at line 33 of file ExternalGeneratorFilter.cc.

34  : id_{id},
35  channel_("extGen", id_, waitTime),
43  //make sure output is flushed before popen does any writing
44  fflush(stdout);
45  fflush(stderr);
46 
47  channel_.setupWorker([&]() {
48  using namespace std::string_literals;
49  edm::LogSystem("ExternalProcess") << id_ << " starting external process \n";
50  std::string verboseCommand;
51  if (verbose) {
52  verboseCommand = "--verbose ";
53  }
54  pipe_ =
55  popen(("cmsExternalGenerator "s + verboseCommand + channel_.sharedMemoryName() + " " + channel_.uniqueID())
56  .c_str(),
57  "w");
58  if (nullptr == pipe_) {
59  abort();
60  }
61 
62  {
63  auto nlines = std::to_string(std::count(iConfig.begin(), iConfig.end(), '\n'));
64  auto result = fwrite(nlines.data(), sizeof(char), nlines.size(), pipe_);
65  assert(result == nlines.size());
66  result = fwrite(iConfig.data(), sizeof(char), iConfig.size(), pipe_);
67  assert(result == iConfig.size());
68  fflush(pipe_);
69  }
70  });
71  }
BufferInfo * toWorkerBufferInfo()
This can be used with WriteBuffer to keep Controller and Worker in sync.
Log< level::System, false > LogSystem
bool verbose
Deserializer< ExternalGeneratorEventInfo > deserializer_
ROOTSerializer< edm::RandomNumberGeneratorState, WriteBuffer > randSerializer_
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)
Deserializer< ExternalGeneratorLumiInfo > bl_deserializer_
Deserializer< GenRunInfoProduct > er_deserializer_
Deserializer< GenLumiInfoProduct > el_deserializer_

◆ ~StreamCache()

externalgen::StreamCache::~StreamCache ( )
inline

Definition at line 116 of file ExternalGeneratorFilter.cc.

References sistrip::pipe_.

Member Function Documentation

◆ beginLumiProduce()

ExternalGeneratorLumiInfo externalgen::StreamCache::beginLumiProduce ( unsigned long long  iTransitionID,
edm::RandomNumberGeneratorState const &  iState 
)
inline

Definition at line 102 of file ExternalGeneratorFilter.cc.

References edm::BeginLuminosityBlock.

103  {
104  //NOTE: root serialize requires a `void*` not a `void const*` even though it doesn't modify the object
105  randSerializer_.serialize(const_cast<edm::RandomNumberGeneratorState&>(iState));
107  }
ROOTSerializer< edm::RandomNumberGeneratorState, WriteBuffer > randSerializer_
Deserializer< ExternalGeneratorLumiInfo > bl_deserializer_
auto doTransition(SERIAL &iDeserializer, edm::Transition iTrans, unsigned long long iTransitionID) -> decltype(iDeserializer.deserialize())

◆ doTransition()

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

Definition at line 74 of file ExternalGeneratorFilter.cc.

References edm::errors::EventGenerationFailure, Exception, and relativeConstraints::value.

75  {
76  decltype(iDeserializer.deserialize()) value;
77  if (not channel_.doTransition(
78  [&value, &iDeserializer]() { value = iDeserializer.deserialize(); }, iTrans, iTransitionID)) {
79  externalFailed_ = true;
81  << "failed waiting for external process " << channel_.uniqueID() << ". Timed out after "
82  << channel_.maxWaitInSeconds() << " seconds.";
83  }
84  return value;
85  }
unsigned int maxWaitInSeconds() const noexcept
Definition: value.py:1
bool doTransition(F &&iF, edm::Transition iTrans, unsigned long long iTransitionID)

◆ endLumiProduce()

std::optional<GenLumiInfoProduct> externalgen::StreamCache::endLumiProduce ( unsigned long long  iTransitionID)
inline

Definition at line 109 of file ExternalGeneratorFilter.cc.

References edm::EndLuminosityBlock.

109  {
110  if (not externalFailed_) {
112  }
113  return {};
114  }
auto doTransition(SERIAL &iDeserializer, edm::Transition iTrans, unsigned long long iTransitionID) -> decltype(iDeserializer.deserialize())
Deserializer< GenLumiInfoProduct > el_deserializer_

◆ endRunProduce()

std::optional<GenRunInfoProduct> externalgen::StreamCache::endRunProduce ( unsigned long long  iTransitionID)
inline

Definition at line 95 of file ExternalGeneratorFilter.cc.

References edm::EndRun.

95  {
96  if (not externalFailed_) {
98  }
99  return {};
100  }
Deserializer< GenRunInfoProduct > er_deserializer_
auto doTransition(SERIAL &iDeserializer, edm::Transition iTrans, unsigned long long iTransitionID) -> decltype(iDeserializer.deserialize())

◆ produce()

ExternalGeneratorEventInfo externalgen::StreamCache::produce ( edm::StreamID  iStream,
unsigned long long  iTransitionID 
)
inline

Definition at line 86 of file ExternalGeneratorFilter.cc.

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

86  {
88  auto& engine = gen->getEngine(iStream);
89  edm::RandomNumberGeneratorState state{engine.put(), engine.getSeed()};
91 
92  return doTransition(deserializer_, edm::Transition::Event, iTransitionID);
93  }
Deserializer< ExternalGeneratorEventInfo > deserializer_
ROOTSerializer< edm::RandomNumberGeneratorState, WriteBuffer > randSerializer_
def gen(fragment, howMuch)
Production test section ####.
auto doTransition(SERIAL &iDeserializer, edm::Transition iTrans, unsigned long long iTransitionID) -> decltype(iDeserializer.deserialize())

◆ unique_name()

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

Definition at line 122 of file ExternalGeneratorFilter.cc.

References to_string().

122  {
123  auto pid = getpid();
124  iBase += std::to_string(pid);
125  iBase += "_";
126  iBase += std::to_string(id_);
127 
128  return iBase;
129  }
static std::string to_string(const XMLCh *ch)

Member Data Documentation

◆ bl_deserializer_

Deserializer<ExternalGeneratorLumiInfo> externalgen::StreamCache::bl_deserializer_
private

Definition at line 141 of file ExternalGeneratorFilter.cc.

◆ channel_

ControllerChannel externalgen::StreamCache::channel_
private

Definition at line 133 of file ExternalGeneratorFilter.cc.

◆ deserializer_

Deserializer<ExternalGeneratorEventInfo> externalgen::StreamCache::deserializer_
private

Definition at line 139 of file ExternalGeneratorFilter.cc.

◆ el_deserializer_

Deserializer<GenLumiInfoProduct> externalgen::StreamCache::el_deserializer_
private

Definition at line 142 of file ExternalGeneratorFilter.cc.

◆ er_deserializer_

Deserializer<GenRunInfoProduct> externalgen::StreamCache::er_deserializer_
private

Definition at line 140 of file ExternalGeneratorFilter.cc.

◆ externalFailed_

bool externalgen::StreamCache::externalFailed_ = false
private

Definition at line 145 of file ExternalGeneratorFilter.cc.

◆ id_

int externalgen::StreamCache::id_
private

Definition at line 131 of file ExternalGeneratorFilter.cc.

◆ pipe_

FILE* externalgen::StreamCache::pipe_
private

Definition at line 132 of file ExternalGeneratorFilter.cc.

◆ randSerializer_

ROOTSerializer<edm::RandomNumberGeneratorState, WriteBuffer> externalgen::StreamCache::randSerializer_
private

Definition at line 143 of file ExternalGeneratorFilter.cc.

◆ readBuffer_

ReadBuffer externalgen::StreamCache::readBuffer_
private

Definition at line 134 of file ExternalGeneratorFilter.cc.

◆ writeBuffer_

WriteBuffer externalgen::StreamCache::writeBuffer_
private

Definition at line 135 of file ExternalGeneratorFilter.cc.