![]() |
HepPDT Reference DocumentationHepPDT |
00001 // $Id: testReadParticleTable.cc.in,v 1.6 2009/11/25 02:20:37 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 infile2[] = "@top_srcdir@/tests/HepPDT/extras.tbl"; 00019 const char outfile[] = "testReadParticleTable.out"; 00020 // open input files 00021 std::ifstream pdfile( infile ); 00022 if( !pdfile ) { 00023 std::cerr << "cannot open " << infile << std::endl; 00024 exit(-1); 00025 } 00026 std::ifstream pdfile2( infile2 ); 00027 if( !pdfile2 ) { 00028 std::cerr << "cannot open " << infile2 << std::endl; 00029 exit(-1); 00030 } 00031 // construct empty PDT 00032 HepPDT::ParticleDataTable datacol( "Generic Particle Table" ); 00033 { 00034 // Construct table builder 00035 HepPDT::TableBuilder tb(datacol); 00036 // read the input - put as many here as you want 00037 // bool addParticleTable( std::istream&, TableBuilder&, 00038 // bool validate = false ); 00039 // where: validate=true => verify that the ParticleID is valid 00040 if( !addParticleTable( pdfile, tb, true ) ) { 00041 std::cout << "error reading PDG pdt file " << std::endl; 00042 } 00043 if( !addParticleTable( pdfile2, tb, true ) ) { 00044 std::cout << "error reading extra pdt file " << std::endl; 00045 } 00046 } // the tb destructor fills datacol 00047 // open the output stream 00048 std::ofstream wfile( outfile ); 00049 if( !wfile ) { 00050 std::cerr << "cannot open " << outfile << std::endl; 00051 exit(-1); 00052 } 00053 // write the data table 00054 datacol.writeParticleData(wfile); 00055 // try some heavy ions 00056 wfile << std::endl; 00057 wfile << std::endl; 00058 HepPDT::ParticleData * pd; 00059 pd=datacol.particle(HepPDT::ParticleID(1000020040)); 00060 if(pd) pd->write(wfile); 00061 pd=datacol.particle(HepPDT::ParticleID(1000050110)); 00062 if(pd) pd->write(wfile); 00063 00064 // check isStable 00065 const char outfile3[] = "testReadParticleTableStatus.out"; 00066 std::ofstream wpdt3( outfile3 ); 00067 if( !wpdt3 ) { 00068 std::cerr << "cannot open " << outfile3 << std::endl; 00069 exit(-1); 00070 } 00071 datacol.writeParticleStatus(wpdt3); 00072 00073 return 0; 00074 }