HepPDT Reference Documentation

HepPDT

testReadParticleTable.cc.in

The HepPDT tests are also useful examples

read particle.tbl and write it out Also write out a list of which particles are stable

00001 // $Id: testReadParticleTable.cc.in,v 1.5 2008/10/24 16:41:40 garren Exp $
00002 // ----------------------------------------------------------------------
00003 // testReadParticleTable.cc
00004 //
00005 // read particle.tbl and write it out
00006 //
00007 // ----------------------------------------------------------------------
00008 
00009 #include <fstream>
00010 
00011 #include "HepPDT/defs.h"
00012 #include "HepPDT/TableBuilder.hh"
00013 #include "HepPDT/ParticleDataTable.hh"
00014 
00015 int main()
00016 {
00017     const char infile[] = "@top_srcdir@/data/particle.tbl";
00018     const char outfile[] = "testReadParticleTable.out";
00019     // open input files
00020     std::ifstream pdfile( infile );
00021     if( !pdfile ) { 
00022       std::cerr << "cannot open " << infile << std::endl;
00023       exit(-1);
00024     }
00025     // construct empty PDT
00026     HepPDT::ParticleDataTable datacol( "Generic Particle Table" );
00027     {
00028         // Construct table builder
00029         HepPDT::TableBuilder  tb(datacol);
00030         // read the input - put as many here as you want
00031         // bool  addParticleTable( std::istream&, TableBuilder&,
00032         //                         bool validate = false );
00033         // where:  validate=true => verify that the ParticleID is valid
00034         if( !addParticleTable( pdfile, tb, true ) ) { 
00035             std::cout << "error reading EvtGen pdt file " << std::endl; 
00036         }
00037     }   // the tb destructor fills datacol
00038     // open the output stream
00039     std::ofstream wfile( outfile );
00040     if( !wfile ) { 
00041       std::cerr << "cannot open " << outfile << std::endl;
00042       exit(-1);
00043     }
00044     // write the data table
00045     datacol.writeParticleData(wfile);
00046     // try some heavy ions
00047     wfile << std::endl;
00048     wfile << std::endl;
00049     HepPDT::ParticleData * pd;
00050     pd=datacol.particle(HepPDT::ParticleID(1000020040));
00051     if(pd) pd->write(wfile);
00052     pd=datacol.particle(HepPDT::ParticleID(1000050110));
00053     if(pd) pd->write(wfile);
00054 
00055     // check isStable
00056     const char outfile3[] = "testReadParticleTableStatus.out";
00057     std::ofstream wpdt3( outfile3 );
00058     if( !wpdt3 ) { 
00059       std::cerr << "cannot open " << outfile3 << std::endl;
00060       exit(-1);
00061     }
00062     datacol.writeParticleStatus(wpdt3);
00063 
00064     return 0;
00065 }

Generated on Fri Oct 24 13:41:35 2008 for HepPDT by  doxygen 1.5.1-3