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

FluxSvc.cxx

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/FluxSvc/src/FluxSvc.cxx,v 1.12 2001/10/31 23:35:29 srobinsn Exp $
00002 // 
00003 //  Original author: Toby Burnett tburnett@u.washington.edu
00004 //
00005 
00006 #include "FluxSvc/FluxSvc.h"
00007 
00008 #include "GaudiKernel/SvcFactory.h"
00009 #include "GaudiKernel/MsgStream.h"
00010 
00011 #include "GaudiKernel/Incident.h"
00012 #include "GaudiKernel/IIncidentSvc.h"
00013 #include "GaudiKernel/Property.h"
00014 #include "GaudiKernel/IRndmGenSvc.h"
00015 
00016 // nasty include needed so that we can get at the HepRandomEngine
00017 // in the initialize method. (Ian Gable) 
00018 // The actual is GaudiSvc
00019 #if 0
00020 #include "src/RndmGenSvc/HepRndmBaseEngine.h"
00021 #endif
00022 #include "CLHEP/Random/Random.h"
00023 #include "CLHEP/Random/RanluxEngine.h"
00024 
00025 
00026 #include "Flux.h"
00027 
00028 #include "flux/FluxMgr.h"
00029 #include <algorithm>
00030 
00031 // declare the service factories for the FluxSvc
00032 static SvcFactory<FluxSvc> a_factory;
00033 const ISvcFactory& FluxSvcFactory = a_factory;
00034 
00035 void FATAL(const char* text){std::cerr << text << std::endl;}
00036 void WARNING(const char* text){std::cerr << text << std::endl;}
00037 
00038 
00039 // ------------------------------------------------
00040 // Implementation of the FluxSvc class
00041 // ------------------------------------------------
00043 FluxSvc::FluxSvc(const std::string& name,ISvcLocator* svc)
00044 : Service(name,svc)
00045 {
00046     
00047     declareProperty("source_lib" , m_source_lib);   
00048   
00049     HepRandom::setTheEngine(new RanluxEngine);
00050 }
00051 
00052 std::list<std::string> FluxSvc::fluxNames()const{
00053     return m_fluxMgr->sourceList();
00054 }
00055 
00056 StatusCode FluxSvc::source(std::string name, IFlux*& flux) {
00057     
00058     std::list<std::string> source_list( fluxNames() );
00059     std::list<std::string> source_list2( SpectrumFactoryTable::instance()->spectrumList() );
00060     
00061     if( std::find(source_list.begin(), source_list.end(), name) == source_list.end() 
00062         &&(std::find(source_list2.begin(), source_list2.end(), name) == source_list2.end()))
00063         //flux =  new Flux(name);
00064         return StatusCode::FAILURE;
00065     
00066     flux =  new Flux(name);
00067     
00068     return StatusCode::SUCCESS;
00069 }
00070 
00072 FluxSvc::~FluxSvc()  
00073 {
00074 }
00075 
00076 
00077 // initialize
00078 StatusCode FluxSvc::initialize () 
00079 {
00080     //std::vector<std::string> fileList;
00081     
00082     StatusCode  status =  Service::initialize ();
00083     
00084     // bind all of the properties for this service
00085     setProperties ();
00086     
00087     //set a default source library, which the user can add to or change
00088     m_source_lib.push_back("$(FLUXROOT)/xml/source_library.xml");
00089     
00090     // open the message log
00091     MsgStream log( msgSvc(), name() );
00092      
00093     // create a FluxMgr object which will then be available.
00094     m_fluxMgr = new FluxMgr(m_source_lib);
00095     
00096     Flux::mgr(m_fluxMgr); // tell our Flux object
00097     
00098     // check that it was made properly
00099     if( m_fluxMgr->sourceList().empty()) {
00100         log << MSG::ERROR  << "Did not initialize properly: no sources detected" << endreq;
00101         status = StatusCode::FAILURE;
00102     }
00103     
00104     return status;
00105 }
00106 
00107 // finalize
00108 StatusCode FluxSvc::finalize ()
00109 {
00110     StatusCode  status = StatusCode::SUCCESS;
00111     
00112     delete m_fluxMgr;
00113     return status;
00114 }
00115 
00117 StatusCode FluxSvc::queryInterface(const IID& riid, void** ppvInterface)  {
00118     if ( IID_IFluxSvc.versionMatch(riid) )  {
00119         *ppvInterface = (IFluxSvc*)this;
00120     }
00121     else  {
00122         return Service::queryInterface(riid, ppvInterface);
00123     }
00124     addRef();
00125     return SUCCESS;
00126 }
00127 
00128 
00130 void FluxSvc::addFactory(std::string name, const ISpectrumFactory* factory ){
00131     m_fluxMgr->addFactory(name, factory);
00132 }
00133 
00135 HepRandomEngine* FluxSvc::getEngine()
00136 {
00137     return HepRandom::getTheEngine();
00138 }

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