00001 #include "DybNextEntryPolicyTool.h"
00002 #include "GaudiKernel/IRndmGenSvc.h"
00003
00004 DybNextEntryPolicyTool::DybNextEntryPolicyTool(const std::string& type,
00005 const std::string& name,
00006 const IInterface* parent)
00007 : GaudiTool(type,name,parent)
00008 , m_entries(-1)
00009 , m_entry(0)
00010 , m_step(1)
00011 , m_last(-1)
00012 {
00013 declareInterface<IDybEntryPolicyTool>(this);
00014 declareProperty("Start",m_entry=0, "Entry to start at");
00015 declareProperty("Step",m_step=1, "Number of entries to step");
00016 declareProperty("Mode",m_modeName="random","Loading mode: random or sequential");
00017 }
00018
00019 DybNextEntryPolicyTool::~DybNextEntryPolicyTool()
00020 {
00021
00022 }
00023
00024 StatusCode DybNextEntryPolicyTool::queryInterface( const InterfaceID& riid, void** ppvIf )
00025 {
00026 if ( riid == IDybEntryPolicyTool::interfaceID() ) {
00027 *ppvIf = (IDybEntryPolicyTool*)this;
00028 addRef();
00029 return StatusCode::SUCCESS;
00030 }
00031 return AlgTool::queryInterface( riid, ppvIf );
00032 }
00033
00034 StatusCode DybNextEntryPolicyTool::initialize()
00035 {
00036 IRndmGenSvc *rgs = 0;
00037 if (service("RndmGenSvc",rgs,true).isFailure()) {
00038 fatal() << "Failed to get random service" << endreq;
00039 return StatusCode::FAILURE;
00040 }
00041
00042 StatusCode sc;
00043 if (m_rand.initialize(rgs, Rndm::Flat(0,1)).isFailure()) {
00044 fatal() << "Failed to initialize flat random numbers" << endreq;
00045 return StatusCode::FAILURE;
00046 }
00047
00048 if( m_modeName=="random" ) {
00049 m_mode=1;
00050 }
00051 if( m_modeName=="sequential" ) {
00052 m_mode=2;
00053 }
00054 info()<<"Running mode: "<<m_modeName<<" "<<m_mode<<endreq;
00055 return StatusCode::SUCCESS;
00056 }
00057
00058 int DybNextEntryPolicyTool::set_entries(int entries)
00059 {
00060 m_entries = entries;
00061 return m_entries;
00062 }
00063
00064 int DybNextEntryPolicyTool::next_entry()
00065 {
00066 int ret;
00067
00068
00069 if( m_mode==1 ) {
00070 do {
00071 ret = int( m_rand() * m_entries );
00072 }
00073 while (ret == m_last);
00074 }
00075
00076 if( m_mode==2 ) {
00077 ret = m_entry;
00078 m_entry += m_step;
00079 if( m_entries>0 ) m_entry = m_entry % m_entries;
00080 }
00081
00082 m_last = ret;
00083 return ret;
00084 }