| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

JobInfoWriterAlg.cc

Go to the documentation of this file.
00001 #include "JobInfoWriterAlg.h"
00002 
00003 #include "Event/JobHeader.h"
00004 #include "Event/JobInfo.h"
00005 #include "DybKernel/IDybStorageSvc.h"
00006 #include "DataSvc/IJobInfoSvc.h"
00007 #include "RootIOSvc/RootIOIncident.h"
00008 
00009 #include "GaudiKernel/IIncidentSvc.h"
00010 #include "GaudiKernel/RegistryEntry.h"
00011 
00012 JobInfoWriterAlg::JobInfoWriterAlg(const std::string& name, 
00013                                    ISvcLocator* pSvcLocator)
00014   : GaudiAlgorithm(name,pSvcLocator),
00015     m_storageSvc(0),
00016     m_jobInfoSvc(0)
00017 {
00018   declareProperty("JobInfoLocation",
00019                   m_jobInfoLocation=DayaBay::JobHeaderLocation::Default,
00020                   "Location in file where job info is to be found.");
00021   declareProperty("WriteToFile",m_writeToFile=false,
00022                   "Write the job info to the current output file?");
00023   declareProperty("WriteToDatabase",m_writeToDatabase=false,
00024                   "Write the job info to the offline database?");
00025 }
00026 
00027 JobInfoWriterAlg::~JobInfoWriterAlg()
00028 {
00029 }
00030 
00031 StatusCode JobInfoWriterAlg::initialize()
00032 {
00033   // Initialize the necessary services
00034   if( m_writeToFile ){
00035     StatusCode sc = this->service("DybStorageSvc",m_storageSvc,true);
00036     if(sc.isFailure()){
00037       error() << "Failed to get DybStorageSvc" << endreq;
00038       return sc;
00039     }
00040   }
00041   StatusCode sc = this->service("JobInfoSvc",m_jobInfoSvc,true);
00042   if(sc.isFailure()){
00043     error() << "Failed to get JobInfoSvc" << endreq;
00044     return sc;
00045   }
00046 
00047   // Get and hold on to the incident service and add ourself.
00048   sc = this->service("IncidentSvc",m_incsvc,true);
00049   if (sc.isFailure()) {
00050       error() << "Failed to get IncidentSvc" << endreq;
00051       return sc;
00052   }
00053   m_incsvc->addListener(this,"RootIOIncident");
00054 
00055   return StatusCode::SUCCESS;
00056 }
00057 
00058 StatusCode JobInfoWriterAlg::execute()
00059 {
00060   return StatusCode::SUCCESS;
00061 }
00062 
00063 StatusCode JobInfoWriterAlg::finalize()
00064 {
00065   m_jobInfoSvc->release();
00066 
00067   // Must remove self.  O.w. we may finalize before RootIOSvc and
00068   // leave beind a dangling handler.
00069   m_incsvc->removeListener(this,"RootIOIncident");
00070   m_incsvc->release();
00071 
00072   return StatusCode::SUCCESS;
00073 }
00074 
00075 
00076 StatusCode JobInfoWriterAlg::endRun()
00077 {
00078   // Write the job info to file/database at the end of the run
00079   StatusCode sc = StatusCode::SUCCESS;
00080   if( m_writeToFile ) sc = this->writeDataToFile();
00081   if( !sc.isSuccess() ) return sc;
00082   if( m_writeToDatabase ) sc = this->writeDataToDatabase();
00083   return sc;
00084 }
00085 
00086 StatusCode JobInfoWriterAlg::writeDataToFile(){
00087   // Write job info to current output file
00088 
00089   debug() << "Writing JobInfo" << endreq;
00090 
00091   std::vector<DayaBay::JobInfo*> jobInfo = m_jobInfoSvc->cachedJobInfo();
00092 
00093   // Create Job Header
00094   DayaBay::JobHeader jobHeader;
00095   jobHeader.setJobInfoList( jobInfo );
00096 
00097   // Have to put JobHeader in a registry for DybStorageSvc to work correctly
00098   DataSvcHelpers::RegistryEntry* regEntry 
00099     = new DataSvcHelpers::RegistryEntry(m_jobInfoLocation);
00100   regEntry->setObject(&jobHeader);
00101 
00102   debug() << "Storing JobHeader with "
00103           << jobInfo.size() << " entries at " 
00104           << m_jobInfoLocation << endreq;
00105   StatusCode sc = m_storageSvc->store(&jobHeader, m_jobInfoLocation);
00106   debug() << "Stored JobHeader" << endreq;
00107   if(sc.isFailure()){
00108     error() << "Failed to store Job Header to output file" << endreq;
00109   }
00110 
00111   // Clear job info to prevent deleting
00112   jobInfo.clear();
00113   jobHeader.setJobInfoList( jobInfo );
00114 
00115   return sc;
00116 }
00117 
00118 StatusCode JobInfoWriterAlg::writeDataToDatabase(){
00119   // Write Job Info to offline database
00120   warning() << "Writing job info to offline database is not yet implemented."
00121             << endreq;
00122   return StatusCode::SUCCESS;
00123 }
00124 
00125 void JobInfoWriterAlg::handle(const Incident& incident)
00126 {
00127     if (!m_writeToFile) return;
00128 
00129     // Handle the incident in a trivial manner
00130 
00131     const RootIOIncident* rioinc = dynamic_cast<const RootIOIncident*>(&incident);
00132     if (!rioinc) {
00133         warning() 
00134             << "Ignoring unexpected incident not of class RootIOIncident" 
00135             << endreq;
00136         return;
00137     }
00138     
00139     if (rioinc->state() != RootIOIncident::opened_output) {
00140         return;
00141     }
00142 
00143     StatusCode sc = this->writeDataToFile();
00144     if (sc.isFailure()) {
00145         error()
00146             << "Failed to write JobInfo to output file "
00147             << "while handling opened output incidence"
00148             << endreq;
00149     }
00150     debug() << "Handled closing_output for " << rioinc->filename() << endreq;
00151 }
00152 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:21:30 2011 for JobInfoSvc by doxygen 1.4.7