CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
< ExternalGeneratorLumiInfo
bl_deserializer_
 
ControllerChannel channel_
 
Deserializer
< ExternalGeneratorEventInfo
deserializer_
 
Deserializer< GenLumiInfoProductel_deserializer_
 
Deserializer< GenRunInfoProducter_deserializer_
 
bool externalFailed_ = false
 
int id_
 
FILE * pipe_
 
ROOTSerializer
< edm::RandomNumberGeneratorState,
WriteBuffer
randSerializer_
 
ReadBuffer readBuffer_
 
WriteBuffer writeBuffer_
 

Detailed Description

Definition at line 32 of file ExternalGeneratorFilter.cc.

Member Typedef Documentation

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

Definition at line 137 of file ExternalGeneratorFilter.cc.

Constructor & Destructor Documentation

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
Deserializer< ExternalGeneratorEventInfo > deserializer_
ROOTSerializer< edm::RandomNumberGeneratorState, WriteBuffer > randSerializer_
std::string to_string(const V &value)
Definition: OMSAccess.h:71
BufferInfo * fromWorkerBufferInfo()
This can be used with ReadBuffer to keep Controller and Worker in sync.
assert(be >=bs)
tuple result
Definition: mps_fire.py:311
static constexpr int verbose
std::string const & sharedMemoryName() const
Deserializer< ExternalGeneratorLumiInfo > bl_deserializer_
Deserializer< GenRunInfoProduct > er_deserializer_
Deserializer< GenLumiInfoProduct > el_deserializer_
externalgen::StreamCache::~StreamCache ( )
inline

Definition at line 115 of file ExternalGeneratorFilter.cc.

References sistrip::pipe_.

Member Function Documentation

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

Definition at line 101 of file ExternalGeneratorFilter.cc.

References edm::BeginLuminosityBlock.

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

75  {
76  decltype(iDeserializer.deserialize()) value;
77  if (not channel_.doTransition(
78  [&value, &iDeserializer]() { value = iDeserializer.deserialize(); }, iTrans, iTransitionID)) {
79  externalFailed_ = true;
80  throw cms::Exception("ExternalFailed")
81  << "failed waiting for external process. Timed out after " << channel_.maxWaitInSeconds() << " seconds.";
82  }
83  return value;
84  }
unsigned int maxWaitInSeconds() const noexcept
bool doTransition(F &&iF, edm::Transition iTrans, unsigned long long iTransitionID)
std::optional<GenLumiInfoProduct> externalgen::StreamCache::endLumiProduce ( unsigned long long  iTransitionID)
inline

Definition at line 108 of file ExternalGeneratorFilter.cc.

References edm::EndLuminosityBlock.

108  {
109  if (not externalFailed_) {
111  }
112  return {};
113  }
auto doTransition(SERIAL &iDeserializer, edm::Transition iTrans, unsigned long long iTransitionID) -> decltype(iDeserializer.deserialize())
Deserializer< GenLumiInfoProduct > el_deserializer_
std::optional<GenRunInfoProduct> externalgen::StreamCache::endRunProduce ( unsigned long long  iTransitionID)
inline

Definition at line 94 of file ExternalGeneratorFilter.cc.

References edm::EndRun.

94  {
95  if (not externalFailed_) {
97  }
98  return {};
99  }
Deserializer< GenRunInfoProduct > er_deserializer_
auto doTransition(SERIAL &iDeserializer, edm::Transition iTrans, unsigned long long iTransitionID) -> decltype(iDeserializer.deserialize())
ExternalGeneratorEventInfo externalgen::StreamCache::produce ( edm::StreamID  iStream,
unsigned long long  iTransitionID 
)
inline

Definition at line 85 of file ExternalGeneratorFilter.cc.

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

85  {
87  auto& engine = gen->getEngine(iStream);
88  edm::RandomNumberGeneratorState state{engine.put(), engine.getSeed()};
90 
91  return doTransition(deserializer_, edm::Transition::Event, iTransitionID);
92  }
Deserializer< ExternalGeneratorEventInfo > deserializer_
ROOTSerializer< edm::RandomNumberGeneratorState, WriteBuffer > randSerializer_
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
auto doTransition(SERIAL &iDeserializer, edm::Transition iTrans, unsigned long long iTransitionID) -> decltype(iDeserializer.deserialize())
std::string externalgen::StreamCache::unique_name ( std::string  iBase)
inlineprivate

Definition at line 121 of file ExternalGeneratorFilter.cc.

References cond::impl::to_string().

121  {
122  auto pid = getpid();
123  iBase += std::to_string(pid);
124  iBase += "_";
125  iBase += std::to_string(id_);
126 
127  return iBase;
128  }
std::string to_string(const V &value)
Definition: OMSAccess.h:71

Member Data Documentation

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

Definition at line 140 of file ExternalGeneratorFilter.cc.

ControllerChannel externalgen::StreamCache::channel_
private

Definition at line 132 of file ExternalGeneratorFilter.cc.

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

Definition at line 138 of file ExternalGeneratorFilter.cc.

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

Definition at line 141 of file ExternalGeneratorFilter.cc.

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

Definition at line 139 of file ExternalGeneratorFilter.cc.

bool externalgen::StreamCache::externalFailed_ = false
private

Definition at line 144 of file ExternalGeneratorFilter.cc.

int externalgen::StreamCache::id_
private

Definition at line 130 of file ExternalGeneratorFilter.cc.

FILE* externalgen::StreamCache::pipe_
private

Definition at line 131 of file ExternalGeneratorFilter.cc.

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

Definition at line 142 of file ExternalGeneratorFilter.cc.

ReadBuffer externalgen::StreamCache::readBuffer_
private

Definition at line 133 of file ExternalGeneratorFilter.cc.

WriteBuffer externalgen::StreamCache::writeBuffer_
private

Definition at line 134 of file ExternalGeneratorFilter.cc.