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)
 
virtual ~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
 
virtual ~EDProducerBase ()
 
- 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 ()
 
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, std::unordered_multimap< std::string, edm::ProductResolverIndex > 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

virtual void beginRunProduce (edm::Run &run, edm::EventSetup const &es) override
 
int closeDescriptors (int preserve)
 
virtual void endRunProduce (edm::Run &, edm::EventSetup const &) override
 
void executeScript ()
 
void nextEvent ()
 
virtual void preallocThreads (unsigned int) override
 
virtual 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
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 69 of file ExternalLHEProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 132 of file ExternalLHEProducer.cc.

References args_, and npars_.

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

Definition at line 150 of file ExternalLHEProducer.cc.

151 {
152 }

Member Function Documentation

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

Definition at line 227 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.

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

Definition at line 337 of file ExternalLHEProducer.cc.

References dir, reco::dp, and NULL.

Referenced by executeScript().

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

Definition at line 312 of file ExternalLHEProducer.cc.

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

313 {
314 
315  if (!runInfoProducts.empty()) {
316  std::unique_ptr<LHERunInfoProduct> product(runInfoProducts.pop_front().release());
317  run.put(std::move(product));
318  }
319 
320  nextEvent();
321  if (partonLevel) {
322  throw edm::Exception(edm::errors::EventGenerationFailure) << "Error in ExternalLHEProducer::endRunProduce(). "
323  << "Event loop is over, but there are still lhe events to process."
324  << "This could happen if lhe file contains more events than requested. This is never expected to happen.";
325  }
326 
327  reader_.reset();
328 
329  if (unlink(outputFile_.c_str())) {
330  throw cms::Exception("OutputDeleteError") << "Unable to delete original script output file " << outputFile_ << " (errno=" << errno << ", " << strerror(errno) << ").";
331  }
332 
333 }
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:111
boost::ptr_deque< LHERunInfoProduct > runInfoProducts
def move(src, dest)
Definition: eostools.py:510
void ExternalLHEProducer::executeScript ( )
private

Definition at line 376 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().

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

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

496  {
497  //The following says we do not know what parameters are allowed so do no validation
498  // Please change this to state exactly what you do use, even if it is no parameters
500  desc.setComment("Executes an external script and places its output file into an EDM collection");
501 
502  edm::FileInPath thePath;
503  desc.add<edm::FileInPath>("scriptName", thePath);
504  desc.add<std::string>("outputFile", "myoutput");
505  desc.add<std::vector<std::string> >("args");
506  desc.add<uint32_t>("numberOfParameters");
507  desc.addUntracked<uint32_t>("nEvents");
508  desc.addUntracked<bool>("storeXML", false);
509 
510  descriptions.addDefault(desc);
511 }
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 513 of file ExternalLHEProducer.cc.

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

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

514 {
515 
516  if (partonLevel)
517  return;
518 
519  if(not reader_) { return;}
520  partonLevel = reader_->next();
521  if (!partonLevel)
522  return;
523 
524  boost::shared_ptr<lhef::LHERunInfo> runInfoThis = partonLevel->getRunInfo();
525  if (runInfoThis != runInfoLast) {
526  runInfo = runInfoThis;
527  runInfoLast = runInfoThis;
528  }
529 }
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 161 of file ExternalLHEProducer.cc.

References nThreads_.

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

Definition at line 168 of file ExternalLHEProducer.cc.

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

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

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

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

Member Data Documentation

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

Definition at line 95 of file ExternalLHEProducer.cc.

Referenced by beginRunProduce().

uint32_t ExternalLHEProducer::npars_
private

Definition at line 94 of file ExternalLHEProducer.cc.

Referenced by ExternalLHEProducer().

unsigned int ExternalLHEProducer::nThreads_ {1}
private

Definition at line 97 of file ExternalLHEProducer.cc.

Referenced by beginRunProduce(), and preallocThreads().

std::string ExternalLHEProducer::outputContents_
private

Definition at line 98 of file ExternalLHEProducer.cc.

std::string ExternalLHEProducer::outputFile_
private

Definition at line 92 of file ExternalLHEProducer.cc.

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

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

Definition at line 103 of file ExternalLHEProducer.cc.

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

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

Definition at line 100 of file ExternalLHEProducer.cc.

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

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

Definition at line 102 of file ExternalLHEProducer.cc.

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

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

Definition at line 101 of file ExternalLHEProducer.cc.

Referenced by beginRunProduce(), and nextEvent().

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

Definition at line 104 of file ExternalLHEProducer.cc.

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

std::string ExternalLHEProducer::scriptName_
private

Definition at line 91 of file ExternalLHEProducer.cc.

Referenced by executeScript().

bool ExternalLHEProducer::storeXML_
private

Definition at line 96 of file ExternalLHEProducer.cc.

Referenced by beginRunProduce().

bool ExternalLHEProducer::wasMerged
private

Definition at line 105 of file ExternalLHEProducer.cc.

Referenced by beginRunProduce(), and produce().