CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
RootCnvSvc-04-01-15/src/EvtRec/EvtRecPrimaryVertexCnv.cxx
Go to the documentation of this file.
1#include "GaudiKernel/MsgStream.h"
2
3#include "EventModel/EventModel.h"
4#include "EvtRecEvent/EvtRecObject.h"
5#include "EvtRecEvent/EvtRecPrimaryVertex.h"
6
7#include "RootEventData/TEvtRecObject.h"
8#include "RootEventData/TEvtRecPrimaryVertex.h"
9
10#include "RootCnvSvc/RootAddress.h"
11#include "RootCnvSvc/EvtRec/EvtRecCnv.h"
12#include "RootCnvSvc/EvtRec/EvtRecPrimaryVertexCnv.h"
13
14#include "CLHEP/Matrix/Vector.h"
15#include "CLHEP/Matrix/SymMatrix.h"
16using CLHEP::HepVector;
17using CLHEP::HepSymMatrix;
18
20 : RootEventBaseCnv(classID(), svc)
21{
22 m_rootBranchname = "m_evtRecPrimaryVertex";
23 m_adresses.push_back(&m_evtRecPrimaryVertex);
24 m_evtRecPrimaryVertex = 0;
25}
26
27StatusCode EvtRecPrimaryVertexCnv::TObjectToDataObject(DataObject*& refpObject) {
28 MsgStream log(msgSvc(), "EvtRecPrimaryVertexCnv");
29 log << MSG::DEBUG << "EvtRecPrimaryVertexCnv::TObjectToDataObject" << endreq;
30
31 // create the TDS location for the EvtRecPrimaryVertex
32 EvtRecPrimaryVertex* evtRecPrimaryVertex = new EvtRecPrimaryVertex;
33 refpObject = evtRecPrimaryVertex;
34
35 if ( ! m_evtRecPrimaryVertex ) return StatusCode::SUCCESS;
36 // convert
37 evtRecPrimaryVertex->setIsValid (m_evtRecPrimaryVertex->isValid() );
38 evtRecPrimaryVertex->setNTracks (m_evtRecPrimaryVertex->nTracks() );
39 evtRecPrimaryVertex->setTrackIdList (m_evtRecPrimaryVertex->trackIdList() );
40 evtRecPrimaryVertex->setChi2 (m_evtRecPrimaryVertex->chi2() );
41 evtRecPrimaryVertex->setNdof (m_evtRecPrimaryVertex->ndof() );
42 evtRecPrimaryVertex->setFitMethod (m_evtRecPrimaryVertex->fitMethod() );
43
44 HepVector vtx(3, 0);
45 for (Int_t i = 0; i < 3; i++) {
46 vtx[i] = m_evtRecPrimaryVertex->vertex(i);
47 }
48
49 HepSymMatrix Evtx(3, 0);
50 Evtx[0][0] = m_evtRecPrimaryVertex->errorVertex(0);
51 Evtx[0][1] = Evtx[1][0] = m_evtRecPrimaryVertex->errorVertex(1);
52 Evtx[0][2] = Evtx[2][0] = m_evtRecPrimaryVertex->errorVertex(2);
53 Evtx[1][1] = m_evtRecPrimaryVertex->errorVertex(3);
54 Evtx[1][2] = Evtx[2][1] = m_evtRecPrimaryVertex->errorVertex(4);
55 Evtx[2][2] = m_evtRecPrimaryVertex->errorVertex(5);
56
57 evtRecPrimaryVertex->setVertex (vtx);
58 evtRecPrimaryVertex->setErrorVertex (Evtx);
59
60 delete m_evtRecPrimaryVertex;
61 m_evtRecPrimaryVertex = 0;
62 return StatusCode::SUCCESS;
63}
64
65StatusCode EvtRecPrimaryVertexCnv::DataObjectToTObject(DataObject* obj, RootAddress* rootaddr) {
66
67 MsgStream log(msgSvc(), "EvtRecPrimaryVertexCnv");
68 log << MSG::DEBUG << "EvtRecPrimaryVertexCnv::DataObjectToTObject" << endreq;
69
70 EvtRecPrimaryVertex* evtRecPrimaryVertex = dynamic_cast<EvtRecPrimaryVertex*> (obj);
71 if ( ! evtRecPrimaryVertex ) {
72 log << MSG::ERROR << "Could not downcast to EvtRecPrimaryVertex" << endreq;
73 return StatusCode::FAILURE;
74 }
75
76 DataObject* evt = NULL;
77 StatusCode sc = m_eds->findObject(EventModel::EvtRec::Event, evt);
78 if ( sc.isFailure() ) {
79 log << MSG::ERROR << "Could not get EvtRecObject in TDS" << endreq;
80 return StatusCode::FAILURE;
81 }
82
83 EvtRecObject* devtTds = dynamic_cast<EvtRecObject*> (evt);
84 if ( ! devtTds ) {
85 log << MSG::ERROR << "EvtRecPrimaryVertexCnv: Could not downcast to TDS EvtRecObject" << endreq;
86 }
87
88 IOpaqueAddress* addr;
89 m_cnvSvc->getEvtRecCnv()->createRep(evt, addr);
91
92 //recEvt->clearEvtRecPrimaryVertex();
93
94 TEvtRecPrimaryVertex* m_evtRecPrimaryVertex = const_cast<TEvtRecPrimaryVertex*>( recEvt->getEvtRecPrimaryVertex() );
95
96 m_evtRecPrimaryVertex->setIsValid (evtRecPrimaryVertex->isValid() );
97 m_evtRecPrimaryVertex->setNTracks (evtRecPrimaryVertex->nTracks() );
98 m_evtRecPrimaryVertex->setTrackIdList (evtRecPrimaryVertex->trackIdList() );
99 m_evtRecPrimaryVertex->setChi2 (evtRecPrimaryVertex->chi2() );
100 m_evtRecPrimaryVertex->setNdof (evtRecPrimaryVertex->ndof() );
101 m_evtRecPrimaryVertex->setFitMethod (evtRecPrimaryVertex->fitMethod() );
102
103 Double_t vtx[3];
104 for (Int_t i = 0; i < 3; i++) {
105 vtx[i] = evtRecPrimaryVertex->vertex()[i];
106 }
107 Double_t Evtx[6];
108 Evtx[0] = evtRecPrimaryVertex->errorVertex()[0][0];
109 Evtx[1] = evtRecPrimaryVertex->errorVertex()[0][1];
110 Evtx[2] = evtRecPrimaryVertex->errorVertex()[0][2];
111 Evtx[3] = evtRecPrimaryVertex->errorVertex()[1][1];
112 Evtx[4] = evtRecPrimaryVertex->errorVertex()[1][2];
113 Evtx[5] = evtRecPrimaryVertex->errorVertex()[2][2];
114 m_evtRecPrimaryVertex->setVertex (vtx);
115 m_evtRecPrimaryVertex->setErrorVertex (Evtx);
116
117 return StatusCode::SUCCESS;
118}
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
Definition of a Root address, derived from IOpaqueAddress.
virtual StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress)
Convert the transient object to the requested representation.