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"
#ifdef HEJ_BUILD_WITH_HepMC3
#include "HepMC3/LHEFAttributes.h"
#include "HepMC3/WriterAscii.h"
#include "HEJ/Version.hh"
#include <utility>
#include "HepMC3/GenParticle.h"
#include "HepMC3/GenVertex.h"
#include "HEJ/Event.hh"
#include "HEJ/exceptions.hh"
#include "HEJ/HepMC3Interface.hh"
namespace {
void reset_weight_info(LHEF::HEPRUP & heprup){
heprup.IDWTUP = 2;
// use placeholders for unknown init block values
// we can overwrite them after processing all events
heprup.XSECUP = {0.};
heprup.XERRUP = {0.};
heprup.XMAXUP = {0.};
}
HepMC3::shared_ptr<HepMC3::GenRunInfo> init_runinfo(LHEF::HEPRUP && heprup){
reset_weight_info(heprup);
HepMC3::GenRunInfo runinfo;
auto hepr = HepMC3::make_shared<HepMC3::HEPRUPAttribute>();
hepr->heprup = heprup;
runinfo.add_attribute(std::string("HEPRUP"), hepr);
for (int i = 0, N = hepr->heprup.generators.size(); i < N; ++i ){
HepMC3::GenRunInfo::ToolInfo tool;
tool.name = hepr->heprup.generators[i].name;
tool.version = hepr->heprup.generators[i].version;
tool.description = hepr->heprup.generators[i].contents;
runinfo.tools().push_back(tool);
}
return HepMC3::make_shared<HepMC3::GenRunInfo>(runinfo);
}
} // namespace anonymous
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;
HepMC3::WriterAscii writer_;
HepMC3WriterImpl(
std::string const & file, LHEF::HEPRUP && heprup
):
HepMC3_(heprup),
writer_{file, init_runinfo(std::move(heprup))}
{}
~HepMC3WriterImpl(){
writer_.close();
}
void write(Event const & ev){
auto out_ev = HepMC3_(ev);
writer_.write_event(out_ev);
}
};
HepMC3Writer::HepMC3Writer(std::string const & file, LHEF::HEPRUP heprup):
impl_{new 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, 5:47 AM (1 d, 7 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6532649
Default Alt Text
HepMC3Writer.cc (2 KB)

Event Timeline