00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "GaudiKernel/MsgStream.h"
00011 #include "GaudiKernel/Bootstrap.h"
00012 #include "GaudiKernel/PropertyMgr.h"
00013 #include "GaudiKernel/ISvcLocator.h"
00014 #include "GaudiKernel/IJobOptionsSvc.h"
00015 #include "RawDataCnv/RawDataOutputSvc.h"
00016
00017
00018 RawDataOutputSvc::RawDataOutputSvc(const std::string& name, ISvcLocator* svcloc)
00019 : IRawDataOutputSvc(name,svcloc),
00020 m_fw(0)
00021 {
00022 PropertyMgr m_propMgr;
00023 m_propMgr.declareProperty("OutputFile", m_outputFile = "offline.raw");
00024
00025 IJobOptionsSvc* jobSvc;
00026 Gaudi::svcLocator()->service("JobOptionsSvc", jobSvc);
00027 jobSvc->setMyProperties(name, &m_propMgr);
00028
00029 m_buffer = new uint32_t[64*1024];
00030 }
00031
00032
00033 RawDataOutputSvc::~RawDataOutputSvc()
00034 {
00035 MsgStream log(messageService(), name() );
00036 log << MSG::DEBUG << "RawDataOutputSvc Destructor called " << endreq;
00037
00038 delete [] m_buffer;
00039 }
00040
00041
00042 StatusCode RawDataOutputSvc::finalize()
00043 {
00044
00045 if ( m_fw ) {
00046 delete m_fw;
00047 m_fw = 0;
00048 }
00049
00050 return StatusCode::SUCCESS;
00051 }
00052
00053
00054 StatusCode RawDataOutputSvc::initialize()
00055 {
00056 MsgStream log(messageService(), name() );
00057
00058
00059 m_fw = new RawFileWriter(m_outputFile);
00060
00061 log << MSG::DEBUG << "Opened output File " << m_outputFile << endreq;
00062
00063 return StatusCode::SUCCESS;
00064 }
00065
00066
00067 bool RawDataOutputSvc::putEvent(WriteRawEvent* re)
00068 {
00069 MsgStream log(messageService(), name() );
00070
00071
00072
00073 const eformat::write::node_t* top = re->bind();
00074 if (eformat::write::copy(*top, m_buffer, 64*1024) == 0) {
00075 log << MSG::ERROR << "failed to copy Event to the buffer !" << endreq;
00076 return false;
00077 }
00078
00079 try {
00080 RawEvent evt(m_buffer);
00081 evt.check_tree();
00082 }
00083 catch (std::exception& ex) {
00084 std::cerr << "Uncaught std exception: " << ex.what() << std::endl;
00085 std::exit(1);
00086 }
00087 catch (...) {
00088 std::cerr << std::endl << "Uncaught unknown exception" << std::endl;
00089 std::exit(1);
00090 }
00091
00092 m_fw->writeEvent(m_buffer);
00093
00094 return true;
00095 }