HepMC3 event record library: WriterRoot.h Source File

HepMC3 event record library

WriterRoot.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// This file is part of HepMC
4// Copyright (C) 2014-2023 The HepMC collaboration (see AUTHORS for details)
5//
6#ifndef HEPMC3_WRITERROOT_H
7#define HEPMC3_WRITERROOT_H
8/**
9 * @file WriterRoot.h
10 * @brief Definition of \b class WriterRoot
11 *
12 * @class HepMC3::WriterRoot
13 * @brief GenEvent I/O serialization for root files
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 <string>
22#include <memory>
23#include "HepMC3/Writer.h"
24#include "HepMC3/GenEvent.h"
25#include "HepMC3/Data/GenEventData.h"
26#include "HepMC3/Data/GenRunInfoData.h"
27
28// ROOT header files
29#ifdef __CINT__
30#include "TFile.h"
31#else
32class TFile;
33#endif
34
35namespace HepMC3 {
36
37 class WriterRoot : public Writer {
38//
39// Constructors
40//
41public:
42 /** @brief Default constructor
43 * @warning If file exists, it will be overwritten
44 */
45 WriterRoot(const std::string& filename,
46 std::shared_ptr<GenRunInfo> run = std::shared_ptr<GenRunInfo>());
47
48//
49// Functions
50//
51public:
52 /** @brief Write event to file
53 *
54 * @param[in] evt Event to be serialized
55 */
56 void write_event(const GenEvent &evt) override;
57
58 /** @brief Write the GenRunInfo object to file. */
59 void write_run_info();
60
61 /** @brief Close file stream */
62 void close() override;
63
64 /** @brief Get stream error state flag */
65 bool failed() override;
66//
67// Fields
68//
69private:
70 TFile* m_file; //!< File handler
71 int m_events_count; //!< Events count. Needed to generate unique object name
72};
73
74} // namespace HepMC3
75
76#endif
GenEventData.h
Definition of struct GenEventData.
GenEvent.h
Definition of class GenEvent.
GenRunInfoData.h
Definition of struct GenRunInfoData.
Writer.h
Definition of interface Writer.
HepMC3::GenEvent
Stores event-related information.
Definition GenEvent.h:47
HepMC3::WriterRoot::failed
bool failed() override
Get stream error state flag.
Definition WriterRoot.cc:79
HepMC3::WriterRoot::WriterRoot
WriterRoot(const std::string &filename, std::shared_ptr< GenRunInfo > run=std::shared_ptr< GenRunInfo >())
Default constructor.
Definition WriterRoot.cc:22
HepMC3::WriterRoot::m_events_count
int m_events_count
Events count. Needed to generate unique object name.
Definition WriterRoot.h:71
HepMC3::WriterRoot::close
void close() override
Close file stream.
Definition WriterRoot.cc:75
HepMC3::WriterRoot::m_file
TFile * m_file
File handler.
Definition WriterRoot.h:70
HepMC3::WriterRoot::write_event
void write_event(const GenEvent &evt) override
Write event to file.
Definition WriterRoot.cc:35
HepMC3::WriterRoot::write_run_info
void write_run_info()
Write the GenRunInfo object to file.
Definition WriterRoot.cc:61
HepMC3::Writer::Writer
Writer()
Constructor.
Definition Writer.h:29
HepMC3
HepMC3 main namespace.
Definition AnalysisExample.h:24