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