Page MenuHomeHEPForge

HepMC3Writer.cc
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

HepMC3Writer.cc

/**
* \authors The HEJ collaboration (see AUTHORS for details)
* \date 2019
* \copyright GPLv2 or later
*/
#include "HEJ/HepMC3Writer.hh"
#include <cassert>
#include "LHEF/LHEF.h"
#include "HEJ/exceptions.hh"
#ifdef HEJ_BUILD_WITH_HepMC3
#include "HepMC3/WriterAscii.h"
#include <utility>
#include "HEJ/Event.hh"
#include "HEJ/HepMC3Interface.hh"
namespace HEJ{
struct HepMC3Writer::HepMC3WriterImpl{
HepMC3Interface HepMC3_;
HepMC3WriterImpl & operator=(HepMC3WriterImpl const & other) = delete;
HepMC3WriterImpl(HepMC3WriterImpl const & other) = delete;
HepMC3WriterImpl & operator=(HepMC3WriterImpl && other) = delete;
HepMC3WriterImpl(HepMC3WriterImpl && other) = delete;
std::unique_ptr<HepMC3::WriterAscii> writer_;
std::string const file_;
HepMC3WriterImpl(
std::string const & file, LHEF::HEPRUP && heprup
):
HepMC3_{std::move(heprup)},
file_{file}
{}
void init_writer(){
writer_ = std::make_unique<HepMC3::WriterAscii>(file_, HepMC3_.run_info);
}
~HepMC3WriterImpl(){
if(!writer_) // make sure that we always write something
init_writer();
writer_->close();
}
void write(Event const & ev){
auto out_ev = HepMC3_(ev);
//! weight names are only available after first event
if(!writer_)
init_writer();
writer_->write_event(out_ev);
}
};
HepMC3Writer::HepMC3Writer(std::string const & file, LHEF::HEPRUP heprup):
impl_{ std::make_unique<HepMC3WriterImpl>(file, std::move(heprup)) }
{}
void HepMC3Writer::write(Event const & ev){
impl_->write(ev);
}
} // namespace HEJ
#else // no HepMC3
namespace HEJ{
class HepMC3Writer::HepMC3WriterImpl{};
HepMC3Writer::HepMC3Writer(std::string const &, LHEF::HEPRUP){
throw std::invalid_argument(
"Failed to create HepMC3 writer: "
"HEJ 2 was built without HepMC3 support"
);
}
void HepMC3Writer::write(Event const &){
assert(false);
}
}
#endif
namespace HEJ{
HepMC3Writer::~HepMC3Writer() = default;
}

File Metadata

Mime Type
text/x-c
Expires
Tue, Sep 30, 6:12 AM (11 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6532645
Default Alt Text
HepMC3Writer.cc (2 KB)

Event Timeline