| 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_READERROOTTREE_H |
| 7 |
#define HEPMC3_READERROOTTREE_H |
| 8 |
/** |
| 9 |
* @file ReaderRootTree.h |
| 10 |
* @brief Definition of \b class ReaderRootTree |
| 11 |
* |
| 12 |
* @class HepMC3::ReaderRootTree |
| 13 |
* @brief GenEvent I/O parsing and 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 file I/O in the same manner as with HepMC::ReaderAscii class. |
| 17 |
* |
| 18 |
* @ingroup IO |
| 19 |
* |
| 20 |
*/ |
| 21 |
#include "HepMC3/Reader.h" |
| 22 |
#include "HepMC3/GenEvent.h" |
| 23 |
#include "HepMC3/Data/GenEventData.h" |
| 24 |
#include "HepMC3/Data/GenRunInfoData.h" |
| 25 |
|
| 26 |
// ROOT header files |
| 27 |
#include "TFile.h" |
| 28 |
#include "TTree.h" |
| 29 |
#include "TBranch.h" |
| 30 |
|
| 31 |
namespace HepMC3 |
| 32 |
{ |
| 33 |
|
| 34 |
class ReaderRootTree : public Reader |
| 35 |
{ |
| 36 |
// |
| 37 |
// Constructors |
| 38 |
// |
| 39 |
public: |
| 40 |
/** @brief Default constructor */ |
| 41 |
ReaderRootTree(const std::string &filename); |
| 42 |
/** @brief Constructor with tree name*/ |
| 43 |
ReaderRootTree(const std::string &filename,const std::string &treename,const std::string &branchname); |
| 44 |
|
| 45 |
// |
| 46 |
// Functions |
| 47 |
// |
| 48 |
public: |
| 49 |
|
| 50 |
/** @brief Read event from file |
| 51 |
* |
| 52 |
* @param[out] evt Contains parsed event |
| 53 |
*/ |
| 54 |
bool read_event(GenEvent &evt); |
| 55 |
|
| 56 |
/** @brief Close file */ |
| 57 |
void close(); |
| 58 |
|
| 59 |
/** @brief Get file error state */ |
| 60 |
bool failed(); |
| 61 |
|
| 62 |
private: |
| 63 |
/** @brief init routine */ |
| 64 |
bool init(); |
| 65 |
// |
| 66 |
// Fields |
| 67 |
// |
| 68 |
private: |
| 69 |
TFile* m_file; //!< File handler |
| 70 |
public: |
| 71 |
TTree* m_tree;//!< Tree handler. Public to allow simple access, e.g. custom branches. |
| 72 |
private: |
| 73 |
int m_events_count; //!< Events count. Needed to read the tree |
| 74 |
GenEventData* m_event_data; //!< Pointer to structure that holds event data |
| 75 |
GenRunInfoData* m_run_info_data; //!< Pointer to structure that holds run info data |
| 76 |
std::string m_tree_name; //!< Name of TTree |
| 77 |
std::string m_branch_name; //!< Name of TBranch in TTree |
| 78 |
}; |
| 79 |
|
| 80 |
} // namespace HepMC3 |
| 81 |
|
| 82 |
#endif |