BOSS 7.0.8
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcMcHitCnv.cxx
Go to the documentation of this file.
1#ifndef MdcMcHitCnv_CXX
2#define MdcMcHitCnv_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/MdcMcHit.h" //TDS object
13#include "RootEventData/TMdcMc.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<MdcMcHitCnv> s_factory;
23//const ICnvFactory& MdcMcHitCnvFactory = s_factory;
24
25MdcMcHitCnv::MdcMcHitCnv(ISvcLocator* svc)
26: RootEventBaseCnv(classID(), svc)
27{
28 // Here we associate this converter with the /Event path on the TDS.
29 MsgStream log(msgSvc(), "MdcMcHitCnv");
30 //log << MSG::DEBUG << "Constructor called for " << objType() << endreq;
31 m_rootBranchname ="m_mdcMcHitCol";
32 //declareObject(EventModel::MC::MdcMcHitCol, objType(), m_rootTreename, m_rootBranchname);
33 m_adresses.push_back(&m_mdcMcHitCol);
34 m_mdcMcHitCol=0;
35}
36
37StatusCode MdcMcHitCnv::TObjectToDataObject(DataObject*& refpObject) {
38 // creation of TDS object from root object
39
40 MsgStream log(msgSvc(), "MdcMcHitCnv");
41 log << MSG::DEBUG << "MdcMcHitCnv::TObjectToDataObject" << endreq;
42 StatusCode sc=StatusCode::SUCCESS;
43
44 // create the TDS location for the MdcMc Collection
45 MdcMcHitCol* mdcMcTdsCol = new MdcMcHitCol;
46 refpObject=mdcMcTdsCol;
47
48
49 // now convert
50 if (!m_mdcMcHitCol) return sc;
51 TIter mdcMcIter(m_mdcMcHitCol);
52 TMdcMc *mdcMcRoot = 0;
53 while ((mdcMcRoot = (TMdcMc*)mdcMcIter.Next())) {
54 unsigned int id = mdcMcRoot ->getId();
55 unsigned int trackIndex = mdcMcRoot ->getTrackIndex();
56 double xPosition = mdcMcRoot ->getPositionX() ;
57 double yPosition = mdcMcRoot ->getPositionY() ;
58 double zPosition = mdcMcRoot ->getPositionZ() ;
59 double driftDistance= mdcMcRoot ->getDriftDistance() ;
60 double depositEnergy = mdcMcRoot ->getDepositEnergy() ;
61 int positionFlag = mdcMcRoot->getPositionFlag();
62
63 MdcMcHit *mdcMcTds = new MdcMcHit;
64 m_common.m_rootMdcMcHitMap[mdcMcRoot] = mdcMcTds;
65
66 mdcMcTds->setIdentifier(id);
67 mdcMcTds->setTrackIndex(trackIndex);
68 mdcMcTds->setPositionX(xPosition);
69 mdcMcTds->setPositionY(yPosition);
70 mdcMcTds->setPositionZ(zPosition);
71 mdcMcTds->setDriftDistance(driftDistance);
72 mdcMcTds->setDepositEnergy(depositEnergy);
73 mdcMcTds->setPositionFlag(positionFlag);
74
75 mdcMcTdsCol->push_back(mdcMcTds);
76 }
77 //m_mdcMcHitCol->Delete(); // wensp add 2005/12/30
78 delete m_mdcMcHitCol;
79 m_mdcMcHitCol = 0;
80 return StatusCode::SUCCESS;
81}
82
83StatusCode MdcMcHitCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
84
85 MsgStream log(msgSvc(), "MdcMcHitCnv");
86 log << MSG::DEBUG << "MdcMcHitCnv::DataObjectToTObject" << endreq;
87 StatusCode sc=StatusCode::SUCCESS;
88
89 MdcMcHitCol * mdcMcHitCnvTds=dynamic_cast<MdcMcHitCol *> (obj);
90 if (!mdcMcHitCnvTds) {
91 log << MSG::ERROR << "Could not downcast to MdcMcHitCol" << endreq;
92 return StatusCode::FAILURE;
93 }
94
95 DataObject *evt;
96 m_eds->findObject(EventModel::MC::Event,evt);
97 if (evt==NULL) {
98 log << MSG::ERROR << "Could not get McEvent in TDS " << endreq;
99 return StatusCode::FAILURE;
100 }
101 McEvent * devtTds=dynamic_cast<McEvent *> (evt);
102 if (!devtTds) {
103 log << MSG::ERROR << "MdcMcHitCnv:Could not downcast to TDS McEvent" << endreq;
104 }
105 IOpaqueAddress *addr;
106
107 m_cnvSvc->getMcCnv()->createRep(evt,addr);
109
110 const TObjArray *m_mdcMcHitCol = McEvt->getMdcMcHitCol();
111 if (!m_mdcMcHitCol) return sc;
112 McEvt->clearMdcMcHitCol(); //necessary in case there is I/O at the same time since array is static
113 MdcMcHitCol::const_iterator mdcMcTds;
114
115 for (mdcMcTds = mdcMcHitCnvTds->begin(); mdcMcTds != mdcMcHitCnvTds->end(); mdcMcTds++) {
116 UInt_t id = ((*mdcMcTds)->identify()).get_value() ;
117 UInt_t trackIndex = (*mdcMcTds) ->getTrackIndex();
118 Double_t xPosition = (*mdcMcTds) ->getPositionX() ;
119 Double_t yPosition = (*mdcMcTds) ->getPositionY() ;
120 Double_t zPosition = (*mdcMcTds) ->getPositionZ() ;
121 Double_t driftDistance= (*mdcMcTds) ->getDriftDistance();
122 Double_t depositEnergy = (*mdcMcTds) ->getDepositEnergy() ;
123 Int_t positionFlag = (*mdcMcTds) ->getPositionFlag();
124
125 TMdcMc *mdcMcRoot = new TMdcMc();
126 //m_common.m_mdcMcHitMap[(*mdcMcTds)] = mdcMcRoot;
127
128 mdcMcRoot->setId(id);
129 mdcMcRoot->setTrackIndex(trackIndex);
130 mdcMcRoot->setPositionX(xPosition);
131 mdcMcRoot->setPositionY(yPosition);
132 mdcMcRoot->setPositionZ(zPosition);
133 mdcMcRoot->setDriftDistance(driftDistance);
134 mdcMcRoot->setDepositEnergy(depositEnergy);
135 mdcMcRoot->setPositionFlag(positionFlag);
136
137 McEvt->addMdcMc(mdcMcRoot);
138 }
139
140 return StatusCode::SUCCESS;
141}
142#endif
143
144
145
146
147
148
149
150
151
152
IMessageSvc * msgSvc()
#define NULL
void setPositionFlag(int posFlag)
Definition: MdcMcHit.h:63
void setPositionZ(double positionZ)
Definition: MdcMcHit.h:60
void setDepositEnergy(double depositEnergy)
Definition: MdcMcHit.h:62
void setIdentifier(unsigned int id)
Definition: MdcMcHit.h:56
void setPositionY(double positionY)
Definition: MdcMcHit.h:59
void setTrackIndex(unsigned int trackIndex)
Definition: MdcMcHit.h:57
void setDriftDistance(double driftDistance)
Definition: MdcMcHit.h:61
void setPositionX(double positionX)
Definition: MdcMcHit.h:58
static TMcEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
Definition: McCnv.h:35
Definition: McEvent.h:8
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
Definition: MdcMcHitCnv.cxx:37
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
Definition: MdcMcHitCnv.cxx:83
MdcMcHitCnv(ISvcLocator *svc)
Definition: MdcMcHitCnv.cxx:25
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 addMdcMc(TMdcMc *mcHit)
Mdc.
Definition: TMcEvent.cxx:103
void clearMdcMcHitCol()
Definition: TMcEvent.h:35
const TObjArray * getMdcMcHitCol() const
Definition: TMcEvent.h:32
Definition: TMdcMc.h:8
UInt_t getId() const
Definition: TMdcMc.h:16
Double_t getDepositEnergy() const
Definition: TMdcMc.h:34
Double_t getPositionZ() const
Definition: TMdcMc.h:28
void setPositionZ(Double_t positionZ)
Definition: TMdcMc.h:47
Double_t getDriftDistance() const
Definition: TMdcMc.h:31
void setId(UInt_t id)
Definition: TMdcMc.h:43
void setTrackIndex(UInt_t trackIndex)
Definition: TMdcMc.h:44
UInt_t getTrackIndex() const
Definition: TMdcMc.h:19
void setDepositEnergy(Double_t depositEnergy)
Definition: TMdcMc.h:49
Int_t getPositionFlag() const
Definition: TMdcMc.h:37
Double_t getPositionX() const
Definition: TMdcMc.h:22
void setPositionX(Double_t positionX)
Definition: TMdcMc.h:45
void setPositionFlag(Int_t posFlag)
Definition: TMdcMc.h:50
Double_t getPositionY() const
Definition: TMdcMc.h:25
void setPositionY(Double_t positionY)
Definition: TMdcMc.h:46
void setDriftDistance(Double_t driftDistance)
Definition: TMdcMc.h:48
static std::map< const TObject *, const MdcMcHit * > m_rootMdcMcHitMap
Definition: commonData.h:170
_EXTERN_ std::string Event
Definition: EventModel.h:39
ObjectVector< MdcMcHit > MdcMcHitCol
Definition: MdcMcHit.h:88