00001
00002 #include "StagePuller.h"
00003 #include "Stage/HeaderStageData.h"
00004 #include "Event/HeaderObject.h"
00005
00006 StagePuller::StagePuller(const std::string& name, ISvcLocator* pSvcLocator)
00007 : GaudiAlgorithm(name,pSvcLocator)
00008 , m_stage("Stage")
00009 , m_startTime(TimeStamp::GetBOT())
00010 {
00011 declareProperty("Stage",m_stage, "Stage to pull from.");
00012 declareProperty("RunTimeSeconds",m_runTimeSeconds=0,
00013 "Period of time, in seconds, that the job should run, if non-zero.");
00014 }
00015
00016 StagePuller::~StagePuller()
00017 {
00018 }
00019
00020 StatusCode StagePuller::initialize()
00021 {
00022 StatusCode sc = this->GaudiAlgorithm::initialize();
00023 if (sc.isFailure()) return sc;
00024
00025 MsgStream log(msgSvc(), name());
00026
00027 log << MSG::DEBUG
00028 << "Retrieving stage " << m_stage.typeAndName() << endreq;
00029 if (m_stage.retrieve().isFailure()) {
00030 log << MSG::ERROR
00031 << "Failed to retrieve " << m_stage << endreq;
00032 return StatusCode::FAILURE;
00033 }
00034
00035 return StatusCode::SUCCESS;
00036 }
00037
00038 StatusCode StagePuller::execute()
00039 {
00040 MsgStream log(msgSvc(), name());
00041
00042 log << MSG::DEBUG
00043 << "===> Pulling from last stage" << endreq;
00044
00045 IStageData* data = 0;
00046 StatusCode sc = m_stage->nextElement(data,true);
00047 if (!data || sc.isFailure()) {
00048 log << MSG::WARNING
00049 << "Failed to pull next element" << endreq;
00050 return sc;
00051 }
00052
00053 if (m_runTimeSeconds) {
00054 if (m_startTime == TimeStamp::GetBOT()) {
00055 m_startTime = data->time();
00056 }
00057 double dt_seconds = data->time() - m_startTime;
00058 if (dt_seconds > m_runTimeSeconds) {
00059
00060 }
00061 }
00062
00063 log << MSG::DEBUG
00064 << "Pulled data at time: " << data->time()
00065 << endreq;
00066
00067 IStageData* hsdb = dynamic_cast< IStageData* >(data);
00068 if (!hsdb) {
00069 debug() << "StageData not a StageData, oh well." << endreq;
00070 delete data;
00071 return StatusCode::SUCCESS;
00072 }
00073
00074 DayaBay::HeaderObject& ho = hsdb->header();
00075 put(&ho,ho.defLoc());
00076 delete data;
00077 return StatusCode::SUCCESS;
00078 }
00079
00080 StatusCode StagePuller::finalize()
00081 {
00082 m_stage->release();
00083 return this->GaudiAlgorithm::finalize();
00084 }
00085
00086
00087
00088