00001
00002
00003
00004
00005
00006 #ifndef McCnv_CXX
00007 #define McCnv_CXX
00008
00009 #include "GaudiKernel/MsgStream.h"
00010 #include "GaudiKernel/DataObject.h"
00011 #include "GaudiKernel/SmartDataPtr.h"
00012 #include "GaudiKernel/RegistryEntry.h"
00013 #include "GaudiKernel/IOpaqueAddress.h"
00014
00015 #include "EventModel/EventHeader.h"
00016 #include "McTruth/McEvent.h"
00017 #include "EventModel/EventModel.h"
00018 #include "RootCnvSvc/Mc/McCnv.h"
00019 #include "RootCnvSvc/RootEvtSelector.h"
00020 #include "RootCnvSvc/RootAddress.h"
00021 #include "RootCnvSvc/Util.h"
00022
00023 using namespace DataSvcHelpers;
00024
00025 TMcEvent* McCnv::m_objWrite = 0;
00026
00027 McCnv::McCnv(ISvcLocator* svc)
00028 : RootEventBaseCnv(classID(), svc)
00029 {
00030
00031
00032
00033
00034 }
00035
00036 StatusCode McCnv::initialize() {
00037 MsgStream log(msgSvc(), "McCnv");
00038 log << MSG::DEBUG << "McCnv::initialize"<< endreq;
00039
00040 StatusCode status = RootEventBaseCnv::initialize();
00041
00042
00043 m_cnvSvc->setMcCnv(this);
00044
00045 return status;
00046
00047 }
00048
00049
00050 StatusCode McCnv::TObjectToDataObject(DataObject*& refpObject) {
00051
00052 StatusCode sc=StatusCode::SUCCESS;
00053
00054 MsgStream log(msgSvc(), "McCnv");
00055 log << MSG::DEBUG << "TObjectToDataObject" << endreq;
00056
00057 SmartDataPtr<Event::EventHeader> evt(m_eds, EventModel::EventHeader);
00058 if (!evt) {
00059 log << MSG::ERROR << "Failed to retrieve McEvent" << endreq;
00060 return StatusCode::FAILURE;
00061 }
00062
00063 McEvent * tdsev = new McEvent();
00064 refpObject = tdsev;
00065
00066 return sc;
00067 }
00068
00069 StatusCode McCnv::DataObjectToTObject(DataObject* obj, RootAddress* rootaddr) {
00070
00071 MsgStream log(msgSvc(), "McCnv");
00072 log << MSG::DEBUG << "McCnv::DataObjectToTObject" << endreq;
00073
00074
00075
00076 if (m_common.m_mcEvt != NULL) return StatusCode::SUCCESS;
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 McEvent * devtTds=dynamic_cast<McEvent *> (obj);
00087 if (!devtTds) {
00088 log << MSG::ERROR << "Could not downcast to TDS McEvent" << endreq;
00089 return StatusCode::FAILURE;
00090 }
00091
00092 m_objWrite = new TMcEvent();
00093 m_common.m_mcEvt = m_objWrite;
00094
00095
00096 if (m_branchNrMc<0) {
00097
00098 StatusCode sc = m_rootInterface->createBranch(rootaddr->getTreename(),"TMcEvent",m_objWrite->ClassName(),&m_objWrite,m_branchNrMc);
00099 if (sc.isFailure()) {
00100 log << MSG::ERROR << "Could not create branch TMcEvent" << endreq;
00101 return sc;
00102 }
00103 }
00104
00105
00106
00107
00108
00109 #ifdef DEBUG
00110 std::cout<<"******************************"<<std::endl;
00111 std::cout<<" eveId: "<<evtId<<std::endl;
00112 std::cout<<" runId: "<<runId<<std::endl;
00113 std::cout<<"******************************"<<std::endl;
00114 #endif
00115 m_objWrite->initialize();
00116
00117 return StatusCode::SUCCESS;
00118 }
00119 #endif
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129