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" 18 #include "HepMC3/Data/GenEventData.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 failed()34 bool failed() { 35 return (bool)m_file.rdstate(); 36 } 37 /// @brief Close file stream 38 void close(); 39 /// @brief Close file stream set_style(const int & istyle)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 57