13 #include "HepMC/GenEvent.h" 14 #include "HepMC/GenRunInfo.h" 15 #include "HepMC/ReaderAscii.h" 16 #include "HepMC/Print.h" 23 using namespace HepMC;
28 #include "MyRunClass.h" 31 int main(
int argc,
char **argv) {
34 cout <<
"Usage: " << argv[0] <<
" <input_hepmc3_file> <output_root_file>" << endl;
40 TFile* fFile =
new TFile(argv[2],
"RECREATE");
42 int events_parsed = 0;
44 bool is_gen_run_info_written =
false;
46 while( !text_input.failed() ) {
50 text_input.read_event(evt);
52 if( text_input.failed() )
break;
54 if( events_parsed == 0 ) {
55 cout <<
"First event: " << endl;
59 if(!is_gen_run_info_written) {
65 my_run->SetRunInfo(&run_info);
67 fFile->WriteObject(my_run,
"MyRunClass");
69 is_gen_run_info_written =
true;
77 std::ostringstream os;
79 std::string stevt =
"Event_" + os.str();
80 const char* chevt = stevt.c_str();
82 cout <<
"writing " << stevt << endl;
84 fFile->WriteObject(myclass, chevt);
88 if( events_parsed%1000 == 0 ) {
89 cout <<
"Event: " << events_parsed << endl;
95 std::cout <<
"Events parsed and written: " << events_parsed << std::endl;
Sample class for root I/O test.
static void listing(const GenEvent &event, unsigned short precision=2)
Print event in listing (HepMC2) format.
Stores run-related information.
Stores event-related information.
Sample class for root I/O test.
void SetEvent(HepMC::GenEvent *)
Set HepMC event.
int main(int argc, char **argv)
Definition of template class SmartPointer.
GenEvent I/O parsing for structured text files.