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-2021 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 <string>
22 #include <memory>
23 #include "HepMC3/Writer.h"
24 #include "HepMC3/GenEvent.h"
27 
28 // ROOT header files
29 #ifdef __CINT__
30 #include "TFile.h"
31 #else
32 class TFile;
33 #endif
34 
35 namespace HepMC3 {
36 
37 class WriterRoot : public Writer {
38 //
39 // Constructors
40 //
41 public:
42  /** @brief Default constructor
43  * @warning If file exists, it will be overwritten
44  */
45  WriterRoot(const std::string& filename,
46  std::shared_ptr<GenRunInfo> run = std::shared_ptr<GenRunInfo>());
47 
48 //
49 // Functions
50 //
51 public:
52  /** @brief Write event to file
53  *
54  * @param[in] evt Event to be serialized
55  */
56  void write_event(const GenEvent &evt) override;
57 
58  /** @brief Write the GenRunInfo object to file. */
59  void write_run_info();
60 
61  /** @brief Close file stream */
62  void close() override;
63 
64  /** @brief Get stream error state flag */
65  bool failed() override;
66 //
67 // Fields
68 //
69 private:
70  TFile* m_file; //!< File handler
71  int m_events_count; //!< Events count. Needed to generate unique object name
72 };
73 
74 } // namespace HepMC3
75 
76 #endif
int m_events_count
Events count. Needed to generate unique object name.
Definition: WriterRoot.h:71
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:70
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:37
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.