00001 #include "DybAlg/DybBaseAlg.h"
00002 #include "DataUtilities/DybArchiveList.h"
00003 #include "GaudiKernel/IRndmGenSvc.h"
00004 #include "GaudiKernel/IRndmEngine.h"
00005 #include "GaudiKernel/StreamBuffer.h"
00006
00007 #include "Context/TimeStamp.h"
00008
00009 #include "DataSvc/IJobInfoSvc.h"
00010
00011 DybBaseAlg::DybBaseAlg(const std::string& name, ISvcLocator* pSvcLocator)
00012 : GaudiAlgorithm(name,pSvcLocator)
00013 , m_headerObject(0)
00014 , m_jobInfoSvc(0)
00015 {
00016 declareProperty("ExecutionNumber",m_execNum = 1,
00017 "The starting execution number.");
00018 declareProperty("SaveRandomState",m_saveRandomState = false,
00019 "Set true/false to save the random state.");
00020
00021 m_pullMode=false;
00022
00023 }
00024
00025 DybBaseAlg::~DybBaseAlg()
00026 {
00027 }
00028
00029 StatusCode DybBaseAlg::sysInitialize()
00030 {
00031
00032 StatusCode sc = this->GaudiAlgorithm::initialize();
00033 if (sc.isFailure()) return sc;
00034
00035
00036
00037
00038
00039
00040 sc = this->Algorithm::sysInitialize();
00041 if (sc.isFailure()) return sc;
00042
00043 return StatusCode::SUCCESS;
00044 }
00045
00046 StatusCode DybBaseAlg::sysExecute()
00047 {
00048 if(!m_pullMode) {
00049 if(preExecute().isFailure()) return StatusCode::FAILURE;
00050 }
00051
00052
00053 if (this->Algorithm::sysExecute().isFailure()) return StatusCode::FAILURE;
00054
00055 if(!m_pullMode) {
00056 if(postExecute().isFailure()) return StatusCode::FAILURE;
00057 }
00058
00059 return StatusCode::SUCCESS;
00060 }
00061
00062 StatusCode DybBaseAlg::preExecute()
00063 {
00064 if (!m_saveRandomState) return StatusCode::SUCCESS;
00065
00066
00067 IRndmEngine *engine = 0;
00068 if (randSvc()->queryInterface(IID_IRndmEngine,(void**)&engine).isFailure()) {
00069 warning() << "Could not get IRndmEngine interace from random service, "
00070 "no state saved!" << endreq;
00071 }
00072 else {
00073 engine->rndmState(m_state);
00074 debug () << "Storing random state: [";
00075 for (size_t ind=0; ind<m_state.size(); ++ind) {
00076 debug () << " " << m_state[ind];
00077 }
00078 debug () << " ]" << endreq;
00079 }
00080
00081 return StatusCode::SUCCESS;
00082 }
00083
00084 StatusCode DybBaseAlg::postExecute()
00085 {
00086
00087 if (m_headerObject) {
00088 m_headerObject->setRandomState(m_state);
00089 const std::vector<const DayaBay::IHeader*> iheaders(m_inputHeaders.begin(),m_inputHeaders.end());
00090 m_headerObject->setInputHeaders(iheaders);
00091
00092
00093
00094
00095
00096
00097 if (!m_pullMode) {
00098 put(m_headerObject,m_location);
00099 }
00100 }
00101
00102
00103 debug() <<"Clearing " << m_inputHeaders.size() << " cached input headers" << endreq;
00104 m_inputHeaders.clear();
00105 ++m_execNum;
00106 m_headerObject = 0;
00107
00108 return StatusCode::SUCCESS;
00109 }
00110
00111 StatusCode DybBaseAlg::sysFinalize()
00112 {
00113 if (this->finalize().isFailure()) {
00114 return StatusCode::FAILURE;
00115 }
00116 return this->GaudiAlgorithm::finalize();
00117 }
00118
00119
00120 void DybBaseAlg::InitializeHeader(DayaBay::HeaderObject* header)
00121 {
00122
00123
00124
00125 header->setExecNumber(m_execNum);
00126
00127
00128 if(!m_jobInfoSvc){
00129
00130 m_jobInfoSvc = svc<IJobInfoSvc>("JobInfoSvc",true);
00131 }
00132 if(m_jobInfoSvc){
00133 header->setJobId(m_jobInfoSvc->currentJobInfo()->jobId());
00134 }else{
00135 warning() << "MakeHeaderObject, failed to get current job ID" << endreq;
00136 }
00137
00138 header->setEarliest(TimeStamp::GetBOT());
00139 header->setLatest(TimeStamp::GetBOT());
00140 }
00141
00142 void DybBaseAlg::AppendInputHeader(const DayaBay::HeaderObject* header) const
00143 {
00144 m_inputHeaders.push_back(header);
00145 }
00146
00147
00148 IDataProviderSvc* DybBaseAlg::arcSvc() const
00149 {
00150 return 0;
00151 }
00152
00153 void DybBaseAlg::putTES(DataObject* obj, std::string location) const
00154 {
00155
00156
00157 std::string::size_type ind = location.find("/");
00158 while (true) {
00159 ind = location.find("/",ind+1);
00160 if (ind == std::string::npos) {
00161 debug() << "Putting final: " << location << endreq;
00162 put(obj,location);
00163 break;
00164 }
00165 else {
00166
00167 debug() << "Making intermediate: " << location.substr(0,ind)
00168 << endreq;
00169 getOrCreate<DataObject,DataObject>(location.substr(0,ind));
00170 }
00171 }
00172 }
00173
00174
00175 std::vector<DataObject*> DybBaseAlg::getAEScollection(std::string location) const
00176 {
00177 DybArchiveList* lst = get<DybArchiveList>(arcSvc(),location);
00178 if (!lst) return std::vector<DataObject*>();
00179 return std::vector<DataObject*>(lst->begin(),lst->end());
00180 }