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)
 
 ~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 137 of file ExternalGeneratorFilter.cc.

Constructor & Destructor Documentation

◆ StreamCache()

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

Definition at line 33 of file ExternalGeneratorFilter.cc.

34  : id_{id},
35  channel_("extGen", id_),
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 
59  if (nullptr == pipe_) {
60  abort();
61  }
62 
63  {
64  auto nlines = std::to_string(std::count(iConfig.begin(), iConfig.end(), '\n'));
65  auto result = fwrite(nlines.data(), sizeof(char), nlines.size(), pipe_);
66  assert(result = nlines.size());
67  result = fwrite(iConfig.data(), sizeof(char), iConfig.size(), pipe_);
68  assert(result == iConfig.size());
69  fflush(pipe_);
70  }
71  });
72  }

◆ ~StreamCache()

externalgen::StreamCache::~StreamCache ( )
inline

Definition at line 115 of file ExternalGeneratorFilter.cc.

115  {
117  pclose(pipe_);
118  }

References sistrip::pipe_.

Member Function Documentation

◆ beginLumiProduce()

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

Definition at line 101 of file ExternalGeneratorFilter.cc.

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  }

References edm::BeginLuminosityBlock.

◆ doTransition()

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

Definition at line 75 of file ExternalGeneratorFilter.cc.

76  {
77  decltype(iDeserializer.deserialize()) value;
78  if (not channel_.doTransition(
79  [&value, &iDeserializer]() { value = iDeserializer.deserialize(); }, iTrans, iTransitionID)) {
80  externalFailed_ = true;
81  throw cms::Exception("ExternalFailed") << "failed waiting for external process";
82  }
83  return value;
84  }

References Exception, and relativeConstraints::value.

◆ endLumiProduce()

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

Definition at line 108 of file ExternalGeneratorFilter.cc.

108  {
109  if (not externalFailed_) {
111  }
112  return {};
113  }

References edm::EndLuminosityBlock.

◆ endRunProduce()

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

Definition at line 94 of file ExternalGeneratorFilter.cc.

94  {
95  if (not externalFailed_) {
97  }
98  return {};
99  }

References edm::EndRun.

◆ produce()

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

Definition at line 85 of file ExternalGeneratorFilter.cc.

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  }

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

◆ unique_name()

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

Definition at line 121 of file ExternalGeneratorFilter.cc.

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

Member Data Documentation

◆ bl_deserializer_

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

Definition at line 140 of file ExternalGeneratorFilter.cc.

◆ channel_

ControllerChannel externalgen::StreamCache::channel_
private

Definition at line 132 of file ExternalGeneratorFilter.cc.

◆ deserializer_

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

Definition at line 138 of file ExternalGeneratorFilter.cc.

◆ el_deserializer_

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

Definition at line 141 of file ExternalGeneratorFilter.cc.

◆ er_deserializer_

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

Definition at line 139 of file ExternalGeneratorFilter.cc.

◆ externalFailed_

bool externalgen::StreamCache::externalFailed_ = false
private

Definition at line 144 of file ExternalGeneratorFilter.cc.

◆ id_

int externalgen::StreamCache::id_
private

Definition at line 130 of file ExternalGeneratorFilter.cc.

◆ pipe_

FILE* externalgen::StreamCache::pipe_
private

Definition at line 131 of file ExternalGeneratorFilter.cc.

◆ randSerializer_

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

Definition at line 142 of file ExternalGeneratorFilter.cc.

◆ readBuffer_

ReadBuffer externalgen::StreamCache::readBuffer_
private

Definition at line 133 of file ExternalGeneratorFilter.cc.

◆ writeBuffer_

WriteBuffer externalgen::StreamCache::writeBuffer_
private

Definition at line 134 of file ExternalGeneratorFilter.cc.

