CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
ExternalLHEProducer Class Reference

#include <Example/ExternalLHEProducer/src/ExternalLHEProducer.cc>

Inheritance diagram for ExternalLHEProducer:
edm::one::EDProducer< edm::BeginRunProducer, edm::EndRunProducer > edm::one::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Classes

class  FileCloseSentry
 

Public Member Functions

 ExternalLHEProducer (const edm::ParameterSet &iConfig)
 
 ~ExternalLHEProducer () override
 
- Public Member Functions inherited from edm::one::EDProducer< edm::BeginRunProducer, edm::EndRunProducer >
 EDProducer ()=default
 
- Public Member Functions inherited from edm::one::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::one::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

void beginRunProduce (edm::Run &run, edm::EventSetup const &es) override
 
int closeDescriptors (int preserve)
 
void endRunProduce (edm::Run &, edm::EventSetup const &) override
 
void executeScript ()
 
void nextEvent ()
 
void preallocThreads (unsigned int) override
 
void produce (edm::Event &, const edm::EventSetup &) override
 
std::unique_ptr< std::string > readOutput ()
 

Private Attributes

std::vector< std::string > args_
 
uint32_t nEvents_
 
uint32_t npars_
 
unsigned int nThreads_ {1}
 
std::string outputContents_
 
std::string outputFile_
 
boost::shared_ptr< lhef::LHEEventpartonLevel
 
std::unique_ptr< lhef::LHEReaderreader_
 
boost::shared_ptr< lhef::LHERunInforunInfo
 
boost::shared_ptr< lhef::LHERunInforunInfoLast
 
boost::ptr_deque< LHERunInfoProductrunInfoProducts
 
std::string scriptName_
 
bool storeXML_
 
bool wasMerged
 

Additional Inherited Members

- Public Types inherited from edm::one::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Description: [one line class summary]

Implementation: [Notes on implementation]

Definition at line 70 of file ExternalLHEProducer.cc.

Constructor & Destructor Documentation

ExternalLHEProducer::ExternalLHEProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 133 of file ExternalLHEProducer.cc.

References args_, and npars_.

