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 144 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  using namespace std::filesystem;
50  edm::LogSystem("ExternalProcess") << id_ << " starting external process \n";
51  std::string verboseCommand;
52  if (verbose) {
53  verboseCommand = "--verbose ";
54  }
55  auto curDir = current_path();
56  auto newDir = path("thread"s + std::to_string(id_));
57  create_directory(newDir);
58  current_path(newDir);
59  pipe_ =
60  popen(("cmsExternalGenerator "s + verboseCommand + channel_.sharedMemoryName() + " " + channel_.uniqueID())
61  .c_str(),
62  "w");
63  current_path(curDir);
64 
65  if (nullptr == pipe_) {
66  abort();
67  }
68 
69  {
70  auto nlines = std::to_string(std::count(iConfig.begin(), iConfig.end(), '\n'));
71  auto result = fwrite(nlines.data(), sizeof(char), nlines.size(), pipe_);
72  assert(result = nlines.size());
73  result = fwrite(iConfig.data(), sizeof(char), iConfig.size(), pipe_);
74  assert(result == iConfig.size());
75  fflush(pipe_);
76  }
77  });
78  }

◆ ~StreamCache()

externalgen::StreamCache::~StreamCache ( )
inline

Definition at line 122 of file ExternalGeneratorFilter.cc.

122  {
124  pclose(pipe_);
125  }

References sistrip::pipe_.

Member Function Documentation

◆ beginLumiProduce()

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

Definition at line 108 of file ExternalGeneratorFilter.cc.

109  {
110  //NOTE: root serialize requires a `void*` not a `void const*` even though it doesn't modify the object
111  randSerializer_.serialize(const_cast<edm::RandomNumberGeneratorState&>(iState));
113  }

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

82  {
83  decltype(iDeserializer.deserialize()) value;
84  if (not channel_.doTransition(
85  [&value, &iDeserializer]() { value = iDeserializer.deserialize(); }, iTrans, iTransitionID)) {
86  externalFailed_ = true;
87  throw cms::Exception("ExternalFailed")
88  << "failed waiting for external process. Timed out after " << channel_.maxWaitInSeconds() << " seconds.";
89  }
90  return value;
91  }

References Exception, and relativeConstraints::value.

◆ endLumiProduce()

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

Definition at line 115 of file ExternalGeneratorFilter.cc.

115  {
116  if (not externalFailed_) {
118  }
119  return {};
120  }

References edm::EndLuminosityBlock.

◆ endRunProduce()

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

Definition at line 101 of file ExternalGeneratorFilter.cc.

101  {
102  if (not externalFailed_) {
103  return doTransition(er_deserializer_, edm::Transition::EndRun, iTransitionID);
104  }
105  return {};
106  }

References edm::EndRun.

◆ produce()

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

Definition at line 92 of file ExternalGeneratorFilter.cc.

92  {
94  auto& engine = gen->getEngine(iStream);
95  edm::RandomNumberGeneratorState state{engine.put(), engine.getSeed()};
97 
98  return doTransition(deserializer_, edm::Transition::Event, iTransitionID);
99  }

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

◆ unique_name()

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

Definition at line 128 of file ExternalGeneratorFilter.cc.

128  {
129  auto pid = getpid();
130  iBase += std::to_string(pid);
131  iBase += "_";
132  iBase += std::to_string(id_);
133 
134  return iBase;
135  }

Member Data Documentation

◆ bl_deserializer_

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

Definition at line 147 of file ExternalGeneratorFilter.cc.

◆ channel_

ControllerChannel externalgen::StreamCache::channel_
private

Definition at line 139 of file ExternalGeneratorFilter.cc.

◆ deserializer_

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

Definition at line 145 of file ExternalGeneratorFilter.cc.

◆ el_deserializer_

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

Definition at line 148 of file ExternalGeneratorFilter.cc.

◆ er_deserializer_

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

Definition at line 146 of file ExternalGeneratorFilter.cc.

◆ externalFailed_

bool externalgen::StreamCache::externalFailed_ = false
private

Definition at line 151 of file ExternalGeneratorFilter.cc.

◆ id_

int externalgen::StreamCache::id_
private

Definition at line 137 of file ExternalGeneratorFilter.cc.

◆ pipe_

FILE* externalgen::StreamCache::pipe_
private

Definition at line 138 of file ExternalGeneratorFilter.cc.

