File: WriterRootTree.h

package info (click to toggle)
hepmc3 3.1.2-2.1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 14,124 kB
  • sloc: fortran: 66,849; cpp: 13,604; ansic: 1,374; xml: 109; sh: 72; makefile: 33
file content (92 lines) | stat: -rw-r--r-- 2,361 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// -*- C++ -*-
//
// This file is part of HepMC
// Copyright (C) 2014-2019 The HepMC collaboration (see AUTHORS for details)
//
#ifndef HEPMC3_WRITERROOTTREE_H
#define HEPMC3_WRITERROOTTREE_H
/**
 *  @file  WriterRootTree.h
 *  @brief Definition of \b class WriterRootTree
 *
 *  @class HepMC3::WriterRootTree
 *  @brief GenEvent I/O serialization for root files based on root TTree
 *
 *  If HepMC was compiled with path to ROOT available, this class can be used
 *  for root writing in the same manner as with HepMC::WriterAscii class.
 *
 *  @ingroup IO
 *
 */
#include "HepMC3/Writer.h"
#include "HepMC3/GenEvent.h"
#include "HepMC3/Data/GenEventData.h"
#include "HepMC3/Data/GenRunInfoData.h"


// ROOT header files
#ifdef __CINT__
#include "TFile.h"
#include "TTree.h"
#else
class TFile;
class TTree;
#endif

namespace HepMC3
{
class WriterRootTree : public Writer
{
//
// Constructors
//
public:
    /** @brief Default constructor
     *  @warning If file exists, it will be overwritten
     */
    WriterRootTree(const std::string &filename,
                   shared_ptr<GenRunInfo> run = shared_ptr<GenRunInfo>());
    /** @brief Constructor with tree name*/
    WriterRootTree(const std::string &filename,const std::string &treename,const std::string &branchname,
                   shared_ptr<GenRunInfo> run = shared_ptr<GenRunInfo>());
//
// Functions
//
public:

    /** @brief Write event to file
     *
     *  @param[in] evt Event to be serialized
     */
    void write_event(const GenEvent &evt);

    /** @brief Write the GenRunInfo object to file. */
    void write_run_info();

    /** @brief Close file stream */
    void close();

    /** @brief Get stream error state flag */
    bool failed();

private:
    /** @brief init routine */
    bool init(shared_ptr<GenRunInfo> run);
//
// Fields
//
private:
    TFile* m_file;         //!< File handler
public:
    TTree* m_tree;//!< Tree handler. Public to allow simple access, e.g. custom branches.
private:
    int   m_events_count; //!< Events count. Needed to read the tree
    GenEventData* m_event_data; //!< Pointer to structure that holds event data
    GenRunInfoData* m_run_info_data; //!< Pointer to structure that holds run info data
    std::string m_tree_name;//!< Name of TTree
    std::string m_branch_name; //!< Name of TBranch in TTree
};

} // namespace HepMC3

#endif