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