HepMC event record
WriterHEPEVT.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 /**
4  * @file WriterHEPEVT.cc
5  * @brief Implementation of \b class WriterHEPEVT
6  *
7  */
8 #include "HepMC/WriterHEPEVT.h"
9 #include "HepMC/HEPEVT_Wrapper.h"
10 #include <cstdio> // sprintf
11 #include "HepMC/Print.h"
12 #include <sstream>
13 namespace HepMC
14 {
15 
16 WriterHEPEVT::WriterHEPEVT(const std::string &filename): m_events_count(0)
17 {
18  m_file=fopen(filename.c_str(),"w");
19  hepevtbuffer=(char*)(new struct HEPEVT());
21 }
22 
23 void WriterHEPEVT::write_hepevt_particle( int index, bool iflong )
24 {
25  fprintf(m_file,"% 8i% 8i",HEPEVT_Wrapper::status(index), HEPEVT_Wrapper::id(index));
26  if (iflong)
27  {
28  fprintf(m_file,"% 8i% 8i",HEPEVT_Wrapper::first_parent(index),HEPEVT_Wrapper::last_parent(index));
29  fprintf(m_file,"% 8i% 8i",HEPEVT_Wrapper::first_child(index),HEPEVT_Wrapper::last_child(index));
30  fprintf(m_file,"% 19.8E% 19.8E% 19.8E% 19.8E% 19.8E\n",HEPEVT_Wrapper::px(index),HEPEVT_Wrapper::py(index),HEPEVT_Wrapper::pz(index),HEPEVT_Wrapper::e(index),HEPEVT_Wrapper::m(index));
31  fprintf(m_file, "%-48s% 19.8E% 19.8E% 19.8E% 19.8E\n"," ",HEPEVT_Wrapper::x(index),HEPEVT_Wrapper::y(index),HEPEVT_Wrapper::z(index),HEPEVT_Wrapper::t(index));
32  }
33  else
34  {
35  fprintf(m_file,"% 8i% 8i",HEPEVT_Wrapper::first_child(index),HEPEVT_Wrapper::last_child(index));
36  fprintf(m_file,"% 19.8E% 19.8E% 19.8E% 19.8E\n",HEPEVT_Wrapper::px(index),HEPEVT_Wrapper::py(index),HEPEVT_Wrapper::pz(index),HEPEVT_Wrapper::m(index));
37  }
38 }
39 
41 {
43 }
44 
46 {
50  for( int i=1; i<=HEPEVT_Wrapper::number_entries(); ++i ) write_hepevt_particle(i);
52 }
53 
55 {
56  fclose(m_file);
57 }
58 
60 {
61  return false;
62 }
63 
64 } // namespace HepMC
static double py(int index)
Get Y momentum.
bool failed()
Get stream error state flag.
Definition: WriterHEPEVT.cc:59
static int status(int index)
Get status code.
static bool GenEvent_to_HEPEVT(const GenEvent *evt)
Convert GenEvent to HEPEVT.
virtual void write_hepevt_particle(int index, bool iflong=true)
Write particle to file.
Definition: WriterHEPEVT.cc:23
virtual void write_hepevt_event_header()
Write event header to file.
Definition: WriterHEPEVT.cc:40
static double y(int index)
Get Y Production vertex.
static double e(int index)
Get Energy.
static double px(int index)
Get X momentum.
static double pz(int index)
Get Z momentum.
static void set_hepevt_address(char *c)
Set Fortran block address.
static int first_child(int index)
Get index of 1st daughter.
static double z(int index)
Get Z Production vertex.
static double t(int index)
Get production time.
Stores event-related information.
void write_event(const GenEvent &evt)
Write event to file.
Definition: WriterHEPEVT.cc:45
static int last_child(int index)
Get index of last daughter.
Fortran common block HEPEVT.
static double x(int index)
Get X Production vertex.
static int first_parent(int index)
Get index of 1st mother.
static int id(int index)
Get PDG particle id.
static double m(int index)
Get generated mass.
void close()
Close file stream.
Definition: WriterHEPEVT.cc:54
int m_events_count
Events count. Needed to generate unique object name.
static int number_entries()
Get number of entries.
static int last_parent(int index)
Get index of last mother.
static bool fix_daughters()
Tries to fix list of daughters.
char * hepevtbuffer
Pointer to HEPEVT Fortran common block/C struct.
Definition of template class SmartPointer.
WriterHEPEVT(const std::string &filename)
Default constructor.
Definition: WriterHEPEVT.cc:16
FILE * m_file
File to write. Need to be public to be accessible by children.