00001
00002
00003
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
00017
00018
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
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
00041
00043
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
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
00078 StatusCode FluxSvc::initialize ()
00079 {
00080
00081
00082 StatusCode status = Service::initialize ();
00083
00084
00085 setProperties ();
00086
00087
00088 m_source_lib.push_back("$(FLUXROOT)/xml/source_library.xml");
00089
00090
00091 MsgStream log( msgSvc(), name() );
00092
00093
00094 m_fluxMgr = new FluxMgr(m_source_lib);
00095
00096 Flux::mgr(m_fluxMgr);
00097
00098
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
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 }