| 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_WRITERROOTTREE_H |
| 7 |
#define HEPMC3_WRITERROOTTREE_H |
| 8 |
/** |
| 9 |
* @file WriterRootTree.h |
| 10 |
* @brief Definition of \b class WriterRootTree |
| 11 |
* |
| 12 |
* @class HepMC3::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 "HepMC3/Writer.h" |
| 22 |
#include "HepMC3/GenEvent.h" |
| 23 |
#include "HepMC3/Data/GenEventData.h" |
| 24 |
#include "HepMC3/Data/GenRunInfoData.h" |
| 25 |
|
| 26 |
|
| 27 |
// ROOT header files |
| 28 |
#ifdef __CINT__ |
| 29 |
#include "TFile.h" |
| 30 |
#include "TTree.h" |
| 31 |
#else |
| 32 |
class TFile; |
| 33 |
class TTree; |
| 34 |
#endif |
| 35 |
|
| 36 |
namespace HepMC3 |
| 37 |
{ |
| 38 |
class WriterRootTree : public Writer |
| 39 |
{ |
| 40 |
// |
| 41 |
// Constructors |
| 42 |
// |
| 43 |
public: |
| 44 |
/** @brief Default constructor |
| 45 |
* @warning If file exists, it will be overwritten |
| 46 |
*/ |
| 47 |
WriterRootTree(const std::string &filename, |
| 48 |
shared_ptr<GenRunInfo> run = shared_ptr<GenRunInfo>()); |
| 49 |
/** @brief Constructor with tree name*/ |
| 50 |
WriterRootTree(const std::string &filename,const std::string &treename,const std::string &branchname, |
| 51 |
shared_ptr<GenRunInfo> run = shared_ptr<GenRunInfo>()); |
| 52 |
// |
| 53 |
// Functions |
| 54 |
// |
| 55 |
public: |
| 56 |
|
| 57 |
/** @brief Write event to file |
| 58 |
* |
| 59 |
* @param[in] evt Event to be serialized |
| 60 |
*/ |
| 61 |
void write_event(const GenEvent &evt); |
| 62 |
|
| 63 |
/** @brief Write the GenRunInfo object to file. */ |
| 64 |
void write_run_info(); |
| 65 |
|
| 66 |
/** @brief Close file stream */ |
| 67 |
void close(); |
| 68 |
|
| 69 |
/** @brief Get stream error state flag */ |
| 70 |
bool failed(); |
| 71 |
|
| 72 |
private: |
| 73 |
/** @brief init routine */ |
| 74 |
bool init(shared_ptr<GenRunInfo> run); |
| 75 |
// |
| 76 |
// Fields |
| 77 |
// |
| 78 |
private: |
| 79 |
TFile* m_file; //!< File handler |
| 80 |
public: |
| 81 |
TTree* m_tree;//!< Tree handler. Public to allow simple access, e.g. custom branches. |
| 82 |
private: |
| 83 |
int m_events_count; //!< Events count. Needed to read the tree |
| 84 |
GenEventData* m_event_data; //!< Pointer to structure that holds event data |
| 85 |
GenRunInfoData* m_run_info_data; //!< Pointer to structure that holds run info data |
| 86 |
std::string m_tree_name;//!< Name of TTree |
| 87 |
std::string m_branch_name; //!< Name of TBranch in TTree |
| 88 |
}; |
| 89 |
|
| 90 |
} // namespace HepMC3 |
| 91 |
|
| 92 |
#endif |