Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:01:14

0001 // -*- C++ -*-
0002 //
0003 // This file is part of HepMC
0004 // Copyright (C) 2014-2023 The HepMC collaboration (see AUTHORS for details)
0005 //
0006 #ifndef HEPMC3_READERROOTTREE_H
0007 #define HEPMC3_READERROOTTREE_H
0008 /**
0009  *  @file  ReaderRootTree.h
0010  *  @brief Definition of \b class ReaderRootTree
0011  *
0012  *  @class HepMC3::ReaderRootTree
0013  *  @brief GenEvent I/O parsing and serialization for root files  based on root TTree
0014  *
0015  *  If HepMC was compiled with path to ROOT available, this class can be used
0016  *  for root file I/O in the same manner as with HepMC::ReaderAscii class.
0017  *
0018  *  @ingroup IO
0019  *
0020  */
0021 #include <string>
0022 #include "HepMC3/Reader.h"
0023 #include "HepMC3/GenEvent.h"
0024 #include "HepMC3/Data/GenEventData.h"
0025 #include "HepMC3/Data/GenRunInfoData.h"
0026 
0027 // ROOT header files
0028 #include "TFile.h"
0029 #include "TTree.h"
0030 #include "TBranch.h"
0031 
0032 namespace HepMC3
0033 {
0034 
0035 class ReaderRootTree : public Reader
0036 {
0037 //
0038 // Constructors
0039 //
0040 public:
0041     /** @brief Default constructor */
0042     ReaderRootTree(const std::string &filename);
0043     /** @brief Constructor with tree name*/
0044     ReaderRootTree(const std::string &filename, const std::string &treename, const std::string &branchname);
0045 
0046 //
0047 // Functions
0048 //
0049 public:
0050     /// @brief skip events
0051     bool skip(const int)  override;
0052 
0053     /** @brief Read event from file
0054      *
0055      *  @param[out] evt Contains parsed event
0056      */
0057     bool read_event(GenEvent &evt)   override;
0058 
0059     /** @brief Close file */
0060     void close()  override;
0061 
0062     /** @brief Get file  error state */
0063     bool failed()  override;
0064 
0065 private:
0066     /** @brief init routine */
0067     bool init();
0068 //
0069 // Fields
0070 //
0071 private:
0072     TFile* m_file = nullptr;         //!< File handler
0073 public:
0074     TTree* m_tree = nullptr;//!< Tree handler. Public to allow simple access, e.g. custom branches.
0075 private:
0076     int   m_events_count = 0; //!< Events count. Needed to read the tree
0077     GenEventData* m_event_data = nullptr; //!< Pointer to structure that holds event data
0078     GenRunInfoData* m_run_info_data = nullptr; //!< Pointer to structure that holds run info data
0079     std::string m_tree_name; //!< Name of TTree
0080     std::string m_branch_name; //!< Name of TBranch in TTree
0081 };
0082 
0083 } // namespace HepMC3
0084 
0085 #endif