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