/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

DybBaseAlg.cc
Go to the documentation of this file.
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     // Call parent
00032     StatusCode sc = this->GaudiAlgorithm::initialize();
00033     if (sc.isFailure()) return sc;
00034 
00035     // This insinuates on GaudiAlgorithm's operation in order to do
00036     // any "dybish" initialization:
00037     // do_dybstuff_init();
00038 
00039     // Trigger calling subclass, back to your regularly scheduled operations
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   // Trigger subclass's execute();                                                                             
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     // Get random state
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     // Set some base HeaderObject values
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         // Add to TES.  This must be done after algorithm has chance to
00094         // fill earliest/latest with non-default values as this put()
00095         // triggers an insert() into the RegistrationSequence.
00096         
00097         if (!m_pullMode) {
00098             put(m_headerObject,m_location);
00099         }
00100     }
00101 
00102     // Prepare alg for next execution cycle
00103     debug() <<"Clearing " << m_inputHeaders.size() << " cached input headers" << endreq;
00104     m_inputHeaders.clear();
00105     ++m_execNum;
00106     m_headerObject = 0;               // owned by TES
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   // Set some standard parameters for this header
00123 
00124   // Set execution number
00125   header->setExecNumber(m_execNum);    
00126   
00127   // Document the ID of the job which made this header
00128   if(!m_jobInfoSvc){
00129     // Get the job information service
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   // Set the header time range
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;                   // fixme
00151 }
00152 
00153 void DybBaseAlg::putTES(DataObject* obj, std::string location) const
00154 {
00155     // Look for pre-existing header object or make new one, creating
00156     // the supporting path as we go.
00157     std::string::size_type ind = location.find("/"); // skip initial "/".
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             // make the supporting path from simple DataObjects
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 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:09:44 for DybAlg by doxygen 1.7.4