Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

testMgr.cxx

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/flux/src/test/testMgr.cxx,v 1.18 2001/10/20 07:20:35 srobinsn Exp $
00002 
00003 #include "flux/FluxMgr.h"
00004 #include "flux/EventSource.h"
00005 #include "flux/ISpectrumFactory.h"
00006 #include "../SpectrumFactoryTable.h"
00007 #include <iostream>
00008 #include <algorithm>
00009 #include "flux/CHIMESpectrum.h"
00010 #include "flux/Orbit.h"
00011 
00012 
00013 static int default_count = 10;
00014 //Testing
00015 static const char * default_source="default";
00016 //Default
00017 //static const char * default_source="CrElectron";
00018 
00019 void help() {
00020     std::cout << 
00021         "   Simple test program to create a particle source, then run it.\n"
00022         "   Command line args are \n"
00023         "      <source name> <count>\n"
00024         "   with defaults \"" 
00025         <<  default_source << "\"," << default_count
00026         << "\n  Also, 'help' for this help, 'list' for a list of sources and Spectrum objects "
00027         << std::endl;
00028 }
00029 void listSources(const std::list<std::string>& source_list ) {
00030     std::cout << "List of available sources:" << std::endl;
00031     for( std::list<std::string>::const_iterator it = source_list.begin(); 
00032     it != source_list.end(); ++it) { 
00033         std::cout << '\t'<< *it << std::endl;
00034     }
00035     
00036 }
00037 void listSpectra() {
00038     std::cout << "List of loaded Spectrum objects: " << std::endl;
00039     std::list<std::string> spectra(SpectrumFactoryTable::instance()->spectrumList());
00040     for( std::list<std::string>::const_iterator it = spectra.begin(); 
00041     it != spectra.end(); ++it) { 
00042         std::cout << '\t'<< *it << std::endl;
00043     }
00044 }
00045 
00046 
00047 #define DLL_DECL_SPECTRUM(x)   extern const ISpectrumFactory& x##Factory; x##Factory.addRef();
00048 
00049 void flux_load() {
00050     
00051     // these are the spectra that we want to make available
00052     DLL_DECL_SPECTRUM( CHIMESpectrum);
00053     DLL_DECL_SPECTRUM( AlbedoPSpectrum);
00054     DLL_DECL_SPECTRUM( HeSpectrum);
00055     DLL_DECL_SPECTRUM( GalElSpectrum);
00056     DLL_DECL_SPECTRUM( CrElectron);
00057     DLL_DECL_SPECTRUM( CrProton);
00058     //  DLL_DECL_SPECTRUM( CREMESpectrum);
00059 }
00060 
00061 int main(int argn, char * argc[]) {
00062     using std::cout;
00063     using std::endl;
00064     flux_load();
00065     //testing 
00066     std::string test("23class");
00067     int ss = test.find_first_not_of("0123456789");
00068     
00069     int count = default_count;
00070     std::string source_name(default_source);
00071     
00072     
00073     //TESTING MULTIPLE XML INPUT
00074     //std::vector<std::string> fileList;
00075     //fileList.push_back("D:/users/srobinsn/code-current/flux/v5r2/xml/user_library.xml");
00076     //fileList.push_back("D:/users/srobinsn/code-current/flux/v5r2/xml/source_library.xml");    
00077     //FluxMgr fm(fileList);
00078     
00079     FluxMgr fm;
00080     
00081     //Testing the addfactory function
00082     //    static PencilBeam* sean=TestSpec::instance();
00083     //    fm.addFactory("seantest", sean );
00084     //End Test
00085     
00086     if ( argn >1 ) source_name = argc[1];
00087     if( source_name =="help") { help(); return 0; }
00088     if( source_name =="list") { 
00089         listSources(fm.sourceList());
00090         listSpectra(); return 0; }
00091     if ( argn >2 ) count = ::atoi(argc[2]);
00092     
00093     cout << "------------------------------------------------------" << endl;
00094     cout << " Flux test program: type 'help' for help" << endl;
00095     cout << ( ( argn ==1)?  " No command line args, using default flux \""
00096         :  " Selected source name \"");
00097     cout  << source_name <<"\"" << endl;
00098     
00099     
00100     std::list<std::string> source_list(fm.sourceList());
00101     
00102     if( std::find(source_list.begin(), source_list.end(), source_name)==source_list.end() ) {
00103         std::list<std::string> spectra(SpectrumFactoryTable::instance()->spectrumList());
00104         
00105         if( std::find(spectra.begin(), spectra.end(), source_name)==spectra.end() ) {
00106             std::cout << "Source \"" << source_name << "\" not found in the list or sources!" << std::endl;
00107             listSources(source_list);
00108             std::cout << "or in specra list, which is:\n";
00109             listSpectra();
00110             
00111             return -1;
00112         }
00113     }
00114     // now have FluxMgr create and run it.
00115     fm.test(std::cout, source_name, count);
00116     return 0;
00117     
00118 }
00119 
00120 void WARNING (const char * text ){  std::cerr << "WARNING: " << text << '\n';}
00121 void FATAL(const char* s){std::cerr << "\nERROR: "<< s;}

Generated at Wed Nov 21 12:20:34 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000