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

testMgr.cxx

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/FluxSvc/src/test/flux/testMgr.cxx,v 1.13 2002/09/05 02:24:01 srobinsn Exp $
00002 
00003 #include "../../FluxMgr.h"
00004 #include "FluxSvc/EventSource.h"
00005 #include "FluxSvc/ISpectrumFactory.h"
00006 #include "../../SpectrumFactoryTable.h"
00007 #include <iostream>
00008 #include <algorithm>
00009 #include "../../CHIMESpectrum.h"
00010 //#include "../../Orbit.h"
00011 
00012 
00013 static int default_count = 200 ;
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( GRBSpectrum);
00059     //  DLL_DECL_SPECTRUM( CREMESpectrum);
00060 }
00061 
00062 int main(int argn, char * argc[]) {
00063     using std::cout;
00064     using std::endl;
00065     flux_load();
00066     //testing 
00067     std::string test("23class");
00068     int ss = test.find_first_not_of("0123456789");
00069     
00070     int count = default_count;
00071     std::string source_name(default_source);
00072     
00073     
00074     //TESTING MULTIPLE XML INPUT
00075     std::vector<std::string> fileList;
00076     fileList.push_back("$(FLUXSVCROOT)/xml/user_library.xml");
00077     fileList.push_back("$(FLUXSVCROOT)/xml/source_library.xml");        
00078     FluxMgr fm(fileList);
00079     
00080     //FluxMgr fm;
00081     
00082     //Testing the addfactory function
00083     //    static PencilBeam* sean=TestSpec::instance();
00084     //    fm.addFactory("seantest", sean );
00085     //End Test
00086     
00087     if ( argn >1 ) source_name = argc[1];
00088     if( source_name =="help") { help(); return 0; }
00089     if( source_name =="list") { 
00090         listSources(fm.sourceList());
00091         listSpectra(); return 0; }
00092     if ( argn >2 ) count = ::atoi(argc[2]);
00093     
00094     cout << "------------------------------------------------------" << endl;
00095     cout << " Flux test program: type 'help' for help" << endl;
00096     cout << ( ( argn ==1)?  " No command line args, using default flux \""
00097         :  " Selected source name \"");
00098     cout  << source_name <<"\"" << endl;
00099     
00100     
00101     std::list<std::string> source_list(fm.sourceList());
00102     
00103     if( std::find(source_list.begin(), source_list.end(), source_name)==source_list.end() ) {
00104         std::list<std::string> spectra(SpectrumFactoryTable::instance()->spectrumList());
00105         
00106         if( std::find(spectra.begin(), spectra.end(), source_name)==spectra.end() ) {
00107             std::cout << "Source \"" << source_name << "\" not found in the list or sources!" << std::endl;
00108             listSources(source_list);
00109             std::cout << "or in specra list, which is:\n";
00110             listSpectra();
00111             
00112             return -1;
00113         }
00114     }
00115     // now have FluxMgr create and run it.
00116     fm.test(std::cout, source_name, count);
00117     return 0;
00118     
00119 }
00120 

Generated on Wed Oct 16 14:01:31 2002 by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001