BOSS 7.0.3
BESIII Offline Software System
Loading...
Searching...
No Matches
RawDataMdcMcHitCnv.cxx
Go to the documentation of this file.
1//====================================================================
2// RawDataMdcMcHitCnv.cxx
3//====================================================================
4//
5// Description: A converter class to unpack Event Filter packed raw
6// event persistent data and place it in the Transient
7// Data Store of Athena.
8//
9//--------------------------------------------------------------------
10
11// Include files.
12#include <assert.h>
13#include <vector>
14#include "GaudiKernel/MsgStream.h"
15#include "GaudiKernel/SmartDataPtr.h"
16// for Mutil-thread by tianhl
17#include "GaudiKernel/ThreadGaudi.h"
18// for Mutil-thread by tianhl
19
20#include "EventModel/EventModel.h"
21#include "Identifier/Identifier.h"
22#include "Identifier/MdcID.h"
23#include "McTruth/MdcMcHit.h"
24#include "RawDataCnv/EventManagement/RAWEVENT.h"
25#include "RawDataCnv/EventManagement/RawEvent.h"
26#include "RawDataCnv/RawDataInputSvc.h"
27#include "RawDataCnv/RawDataMdcMcHitCnv.h"
28
29using Event::MdcMcHit;
31
32
33extern const CLID& CLID_MdcMcHitCol;
34
35// Constructor.
38{
39 //init();
40}
41
42// Return the identification number of this converter to the
43// persistency service.
45{
46 return CLID_MdcMcHitCol;
47}
48
50{
51
52 std::string PackedRawDataCnvSvc_Name("PackedRawDataCnvSvc");
53 std::string RawDataInputSvc_Name("RawDataInputSvc");
54 std::string RawDataMdcMcHitCnv_Name("RawDataMdcMcHitCnv");
55
56 // for Mutil-thread by tianhl
57 //ConversionSvc* pCnvSvc = 0;
58 //if (pCnvSvc = dynamic_cast<ConversionSvc*>(conversionSvc())){
59 SmartIF<IService> pCnvSvc(conversionSvc());
60 if (isGaudiThreaded(pCnvSvc->name())){
61 PackedRawDataCnvSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
62 RawDataInputSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
63 RawDataMdcMcHitCnv_Name += getGaudiThreadIDfromName(pCnvSvc->name());
64 }
65 //}
66
67 MsgStream log(messageService(), RawDataMdcMcHitCnv_Name.c_str());
68
69 StatusCode sc = RawDataBaseCnv::initialize();
70 if (StatusCode::SUCCESS != sc) {
71 log << MSG::ERROR << "RawDataBaseCnv: Cant initialize PackedRawDataCnvSvc" << endreq;
72 return sc;
73 }
74
75 // Check RawDataCnvSvc
76 IService* isvc = 0;
77 sc = serviceLocator()->service(PackedRawDataCnvSvc_Name.c_str(), isvc, true);
78 if (sc != StatusCode::SUCCESS) {
79 log << MSG::ERROR << "Cant get PackedRawDataCnvSvc" << endreq;
80 }
81
82 m_RawDataAccess = dynamic_cast<PackedRawDataCnvSvc*> (isvc);
83 if (m_RawDataAccess == 0 ) {
84 log << MSG::ERROR << "RawDataMdcCnv: Cant cast to RawDataCnvSvc " << endreq;
85 return StatusCode::FAILURE;
86 }
87
88 IService* svc = 0;
89 sc = serviceLocator()->getService(RawDataInputSvc_Name.c_str(), svc);
90 if (sc != StatusCode::SUCCESS ) {
91 log << MSG::WARNING << "Cant get RawDataInputSvc " << endreq;
92 return sc ;
93 }
94
95 m_inputSvc = dynamic_cast<RawDataInputSvc*> (svc);
96 if (m_inputSvc == 0 ) {
97 log << MSG::WARNING << "Cant cast to RawDataInputSvc " << endreq;
98 return StatusCode::FAILURE ;
99 }
100
101 return StatusCode::SUCCESS;
102}
103
104
105StatusCode RawDataMdcMcHitCnv::updateObj(IOpaqueAddress* pAddr, DataObject* pObj) {
106 // Purpose and Method: This method does nothing other than announce it has
107 // been called.
108
109 //MsgStream log(msgSvc(), "RawDataMdcMcHitCnv");
110 //log << MSG::DEBUG << "RawDataMdcMcHitCnv::updateObj" << endreq;
111 return Converter::updateObj(pAddr, pObj);
112}
113
114// Create a converted object in the Transient Data Store.
115StatusCode RawDataMdcMcHitCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
116{
117 //MsgStream log(msgSvc(), "RawDataMdcMcHitCnv");
118
119 //This converter will create an empty MdcMcHitCol on the TDS
120 MdcMcHitCol *mdcMcHitCol = new MdcMcHitCol;
121 pObj = mdcMcHitCol;
122
123 RAWEVENT *evt = m_inputSvc->currentEvent();
124 if (evt == NULL) {
125 //log << MSG::ERROR << "RawDataCnv has no event!" << endreq;
126 return StatusCode::FAILURE;
127 }
128
129 assert((evt->getMdcTruth().size())%6 == 0);
130
131 MdcTruth_t m_MdcTruth;
132 MdcMcHit* mdcMcHit;
133
134 std::vector<uint32_t>::const_iterator iter = evt->getMdcTruth().begin();
135 std::vector<uint32_t>::const_iterator eiter = evt->getMdcTruth().end();
136
137 for (int mdcMcHitId = 0; iter != eiter; mdcMcHitId++) {
138 // retrieve the MdcTruth data
139 m_mdcMcHitBuilder.unPack(iter, eiter, m_MdcTruth);
140 //construct the identifier
141 const Identifier ident = MdcID::wire_id (m_MdcTruth.layerId, m_MdcTruth.cellId);
142 /// construct the MdcMcHit
143 mdcMcHit = new MdcMcHit(ident, m_MdcTruth.trackIndex,
144 m_MdcTruth.x/(m_mdcMcHitBuilder.m_xCoeff*1.0),
145 m_MdcTruth.y/(m_mdcMcHitBuilder.m_yCoeff*1.0),
146 m_MdcTruth.z/(m_mdcMcHitBuilder.m_zCoeff*1.0),
147 m_MdcTruth.driftD/(m_mdcMcHitBuilder.m_driftDCoeff*1.0),
148 m_MdcTruth.edep/(m_mdcMcHitBuilder.m_edepCoeff*1.0),
149 m_MdcTruth.posFlag );
150 // And add the stuff to the container
151 mdcMcHitCol->push_back(mdcMcHit);
152 }
153
154 return StatusCode::SUCCESS;
155}
156
157StatusCode RawDataMdcMcHitCnv::createRep(DataObject* pObj, IOpaqueAddress*& pAddr)
158{
159 // convert PixelRaw in the container into ByteStream
160 //MsgStream log(messageService(), "RawDataMdcMcHitCnv");
161
162 WriteRawEvent*& re = m_RawDataAccess->getRawEvent();
163
164 if (re == 0) {
165 //log << " get RawEvent failed !" << endreq;
166 return StatusCode::FAILURE;
167 }
168
169 SmartDataPtr<MdcMcHitCol> mdcHitCol(dataProvider(), EventModel::MC::MdcMcHitCol);
170
171 if (mdcHitCol == 0) {
172 //log << "no MdcMcHitCol found" << endreq;
173 return StatusCode::FAILURE;
174 }
175 /*else {
176 log << MSG::INFO << endreq << "Detailed dump of 1st event: " << endreq;
177 int nMcHit = 0;
178 MdcMcHitCol::const_iterator pMdcMcHit = mdcHitCol->begin();
179 for ( ; pMdcMcHit != mdcHitCol->end(); pMdcMcHit++) {
180 log << MSG::INFO << "McHit " << nMcHit++ << " "
181 << (*pMdcMcHit)->getTrackIndex() << " "
182 << (*pMdcMcHit)->identify() << " "
183 << (*pMdcMcHit)->getDepositEnergy() << " "
184 << (*pMdcMcHit)->getDriftDistance() << " "
185 << (*pMdcMcHit)->getPositionX() << " "
186 << (*pMdcMcHit)->getPositionY() << " "
187 << (*pMdcMcHit)->getPositionZ() << endreq;
188 }
189 }*/
190
191 StatusCode sc = m_mdcMcHitBuilder.pack(mdcHitCol, re);
192
193 return sc;
194
195}
196
const CLID & CLID_MdcMcHitCol
Definition: EventModel.cxx:215
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
const CLID & CLID_MdcMcHitCol
Definition: EventModel.cxx:215
virtual RAWEVENT * currentEvent()=0
static Identifier wire_id(int wireType, int layer, int wire)
For a single wire.
Definition: MdcID.cxx:77
virtual StatusCode pack(MdcMcHitCol *mdcMcHitCol, WriteRawEvent *&re)
virtual void unPack(vector< uint32_t >::const_iterator &, vector< uint32_t >::const_iterator &, MdcTruth_t &)
StatusCode initialize()
virtual StatusCode createRep(DataObject *pObj, IOpaqueAddress *&pAddr)
Convert the transient object to the requested representation.
RawDataMdcMcHitCnv(ISvcLocator *svc)
static const CLID & classID()
StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj)
virtual StatusCode updateObj(IOpaqueAddress *, DataObject *)
override the RawDataBaseCnv version
ObjectVector< MdcMcHit > MdcMcHitCol