HepMC3 event record library: WriterDOT.h Source File

HepMC3 event record library

WriterDOT.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_WRITERDOT_H
7#define HEPMC3_WRITERDOT_H
8///
9/// @file WriterDOT.h
10/// @brief Definition of class \b WriterDOT converter of GenEvent into .dot format
11///
12/// @class HepMC3::WriterDOT
13/// @brief GenEvent I/O output to dot files that should be processed by graphviz or other software
14///
15/// @ingroup Examples
16///
17#include <string>
18#include <fstream>
19#include "HepMC3/Writer.h"
20#include "HepMC3/GenEvent.h"
21#include "HepMC3/GenParticle.h"
22#include "HepMC3/GenVertex.h"
23#include "HepMC3/Data/GenEventData.h"
24namespace HepMC3
25{
26 class WriterDOT : public Writer
27{
28public:
29 /// @brief Constructor
30 /// @warning If file already exists, it will be cleared before writing
31 WriterDOT(const std::string &filename,std::shared_ptr<GenRunInfo> run = std::shared_ptr<GenRunInfo>());
32 /// @brief Constructor from ostream
33 WriterDOT(std::ostream& stream,std::shared_ptr<GenRunInfo> run =std:: shared_ptr<GenRunInfo>());
34 /// @brief Write event to file
35 ///
36 /// @param[in] evt Event to be serialized
37 void write_event(const GenEvent &evt) override;
38 /// @brief Return status of the stream
39 bool failed() override {
40 return static_cast<bool>(m_file.rdstate());
41 }
42 /// @brief Close file stream
43 void close() override;
44 /// @brief Close file stream
45 void set_style(const int& istyle) {
46 m_style=istyle;
47 };
48
49private:
50 void allocate_buffer(); //!< allocates buffer for output
51 void flush(); //!< flushes output buffer
52 void forced_flush(); //!< flushes output buffer
53 std::ofstream m_file; //!< Output file
54 std::ostream* m_stream; //!< Output stream
55 int m_style; //!< style of dot file
56 char* m_buffer; //!< Stream buffer
57 char* m_cursor; //!< Cursor inside stream buffer
58 unsigned long m_buffer_size; //!< Buffer size
59};
60}
61#endif
GenEventData.h
Definition of struct GenEventData.
GenEvent.h
Definition of class GenEvent.
GenParticle.h
Definition of class GenParticle.
GenVertex.h
Definition of class GenVertex.
Writer.h
Definition of interface Writer.
HepMC3::GenEvent
Stores event-related information.
Definition GenEvent.h:47
HepMC3::WriterDOT::allocate_buffer
void allocate_buffer()
allocates buffer for output
Definition WriterDOT.cc:109
HepMC3::WriterDOT::m_cursor
char * m_cursor
Cursor inside stream buffer.
Definition WriterDOT.h:57
HepMC3::WriterDOT::failed
bool failed() override
Return status of the stream.
Definition WriterDOT.h:39
HepMC3::WriterDOT::set_style
void set_style(const int &istyle)
Close file stream.
Definition WriterDOT.h:45
HepMC3::WriterDOT::m_buffer
char * m_buffer
Stream buffer.
Definition WriterDOT.h:56
HepMC3::WriterDOT::close
void close() override
Close file stream.
Definition WriterDOT.cc:35
HepMC3::WriterDOT::m_file
std::ofstream m_file
Output file.
Definition WriterDOT.h:53
HepMC3::WriterDOT::m_buffer_size
unsigned long m_buffer_size
Buffer size.
Definition WriterDOT.h:58
HepMC3::WriterDOT::write_event
void write_event(const GenEvent &evt) override
Write event to file.
Definition WriterDOT.cc:55
HepMC3::WriterDOT::flush
void flush()
flushes output buffer
Definition WriterDOT.cc:127
HepMC3::WriterDOT::forced_flush
void forced_flush()
flushes output buffer
Definition WriterDOT.cc:136
HepMC3::WriterDOT::m_stream
std::ostream * m_stream
Output stream.
Definition WriterDOT.h:54
HepMC3::WriterDOT::m_style
int m_style
style of dot file
Definition WriterDOT.h:55
HepMC3::WriterDOT::WriterDOT
WriterDOT(const std::string &filename, std::shared_ptr< GenRunInfo > run=std::shared_ptr< GenRunInfo >())
Constructor.
Definition WriterDOT.cc:14
HepMC3::Writer::Writer
Writer()
Constructor.
Definition Writer.h:29
HepMC3
HepMC3 main namespace.
Definition AnalysisExample.h:24