27#ifdef HEPMCCONVERT_EXTENSION_ROOTTREEOPAL
29#warning "HEPMCCONVERT_EXTENSION_ROOTTREEOPAL requires compilation with of HepMC with ROOT, i.e. HEPMC3_ROOTIO.This extension will be disabled."
30#undef HEPMCCONVERT_EXTENSION_ROOTTREEOPAL
35#ifdef HEPMCCONVERT_EXTENSION_HEPEVTZEUS
38#ifdef HEPMCCONVERT_EXTENSION_DOT
41#ifdef HEPMCCONVERT_EXTENSION_GZ
49enum formats {hepmc2, hepmc3, hpe ,root, treeroot ,treerootopal, hpezeus, lhef, dump, dot, gz, none};
50int main(
int argc,
char** argv)
52 gengetopt_args_info ai;
53 if (cmdline_parser (argc, argv, &ai) != 0) {
58 printf(
"Exactly two arguments are requred: the name of input and output files\n");
61 std::map<std::string,formats> format_map;
62 format_map.insert(std::pair<std::string,formats> (
"hepmc2", hepmc2 ));
63 format_map.insert(std::pair<std::string,formats> (
"hepmc3", hepmc3 ));
64 format_map.insert(std::pair<std::string,formats> (
"hpe", hpe ));
65 format_map.insert(std::pair<std::string,formats> (
"root", root ));
66 format_map.insert(std::pair<std::string,formats> (
"treeroot", treeroot ));
67 format_map.insert(std::pair<std::string,formats> (
"treerootopal", treerootopal ));
68 format_map.insert(std::pair<std::string,formats> (
"hpezeus", hpezeus ));
69 format_map.insert(std::pair<std::string,formats> (
"lhef", lhef ));
70 format_map.insert(std::pair<std::string,formats> (
"dump", dump ));
71 format_map.insert(std::pair<std::string,formats> (
"dot", dot ));
72 format_map.insert(std::pair<std::string,formats> (
"gz", gz ));
73 format_map.insert(std::pair<std::string,formats> (
"none", none ));
74 std::map<std::string, std::string> options;
75 for (
size_t i=0; i<ai.extensions_given; i++)
77 std::string optarg=std::string(ai.extensions_arg[i]);
78 size_t pos=optarg.find_first_of(
'=');
79 if (pos<optarg.length())
80 options[std::string(optarg,0,pos)]=std::string(optarg,pos+1,optarg.length());
82 long int events_parsed = 0;
83 long int events_limit = ai.events_limit_arg;
84 long int first_event_number = ai.first_event_number_arg;
85 long int last_event_number = ai.last_event_number_arg;
86 long int print_each_events_parsed = ai.print_every_events_parsed_arg;
88 bool ignore_writer=
false;
89 switch (format_map.at(std::string(ai.input_format_arg)))
104#ifdef HEPMCCONVERT_EXTENSION_GZ
105 input_file=
new ReaderGZ(ai.inputs[0]);
108 printf(
"Input format %s is not supported\n",ai.input_format_arg);
116 printf(
"Input format %s is not supported\n",ai.input_format_arg);
124 printf(
"Input format %s is not supported\n",ai.input_format_arg);
128 printf(
"Input format %s is not known\n",ai.input_format_arg);
133 switch (format_map.at(std::string(ai.output_format_arg)))
149 printf(
"Output format %s is not supported\n",ai.output_format_arg);
157 printf(
"Output format %s is not supported\n",ai.output_format_arg);
162#ifdef HEPMCCONVERT_EXTENSION_ROOTTREEOPAL
165 if (options.find(
"Run")!=options.end()) ((
WriterRootTreeOPAL*)(output_file))->set_run_number(std::atoi(options.at(
"Run").c_str()));
168 printf(
"Output format %s is not supported\n",ai.output_format_arg);
173#ifdef HEPMCCONVERT_EXTENSION_HEPEVTZEUS
177 printf(
"Output format %s is not supported\n",ai.output_format_arg);
181#ifdef HEPMCCONVERT_EXTENSION_DOT
183 if (options.find(
"Style")!=options.end()) ((
WriterDOT*)(output_file))->set_style(std::atoi(options.at(
"Style").c_str()));
186 printf(
"Output format %s is not supported\n",ai.output_format_arg);
198 printf(
"Output format %s is not known\n",ai.output_format_arg);
202 while( !input_file->
failed() )
206 if( input_file->
failed() ) {
207 printf(
"End of file reached. Exit.\n");
210 if (evt.event_number()<first_event_number)
continue;
211 if (evt.event_number()>last_event_number)
continue;
212 evt.set_run_info(input_file->
run_info());
225 if( events_parsed%print_each_events_parsed == 0 ) printf(
"Events parsed: %li\n",events_parsed);
226 if( events_parsed >= events_limit ) {
227 printf(
"Event limit reached:->events_parsed(%li) >= events_limit(%li)<-. Exit.\n",events_parsed , events_limit);
232 if (input_file) input_file->
close();
233 if (output_file) output_file->
close();
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.
static void content(std::ostream &os, const GenEvent &event)
Print content of all GenEvent containers.
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.