Basic example of use of root I/O: writing events to file.
 
#include "TFile.h"
 
#include <iostream>
#include <sstream>
 
 
#include "MyClass.h"
#include "MyRunClass.h"
 
int main(int argc, char **argv) {
 
    if( argc<3 ) {
        std::cout << "Usage: " << argv[0] << " <input_hepmc3_file> <output_root_file>" <<std:: endl;
        exit(-1);
    }
 
 
    auto* fFile = new TFile(argv[2],"RECREATE");
 
    int events_parsed = 0;
 
    bool is_gen_run_info_written = false;
 
    while( !text_input.
failed() ) {
 
 
 
 
        if( text_input.
failed() ) 
break;
 
 
        if( events_parsed == 0 ) {
            std::cout << "First event: " << std::endl;
        }
 
        if(!is_gen_run_info_written) {
 
 
                my_run->SetRunInfo(&run_info);
 
                fFile->WriteObject(my_run,"MyRunClass");
 
                is_gen_run_info_written = true;
            }
        }
 
 
        myclass->SetEvent(&evt);
        
        std::ostringstream os;
        os << events_parsed;
        std::string stevt = "Event_" + os.str();
        const char* chevt = stevt.c_str();
 
        std::cout << "writing " << stevt << std::endl;
 
        fFile->WriteObject(myclass, chevt);
 
        ++events_parsed;
 
        if( events_parsed%100 == 0 ) {
            std::cout << "Event: " << events_parsed << std::endl;
        }
    }
 
    fFile->Close();
    std::cout << "Events parsed and written: " << events_parsed << std::endl;
 
    return 0;
}
Definition of class GenEvent.
Definition of class GenRunInfo.
Definition of static class Print.
Definition of class ReaderAscii.
Stores event-related information.
std::shared_ptr< GenRunInfo > run_info() const
Get a pointer to the the GenRunInfo object.
Stores run-related information.
static void listing(std::ostream &os, const GenEvent &event, unsigned short precision=2)
Print event in listing (HepMC2) format.
GenEvent I/O parsing for structured text files.
bool read_event(GenEvent &evt) override
Load event from file.
bool failed() override
Return status of the stream.
void close() override
Close file stream.
Sample class for root I/O test.
Sample class for root I/O test.