HepMC3 event record library: WriterHEPEVT.h Source File

HepMC3 event record library

WriterHEPEVT.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// This file is part of HepMC
4// Copyright (C) 2014-2023 The HepMC collaboration (see AUTHORS for details)
5//
6#ifndef HEPMC3_WRITERHEPEVT_H
7#define HEPMC3_WRITERHEPEVT_H
8/**
9 * @file WriterHEPEVT.h
10 * @brief Definition of \b class WriterHEPEVT
11 *
12 * @class HepMC3::WriterHEPEVT
13 * @brief GenEvent I/O serialization for HEPEVT files
14 *
15 *
16 * @ingroup IO
17 *
18 */
19#include <fstream>
20#include "HepMC3/Writer.h"
21#include "HepMC3/GenEvent.h"
22#include "HepMC3/Data/GenEventData.h"
23#include "HepMC3/HEPEVT_Wrapper_Template.h"
24namespace HepMC3
25{
26
27 class WriterHEPEVT : public Writer
28{
29//
30// Constructors
31//
32public:
33 /** @brief Default constructor
34 * @warning If file exists, it will be overwritten
35 */
36 WriterHEPEVT(const std::string &filename,
37 std::shared_ptr<GenRunInfo> run = nullptr);
38
39 /// @brief Constructor from ostream
40 WriterHEPEVT(std::ostream& stream,
41 std::shared_ptr<GenRunInfo> run = nullptr);
42 /// @brief Constructor from temp ostream
43 WriterHEPEVT(std::shared_ptr<std::ostream> s_stream,
44 std::shared_ptr<GenRunInfo> run = nullptr);
45//
46// Functions
47//
48public:
49
50 /** @brief Write particle to file
51 *
52 * @param[in] index Particle to be serialized
53 * @param[in] iflong Format of record
54 */
55
56 virtual void write_hepevt_particle( int index, bool iflong = true );
57 /** @brief Write event header to file
58 *
59 */
60 virtual void write_hepevt_event_header();
61
62 /** @brief Write event to file
63 *
64 * @param[in] evt Event to be serialized
65 */
66 void write_event(const GenEvent &evt) override;
67
68 /** @brief Close file stream */
69 void close() override;
70
71 /** @brief Get stream error state flag */
72 bool failed() override;
73 /** @brief set flag if vertex positions are available.
74 * Effectively this adds or removes key "vertices_positions_are_absent"
75 * to/from the m_options.*/
76 void set_vertices_positions_present(bool iflong);
77
78 /** @brief get flag if vertex positions are available.
79 * The flag is deduced from m_options. If the m_options have the key
80 * "vertices_positions_are_absent" the result if false. True otherwise. */
81 bool get_vertices_positions_present() const;
82
83protected:
84 std::ofstream m_file; //!< Output file
85 std::shared_ptr<std::ostream> m_shared_stream;///< Output temp. stream
86 std::ostream* m_stream; //!< Output stream
87 char* hepevtbuffer = nullptr; //!< Pointer to HEPEVT Fortran common block/C struct
88 int m_events_count = 0; //!< Events count. Needed to generate unique object name
89 HEPEVT_Wrapper_Template<100000> m_hepevt_interface; //!< Templated HEPEVT interface
90};
91
92} // namespace HepMC3
93#endif
GenEventData.h
Definition of struct GenEventData.
GenEvent.h
Definition of class GenEvent.
HEPEVT_Wrapper_Template.h
Definition of class HEPEVT_Wrapper_Template.
Writer.h
Definition of interface Writer.
HepMC3::GenEvent
Stores event-related information.
Definition GenEvent.h:47
HepMC3::HEPEVT_Wrapper_Template
An interface to HEPEVT common block implemented as template class.
Definition HEPEVT_Wrapper_Template.h:32
HepMC3::WriterHEPEVT::m_hepevt_interface
HEPEVT_Wrapper_Template< 100000 > m_hepevt_interface
Templated HEPEVT interface.
Definition WriterHEPEVT.h:89
HepMC3::WriterHEPEVT::failed
bool failed() override
Get stream error state flag.
Definition WriterHEPEVT.cc:88
HepMC3::WriterHEPEVT::get_vertices_positions_present
bool get_vertices_positions_present() const
get flag if vertex positions are available. The flag is deduced from m_options. If the m_options have...
Definition WriterHEPEVT.cc:95
HepMC3::WriterHEPEVT::set_vertices_positions_present
void set_vertices_positions_present(bool iflong)
set flag if vertex positions are available. Effectively this adds or removes key "vertices_positions_...
Definition WriterHEPEVT.cc:93
HepMC3::WriterHEPEVT::write_hepevt_event_header
virtual void write_hepevt_event_header()
Write event header to file.
Definition WriterHEPEVT.cc:63
HepMC3::WriterHEPEVT::m_events_count
int m_events_count
Events count. Needed to generate unique object name.
Definition WriterHEPEVT.h:88
HepMC3::WriterHEPEVT::write_hepevt_particle
virtual void write_hepevt_particle(int index, bool iflong=true)
Write particle to file.
Definition WriterHEPEVT.cc:42
HepMC3::WriterHEPEVT::close
void close() override
Close file stream.
Definition WriterHEPEVT.cc:81
HepMC3::WriterHEPEVT::m_shared_stream
std::shared_ptr< std::ostream > m_shared_stream
Output temp. stream.
Definition WriterHEPEVT.h:85
HepMC3::WriterHEPEVT::m_file
std::ofstream m_file
Output file.
Definition WriterHEPEVT.h:84
HepMC3::WriterHEPEVT::WriterHEPEVT
WriterHEPEVT(const std::string &filename, std::shared_ptr< GenRunInfo > run=nullptr)
Default constructor.
Definition WriterHEPEVT.cc:21
HepMC3::WriterHEPEVT::hepevtbuffer
char * hepevtbuffer
Pointer to HEPEVT Fortran common block/C struct.
Definition WriterHEPEVT.h:87
HepMC3::WriterHEPEVT::write_event
void write_event(const GenEvent &evt) override
Write event to file.
Definition WriterHEPEVT.cc:72
HepMC3::WriterHEPEVT::m_stream
std::ostream * m_stream
Output stream.
Definition WriterHEPEVT.h:86
HepMC3::Writer::Writer
Writer()
Constructor.
Definition Writer.h:29
HepMC3
HepMC3 main namespace.
Definition AnalysisExample.h:24