Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F19252148
HepMCWriter.cc
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
HepMCWriter.cc
View Options
/**
* \authors The HEJ collaboration (see AUTHORS for details)
* \date 2019
* \copyright GPLv2 or later
*/
#include
"HEJ/HepMCWriter.hh"
#include
<cassert>
#include
"LHEF/LHEF.h"
#ifdef HEJ_BUILD_WITH_HepMC_VERSION
#if HEJ_BUILD_WITH_HepMC_VERSION >= 3
#include
"HepMC/LHEFAttributes.h"
#include
"HepMC/WriterAscii.h"
#include
"HEJ/Version.hh"
#else
#include
"HepMC/IO_GenEvent.h"
#endif
#include
<utility>
#include
"HepMC/GenParticle.h"
#include
"HepMC/GenVertex.h"
#include
"HEJ/Event.hh"
#include
"HEJ/exceptions.hh"
#include
"HEJ/HepMCInterface.hh"
#if HEJ_BUILD_WITH_HepMC_VERSION >= 3
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.
};
}
HepMC
::
shared_ptr
<
HepMC
::
GenRunInfo
>
init_runinfo
(
LHEF
::
HEPRUP
&&
heprup
){
reset_weight_info
(
heprup
);
HepMC
::
GenRunInfo
runinfo
;
auto
hepr
=
HepMC
::
make_shared
<
HepMC
::
HEPRUPAttribute
>
();
hepr
->
heprup
=
heprup
;
runinfo
.
add_attribute
(
std
::
string
(
"HEPRUP"
),
hepr
);
for
(
int
i
=
0
,
N
=
hepr
->
heprup
.
generators
.
size
();
i
<
N
;
++
i
){
HepMC
::
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
HepMC
::
make_shared
<
HepMC
::
GenRunInfo
>
(
runinfo
);
}
}
// namespace anonymous
#endif
// HepMC 3
namespace
HEJ
{
struct
HepMCWriter
::
HepMCWriterImpl
{
HepMCInterface
hepmc_
;
HepMCWriterImpl
&
operator
=
(
HepMCWriterImpl
const
&
other
)
=
delete
;
HepMCWriterImpl
(
HepMCWriterImpl
const
&
other
)
=
delete
;
HepMCWriterImpl
&
operator
=
(
HepMCWriterImpl
&&
other
)
=
delete
;
HepMCWriterImpl
(
HepMCWriterImpl
&&
other
)
=
delete
;
#if HEJ_BUILD_WITH_HepMC_VERSION >= 3
HepMC
::
WriterAscii
writer_
;
HepMCWriterImpl
(
std
::
string
const
&
file
,
LHEF
::
HEPRUP
&&
heprup
)
:
hepmc_
(
heprup
),
writer_
{
file
,
init_runinfo
(
std
::
move
(
heprup
))}
{}
~
HepMCWriterImpl
(){
writer_
.
close
();
}
#else
// HepMC 2
HepMC
::
IO_GenEvent
writer_
;
HepMCWriterImpl
(
std
::
string
const
&
file
,
LHEF
::
HEPRUP
&&
heprup
)
:
hepmc_
(
heprup
),
writer_
{
file
}
{}
#endif
void
write
(
Event
const
&
ev
){
auto
out_ev
=
hepmc_
(
ev
);
#if HEJ_BUILD_WITH_HepMC_VERSION >= 3
writer_
.
write_event
(
out_ev
);
#else
// HepMC 2
writer_
.
write_event
(
&
out_ev
);
#endif
}
};
void
HepMCWriter
::
HepMCWriterImplDeleter
::
operator
()(
HepMCWriterImpl
*
p
)
{
delete
p
;
}
HepMCWriter
::
HepMCWriter
(
std
::
string
const
&
file
,
LHEF
::
HEPRUP
heprup
)
:
impl_
{
std
::
unique_ptr
<
HepMCWriterImpl
,
HepMCWriterImplDeleter
>
{
new
HepMCWriterImpl
(
file
,
std
::
move
(
heprup
))
}}
{}
void
HepMCWriter
::
write
(
Event
const
&
ev
){
impl_
->
write
(
ev
);
}
}
// namespace HEJ
#else
// no HepMC
namespace
HEJ
{
class
HepMCWriter
::
HepMCWriterImpl
{};
HepMCWriter
::
HepMCWriter
(
std
::
string
const
&
,
LHEF
::
HEPRUP
){
throw
std
::
invalid_argument
(
"Failed to create HepMC writer: "
"HEJ 2 was built without HepMC support"
);
}
void
HepMCWriter
::
write
(
Event
const
&
){
assert
(
false
);
}
void
HepMCWriter
::
HepMCWriterImplDeleter
::
operator
()(
HepMCWriterImpl
*
p
)
{
delete
p
;
}
}
#endif
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Tue, Sep 30, 6:14 AM (2 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6507323
Default Alt Text
HepMCWriter.cc (3 KB)
Attached To
Mode
rHEJ HEJ
Attached
Detach File
Event Timeline
Log In to Comment