externalgen::StreamCache::pipe_
FILE * pipe_
Definition: ExternalGeneratorFilter.cc:131
parallelization.stderr
stderr
Definition: parallelization.py:172
edm::shared_memory::ControllerChannel::setupWorker
void setupWorker(F &&iF)
Definition: ControllerChannel.h:56
edm::shared_memory::ControllerChannel::toWorkerBufferInfo
BufferInfo * toWorkerBufferInfo()
This can be used with WriteBuffer to keep Controller and Worker in sync.
Definition: ControllerChannel.h:87
edm::Transition::Event
edm::LogSystem
Definition: MessageLogger.h:222
cms::cuda::assert
assert(be >=bs)
edm::shared_memory::ControllerChannel::uniqueID
std::string uniqueID() const
Definition: ControllerChannel.h:102
externalgen::StreamCache::el_deserializer_
Deserializer< GenLumiInfoProduct > el_deserializer_
Definition: ExternalGeneratorFilter.cc:141
alignCSCRings.s
s
Definition: alignCSCRings.py:92
edm::RandomNumberGeneratorState
Definition: RandomNumberGeneratorState.h:11
verbose
static constexpr int verbose
Definition: HLTExoticaSubAnalysis.cc:25
edm::shared_memory::ControllerChannel::stopWorker
void stopWorker()
Definition: ControllerChannel.h:91
edm::Transition::BeginLuminosityBlock
gen
Definition: PythiaDecays.h:13
edm::shared_memory::ROOTSerializer::serialize
void serialize(T &iValue)
Definition: ROOTSerializer.h:44
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::shared_memory::ControllerChannel::fromWorkerBufferInfo
BufferInfo * fromWorkerBufferInfo()
This can be used with ReadBuffer to keep Controller and Worker in sync.
Definition: ControllerChannel.h:89
mps_setup.stdout
stdout
Definition: mps_setup.py:250
externalgen::StreamCache::doTransition
auto doTransition(SERIAL &iDeserializer, edm::Transition iTrans, unsigned long long iTransitionID) -> decltype(iDeserializer.deserialize())
Definition: ExternalGeneratorFilter.cc:75
externalgen::StreamCache::id_
int id_
Definition: ExternalGeneratorFilter.cc:130
KineDebug3::count
void count()
Definition: KinematicConstrainedVertexUpdatorT.h:21
externalgen::StreamCache::readBuffer_
ReadBuffer readBuffer_
Definition: ExternalGeneratorFilter.cc:133
edm::Service< edm::RandomNumberGenerator >
value
Definition: value.py:1
edm::shared_memory::ControllerChannel::sharedMemoryName
std::string const & sharedMemoryName() const
Definition: ControllerChannel.h:101
externalgen::StreamCache::bl_deserializer_
Deserializer< ExternalGeneratorLumiInfo > bl_deserializer_
Definition: ExternalGeneratorFilter.cc:140
externalgen::StreamCache::writeBuffer_
WriteBuffer writeBuffer_
Definition: ExternalGeneratorFilter.cc:134
edm::Transition::EndLuminosityBlock
externalgen::StreamCache::deserializer_
Deserializer< ExternalGeneratorEventInfo > deserializer_
Definition: ExternalGeneratorFilter.cc:138
relativeConstraints.value
value
Definition: relativeConstraints.py:53
Exception
Definition: hltDiff.cc:246
relval_steps.gen
def gen(fragment, howMuch)
Production test section ####.
Definition: relval_steps.py:500
externalgen::StreamCache::randSerializer_
ROOTSerializer< edm::RandomNumberGeneratorState, WriteBuffer > randSerializer_
Definition: ExternalGeneratorFilter.cc:142
mps_fire.result
result
Definition: mps_fire.py:303
externalgen::StreamCache::externalFailed_
bool externalFailed_
Definition: ExternalGeneratorFilter.cc:144
edm::shared_memory::ControllerChannel::doTransition
bool doTransition(F &&iF, edm::Transition iTrans, unsigned long long iTransitionID)
Definition: ControllerChannel.h:72
edm::Transition::EndRun
externalgen::StreamCache::er_deserializer_
Deserializer< GenRunInfoProduct > er_deserializer_
Definition: ExternalGeneratorFilter.cc:139
externalgen::StreamCache::channel_
ControllerChannel channel_
Definition: ExternalGeneratorFilter.cc:132