BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
TofMcHitCnv.cxx
Go to the documentation of this file.
1#ifndef TofMcHitCnv_CXX
2#define TofMcHitCnv_CXX 1
3
4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/DataObject.h"
6#include "GaudiKernel/ObjectVector.h"
7
8#include "TClonesArray.h"
9
10#include "EventModel/EventModel.h"
11#include "McTruth/McEvent.h" //TDS object
12#include "McTruth/TofMcHit.h" //TDS object
13#include "RootEventData/TTofMc.h" // standard root object
14#include "RootEventData/TMcEvent.h"
15#include "RootCnvSvc/Mc/McCnv.h"
16#include "RootCnvSvc/Mc/TofMcHitCnv.h"
17#include "RootCnvSvc/RootAddress.h"
18
19
20// Instantiation of a static factory class used by clients to create
21// instances of this service
22//static CnvFactory<TofMcHitCnv> s_factory;
23//const ICnvFactory& TofMcHitCnvFactory = s_factory;
24
25TofMcHitCnv::TofMcHitCnv(ISvcLocator* svc)
26: RootEventBaseCnv(classID(), svc)
27{
28 // Here we associate this converter with the /Event path on the TDS.
29 MsgStream log(msgSvc(), "TofMcHitCnv");
30 //log << MSG::DEBUG << "Constructor called for " << objType() << endreq;
31 m_rootBranchname ="m_tofMcHitCol";
32 //declareObject(EventModel::MC::TofMcHitCol, objType(), m_rootTreename, m_rootBranchname);
33 m_adresses.push_back(&m_tofMcHitCol);
34 m_tofMcHitCol=0;
35}
36
37StatusCode TofMcHitCnv::TObjectToDataObject(DataObject*& refpObject) {
38 // creation of TDS object from root object
39
40 MsgStream log(msgSvc(), "TofMcHitCnv");
41 log << MSG::DEBUG << "TofMcHitCnv::TObjectToDataObject" << endreq;
42 StatusCode sc=StatusCode::SUCCESS;
43
44 // create the TDS location for the MdcMc Collection
45 TofMcHitCol* tofMcTdsCol = new TofMcHitCol;
46 refpObject=tofMcTdsCol;
47
48
49 // now convert
50 if (!m_tofMcHitCol) return sc;
51 TIter tofMcIter(m_tofMcHitCol);
52 TTofMc *tofMcRoot = 0;
53 while ((tofMcRoot = (TTofMc*)tofMcIter.Next())) {
54 unsigned int id = tofMcRoot ->getId();
55 unsigned int trackIndex = tofMcRoot ->getTrackIndex();
56 double xPosition = tofMcRoot ->getPositionX() ;
57 double yPosition = tofMcRoot ->getPositionY() ;
58 double zPosition = tofMcRoot ->getPositionZ() ;
59 double px= tofMcRoot ->getPx() ;
60 double py = tofMcRoot ->getPy() ;
61 double pz = tofMcRoot ->getPz() ;
62 double trackLength = tofMcRoot->getTrackLength() ;
63 double flightTime = tofMcRoot->getFlightTime() ;
64
65
66 TofMcHit *tofMcTds = new TofMcHit;
67 m_common.m_rootTofMcHitMap[tofMcRoot] = tofMcTds;
68
69 tofMcTds->setIdentifier(id);
70 tofMcTds->setTrackIndex(trackIndex);
71 tofMcTds->setPositionX(xPosition);
72 tofMcTds->setPositionY(yPosition);
73 tofMcTds->setPositionZ(zPosition);
74 tofMcTds->setPx(px);
75 tofMcTds->setPy(py);
76 tofMcTds->setPz(pz);
77 tofMcTds->setTrackLength(trackLength);
78 tofMcTds->setFlightTime(flightTime);
79
80
81 tofMcTdsCol->push_back(tofMcTds);
82 }
83 //m_tofMcHitCol->Delete(); // wensp add 2005/12/30
84 delete m_tofMcHitCol;
85 m_tofMcHitCol = 0;
86 return StatusCode::SUCCESS;
87}
88
89StatusCode TofMcHitCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
90
91 MsgStream log(msgSvc(), "TofMcHitCnv");
92 log << MSG::DEBUG << "TofMcHitCnv::DataObjectToTObject" << endreq;
93 StatusCode sc=StatusCode::SUCCESS;
94
95 TofMcHitCol * tofMcHitCnvTds=dynamic_cast<TofMcHitCol *> (obj);
96 if (!tofMcHitCnvTds) {
97 log << MSG::ERROR << "Could not downcast to TofMcHitCol" << endreq;
98 return StatusCode::FAILURE;
99 }
100
101 DataObject *evt;
102 m_eds->findObject(EventModel::MC::Event,evt);
103 if (evt==NULL) {
104 log << MSG::ERROR << "Could not get McEvent in TDS " << endreq;
105 return StatusCode::FAILURE;
106 }
107 McEvent * devtTds=dynamic_cast<McEvent *> (evt);
108 if (!devtTds) {
109 log << MSG::ERROR << "TofMcHitCnv:Could not downcast to TDS McEvent" << endreq;
110 }
111 IOpaqueAddress *addr;
112
113 m_cnvSvc->getMcCnv()->createRep(evt,addr);
115
116 const TObjArray *m_tofMcHitCol = McEvt->getTofMcHitCol();
117 if (!m_tofMcHitCol) return sc;
118 McEvt->clearTofMcHitCol(); //necessary in case there is I/O at the same time since array is static
119 TofMcHitCol::const_iterator tofMcTds;
120
121 for (tofMcTds = tofMcHitCnvTds->begin(); tofMcTds != tofMcHitCnvTds->end(); tofMcTds++) {
122 UInt_t id = ((*tofMcTds)->identify()).get_value() ;
123 UInt_t trackIndex = (*tofMcTds) ->getTrackIndex();
124 Double_t xPosition = (*tofMcTds) ->getPositionX() ;
125 Double_t yPosition = (*tofMcTds) ->getPositionY() ;
126 Double_t zPosition = (*tofMcTds) ->getPositionZ() ;
127 Double_t px= (*tofMcTds) ->getPx() ;
128 Double_t py = (*tofMcTds) ->getPy() ;
129 Double_t pz = (*tofMcTds) ->getPz() ;
130 Double_t trackLength = (*tofMcTds) ->getTrackLength() ;
131 Double_t flightTime = (*tofMcTds) ->getFlightTime() ;
132
133 TTofMc *tofMcRoot = new TTofMc();
134 //m_common.m_tofMcHitMap[(*tofMcTds)] = tofMcRoot;
135
136 tofMcRoot->setId(id);
137 tofMcRoot->setTrackIndex(trackIndex);
138 tofMcRoot->setPositionX(xPosition);
139 tofMcRoot->setPositionY(yPosition);
140 tofMcRoot->setPositionZ(zPosition);
141 tofMcRoot->setPx(px);
142 tofMcRoot->setPy(py);
143 tofMcRoot->setPz(pz);
144 tofMcRoot->setTrackLength(trackLength);
145 tofMcRoot->setFlightTime(flightTime);
146
147 McEvt->addTofMc(tofMcRoot);
148 }
149
150 return StatusCode::SUCCESS;
151}
152#endif
153
154
155
156
157
158
159
160
161
162
static TMcEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
Definition of a Root address, derived from IOpaqueAddress.
IDataProviderSvc * m_eds
pointer to eventdataservice
std::vector< void * > m_adresses
each converter knows the corresponding adresses
std::string m_rootBranchname
root branchname (may be concatenated of severals)
virtual StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress)
Convert the transient object to the requested representation.
void addTofMc(TTofMc *mcHit)
Tof.
Definition: TMcEvent.cxx:124
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
Definition: TofMcHitCnv.cxx:37
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
Definition: TofMcHitCnv.cxx:89
TofMcHitCnv(ISvcLocator *svc)
Definition: TofMcHitCnv.cxx:25
static std::map< const TObject *, const TofMcHit * > m_rootTofMcHitMap