| 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_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 "HepMC3/Writer.h" |
| 22 |
#include "HepMC3/GenEvent.h" |
| 23 |
#include "HepMC3/Data/GenEventData.h" |
| 24 |
#include "HepMC3/Data/GenRunInfoData.h" |
| 25 |
|
| 26 |
// ROOT header files |
| 27 |
#ifdef __CINT__ |
| 28 |
#include "TFile.h" |
| 29 |
#else |
| 30 |
class TFile; |
| 31 |
#endif |
| 32 |
|
| 33 |
namespace HepMC3 { |
| 34 |
|
| 35 |
class WriterRoot : public Writer { |
| 36 |
// |
| 37 |
// Constructors |
| 38 |
// |
| 39 |
public: |
| 40 |
/** @brief Default constructor |
| 41 |
* @warning If file exists, it will be overwritten |
| 42 |
*/ |
| 43 |
WriterRoot(const std::string& filename, |
| 44 |
shared_ptr<GenRunInfo> run = shared_ptr<GenRunInfo>()); |
| 45 |
|
| 46 |
// |
| 47 |
// Functions |
| 48 |
// |
| 49 |
public: |
| 50 |
|
| 51 |
/** @brief Write event to file |
| 52 |
* |
| 53 |
* @param[in] evt Event to be serialized |
| 54 |
*/ |
| 55 |
void write_event(const GenEvent &evt); |
| 56 |
|
| 57 |
/** @brief Write the GenRunInfo object to file. */ |
| 58 |
void write_run_info(); |
| 59 |
|
| 60 |
/** @brief Close file stream */ |
| 61 |
void close(); |
| 62 |
|
| 63 |
/** @brief Get stream error state flag */ |
| 64 |
bool failed(); |
| 65 |
// |
| 66 |
// Fields |
| 67 |
// |
| 68 |
private: |
| 69 |
TFile* m_file; //!< File handler |
| 70 |
int m_events_count; //!< Events count. Needed to generate unique object name |
| 71 |
}; |
| 72 |
|
| 73 |
} // namespace HepMC3 |
| 74 |
|
| 75 |
#endif |