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

Member Typedef Documentation

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

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

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

36  : id_{id},
37  channel_("extGen", id_, waitTime),
45  //make sure output is flushed before popen does any writing
46  fflush(stdout);
47  fflush(stderr);
48 
49  channel_.setupWorker([&]() {
50  using namespace std::string_literals;
51  using namespace boost::filesystem;
52  edm::LogSystem("ExternalProcess") << id_ << " starting external process \n";
53  std::string verboseCommand;
54  if (verbose) {
55  verboseCommand = "--verbose ";
56  }
57  auto curDir = current_path();
58  auto newDir = path("thread"s + std::to_string(id_));
59  create_directory(newDir);
60  current_path(newDir);
61  pipe_ =
62  popen(("cmsExternalGenerator "s + verboseCommand + channel_.sharedMemoryName() + " " + channel_.uniqueID())
63  .c_str(),
64  "w");
65  current_path(curDir);
66 
67  if (nullptr == pipe_) {
68  abort();
69  }
70 
71  {
72  auto nlines = std::to_string(std::count(iConfig.begin(), iConfig.end(), '\n'));
73  auto result = fwrite(nlines.data(), sizeof(char), nlines.size(), pipe_);
74  assert(result = nlines.size());
75  result = fwrite(iConfig.data(), sizeof(char), iConfig.size(), pipe_);
76  assert(result == iConfig.size());
77  fflush(pipe_);
78  }
79  });
80  }
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 123 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 109 of file ExternalGeneratorFilter.cc.

References edm::BeginLuminosityBlock.

110  {
111  //NOTE: root serialize requires a `void*` not a `void const*` even though it doesn't modify the object
112  randSerializer_.serialize(const_cast<edm::RandomNumberGeneratorState&>(iState));
114  }
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 83 of file ExternalGeneratorFilter.cc.

References Exception, and relativeConstraints::value.

84  {
85  decltype(iDeserializer.deserialize()) value;
86  if (not channel_.doTransition(
87  [&value, &iDeserializer]() { value = iDeserializer.deserialize(); }, iTrans, iTransitionID)) {
88  externalFailed_ = true;
89  throw cms::Exception("ExternalFailed") << "failed waiting for external process";
90  }
91  return value;
92  }
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 116 of file ExternalGeneratorFilter.cc.

References edm::EndLuminosityBlock.

116  {
117  if (not externalFailed_) {
119  }
120  return {};
121  }
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 102 of file ExternalGeneratorFilter.cc.

References edm::EndRun.

102  {
103  if (not externalFailed_) {
104  return doTransition(er_deserializer_, edm::Transition::EndRun, iTransitionID);
105  }
106  return {};
107  }
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 93 of file ExternalGeneratorFilter.cc.

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

93  {
95  auto& engine = gen->getEngine(iStream);
96  edm::RandomNumberGeneratorState state{engine.put(), engine.getSeed()};
98 
99  return doTransition(deserializer_, edm::Transition::Event, iTransitionID);
100  }
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 129 of file ExternalGeneratorFilter.cc.

References sysUtil::pid.

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

Member Data Documentation

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

Definition at line 148 of file ExternalGeneratorFilter.cc.

ControllerChannel externalgen::StreamCache::channel_
private

Definition at line 140 of file ExternalGeneratorFilter.cc.

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

Definition at line 146 of file ExternalGeneratorFilter.cc.

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

Definition at line 149 of file ExternalGeneratorFilter.cc.

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

Definition at line 147 of file ExternalGeneratorFilter.cc.

bool externalgen::StreamCache::externalFailed_ = false
private

Definition at line 152 of file ExternalGeneratorFilter.cc.

int externalgen::StreamCache::id_
private

Definition at line 138 of file ExternalGeneratorFilter.cc.

FILE* externalgen::StreamCache::pipe_
private

Definition at line 139 of file ExternalGeneratorFilter.cc.

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

Definition at line 150 of file ExternalGeneratorFilter.cc.

ReadBuffer externalgen::StreamCache::readBuffer_
private

Definition at line 141 of file ExternalGeneratorFilter.cc.

WriteBuffer externalgen::StreamCache::writeBuffer_
private

Definition at line 142 of file ExternalGeneratorFilter.cc.