Utility to convert between different types of event records.
#ifdef HEPMC3_ROOTIO
#endif
#ifdef HEPMCCONVERT_EXTENSION_ROOTTREEOPAL
#ifndef HEPMC3_ROOTIO
#warning "HEPMCCONVERT_EXTENSION_ROOTTREEOPAL requires compilation with of HepMC with ROOT, i.e. HEPMC3_ROOTIO.This extension will be disabled."
#undef HEPMCCONVERT_EXTENSION_ROOTTREEOPAL
#else
#endif
#endif
#ifdef HEPMCCONVERT_EXTENSION_HEPEVTZEUS
#endif
#ifdef HEPMCCONVERT_EXTENSION_DOT
#endif
#ifdef HEPMCCONVERT_EXTENSION_GZ
#endif
#include "cmdline.h"
enum formats {hepmc2, hepmc3, hpe ,root, treeroot ,treerootopal, hpezeus, lhef, dump, dot, gz, none};
int main(int argc, char** argv)
{
gengetopt_args_info ai;
if (cmdline_parser (argc, argv, &ai) != 0) {
exit(1);
}
if (ai.inputs_num!=2)
{
printf("Exactly two arguments are requred: the name of input and output files\n");
exit(1);
}
std::map<std::string,formats> format_map;
format_map.insert(std::pair<std::string,formats> ( "hepmc2", hepmc2 ));
format_map.insert(std::pair<std::string,formats> ( "hepmc3", hepmc3 ));
format_map.insert(std::pair<std::string,formats> ( "hpe", hpe ));
format_map.insert(std::pair<std::string,formats> ( "root", root ));
format_map.insert(std::pair<std::string,formats> ( "treeroot", treeroot ));
format_map.insert(std::pair<std::string,formats> ( "treerootopal", treerootopal ));
format_map.insert(std::pair<std::string,formats> ( "hpezeus", hpezeus ));
format_map.insert(std::pair<std::string,formats> ( "lhef", lhef ));
format_map.insert(std::pair<std::string,formats> ( "dump", dump ));
format_map.insert(std::pair<std::string,formats> ( "dot", dot ));
format_map.insert(std::pair<std::string,formats> ( "gz", gz ));
format_map.insert(std::pair<std::string,formats> ( "none", none ));
std::map<std::string, std::string> options;
for (size_t i=0; i<ai.extensions_given; i++)
{
std::string optarg=std::string(ai.extensions_arg[i]);
size_t pos=optarg.find_first_of('=');
if (pos<optarg.length())
options[std::string(optarg,0,pos)]=std::string(optarg,pos+1,optarg.length());
}
long int events_parsed = 0;
long int events_limit = ai.events_limit_arg;
long int first_event_number = ai.first_event_number_arg;
long int last_event_number = ai.last_event_number_arg;
long int print_each_events_parsed = ai.print_every_events_parsed_arg;
bool ignore_writer=false;
switch (format_map.at(std::string(ai.input_format_arg)))
{
case hepmc2:
break;
case hepmc3:
break;
case hpe:
break;
case lhef:
break;
case gz:
#ifdef HEPMCCONVERT_EXTENSION_GZ
break;
#else
printf("Input format %s is not supported\n",ai.input_format_arg);
exit(2);
#endif
case treeroot:
#ifdef HEPMC3_ROOTIO
break;
#else
printf("Input format %s is not supported\n",ai.input_format_arg);
exit(2);
#endif
case root:
#ifdef HEPMC3_ROOTIO
break;
#else
printf("Input format %s is not supported\n",ai.input_format_arg);
exit(2);
#endif
default:
printf("Input format %s is not known\n",ai.input_format_arg);
exit(2);
break;
}
switch (format_map.at(std::string(ai.output_format_arg)))
{
case hepmc2:
break;
case hepmc3:
break;
case hpe:
break;
case root:
#ifdef HEPMC3_ROOTIO
break;
#else
printf("Output format %s is not supported\n",ai.output_format_arg);
exit(2);
#endif
case treeroot:
#ifdef HEPMC3_ROOTIO
break;
#else
printf("Output format %s is not supported\n",ai.output_format_arg);
exit(2);
#endif
case treerootopal:
#ifdef HEPMCCONVERT_EXTENSION_ROOTTREEOPAL
if (options.find(
"Run")!=options.end()) ((
WriterRootTreeOPAL*)(output_file))->set_run_number(std::atoi(options.at(
"Run").c_str()));
break;
#else
printf("Output format %s is not supported\n",ai.output_format_arg);
exit(2);
break;
#endif
case hpezeus:
#ifdef HEPMCCONVERT_EXTENSION_HEPEVTZEUS
break;
#else
printf("Output format %s is not supported\n",ai.output_format_arg);
exit(2);
#endif
case dot:
#ifdef HEPMCCONVERT_EXTENSION_DOT
if (options.find(
"Style")!=options.end()) ((
WriterDOT*)(output_file))->set_style(std::atoi(options.at(
"Style").c_str()));
break;
#else
printf("Output format %s is not supported\n",ai.output_format_arg);
exit(2);
break;
#endif
case dump:
output_file=NULL;
break;
case none:
output_file=NULL;
ignore_writer=true;
break;
default:
printf("Output format %s is not known\n",ai.output_format_arg);
exit(2);
break;
}
while( !input_file->
failed() )
{
printf("End of file reached. Exit.\n");
break;
}
if (evt.event_number()<first_event_number) continue;
if (evt.event_number()>last_event_number) continue;
evt.set_run_info(input_file->
run_info());
if (!ignore_writer)
if (output_file)
{
}
else
{
Print::content(evt);
}
evt.clear();
++events_parsed;
if( events_parsed%print_each_events_parsed == 0 ) printf("Events parsed: %li\n",events_parsed);
if( events_parsed >= events_limit ) {
printf("Event limit reached:->events_parsed(%li) >= events_limit(%li)<-. Exit.\n",events_parsed , events_limit);
break;
}
}
if (input_file) input_file->
close();
if (output_file) output_file->
close();
return EXIT_SUCCESS;
}
Definition of class GenEvent.
Definition of static class Print.
Definition of class ReaderAsciiHepMC2.
Definition of class ReaderAscii.
Definition of class ReaderGZ.
Definition of class ReaderHEPEVT.
Definition of class ReaderLHEF.
Definition of class ReaderRootTree.
Definition of class ReaderRoot.
Definition of class WriterAsciiHepMC2.
Definition of class WriterAscii.
Definition of class WriterDOT.
Definition of class WriterHEPEVTZEUS.
Definition of class WriterHEPEVT.
Definition of class WriterRootTreeOPAL.
Definition of class WriterRootTree.
Definition of class WriterRoot.
Stores event-related information.
Parser for HepMC2 I/O files.
GenEvent I/O parsing for structured text files.
GenEvent I/O parsing for structured text files compressed with gzip.
GenEvent I/O parsing and serialization for HEPEVT files.
GenEvent I/O parsing and serialization for LHEF files.
GenEvent I/O parsing and serialization for root files based on root TTree.
GenEvent I/O parsing and serialization for root files.
Base class for all I/O readers.
virtual bool read_event(GenEvent &evt)=0
Fill next event from input into evt.
shared_ptr< GenRunInfo > run_info() const
Get the global GenRunInfo object.
virtual bool failed()=0
Get file and/or stream error state.
virtual void close()=0
Close file and/or stream.
GenEvent I/O serialization for structured text files.
GenEvent I/O serialization for structured text files.
GenEvent I/O output to dot files that should be processed by graphviz or other software.
GenEvent I/O output to files readable by ZEUS software.
GenEvent I/O serialization for HEPEVT files.
GenEvent I/O output to files similar to these produced by OPAL software.
GenEvent I/O serialization for root files based on root TTree.
GenEvent I/O serialization for root files.
Base class for all I/O writers.
virtual void write_event(const GenEvent &evt)=0
Write event evt to output target.
virtual void close()=0
Close file and/or stream.