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 33 of file ExternalGeneratorFilter.cc.

Member Typedef Documentation

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

Definition at line 138 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 34 of file ExternalGeneratorFilter.cc.

References KineDebug3::count(), sistrip::pipe_, mps_fire::result, alignCSCRings::s, mps_setup::stdout, and AlCaHLTBitMon_QueryRunRegistry::string.

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

Definition at line 116 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 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())
template<typename SERIAL >
auto externalgen::StreamCache::doTransition ( SERIAL &  iDeserializer,
edm::Transition  iTrans,
unsigned long long  iTransitionID 
) -> decltype(iDeserializer.deserialize())
inline

Definition at line 76 of file ExternalGeneratorFilter.cc.

References Exception, and relativeConstraints::value.

77  {
78  decltype(iDeserializer.deserialize()) value;
79  if (not channel_.doTransition(
80  [&value, &iDeserializer]() { value = iDeserializer.deserialize(); }, iTrans, iTransitionID)) {
81  externalFailed_ = true;
82  throw cms::Exception("ExternalFailed") << "failed waiting for external process";
83  }
84  return value;
85  }
Definition: value.py:1
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 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_
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())
ExternalGeneratorEventInfo externalgen::StreamCache::produce ( edm::StreamID  iStream,
unsigned long long  iTransitionID 
)
inline

Definition at line 86 of file ExternalGeneratorFilter.cc.

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

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_
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
def gen(fragment, howMuch)
Production test section ####.
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 122 of file ExternalGeneratorFilter.cc.

References sysUtil::pid.

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

Member Data Documentation

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

Definition at line 141 of file ExternalGeneratorFilter.cc.

ControllerChannel externalgen::StreamCache::channel_
private

Definition at line 133 of file ExternalGeneratorFilter.cc.

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

Definition at line 139 of file ExternalGeneratorFilter.cc.

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

Definition at line 142 of file ExternalGeneratorFilter.cc.

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

Definition at line 140 of file ExternalGeneratorFilter.cc.

bool externalgen::StreamCache::externalFailed_ = false
private

Definition at line 145 of file ExternalGeneratorFilter.cc.

int externalgen::StreamCache::id_
private

Definition at line 131 of file ExternalGeneratorFilter.cc.

FILE* externalgen::StreamCache::pipe_
private

Definition at line 132 of file ExternalGeneratorFilter.cc.

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

Definition at line 143 of file ExternalGeneratorFilter.cc.

ReadBuffer externalgen::StreamCache::readBuffer_
private

Definition at line 134 of file ExternalGeneratorFilter.cc.

WriteBuffer externalgen::StreamCache::writeBuffer_
private

Definition at line 135 of file ExternalGeneratorFilter.cc.