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_WRITERROOTTREE_H
0007 #define HEPMC3_WRITERROOTTREE_H
0008 /**
0009  *  @file  WriterRootTree.h
0010  *  @brief Definition of \b class WriterRootTree
0011  *
0012  *  @class HepMC3::WriterRootTree
0013  *  @brief GenEvent I/O 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 writing in the same manner as with HepMC::WriterAscii class.
0017  *
0018  *  @ingroup IO
0019  *
0020  */
0021 #include <string>
0022 #include <memory>
0023 #include "HepMC3/Writer.h"
0024 #include "HepMC3/GenEvent.h"
0025 #include "HepMC3/Data/GenEventData.h"
0026 #include "HepMC3/Data/GenRunInfoData.h"
0027 
0028 
0029 // ROOT header files
0030 #ifdef __CINT__
0031 #include "TFile.h"
0032 #include "TTree.h"
0033 #else
0034 class TFile;
0035 class TTree;
0036 #endif
0037 
0038 namespace HepMC3
0039 {
0040 class WriterRootTree : public Writer
0041 {
0042 //
0043 // Constructors
0044 //
0045 public:
0046     /** @brief Default constructor
0047      *  @warning If file exists, it will be overwritten
0048      */
0049     WriterRootTree(const std::string &filename,
0050                    std::shared_ptr<GenRunInfo> run = std::shared_ptr<GenRunInfo>());
0051     /** @brief Constructor with tree name*/
0052     WriterRootTree(const std::string &filename, const std::string &treename, const std::string &branchname,
0053                    std::shared_ptr<GenRunInfo> run = std::shared_ptr<GenRunInfo>());
0054 //
0055 // Functions
0056 //
0057 public:
0058     /** @brief Write event to file
0059      *
0060      *  @param[in] evt Event to be serialized
0061      */
0062     void write_event(const GenEvent &evt) override;
0063 
0064     /** @brief Write the GenRunInfo object to file. */
0065     void write_run_info();
0066 
0067     /** @brief Close file stream */
0068     void close() override;
0069 
0070     /** @brief Get stream error state flag */
0071     bool failed()  override;
0072 
0073 private:
0074     /** @brief init routine */
0075     bool init(std::shared_ptr<GenRunInfo> run);
0076 //
0077 // Fields
0078 //
0079 private:
0080     TFile* m_file = nullptr;         //!< File handler
0081 public:
0082     TTree* m_tree = nullptr;//!< Tree handler. Public to allow simple access, e.g. custom branches.
0083 private:
0084     int   m_events_count = 0; //!< Events count. Needed to read the tree
0085     GenEventData* m_event_data = nullptr; //!< Pointer to structure that holds event data
0086     GenRunInfoData* m_run_info_data = nullptr; //!< Pointer to structure that holds run info data
0087     std::string m_tree_name;//!< Name of TTree
0088     std::string m_branch_name; //!< Name of TBranch in TTree
0089 };
0090 
0091 } // namespace HepMC3
0092 
0093 #endif