HepMC event record
WriterRootTree.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_WRITERROOTTREE_H
7 #define HEPMC_WRITERROOTTREE_H
8 /**
9  * @file WriterRootTree.h
10  * @brief Definition of \b class WriterRootTree
11  *
12  * @class HepMC::WriterRootTree
13  * @brief GenEvent I/O serialization for root files based on root TTree
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 
27 // ROOT header files
28 #include "TFile.h"
29 #include "TTree.h"
30 
31 namespace HepMC
32 {
33 class WriterRootTree : public Writer
34 {
35 //
36 // Constructors
37 //
38 public:
39  /** @brief Default constructor
40  * @warning If file exists, it will be overwritten
41  */
42  WriterRootTree(const std::string &filename,
43  shared_ptr<GenRunInfo> run = shared_ptr<GenRunInfo>());
44  /** @brief Constructor with tree name*/
45  WriterRootTree(const std::string &filename,const std::string &treename,const std::string &branchname,
46  shared_ptr<GenRunInfo> run = shared_ptr<GenRunInfo>());
47 //
48 // Functions
49 //
50 public:
51 
52  /** @brief Write event to file
53  *
54  * @param[in] evt Event to be serialized
55  */
56  void write_event(const GenEvent &evt);
57 
58  /** @brief Write the GenRunInfo object to file. */
59  void write_run_info();
60 
61  /** @brief Close file stream */
62  void close();
63 
64  /** @brief Get stream error state flag */
65  bool failed();
66 
67 private:
68  /** @brief init routine */
69  bool init(shared_ptr<GenRunInfo> run);
70 //
71 // Fields
72 //
73 private:
74  TFile m_file; //!< File handler
75 public:
76  TTree* m_tree;//!< Tree handler. Public to allow simple access, e.g. custom branches.
77 private:
78  int m_events_count; //!< Events count. Needed to read the tree
79  GenEventData* m_event_data;
80  std::string m_tree_name;
81  std::string m_branch_name;
82 };
83 
84 } // namespace HepMC
85 
86 #endif
TTree * m_tree
Tree handler. Public to allow simple access, e.g. custom branches.
bool init(shared_ptr< GenRunInfo > run)
init routine
void close()
Close file stream.
TFile m_file
File handler.
int m_events_count
Events count. Needed to read the tree.
Stores event-related information.
GenEvent I/O serialization for root files based on root TTree.
Base class for all I/O writers.
void write_run_info()
Write the GenRunInfo object to file.
Definition of template class SmartPointer.
bool failed()
Get stream error state flag.
WriterRootTree(const std::string &filename, shared_ptr< GenRunInfo > run=shared_ptr< GenRunInfo >())
Default constructor.
void write_event(const GenEvent &evt)
Write event to file.
Stores serializable event information.