BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
RawDataOutputSvc.cxx
Go to the documentation of this file.
1//===================================================================
2// Implementation of RawDataOutputSvc
3// Revision: July 11, 2002
4// Modified for RawFileReader
5//
6//===================================================================
7//
8
9// Include files.
10#include "GaudiKernel/Bootstrap.h"
11#include "GaudiKernel/ISvcLocator.h"
12#include "GaudiKernel/MsgStream.h"
13#include "GaudiKernel/PropertyMgr.h"
14
15#include "RawDataOutputSvc.h"
16
18// Constructor.
19RawDataOutputSvc::RawDataOutputSvc( const std::string& name, ISvcLocator* svcloc )
20 : base_class( name, svcloc ), m_fw( 0 ) {
21
22 declareProperty( "OutputFile", m_outputFile = "offline.raw" );
23
24 m_buffer = new uint32_t[64 * 1024]; // 256k bytes
25}
26
27// Destructor.
29 MsgStream log( msgSvc(), name() );
30 log << MSG::DEBUG << "RawDataOutputSvc Destructor called " << endmsg;
31
32 delete[] m_buffer;
33}
34
36 // clean up
37 if ( m_fw )
38 {
39 delete m_fw;
40 m_fw = nullptr;
41 }
42
43 return StatusCode::SUCCESS;
44}
45
46// Open the first input file and read the first event.
48
49 auto sc = Service::initialize();
50 if ( sc.isFailure() )
51 {
52 error() << "Failed to initialize Service" << endmsg;
53 return sc;
54 }
55 // Open the first output file for writing.
56 m_fw = new RawFileWriter( m_outputFile );
57
58 debug() << "Opened output File " << m_outputFile << endmsg;
59
60 return StatusCode::SUCCESS;
61}
62
63// Write the next event.
65 MsgStream log( msgSvc(), name() );
66
67 // uint32_t evt_size_w = re->size_word();
68
69 const eformat::write::node_t* top = re->bind();
70 if ( eformat::write::copy( *top, m_buffer, 64 * 1024 ) == 0 )
71 {
72 log << MSG::ERROR << "failed to copy Event to the buffer !" << endmsg;
73 return false;
74 }
75
76 try
77 {
78 RawEvent evt( m_buffer );
79 evt.check_tree();
80 } catch ( std::exception& ex )
81 {
82 std::cerr << "Uncaught std exception: " << ex.what() << std::endl;
83 std::exit( 1 );
84 } catch ( ... )
85 {
86 std::cerr << std::endl << "Uncaught unknown exception" << std::endl;
87 std::exit( 1 );
88 }
89
90 m_fw->writeEvent( m_buffer );
91
92 return true;
93}
DECLARE_COMPONENT(BesBdkRc)
eformat::FullEventFragment< const uint32_t * > RawEvent
eformat::write::FullEventFragment WriteRawEvent
IMessageSvc * msgSvc()
RawDataOutputSvc(const std::string &name, ISvcLocator *svcloc)
StatusCode initialize()
bool putEvent(WriteRawEvent *re)
const eformat::write::node_t * bind(void)
uint32_t copy(const node_t &list, uint32_t *dest, size_t max)
Definition node.cxx:60