00001
00006 #include "GaudiKernel/MsgStream.h"
00007 #include "GaudiKernel/GaudiException.h"
00008 #include "GaudiKernel/IAlgManager.h"
00009 #include "GaudiKernel/IJobOptionsSvc.h"
00010
00011
00012 #include "Stage.h"
00013
00014
00015 Stage::Stage( const std::string& type,
00016 const std::string& name,
00017 const IInterface* parent )
00018 : GaudiTool( type, name, parent )
00019 , m_SeqName("")
00020 {
00021
00022 declareInterface<IStage>(this);
00023
00024 declareProperty( "Sequencer", m_SeqName, "Sequencer's Name");
00025 }
00026
00027
00028 FFTimeStamp Stage::currentTime() const
00029
00030 {
00031 MsgStream log(msgSvc(), name());
00032 log << MSG::DEBUG << "currentTime() is: " << m_CurrentTime << endreq;
00033 return m_CurrentTime;
00034 }
00035
00036
00037 StatusCode Stage::nextElement(IStageData*& pIStgData,
00038 bool erase)
00039
00040 {
00041 debug() << " -- == nextElement() is called == -- " << endreq;
00042
00043 std::vector<Algorithm*>::iterator pVec;
00044
00045 if(m_read_erase==true) {
00047 m_sequencer->resetExecuted();
00048 StatusCode sc = m_sequencer->execute();
00049 if (sc.isFailure()) {
00050 error() << "Sequence failed" << endreq;
00051 return sc;
00052 }
00053 debug() << "every processor retured" << endreq;
00054 } else {
00058 }
00059
00064 IStageDataList::iterator ppData;
00065
00066 debug() << "current number of elements: "<< m_DataList.size() <<endreq;
00067 if(m_DataList.size()<=0) {
00068 fatal()<<"NO data available! Where is data? Check processors!"<<endreq;
00069 return StatusCode::FAILURE;
00070 }
00071
00072 ppData=m_DataList.begin();
00073 m_CurrentTime=ppData->first;
00074 debug() << "Smallest time found T_min = "<< m_CurrentTime << endreq;
00075
00077 pIStgData=ppData->second;
00078
00079 if(erase) {
00080 m_DataList.erase(ppData);
00081 }
00082
00084 m_read_erase=erase;
00085
00086 debug() << " -- == nextElement() call finished == --" << endreq;
00087 return StatusCode::SUCCESS;
00088 }
00089
00090 StatusCode Stage::pushElement(IStageData* pIStgData)
00091 {
00093 MsgStream log(msgSvc(), name());
00094 StatusCode sc;
00095
00096 m_DataList.insert(IStageDataList::value_type(pIStgData->time(),pIStgData));
00097
00098 return sc;
00099 }
00100
00101
00102 StatusCode Stage::initialize()
00103
00104 {
00105
00106 IMessageSvc* msg = svc<IMessageSvc>("MessageSvc");
00107 MsgStream log(msg, name());
00108 log << MSG::DEBUG << "intializing ......" << endreq;
00109
00110 if ("" == m_SeqName) {
00111 log << MSG::ERROR << "No seqencer given to stage " << name() << endreq;
00112 return StatusCode::FAILURE;
00113 }
00114
00115 {
00116
00117
00118 SmartIF<IAlgManager> am(IID_IAlgManager,serviceLocator());
00119
00120 IAlgorithm *tmp = 0;
00121
00122 StatusCode sc = am->getAlgorithm(m_SeqName, tmp);
00123 if (sc.isFailure()) {
00124 log << MSG::DEBUG
00125 << "Failed to get GaudiSequencer named " << m_SeqName
00126 << ". Will try to create..." << endreq;
00127
00128 sc = am->createAlgorithm ("GaudiSequencer", m_SeqName, tmp);
00129 if( sc.isFailure() ) {
00130 log << MSG::ERROR
00131 << "Failed to create GaudiSequencer named "
00132 << m_SeqName << endreq;
00133 return StatusCode::FAILURE;
00134 }
00135 }
00136
00137 try{
00138 m_sequencer = dynamic_cast<Algorithm*>(tmp);
00139 }
00140 catch(...) {
00141 log << MSG::ERROR
00142 << "GaudiSequencer named " << m_SeqName << " not an Algorithm?!?"
00143 << endreq;
00144 return StatusCode::FAILURE;
00145 }
00146 if (!m_sequencer) {
00147 log << MSG::ERROR
00148 << "GaudiSequencer not an algorithm??"
00149 << endreq;
00150 return StatusCode::FAILURE;
00151 }
00152
00153 log << MSG::INFO
00154 << "Got algorithm " << m_sequencer->name()
00155 << " setting properties on it"
00156 << endreq;
00157
00158 IJobOptionsSvc* jos = svc<IJobOptionsSvc>("JobOptionsSvc");
00159 jos->setMyProperties(m_SeqName,m_sequencer);
00160 jos->release();
00161 }
00162
00163
00164 StatusCode sc = m_sequencer->initialize();
00165 if (sc.isFailure()) {
00166 log << MSG::ERROR
00167 << "GaudiSequencer::initialize() failed" << endreq;
00168 return sc;
00169 }
00170 log << MSG::DEBUG
00171 << "Got GaudiSequencer/" << m_sequencer->name() << endreq;
00172
00173
00174 m_CurrentTime=0;
00175
00176 m_DataList.clear();
00177
00180 m_read_erase=true;
00181
00182 return StatusCode::SUCCESS;
00183 }
00184
00185 StatusCode Stage::finalize()
00186
00187 {
00188 MsgStream log(msgSvc(), name());
00189 log << MSG::DEBUG << "finalizing ......" << endreq;
00190
00191
00192 return m_sequencer->finalize();
00193 }
00194
00195
00196 Stage::~Stage( )
00197
00198 {
00199 MsgStream log(msgSvc(), name());
00200 log << MSG::DEBUG << "destructing ......" << endreq;
00201 }
00202
00203
00204
00205