File: rootIOTree_example_read.cc

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 (62 lines) | stat: -rw-r--r-- 1,368 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
// -*- C++ -*-
//
// This file is part of HepMC
// Copyright (C) 2014-2019 The HepMC collaboration (see AUTHORS for details)
//
/**
 *  @file rootIOTree_example_read.cc
 *  @brief Basic example of use of root I/O with tree: reading events from file
 *
 *  @author Witold Pokorski/Andrii Verbytskyi
 *  @date   29/10/15
 */
#include "HepMC3/GenEvent.h"
#include "HepMC3/WriterAscii.h"
#include "HepMC3/ReaderRootTree.h"
#include "HepMC3/Print.h"

#include <iostream>

using namespace HepMC3;

/** Main */
int main(int argc, char **argv) {

    if( argc<3 ) {
        cout << "Usage: " << argv[0] << " <input_root_file> <output_hepmc3_file>" << endl;
        exit(-1);
    }

    ReaderRootTree  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 ) {
            cout << "First event: " << endl;
            Print::listing(evt);
        }

        text_output.write_event(evt);
        ++events_parsed;

        if( events_parsed%1000 == 0 ) {
            cout << "Event: " << events_parsed << endl;
        }
    }

    root_input.close();
    text_output.close();

    std::cout << "Events parsed and written: " << events_parsed << std::endl;

    return 0;
}