HepMC3 event record library
rootIO_example_read.cc

Basic example of use of root I/O: reading events from file

Author
Witold Pokorski
Date
16/10/14
// -*- C++ -*-
//
// This file is part of HepMC
// Copyright (C) 2014-2019 The HepMC collaboration (see AUTHORS for details)
//
/**
* @example rootIO_example_read.cc
* @brief Basic example of use of root I/O: reading events from file
*
* @author Witold Pokorski
* @date 16/10/14
*/
#include "HepMC3/Print.h"
#include <iostream>
using namespace HepMC3;
/** Main */
int main(int argc, char **argv) {
if( argc<3 ) {
std::cout << "Usage: " << argv[0] << " <input_root_file> <output_hepmc3_file>" << std::endl;
exit(-1);
}
ReaderRoot root_input (argv[1]);
WriterAscii text_output(argv[2]);
int events_parsed = 0;
while( !root_input.failed() ) {
GenEvent evt;
root_input.read_event(evt);
if( root_input.failed() ) break;
if( events_parsed == 0 ) {
std::cout << "First event: " << std::endl;
}
text_output.write_event(evt);
++events_parsed;
if( events_parsed%100 == 0 ) {
std::cout << "Event: " << events_parsed << std::endl;
}
}
root_input.close();
text_output.close();
std::cout << "Events parsed and written: " << events_parsed << std::endl;
return 0;
}
ReaderRoot.h
Definition of class ReaderRoot.
GenEvent.h
Definition of class GenEvent.
HepMC3::WriterAscii
GenEvent I/O serialization for structured text files.
Definition: WriterAscii.h:25
HepMC3::GenEvent
Stores event-related information.
Definition: GenEvent.h:41
HepMC3
HepMC3 main namespace.
Definition: AnalysisExample.h:19
HepMC3::ReaderRoot::read_event
bool read_event(GenEvent &evt) override
Read event from file.
Definition: ReaderRoot.cc:50
HepMC3::Print::listing
static void listing(std::ostream &os, const GenEvent &event, unsigned short precision=2)
Print event in listing (HepMC2) format.
Definition: Print.cc:50
HepMC3::ReaderRoot::close
void close() override
Close file stream.
Definition: ReaderRoot.cc:88
WriterAscii.h
Definition of class WriterAscii.
HepMC3::ReaderRoot
GenEvent I/O parsing and serialization for root files.
Definition: ReaderRoot.h:32
Print.h
Definition of static class Print.
HepMC3::ReaderRoot::failed
bool failed() override
Get stream error state.
Definition: ReaderRoot.cc:92
main
int main(int argc, char **argv)
Definition: rootIOTree_example_read.cc:23
HepMC3::WriterAscii::write_event
void write_event(const GenEvent &evt) override
Write event to file.
Definition: WriterAscii.cc:63
HepMC3::WriterAscii::close
void close() override
Close file stream.
Definition: WriterAscii.cc:354