BOSS 7.1.2
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
11#include "McTruth/McEvent.h" //TDS object
12#include "McTruth/TofMcHit.h" //TDS object
13#include "RootEventData/TTofMc.h" // standard root object
15#include "RootCnvSvc/Mc/McCnv.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
IMessageSvc * msgSvc()
#define NULL
void setTrackIndex(unsigned int trackIndex)
Definition TofMcHit.h:61
void setPx(double px)
Definition TofMcHit.h:65
void setPositionX(double positionX)
Definition TofMcHit.h:62
void setPz(double pz)
Definition TofMcHit.h:67
void setPy(double py)
Definition TofMcHit.h:66
void setIdentifier(unsigned int id)
Definition TofMcHit.h:60
void setFlightTime(double flightTime)
Definition TofMcHit.h:69
void setTrackLength(double trackLength)
Definition TofMcHit.h:68
void setPositionZ(double positionZ)
Definition TofMcHit.h:64
void setPositionY(double positionY)
Definition TofMcHit.h:63
static TMcEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
Definition McCnv.h:35
Definition of a Root address, derived from IOpaqueAddress.
Definition RootAddress.h:21
McCnv * getMcCnv()
Definition RootCnvSvc.h:156
Base class for all Root Converters.
std::vector< void * > m_adresses
each converter knows the corresponding adresses
RootCnvSvc * m_cnvSvc
IDataProviderSvc * m_eds
pointer to eventdataservice
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 clearTofMcHitCol()
Definition TMcEvent.h:47
void addTofMc(TTofMc *mcHit)
Tof.
Definition TMcEvent.cxx:124
const TObjArray * getTofMcHitCol() const
Definition TMcEvent.h:44
Definition TTofMc.h:8
void setTrackIndex(UInt_t trackIndex)
Definition TTofMc.h:47
Double_t getPositionY() const
Definition TTofMc.h:25
Double_t getPz() const
Definition TTofMc.h:37
void setId(UInt_t id)
Definition TTofMc.h:46
void setPositionY(Double_t positionY)
Definition TTofMc.h:49
Double_t getPositionX() const
Definition TTofMc.h:22
void setTrackLength(Double_t trackLength)
Definition TTofMc.h:54
void setPz(Double_t pz)
Definition TTofMc.h:53
UInt_t getTrackIndex() const
Definition TTofMc.h:19
Double_t getPx() const
Definition TTofMc.h:31
void setPy(Double_t py)
Definition TTofMc.h:52
void setFlightTime(Double_t flightTime)
Definition TTofMc.h:55
void setPx(Double_t px)
Definition TTofMc.h:51
void setPositionZ(Double_t positionZ)
Definition TTofMc.h:50
Double_t getPositionZ() const
Definition TTofMc.h:28
void setPositionX(Double_t positionX)
Definition TTofMc.h:48
Double_t getFlightTime() const
Definition TTofMc.h:43
Double_t getPy() const
Definition TTofMc.h:34
UInt_t getId() const
Definition TTofMc.h:16
Double_t getTrackLength() const
Definition TTofMc.h:40
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
TofMcHitCnv(ISvcLocator *svc)
static std::map< const TObject *, const TofMcHit * > m_rootTofMcHitMap
Definition commonData.h:173
_EXTERN_ std::string Event
Definition EventModel.h:39
ObjectVector< TofMcHit > TofMcHitCol
Definition TofMcHit.h:100