133  :
134  scriptName_((iConfig.getParameter<edm::FileInPath>("scriptName")).fullPath()),
135  outputFile_(iConfig.getParameter<std::string>("outputFile")),
136  args_(iConfig.getParameter<std::vector<std::string> >("args")),
137  npars_(iConfig.getParameter<uint32_t>("numberOfParameters")),
138  nEvents_(iConfig.getUntrackedParameter<uint32_t>("nEvents")),
139  storeXML_(iConfig.getUntrackedParameter<bool>("storeXML"))
140 {
141  if (npars_ != args_.size())
142  throw cms::Exception("ExternalLHEProducer") << "Problem with configuration: " << args_.size() << " script arguments given, expected " << npars_;
143  produces<LHEXMLStringProduct, edm::Transition::BeginRun>("LHEScriptOutput");
144 
145  produces<LHEEventProduct>();
146  produces<LHERunInfoProduct, edm::Transition::BeginRun>();
147  produces<LHERunInfoProduct, edm::Transition::EndRun>();
148 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< std::string > args_
ExternalLHEProducer::~ExternalLHEProducer ( )
override

Definition at line 151 of file ExternalLHEProducer.cc.

152 {
153 }

Member Function Documentation

void ExternalLHEProducer::beginRunProduce ( edm::Run run,
edm::EventSetup const &  es 
)
overrideprivate

Definition at line 228 of file ExternalLHEProducer.cc.

References LHERunInfoProduct::addComment(), LHERunInfoProduct::addHeader(), args_, Exception, executeScript(), edm::Service< T >::isAvailable(), LogDebug, eostools::move(), edm::RandomNumberGenerator::mySeed(), nEvents_, nextEvent(), nThreads_, outputFile_, AlCaHLTBitMon_ParallelJobs::p, edm::Run::put(), reader_, runInfo, runInfoLast, runInfoProducts, createPayload::skip, storeXML_, and wasMerged.

229 {
230 
231  // pass the number of events as previous to last argument
232 
233  std::ostringstream eventStream;
234  eventStream << nEvents_;
235  // args_.push_back(eventStream.str());
236  args_.insert(args_.begin() + 1, eventStream.str());
237 
238  // pass the random number generator seed as last argument
239 
241 
242  if ( ! rng.isAvailable()) {
243  throw cms::Exception("Configuration")
244  << "The ExternalLHEProducer module requires the RandomNumberGeneratorService\n"
245  "which is not present in the configuration file. You must add the service\n"
246  "in the configuration file if you want to run ExternalLHEProducer";
247  }
248  std::ostringstream randomStream;
249  randomStream << rng->mySeed();
250  // args_.push_back(randomStream.str());
251  args_.insert(args_.begin() + 2, randomStream.str());
252 
253  // args_.emplace_back(std::to_string(nThreads_));
254  args_.insert(args_.begin() + 3, std::to_string(nThreads_));
255 
256  for ( unsigned int iArg = 0; iArg < args_.size() ; iArg++ ) {
257  LogDebug("LHEInputArgs") << "arg [" << iArg << "] = " << args_[iArg];
258  }
259 
260  executeScript();
261 
262  //fill LHEXMLProduct (streaming read directly into compressed buffer to save memory)
263  std::unique_ptr<LHEXMLStringProduct> p(new LHEXMLStringProduct);
264 
265  //store the XML file only if explictly requested
266  if (storeXML_) {
267  std::ifstream instream(outputFile_);
268  if (!instream) {
269  throw cms::Exception("OutputOpenError") << "Unable to open script output file " << outputFile_ << ".";
270  }
271  instream.seekg (0, instream.end);
272  int insize = instream.tellg();
273  instream.seekg (0, instream.beg);
274  p->fillCompressedContent(instream, 0.25*insize);
275  instream.close();
276  }
277  run.put(std::move(p), "LHEScriptOutput");
278 
279  // LHE C++ classes translation
280  // (read back uncompressed file from disk in streaming mode again to save memory)
281 
282  std::vector<std::string> infiles(1, outputFile_);
283  unsigned int skip = 0;
284  reader_ = std::make_unique<lhef::LHEReader>(infiles, skip);
285 
286  nextEvent();
287  if (runInfoLast) {
289 
290  std::unique_ptr<LHERunInfoProduct> product(new LHERunInfoProduct(*runInfo->getHEPRUP()));
291  std::for_each(runInfo->getHeaders().begin(),
292  runInfo->getHeaders().end(),
293  boost::bind(&LHERunInfoProduct::addHeader,
294  product.get(), _1));
295  std::for_each(runInfo->getComments().begin(),
296  runInfo->getComments().end(),
297  boost::bind(&LHERunInfoProduct::addComment,
298  product.get(), _1));
299 
300  // keep a copy around in case of merging
301  runInfoProducts.push_back(new LHERunInfoProduct(*product));
302  wasMerged = false;
303 
304  run.put(std::move(product));
305 
306  runInfo.reset();
307  }
308 
309 }
#define LogDebug(id)
void addHeader(const Header &header)
std::vector< std::string > args_
boost::shared_ptr< lhef::LHERunInfo > runInfoLast
std::unique_ptr< lhef::LHEReader > reader_
bool isAvailable() const
Definition: Service.h:46
virtual std::uint32_t mySeed() const =0
boost::shared_ptr< lhef::LHERunInfo > runInfo
void addComment(const std::string &line)
void put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Run.h:114
boost::ptr_deque< LHERunInfoProduct > runInfoProducts
def move(src, dest)
Definition: eostools.py:510
int ExternalLHEProducer::closeDescriptors ( int  preserve)
private

Definition at line 345 of file ExternalLHEProducer.cc.

References dir, and reco::dp.

Referenced by executeScript().

346 {
347  int maxfd = 1024;
348  int fd;
349 #ifdef __linux__
350  DIR * dir;
351  struct dirent *dp;
352  maxfd = preserve;
353  if ((dir = opendir("/proc/self/fd"))) {
354  errno = 0;
355  while ((dp = readdir (dir)) != nullptr) {
356  if ((strcmp(dp->d_name, ".") == 0) || (strcmp(dp->d_name, "..") == 0)) {
357  continue;
358  }
359  if (sscanf(dp->d_name, "%d", &fd) != 1) {
360  //throw cms::Exception("closeDescriptors") << "Found unexpected filename in /proc/self/fd: " << dp->d_name;
361  return -1;
362  }
363  if (fd > maxfd) {
364  maxfd = fd;
365  }
366  }
367  if (errno) {
368  //throw cms::Exception("closeDescriptors") << "Unable to determine the number of fd (errno=" << errno << ", " << strerror(errno) << ").";
369  return errno;
370  }
371  closedir(dir);
372  }
373 #endif
374  // TODO: assert for an unreasonable number of fds?
375  for (fd=3; fd<maxfd+1; fd++) {
376  if (fd != preserve)
377  close(fd);
378  }
379  return 0;
380 }
auto dp
Definition: deltaR.h:22
dbl *** dir
Definition: mlp_gen.cc:35
void ExternalLHEProducer::endRunProduce ( edm::Run run,
edm::EventSetup const &  es 
)
overrideprivate

Definition at line 313 of file ExternalLHEProducer.cc.

References Exception, eostools::move(), nextEvent(), outputFile_, partonLevel, edm::Run::put(), reader_, and runInfoProducts.

314 {
315 
316  if (!runInfoProducts.empty()) {
317  std::unique_ptr<LHERunInfoProduct> product(runInfoProducts.pop_front().release());
318  run.put(std::move(product));
319  }
320 
321  nextEvent();
322  if (partonLevel) {
323  // VALIDATION_RUN env variable allows to finish event processing early without errors by sending SIGINT
324  if (std::getenv("VALIDATION_RUN") != nullptr) {
325  edm::LogWarning("ExternalLHEProducer")
326  << "Event loop is over, but there are still lhe events to process, ignoring...";
327  } else {
328  throw cms::Exception("ExternalLHEProducer")
329  << "Error in ExternalLHEProducer::endRunProduce(). "
330  << "Event loop is over, but there are still lhe events to process."
331  << "This could happen if lhe file contains more events than requested. This is never expected to happen.";
332  }
333  }
334 
335  reader_.reset();
336 
337  if (unlink(outputFile_.c_str())) {
338  throw cms::Exception("OutputDeleteError") << "Unable to delete original script output file " << outputFile_ << " (errno=" << errno << ", " << strerror(errno) << ").";
339  }
340 
341 }
boost::shared_ptr< lhef::LHEEvent > partonLevel
std::unique_ptr< lhef::LHEReader > reader_
void put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Run.h:114
boost::ptr_deque< LHERunInfoProduct > runInfoProducts
def move(src, dest)
Definition: eostools.py:510
void ExternalLHEProducer::executeScript ( )
private

Definition at line 384 of file ExternalLHEProducer.cc.

References edm::TimingServiceBase::addToCPUTime(), dir2webdir::argc, args_, cmsBatch::argv, closeDescriptors(), Exception, mps_fire::i, edm::Service< T >::isAvailable(), NULL, sysUtil::pid, pipe::pipe(), scriptName_, mps_update::status, ntuplemaker::time, and TriggerAnalyzer::write().

Referenced by beginRunProduce().

385 {
386 
387  // Fork a script, wait until it finishes.
388 
389  int rc = 0, rc2 = 0;
390  int filedes[2], fd_flags;
391  unsigned int argc;
392 
393  if (pipe(filedes)) {
394  throw cms::Exception("Unable to create a new pipe");
395  }
396  FileCloseSentry sentry1(filedes[0]), sentry2(filedes[1]);
397 
398  if ((fd_flags = fcntl(filedes[1], F_GETFD, NULL)) == -1) {
399  throw cms::Exception("ExternalLHEProducer") << "Failed to get pipe file descriptor flags (errno=" << rc << ", " << strerror(rc) << ")";
400  }
401  if (fcntl(filedes[1], F_SETFD, fd_flags | FD_CLOEXEC) == -1) {
402  throw cms::Exception("ExternalLHEProducer") << "Failed to set pipe file descriptor flags (errno=" << rc << ", " << strerror(rc) << ")";
403  }
404 
405  argc = 1 + args_.size();
406  // TODO: assert that we have a reasonable number of arguments
407  char **argv = new char *[argc+1];
408  argv[0] = strdup(scriptName_.c_str());
409  for (unsigned int i=1; i<argc; i++) {
410  argv[i] = strdup(args_[i-1].c_str());
411  }
412  argv[argc] = nullptr;
413 
414  pid_t pid = fork();
415  if (pid == 0) {
416  // The child process
417  if (!(rc = closeDescriptors(filedes[1]))) {
418  execvp(argv[0], argv); // If execv returns, we have an error.
419  rc = errno;
420  }
421  while ((write(filedes[1], &rc, sizeof(int)) == -1) && (errno == EINTR)) {}
422  _exit(1);
423  }
424 
425  // Free the arg vector ASAP
426  for (unsigned int i=0; i<args_.size()+1; i++) {
427  free(argv[i]);
428  }
429  delete [] argv;
430 
431  if (pid == -1) {
432  throw cms::Exception("ForkException") << "Unable to fork a child (errno=" << errno << ", " << strerror(errno) << ")";
433  }
434 
435  close(filedes[1]);
436  // If the exec succeeds, the read will fail.
437  while (((rc2 = read(filedes[0], &rc, sizeof(int))) == -1) && (errno == EINTR)) { rc2 = 0; }
438  if ((rc2 == sizeof(int)) && rc) {
439  throw cms::Exception("ExternalLHEProducer") << "Failed to execute script (errno=" << rc << ", " << strerror(rc) << ")";
440  }
441  close(filedes[0]);
442 
443  int status = 0;
444  errno = 0;
445  do {
446  if (waitpid(pid, &status, 0) < 0) {
447  if (errno == EINTR) {
448  continue;
449  } else {
450  throw cms::Exception("ExternalLHEProducer") << "Failed to read child status (errno=" << errno << ", " << strerror(errno) << ")";
451  }
452  }
453  if (WIFSIGNALED(status)) {
454  throw cms::Exception("ExternalLHEProducer") << "Child exited due to signal " << WTERMSIG(status) << ".";
455  }
456  if (WIFEXITED(status)) {
457  rc = WEXITSTATUS(status);
458  break;
459  }
460  } while (true);
462  if(ts.isAvailable()) {
463  struct rusage ru;
464  getrusage(RUSAGE_CHILDREN,&ru);
465  double time = static_cast<double>(ru.ru_stime.tv_sec) + (static_cast<double>(ru.ru_stime.tv_usec) * 1E-6);
466  ts->addToCPUTime(time);
467  }
468  if (rc) {
469  throw cms::Exception("ExternalLHEProducer") << "Child failed with exit code " << rc << ".";
470  }
471 
472 }
#define NULL
Definition: scimark2.h:8
std::vector< std::string > args_
virtual void addToCPUTime(double iTime)=0
int closeDescriptors(int preserve)
bool isAvailable() const
Definition: Service.h:46
def pipe(cmdline, input=None)
Definition: pipe.py:5
def write(self, setup)
void ExternalLHEProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 504 of file ExternalLHEProducer.cc.

References edm::ParameterSetDescription::add(), edm::ConfigurationDescriptions::addDefault(), edm::ParameterSetDescription::addUntracked(), edm::ParameterSetDescription::setComment(), and AlCaHLTBitMon_QueryRunRegistry::string.

504  {
505  //The following says we do not know what parameters are allowed so do no validation
506  // Please change this to state exactly what you do use, even if it is no parameters
508  desc.setComment("Executes an external script and places its output file into an EDM collection");
509 
510  edm::FileInPath thePath;
511  desc.add<edm::FileInPath>("scriptName", thePath);
512  desc.add<std::string>("outputFile", "myoutput");
513  desc.add<std::vector<std::string> >("args");
514  desc.add<uint32_t>("numberOfParameters");
515  desc.addUntracked<uint32_t>("nEvents");
516  desc.addUntracked<bool>("storeXML", false);
517 
518  descriptions.addDefault(desc);
519 }
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void setComment(std::string const &value)
void addDefault(ParameterSetDescription const &psetDescription)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void ExternalLHEProducer::nextEvent ( )
private

Definition at line 521 of file ExternalLHEProducer.cc.

References DEFINE_FWK_MODULE, partonLevel, reader_, runInfo, and runInfoLast.

Referenced by beginRunProduce(), endRunProduce(), and produce().

522 {
523 
524  if (partonLevel)
525  return;
526 
527  if(not reader_) { return;}
528  partonLevel = reader_->next();
529  if (!partonLevel)
530  return;
531 
532  boost::shared_ptr<lhef::LHERunInfo> runInfoThis = partonLevel->getRunInfo();
533  if (runInfoThis != runInfoLast) {
534  runInfo = runInfoThis;
535  runInfoLast = runInfoThis;
536  }
537 }
boost::shared_ptr< lhef::LHEEvent > partonLevel
boost::shared_ptr< lhef::LHERunInfo > runInfoLast
std::unique_ptr< lhef::LHEReader > reader_
boost::shared_ptr< lhef::LHERunInfo > runInfo
void ExternalLHEProducer::preallocThreads ( unsigned int  iThreads)
overrideprivatevirtual

Reimplemented from edm::one::EDProducerBase.

Definition at line 162 of file ExternalLHEProducer.cc.

References nThreads_.

163 {
164  nThreads_ = iThreads;
165 }
void ExternalLHEProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 169 of file ExternalLHEProducer.cc.

References LHEEventProduct::addComment(), LHERunInfoProduct::addComment(), LHERunInfoProduct::addHeader(), LHEEventProduct::addWeight(), Exception, eostools::move(), nextEvent(), partonLevel, edm::Event::put(), runInfo, runInfoProducts, and wasMerged.

170 {
171  nextEvent();
172  if (!partonLevel) {
173  throw cms::Exception("ExternalLHEProducer") << "No lhe event found in ExternalLHEProducer::produce(). "
174  << "The likely cause is that the lhe file contains fewer events than were requested, which is possible "
175  << "in case of phase space integration or uneweighting efficiency problems.";
176  }
177 
178  std::unique_ptr<LHEEventProduct> product(
179  new LHEEventProduct(*partonLevel->getHEPEUP(),
180  partonLevel->originalXWGTUP())
181  );
182  if (partonLevel->getPDF()) {
183  product->setPDF(*partonLevel->getPDF());
184  }
185  std::for_each(partonLevel->weights().begin(),
186  partonLevel->weights().end(),
187  boost::bind(&LHEEventProduct::addWeight,
188  product.get(), _1));
189  product->setScales(partonLevel->scales());
190  product->setNpLO(partonLevel->npLO());
191  product->setNpNLO(partonLevel->npNLO());
192  std::for_each(partonLevel->getComments().begin(),
193  partonLevel->getComments().end(),
194  boost::bind(&LHEEventProduct::addComment,
195  product.get(), _1));
196 
197  iEvent.put(std::move(product));
198 
199  if (runInfo) {
200  std::auto_ptr<LHERunInfoProduct> product(new LHERunInfoProduct(*runInfo->getHEPRUP()));
201  std::for_each(runInfo->getHeaders().begin(),
202  runInfo->getHeaders().end(),
203  boost::bind(&LHERunInfoProduct::addHeader,
204  product.get(), _1));
205  std::for_each(runInfo->getComments().begin(),
206  runInfo->getComments().end(),
207  boost::bind(&LHERunInfoProduct::addComment,
208  product.get(), _1));
209 
210  if (!runInfoProducts.empty()) {
211  runInfoProducts.front().mergeProduct(*product);
212  if (!wasMerged) {
213  runInfoProducts.pop_front();
214  runInfoProducts.push_front(product);
215  wasMerged = true;
216  }
217  }
218 
219  runInfo.reset();
220  }
221 
222  partonLevel.reset();
223  return;
224 }
boost::shared_ptr< lhef::LHEEvent > partonLevel
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
void addHeader(const Header &header)
void addComment(const std::string &line)
void addWeight(const WGT &wgt)
boost::shared_ptr< lhef::LHERunInfo > runInfo
void addComment(const std::string &line)
boost::ptr_deque< LHERunInfoProduct > runInfoProducts
def move(src, dest)
Definition: eostools.py:510
std::unique_ptr< std::string > ExternalLHEProducer::readOutput ( )
private

Definition at line 476 of file ExternalLHEProducer.cc.

References BUFSIZE, Exception, gen::n, outputFile_, and AlCaHLTBitMon_QueryRunRegistry::string.

477 {
478  int fd;
479  ssize_t n;
480  char buf[BUFSIZE];
481 
482  if ((fd = open(outputFile_.c_str(), O_RDONLY)) == -1) {
483  throw cms::Exception("OutputOpenError") << "Unable to open script output file " << outputFile_ << " (errno=" << errno << ", " << strerror(errno) << ").";
484  }
485 
486  std::stringstream ss;
487  while ((n = read(fd, buf, BUFSIZE)) > 0 || (n == -1 && errno == EINTR)) {
488  if (n > 0)
489  ss.write(buf, n);
490  }
491  if (n == -1) {
492  throw cms::Exception("OutputOpenError") << "Unable to read from script output file " << outputFile_ << " (errno=" << errno << ", " << strerror(errno) << ").";
493  }
494 
495  if (unlink(outputFile_.c_str())) {
496  throw cms::Exception("OutputDeleteError") << "Unable to delete original script output file " << outputFile_ << " (errno=" << errno << ", " << strerror(errno) << ").";
497  }
498 
499  return std::unique_ptr<std::string>(new std::string(ss.str()));
500 }
#define BUFSIZE

Member Data Documentation

std::vector<std::string> ExternalLHEProducer::args_
private
uint32_t ExternalLHEProducer::nEvents_
private

Definition at line 96 of file ExternalLHEProducer.cc.

Referenced by beginRunProduce().

uint32_t ExternalLHEProducer::npars_
private

Definition at line 95 of file ExternalLHEProducer.cc.

Referenced by ExternalLHEProducer().

unsigned int ExternalLHEProducer::nThreads_ {1}
private

Definition at line 98 of file ExternalLHEProducer.cc.

Referenced by beginRunProduce(), and preallocThreads().

std::string ExternalLHEProducer::outputContents_
private

Definition at line 99 of file ExternalLHEProducer.cc.

std::string ExternalLHEProducer::outputFile_
private

Definition at line 93 of file ExternalLHEProducer.cc.

Referenced by beginRunProduce(), endRunProduce(), and readOutput().

boost::shared_ptr<lhef::LHEEvent> ExternalLHEProducer::partonLevel
private

Definition at line 104 of file ExternalLHEProducer.cc.

Referenced by endRunProduce(), nextEvent(), and produce().

std::unique_ptr<lhef::LHEReader> ExternalLHEProducer::reader_
private

Definition at line 101 of file ExternalLHEProducer.cc.

Referenced by beginRunProduce(), endRunProduce(), and nextEvent().

boost::shared_ptr<lhef::LHERunInfo> ExternalLHEProducer::runInfo
private

Definition at line 103 of file ExternalLHEProducer.cc.

Referenced by beginRunProduce(), nextEvent(), and produce().

boost::shared_ptr<lhef::LHERunInfo> ExternalLHEProducer::runInfoLast
private

Definition at line 102 of file ExternalLHEProducer.cc.

Referenced by beginRunProduce(), and nextEvent().

boost::ptr_deque<LHERunInfoProduct> ExternalLHEProducer::runInfoProducts
private

Definition at line 105 of file ExternalLHEProducer.cc.

Referenced by beginRunProduce(), endRunProduce(), and produce().

std::string ExternalLHEProducer::scriptName_
private

Definition at line 92 of file ExternalLHEProducer.cc.

Referenced by executeScript().

bool ExternalLHEProducer::storeXML_
private

Definition at line 97 of file ExternalLHEProducer.cc.

Referenced by beginRunProduce().

bool ExternalLHEProducer::wasMerged
private

Definition at line 106 of file ExternalLHEProducer.cc.

Referenced by beginRunProduce(), and produce().