HepMC3 event record library
WriterRoot.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // This file is part of HepMC
4 // Copyright (C) 2014-2019 The HepMC collaboration (see AUTHORS for details)
5 //
6 #ifndef HEPMC3_WRITERROOT_H
7 #define HEPMC3_WRITERROOT_H
8 /**
9  * @file WriterRoot.h
10  * @brief Definition of \b class WriterRoot
11  *
12  * @class HepMC3::WriterRoot
13  * @brief GenEvent I/O serialization for root files
14  *
15  * If HepMC was compiled with path to ROOT available, this class can be used
16  * for root writing in the same manner as with HepMC::WriterAscii class.
17  *
18  * @ingroup IO
19  *
20  */
21 #include "HepMC3/Writer.h"
22 #include "HepMC3/GenEvent.h"
25 
26 // ROOT header files
27 #ifdef __CINT__
28 #include "TFile.h"
29 #else
30 class TFile;
31 #endif
32 
33 namespace HepMC3 {
34 
35 class WriterRoot : public Writer {
36 //
37 // Constructors
38 //
39 public:
40  /** @brief Default constructor
41  * @warning If file exists, it will be overwritten
42  */
43  WriterRoot(const std::string& filename,
44  std::shared_ptr<GenRunInfo> run = std::shared_ptr<GenRunInfo>());
45 
46 //
47 // Functions
48 //
49 public:
50 
51  /** @brief Write event to file
52  *
53  * @param[in] evt Event to be serialized
54  */
55  void write_event(const GenEvent &evt) override;
56 
57  /** @brief Write the GenRunInfo object to file. */
58  void write_run_info();
59 
60  /** @brief Close file stream */
61  void close() override;
62 
63  /** @brief Get stream error state flag */
64  bool failed() override;
65 //
66 // Fields
67 //
68 private:
69  TFile* m_file; //!< File handler
70  int m_events_count; //!< Events count. Needed to generate unique object name
71 };
72 
73 } // namespace HepMC3
74 
75 #endif
int m_events_count
Events count. Needed to generate unique object name.
Definition: WriterRoot.h:70
void write_run_info()
Write the GenRunInfo object to file.
Definition: WriterRoot.cc:61
bool failed() override
Get stream error state flag.
Definition: WriterRoot.cc:79
Definition of struct GenEventData.
TFile * m_file
File handler.
Definition: WriterRoot.h:69
WriterRoot(const std::string &filename, std::shared_ptr< GenRunInfo > run=std::shared_ptr< GenRunInfo >())
Default constructor.
Definition: WriterRoot.cc:21
Stores event-related information.
Definition: GenEvent.h:41
Definition of interface Writer.
GenEvent I/O serialization for root files.
Definition: WriterRoot.h:35
Base class for all I/O writers.
Definition: Writer.h:25
Definition of class GenEvent.
void close() override
Close file stream.
Definition: WriterRoot.cc:75
void write_event(const GenEvent &evt) override
Write event to file.
Definition: WriterRoot.cc:34
Definition of struct GenRunInfoData.