BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
McCnv.cxx
Go to the documentation of this file.
1// File and Version Information:
2// Description:
3// McCnv is the concrete converter for the Mc branch
4//
5
6#ifndef McCnv_CXX
7#define McCnv_CXX
8
9#include "GaudiKernel/DataObject.h"
10#include "GaudiKernel/IOpaqueAddress.h"
11#include "GaudiKernel/MsgStream.h"
12#include "GaudiKernel/RegistryEntry.h"
13#include "GaudiKernel/SmartDataPtr.h"
14
15#include "EventModel/EventHeader.h"
16#include "EventModel/EventModel.h"
17#include "McTruth/McEvent.h"
18#include "RootCnvSvc/Mc/McCnv.h"
19#include "RootCnvSvc/RootAddress.h"
20#include "RootCnvSvc/RootEvtSelector.h"
21// #include "RootCnvSvc/Util.h"
22
23using namespace DataSvcHelpers;
24
25TMcEvent* McCnv::m_objWrite = 0;
26
27McCnv::McCnv( ISvcLocator* svc ) : RootEventBaseCnv( classID(), svc ) {
28 // Here we associate this converter with the path on the TDS.
29 // declareObject(EventModel::MC::Event, objType(), m_rootTreename, m_rootBranchname);
30
31 // m_objWrite=0;
32}
33
34StatusCode McCnv::initialize() {
35 MsgStream log( msgSvc(), "McCnv" );
36 log << MSG::DEBUG << "McCnv::initialize" << endmsg;
37
38 StatusCode status = RootEventBaseCnv::initialize();
39
40 // pass dst converter to the conversion service
41 m_cnvSvc->setMcCnv( this );
42
43 return status;
44}
45
46StatusCode McCnv::TObjectToDataObject( DataObject*& refpObject ) {
47 // fills the TDS object from the persistent one
48 StatusCode sc = StatusCode::SUCCESS;
49
50 MsgStream log( msgSvc(), "McCnv" );
51 log << MSG::DEBUG << "TObjectToDataObject" << endmsg;
52
53 SmartDataPtr<Event::EventHeader> evt( m_eds, EventModel::EventHeader );
54 if ( !evt )
55 {
56 log << MSG::ERROR << "Failed to retrieve McEvent" << endmsg;
57 return StatusCode::FAILURE;
58 }
59
60 McEvent* tdsev = new McEvent();
61 refpObject = tdsev;
62
63 return sc;
64}
65
66StatusCode McCnv::DataObjectToTObject( DataObject* obj, RootAddress* rootaddr ) {
67 // transforms TDS event to Mc event in root format
68 MsgStream log( msgSvc(), "McCnv" );
69 log << MSG::DEBUG << "McCnv::DataObjectToTObject" << endmsg;
70
71 // test if already done for this event
72 // zoujh: if (m_objWrite && (m_objWrite->getRunId()!=0 || m_objWrite->getEventId()!=0))
73 // return StatusCode::SUCCESS;
74 if ( m_common.m_mcEvt != NULL ) return StatusCode::SUCCESS;
75
76 /*
77 SmartDataPtr<Event::EventHeader> evtTds(m_eds, EventModel::EventHeader);
78
79 if (!evtTds) {
80 log << MSG::ERROR << "Failed to retrieve EventHeader in TDS" << endmsg;
81 return StatusCode::FAILURE;
82 }
83 */
84 McEvent* devtTds = dynamic_cast<McEvent*>( obj );
85 if ( !devtTds )
86 {
87 log << MSG::ERROR << "Could not downcast to TDS McEvent" << endmsg;
88 return StatusCode::FAILURE;
89 }
90
91 m_objWrite = new TMcEvent(); // zoujh
92 m_common.m_mcEvt = m_objWrite; // zoujh
93
94 // create branch if not yet done
95 if ( m_branchNrMc < 0 )
96 {
97 // zoujh: m_objWrite = new TMcEvent();
98 StatusCode sc =
99 m_rootInterface->createBranch( rootaddr->getTreename(), "TMcEvent",
100 m_objWrite->ClassName(), &m_objWrite, m_branchNrMc );
101 if ( sc.isFailure() )
102 {
103 log << MSG::ERROR << "Could not create branch TMcEvent" << endmsg;
104 return sc;
105 }
106 }
107
108 // Int_t evtId = evtTds->eventNumber();
109 // Int_t runId = evtTds->runNumber();
110
111#ifdef DEBUG
112 std::cout << "******************************" << std::endl;
113 std::cout << " eveId: " << evtId << std::endl;
114 std::cout << " runId: " << runId << std::endl;
115 std::cout << "******************************" << std::endl;
116#endif
117 m_objWrite->initialize();
118
119 return StatusCode::SUCCESS;
120}
121#endif
IMessageSvc * msgSvc()
McCnv(ISvcLocator *svc)
Definition McCnv.cxx:27
virtual StatusCode TObjectToDataObject(DataObject *&refpObject)
do the transformation from ROOT to TDS object
Definition McCnv.cxx:46
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation from TDS object to ROOT
Definition McCnv.cxx:66
virtual StatusCode initialize()
Definition McCnv.cxx:34
Definition of a Root address, derived from IOpaqueAddress.
IDataProviderSvc * m_eds
pointer to eventdataservice
virtual StatusCode initialize()
RootInterface * m_rootInterface
pointer to the RootInterface
RootEventBaseCnv(const CLID &clid, ISvcLocator *svc)