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