◆ randSerializer_

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

Definition at line 149 of file ExternalGeneratorFilter.cc.

◆ readBuffer_

ReadBuffer externalgen::StreamCache::readBuffer_
private

Definition at line 140 of file ExternalGeneratorFilter.cc.

◆ writeBuffer_

WriteBuffer externalgen::StreamCache::writeBuffer_
private

Definition at line 141 of file ExternalGeneratorFilter.cc.

edm::LogSystem
Log< level::System, false > LogSystem
Definition: MessageLogger.h:124
externalgen::StreamCache::pipe_
FILE * pipe_
Definition: ExternalGeneratorFilter.cc:138
edm::shared_memory::ControllerChannel::maxWaitInSeconds
unsigned int maxWaitInSeconds() const noexcept
Definition: ControllerChannel.h:163
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:143
edm::Transition::Event
cms::cuda::assert
assert(be >=bs)
edm::shared_memory::ControllerChannel::uniqueID
std::string uniqueID() const
Definition: ControllerChannel.h:158
externalgen::StreamCache::el_deserializer_
Deserializer< GenLumiInfoProduct > el_deserializer_
Definition: ExternalGeneratorFilter.cc:148
alignCSCRings.s
s
Definition: alignCSCRings.py:92
edm::RandomNumberGeneratorState
Definition: RandomNumberGeneratorState.h:11
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
verbose
static constexpr int verbose
Definition: HLTExoticaSubAnalysis.cc:25
edm::shared_memory::ControllerChannel::stopWorker
void stopWorker()
Definition: ControllerChannel.h:147
edm::Transition::BeginLuminosityBlock
gen
Definition: PythiaDecays.h:13
edm::shared_memory::ROOTSerializer::serialize
void serialize(T &iValue)
Definition: ROOTSerializer.h:44
submitPVResolutionJobs.stderr
stderr
Definition: submitPVResolutionJobs.py:45
edm::shared_memory::ControllerChannel::fromWorkerBufferInfo
BufferInfo * fromWorkerBufferInfo()
This can be used with ReadBuffer to keep Controller and Worker in sync.
Definition: ControllerChannel.h:145
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:81
externalgen::StreamCache::id_
int id_
Definition: ExternalGeneratorFilter.cc:137
externalgen::StreamCache::readBuffer_
ReadBuffer readBuffer_
Definition: ExternalGeneratorFilter.cc:140
edm::Service< edm::RandomNumberGenerator >
value
Definition: value.py:1
edm::shared_memory::ControllerChannel::sharedMemoryName
std::string const & sharedMemoryName() const
Definition: ControllerChannel.h:157
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
externalgen::StreamCache::bl_deserializer_
Deserializer< ExternalGeneratorLumiInfo > bl_deserializer_
Definition: ExternalGeneratorFilter.cc:147
externalgen::StreamCache::writeBuffer_
WriteBuffer writeBuffer_
Definition: ExternalGeneratorFilter.cc:141
edm::Transition::EndLuminosityBlock
RunInfoPI::state
state
Definition: RunInfoPayloadInspectoHelper.h:16
externalgen::StreamCache::deserializer_
Deserializer< ExternalGeneratorEventInfo > deserializer_
Definition: ExternalGeneratorFilter.cc:145
relativeConstraints.value
value
Definition: relativeConstraints.py:53
Exception
Definition: hltDiff.cc:245
relval_steps.gen
def gen(fragment, howMuch)
Production test section ####.
Definition: relval_steps.py:506
externalgen::StreamCache::randSerializer_
ROOTSerializer< edm::RandomNumberGeneratorState, WriteBuffer > randSerializer_
Definition: ExternalGeneratorFilter.cc:149
mps_fire.result
result
Definition: mps_fire.py:311
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
externalgen::StreamCache::externalFailed_
bool externalFailed_
Definition: ExternalGeneratorFilter.cc:151
edm::shared_memory::ControllerChannel::doTransition
bool doTransition(F &&iF, edm::Transition iTrans, unsigned long long iTransitionID)
Definition: ControllerChannel.h:102
edm::Transition::EndRun
externalgen::StreamCache::er_deserializer_
Deserializer< GenRunInfoProduct > er_deserializer_
Definition: ExternalGeneratorFilter.cc:146
externalgen::StreamCache::channel_
ControllerChannel channel_
Definition: ExternalGeneratorFilter.cc:139