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

In This Package:

RunDataWriterAlg.cc

Go to the documentation of this file.
00001 #include "RunDataWriterAlg.h"
00002 
00003 #include "Event/RunHeader.h"
00004 #include "Event/RunData.h"
00005 #include "DybKernel/IDybStorageSvc.h"
00006 #include "DataSvc/IRunDataSvc.h"
00007 #include "GaudiKernel/RegistryEntry.h"
00008 
00009 RunDataWriterAlg::RunDataWriterAlg(const std::string& name, 
00010                                    ISvcLocator* pSvcLocator)
00011   : GaudiAlgorithm(name,pSvcLocator),
00012     m_storageSvc(0),
00013     m_runDataSvc(0)
00014 {
00015   declareProperty("RunDataLocation",
00016                   m_runDataLocation=DayaBay::RunHeaderLocation::Default,
00017                   "Location in file where Run Data is to be found.");
00018   declareProperty("WriteToFile",m_writeToFile=false,
00019                   "Write the run data to the current output file?");
00020   declareProperty("WriteToDatabase",m_writeToDatabase=false,
00021                   "Write the run data to the offline database?");
00022 }
00023 
00024 RunDataWriterAlg::~RunDataWriterAlg()
00025 {
00026 }
00027 
00028 StatusCode RunDataWriterAlg::initialize()
00029 {
00030   // Initialize the necessary services
00031   if( m_writeToFile ){
00032     StatusCode sc = this->service("DybStorageSvc",m_storageSvc,true);
00033     if(sc.isFailure()){
00034       error() << "Failed to get DybStorageSvc" << endreq;
00035       return sc;
00036     }
00037   }
00038   StatusCode sc = this->service("RunDataSvc",m_runDataSvc,true);
00039   if(sc.isFailure()){
00040     error() << "Failed to get RunDataSvc" << endreq;
00041     return sc;
00042   }
00043   return StatusCode::SUCCESS;
00044 }
00045 
00046 StatusCode RunDataWriterAlg::execute()
00047 {
00048   return StatusCode::SUCCESS;
00049 }
00050 
00051 StatusCode RunDataWriterAlg::finalize()
00052 {
00053   if( m_writeToFile ) m_storageSvc->release();
00054   m_runDataSvc->release();
00055   return StatusCode::SUCCESS;
00056 }
00057 
00058 
00059 StatusCode RunDataWriterAlg::endRun()
00060 {
00061   // Write the run data to file/database at the end of the run
00062   StatusCode sc = StatusCode::SUCCESS;
00063   if( m_writeToFile ) sc = this->writeDataToFile();
00064   if( !sc.isSuccess() ) return sc;
00065   if( m_writeToDatabase ) sc = this->writeDataToDatabase();
00066   return sc;
00067 }
00068 
00069 StatusCode RunDataWriterAlg::writeDataToFile(){
00070   // Write Run Data to current output file
00071 
00072   debug() << "Writing RunData" << endreq;
00073   // Create Run Header
00074   DayaBay::RunHeader runHeader;
00075   runHeader.setRunDataList( m_runDataSvc->cachedRunData() );
00076   // Have to put RunHeader in a registry for DybStorageSvc to work correctly
00077   DataSvcHelpers::RegistryEntry* regEntry 
00078     = new DataSvcHelpers::RegistryEntry(m_runDataLocation);
00079   regEntry->setObject(&runHeader);
00080   debug() << "Storing RunHeader" << endreq;
00081   StatusCode sc = m_storageSvc->store(&runHeader, m_runDataLocation);
00082   debug() << "Stored RunHeader" << endreq;
00083   if(sc.isFailure()){
00084     error() << "Failed to store Run Header to output file" << endreq;
00085   }
00086   // Clear run data to prevent deleting
00087   debug() << "Clearing RunData in RunHeader" << endreq;
00088   std::vector<DayaBay::RunData*> emptyList;
00089   runHeader.setRunDataList( emptyList );
00090   debug() << "Cleared RunData in RunHeader" << endreq;
00091   return sc;
00092 }
00093 
00094 StatusCode RunDataWriterAlg::writeDataToDatabase(){
00095   // Write Run Data to offline database
00096   warning() << "Writing Run Data to offline database is not yet implemented."
00097             << endreq;
00098   return StatusCode::SUCCESS;
00099 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:22:43 2011 for RunDataSvc by doxygen 1.4.7