CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
CgemTrackCnv.cxx
Go to the documentation of this file.
1#ifndef CgemTrackCnv_CXX
2#define CgemTrackCnv_CXX 1
3
4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/DataObject.h"
6#include "GaudiKernel/ObjectVector.h"
7#include "TClonesArray.h"
9#include "DstEvent/DstEvent.h" //TDS object
10#include "DstEvent/DstCgemTrack.h" //TDS object
11#include "RootEventData/TCgemTrack.h" // standard root object
16#include <vector>
17#include "CLHEP/Matrix/Vector.h"
18#include "CLHEP/Matrix/SymMatrix.h"
19#include "CLHEP/Geometry/Point3D.h"
20
21using namespace std;
22
23
25: RootEventBaseCnv(classID(), svc)
26{
27 // Here we associate this converter with the /Event path on the TDS.
28 MsgStream log(msgSvc(), "CgemTrackCnv");
29 m_rootBranchname ="m_cgemTrackCol";
30 m_adresses.push_back(&m_cgemTrackCol);
31 m_cgemTrackCol=0;
32}
33
34StatusCode CgemTrackCnv::TObjectToDataObject(DataObject*& refpObject) {
35 // creation of TDS object from root object
36 MsgStream log(msgSvc(), "CgemTrackCnv");
37//myModify
38 log << MSG::INFO << "My Message::CgemTrackCnv::TObjectToDataObject()"<<endreq;
39
40 log << MSG::DEBUG << "CgemTrackCnv::TObjectToDataObject" << endreq;
41 StatusCode sc=StatusCode::SUCCESS;
42
43 // create the TDS location for the CgemTrack Collection
44 DstCgemTrackCol* cgemTrackTdsCol = new DstCgemTrackCol;
45 refpObject=cgemTrackTdsCol;
46
47 // now convert
48 if (!m_cgemTrackCol) return sc;
49 TIter cgemTrackIter(m_cgemTrackCol);
50 TCgemTrack *cgemTrackRoot = 0;
51 while ((cgemTrackRoot = (TCgemTrack*)cgemTrackIter.Next())) {
52
53 int trackId = cgemTrackRoot->trackId();
54 int charge = cgemTrackRoot->charge();
55 double helix[5];
56 for(int i=0; i<5; i++){
57 helix[i] = cgemTrackRoot->helix(i);
58 log<<MSG::INFO<<"in CgemTrackCnv, helix["<<i<<"]: "<<helix[i]<<endreq;
59 }
60 double pxy = cgemTrackRoot->pxy();
61 double px = cgemTrackRoot->px();
62 double py = cgemTrackRoot->py();
63 double pz = cgemTrackRoot->pz();
64 double p = cgemTrackRoot->p();
65 double theta = cgemTrackRoot->theta();
66 double phi = cgemTrackRoot->phi();
67 double x = cgemTrackRoot->x();
68 double y = cgemTrackRoot->y();
69 double z = cgemTrackRoot->z();
70 double r = cgemTrackRoot->r();
71 int stat = cgemTrackRoot->stat();
72 double chi = cgemTrackRoot->chi2();
73 int ndof = cgemTrackRoot->ndof();
74
75 double err[15];
76 for (int i=0; i<15; i++){
77 err[i] = cgemTrackRoot->err(i);
78 }
79
80 double poca[3];
81 poca[0] = x;
82 poca[1] = y;
83 poca[2] = z;
84
85//myModify
86 log << MSG::INFO << "My Message::CgemTrackCnv::TObjectToDataObject::charge:"<<charge<<",p:"<<p<<",r:"<<r<<",z:"<<z<<endreq;
87
88 DstCgemTrack *cgemTrackTds = new DstCgemTrack();
89 m_common.m_rootCgemTrackMap[cgemTrackRoot] = cgemTrackTds;
90
91 cgemTrackTds->setTrackId( trackId );
92 log<<MSG::INFO<<" dstCgemTrack trkid: "<<cgemTrackTds->trackId()<<endreq;
93
94 cgemTrackTds->setCharge( charge );
95 cgemTrackTds->setHelix(helix);
96 cgemTrackTds->setPoca(poca);
97
98 log<<MSG::INFO<<"dstCgemTrack helix: "<<cgemTrackTds->helix()<<endreq;
99
100 cgemTrackTds->setPxy( pxy );
101 cgemTrackTds->setPx( px );
102 cgemTrackTds->setPy( py );
103 cgemTrackTds->setPz( pz );
104 cgemTrackTds->setP( p );
105 cgemTrackTds->setTheta( theta );
106 cgemTrackTds->setPhi( phi );
107 cgemTrackTds->setX( x );
108 cgemTrackTds->setY( y );
109 cgemTrackTds->setZ( z );
110 cgemTrackTds->setR( r );
111 cgemTrackTds->setStat( stat );
112 cgemTrackTds->setChi2( chi );
113 cgemTrackTds->setNdof( ndof );
114 cgemTrackTds->setError( err );
115
116 cgemTrackTdsCol->push_back(cgemTrackTds);
117
118 }
119 delete m_cgemTrackCol;
120 m_cgemTrackCol = 0;
121//myModify
122 log << MSG::INFO << "My Message::CgemTrackCnv::TObjectToDataObject()-finished"<<endreq;
123
124 return StatusCode::SUCCESS;
125}
126
127StatusCode CgemTrackCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
128
129 MsgStream log(msgSvc(), "CgemTrackCnv");
130//myModify
131 log << MSG::INFO << "My Message::CgemTrackCnv::DataObjectToTObject("<<rootaddr->getTreename()<<")"<<endreq;
132
133 log << MSG::DEBUG << "CgemTrackCnv::DataObjectToTObject" << endreq;
134 StatusCode sc=StatusCode::SUCCESS;
135
136 DstCgemTrackCol * cgemTrackColTds=dynamic_cast<DstCgemTrackCol *> (obj);
137 if (!cgemTrackColTds) {
138 log << MSG::ERROR << "Could not downcast to CgemTrackCol" << endreq;
139//myModify
140 log << MSG::INFO << "My Message::CgemTrackCnv::DataObjectToTObject("<<rootaddr->getTreename()<<")-finished"<<endreq;
141
142 return StatusCode::FAILURE;
143 }
144
145 DataObject *evt;
146 m_eds->findObject(EventModel::Dst::Event,evt);
147 if (evt==NULL) {
148 log << MSG::ERROR << "Could not get DstEvent in TDS " << endreq;
149//myModify
150 log << MSG::INFO << "My Message::CgemTrackCnv::DataObjectToTObject("<<rootaddr->getTreename()<<")-finished"<<endreq;
151
152 return StatusCode::FAILURE;
153 }
154 DstEvent * devtTds=dynamic_cast<DstEvent *> (evt);
155 if (!devtTds) {
156 log << MSG::ERROR << "CgemTrackCnv:Could not downcast to TDS DstEvent" << endreq;
157 }
158 IOpaqueAddress *addr;
159
160//myModify
161 log << MSG::INFO << "My Message::CgemTrackCnv::DataObjectToTObject("<<rootaddr->getTreename()<<")::DstCnv"<<endreq;
162
163 m_cnvSvc->getDstCnv()->createRep(evt,addr);
165
166 const TObjArray *m_cgemTrackCol = recEvt->getCgemTrackCol();
167 if (!m_cgemTrackCol) return sc;
168 recEvt->clearCgemTrackCol(); //necessary in case there is I/O at the same time since array is static
169 DstCgemTrackCol::const_iterator cgemTrackTds;
170
171 for (cgemTrackTds = cgemTrackColTds->begin(); cgemTrackTds != cgemTrackColTds->end(); cgemTrackTds++) {
172 Int_t trackId =(*cgemTrackTds)->trackId();
173 Double_t helix[5];
174 for(int i=0;i<5;i++){
175 helix[i] = (*cgemTrackTds)->helix(i) ;
176 }
177 Int_t stat = (*cgemTrackTds)->stat();
178 Double_t chi = (*cgemTrackTds)->chi2();
179 Int_t ndof = (*cgemTrackTds)->ndof();
180 Double_t err[15];
181 for (Int_t i=0; i<15; i++){
182 err[i] = (*cgemTrackTds)->err(i);
183 }
184 Int_t fL = (*cgemTrackTds)->firstLayer();
185 Int_t lL = (*cgemTrackTds)->lastLayer();
186
187 TCgemTrack *cgemTrackRoot = new TCgemTrack();
188 //m_common.m_cgemTrackMap[(*cgemTrackTds)] = cgemTrackRoot;
189 cgemTrackRoot->setTrackId( trackId );
190
191 cgemTrackRoot->setHelix(helix);
192 log<<MSG::INFO<<"test,trackId: "<<cgemTrackRoot->trackId()<<endreq;
193 log<<MSG::INFO<<"test,px: "<<cgemTrackRoot->px()
194 <<"test,py: "<<cgemTrackRoot->py()
195 <<"test,pz: "<<cgemTrackRoot->pz()<<endreq;
196
197 cgemTrackRoot->setStat( stat );
198 cgemTrackRoot->setChi2( chi );
199 cgemTrackRoot->setNdof( ndof );
200 cgemTrackRoot->setErr( err );
201 cgemTrackRoot->setFirstLayer(fL);
202 cgemTrackRoot->setLastLayer(lL);
203
204 recEvt->addCgemTrack(cgemTrackRoot);
205 }
206
207//myModify
208 log << MSG::INFO << "My Message::CgemTrackCnv::DataObjectToTObject("<<rootaddr->getTreename()<<")-finished"<<endreq;
209
210 return StatusCode::SUCCESS;
211}
212#endif
Double_t x[10]
ObjectVector< DstCgemTrack > DstCgemTrackCol
Definition: DstCgemTrack.h:127
IMessageSvc * msgSvc()
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
CgemTrackCnv(ISvcLocator *svc)
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
void setStat(const int stat)
Definition: DstCgemTrack.h:93
void setPx(const double px)
Definition: DstCgemTrack.h:83
void setPhi(const double phi)
Definition: DstCgemTrack.h:88
void setTheta(const double theta)
Definition: DstCgemTrack.h:87
void setCharge(const int charge)
Definition: DstCgemTrack.h:81
void setHelix(double helix[5])
void setZ(const double z)
Definition: DstCgemTrack.h:91
void setP(const double p)
Definition: DstCgemTrack.h:86
const int trackId() const
Definition: DstCgemTrack.h:52
void setTrackId(const int trackId)
Definition: DstCgemTrack.h:80
void setError(double err[15])
void setPxy(const double pxy)
Definition: DstCgemTrack.h:82
void setPy(const double py)
Definition: DstCgemTrack.h:84
void setY(const double y)
Definition: DstCgemTrack.h:90
void setPoca(double poca[3])
void setX(const double x)
Definition: DstCgemTrack.h:89
void setNdof(const int ndof)
Definition: DstCgemTrack.h:95
void setR(const double r)
Definition: DstCgemTrack.h:92
void setPz(const double pz)
Definition: DstCgemTrack.h:85
void setChi2(const double chi)
Definition: DstCgemTrack.h:94
const HepVector helix() const
......
static TDstEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
Definition: DstCnv.h:36
Definition of a Root address, derived from IOpaqueAddress.
Definition: RootAddress.h:21
std::string getTreename() const
Definition: RootAddress.h:27
DstCnv * getDstCnv()
Definition: RootCnvSvc.h:148
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 setLastLayer(const Int_t lL)
Definition: TCgemTrack.h:44
const Int_t ndof() const
Definition: TCgemTrack.h:17
void setTrackId(const Int_t trackId)
Definition: TCgemTrack.h:39
const Int_t trackId() const
Definition: TCgemTrack.h:13
const Double_t x() const
Definition: TCgemTrack.cxx:30
const Double_t p() const
Definition: TCgemTrack.cxx:65
void setStat(const Int_t stat)
Definition: TCgemTrack.h:40
const Double_t r() const
Definition: TCgemTrack.cxx:42
void setErr(const Double_t err[15])
Definition: TCgemTrack.cxx:84
const Int_t stat() const
Definition: TCgemTrack.h:15
const Double_t y() const
Definition: TCgemTrack.cxx:34
void setHelix(const Double_t helix[5])
Definition: TCgemTrack.cxx:78
const Double_t theta() const
Definition: TCgemTrack.cxx:70
const Int_t charge() const
Definition: TCgemTrack.cxx:18
const Double_t z() const
Definition: TCgemTrack.cxx:38
const Double_t pz() const
Definition: TCgemTrack.cxx:61
void setFirstLayer(const Int_t fL)
Definition: TCgemTrack.h:43
const Double_t phi() const
Definition: TCgemTrack.cxx:74
const Double_t helix(Int_t i) const
Definition: TCgemTrack.h:14
const Double_t chi2() const
Definition: TCgemTrack.h:16
const Double_t err(Int_t i) const
Definition: TCgemTrack.h:18
const Double_t px() const
Definition: TCgemTrack.cxx:53
const Double_t py() const
Definition: TCgemTrack.cxx:57
const Double_t pxy() const
Definition: TCgemTrack.cxx:47
void setNdof(const Int_t ndof)
Definition: TCgemTrack.h:42
void setChi2(const Double_t chi)
Definition: TCgemTrack.h:41
const TObjArray * getCgemTrackCol() const
retrieve the whole TObjArray of CgemTrack Data
Definition: TDstEvent.h:52
void addCgemTrack(TCgemTrack *Track)
Add a tkrtrack into the Cgem data collection.
Definition: TDstEvent.cxx:174
void clearCgemTrackCol()
clear the whole array (necessary because of the consts-s)
Definition: TDstEvent.h:61
static std::map< const TObject *, const DstCgemTrack * > m_rootCgemTrackMap
Definition: commonData.h:172
_EXTERN_ std::string Event
Definition: EventModel.h:146