CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
RawDataEmcMcHitCnv.cxx
Go to the documentation of this file.
1//====================================================================
2// RawDataEmcMcHitCnv.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 "GaudiKernel/SmartDataPtr.h"
14#include "GaudiKernel/MsgStream.h"
15// for Mutil-thread by tianhl
16#include "GaudiKernel/ThreadGaudi.h"
17// for Mutil-thread by tianhl
18
19#include "EventModel/EventModel.h"
20#include "Identifier/Identifier.h"
21#include "Identifier/EmcID.h"
22#include "McTruth/EmcMcHit.h"
23#include "RawDataCnv/EventManagement/RAWEVENT.h"
24#include "RawDataCnv/EventManagement/RawEvent.h"
25#include "RawDataCnv/RawDataInputSvc.h"
26#include "RawDataCnv/RawDataEmcMcHitCnv.h"
27
28using Event::EmcMcHit;
30
31extern const CLID& CLID_EmcMcHitCol;
32
33// Constructor.
36{
37 //init();
38}
39
40// Return the identification number of this converter to the
41// persistency service.
43{
44 return CLID_EmcMcHitCol;
45}
46
48{
49 std::string PackedRawDataCnvSvc_Name("PackedRawDataCnvSvc");
50 std::string RawDataInputSvc_Name("RawDataInputSvc");
51 std::string RawDataEmcMcHitCnv_Name("RawDataEmcMcHitCnv");
52
53 // for Mutil-thread by tianhl
54 //ConversionSvc* pCnvSvc = 0;
55 //if (pCnvSvc = dynamic_cast<ConversionSvc*>(conversionSvc())){
56 SmartIF<IService> pCnvSvc(conversionSvc());
57 if (isGaudiThreaded(pCnvSvc->name())){
58 PackedRawDataCnvSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
59 RawDataInputSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
60 RawDataEmcMcHitCnv_Name += getGaudiThreadIDfromName(pCnvSvc->name());
61 }
62 //}
63
64 MsgStream log(messageService(), RawDataEmcMcHitCnv_Name.c_str());
65
66 StatusCode sc = RawDataBaseCnv::initialize();
67 if (StatusCode::SUCCESS != sc) {
68 log << MSG::ERROR << "RawDataBaseCnv: Cant initialize PackedRawDataCnvSvc" << endreq;
69 return sc;
70 }
71
72 // Check RawDataCnvSvc
73 IService* isvc = 0;
74 sc = serviceLocator()->service(PackedRawDataCnvSvc_Name.c_str(), isvc, true);
75 if (sc != StatusCode::SUCCESS) {
76 log << MSG::ERROR << "Cant get PackedRawDataCnvSvc" << endreq;
77 }
78
79 m_RawDataAccess = dynamic_cast<PackedRawDataCnvSvc*> (isvc);
80 if (m_RawDataAccess == 0 ) {
81 log << MSG::ERROR << "RawDataEmcCnv: Cant cast to RawDataCnvSvc " << endreq;
82 return StatusCode::FAILURE;
83 }
84
85 sc = serviceLocator()->getService(RawDataInputSvc_Name.c_str(), isvc);
86 if (sc != StatusCode::SUCCESS ) {
87 log << MSG::WARNING << "Cant get RawDataInputSvc " << endreq;
88 return sc ;
89 }
90
91 m_inputSvc = dynamic_cast<RawDataInputSvc*> (isvc);
92 if (m_inputSvc == 0 ) {
93 log << MSG::WARNING << "Cant cast to RawDataInputSvc " << endreq;
94 return StatusCode::FAILURE ;
95 }
96
97 return StatusCode::SUCCESS;
98}
99
100
101StatusCode RawDataEmcMcHitCnv::updateObj(IOpaqueAddress* pAddr, DataObject* pObj) {
102 // Purpose and Method: This method does nothing other than announce it has
103 // been called.
104
105 //MsgStream log(msgSvc(), "RawDataEmcMcHitCnv");
106 //log << MSG::DEBUG << "RawDataEmcMcHitCnv::updateObj" << endreq;
107 return Converter::updateObj(pAddr, pObj);
108}
109
110// Create a converted object in the Transient Data Store.
111StatusCode RawDataEmcMcHitCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
112{
113
114 //This converter will create an empty EmcMcHitCol on the TDS
115 EmcMcHitCol *emcMcHitCol = new EmcMcHitCol;
116 pObj = emcMcHitCol;
117
118 RAWEVENT *evt = m_inputSvc->currentEvent();
119 if (evt == NULL) {
120 //MsgStream log(msgSvc(), "RawDataEmcMcHitCnv");
121 //log << MSG::ERROR << "RawDataCnv has no event!" << endreq;
122 return StatusCode::FAILURE;
123 }
124
125 EmcMcHit* emcMcHit;
126 EmcTruth_t m_EmcTruth;
127
128 assert((evt->getEmcTruth().size()%8) == 0);
129
130 std::vector<uint32_t>::const_iterator iter = evt->getEmcTruth().begin();
131 std::vector<uint32_t>::const_iterator eiter = evt->getEmcTruth().end();
132
133 for (int emcMcHitId = 0; iter != eiter; emcMcHitId++) {
134 // retrieve the McTruth data
135 m_emcMcHitBuilder.unPack(iter, eiter, m_EmcTruth);
136 // construct the identifier
137 Identifier ident = EmcID::crystal_id(m_EmcTruth.partId, m_EmcTruth.numTheta, m_EmcTruth.numPhi);
138 // construct the EmcMcHit
139 emcMcHit = new EmcMcHit(ident, m_EmcTruth.trackIndex,
140 m_EmcTruth.x/(m_emcMcHitBuilder.m_xCoeff*1.0),
141 m_EmcTruth.y/(m_emcMcHitBuilder.m_yCoeff*1.0),
142 m_EmcTruth.z/(m_emcMcHitBuilder.m_zCoeff*1.0),
143 m_EmcTruth.px/(m_emcMcHitBuilder.m_pxCoeff*1.0),
144 m_EmcTruth.py/(m_emcMcHitBuilder.m_pyCoeff*1.0),
145 m_EmcTruth.pz/(m_emcMcHitBuilder.m_pzCoeff*1.0),
146 m_EmcTruth.totalEdep/(m_emcMcHitBuilder.m_totalEdepCoeff*1.0) );
147 // And add the stuff to the container
148 emcMcHitCol->push_back(emcMcHit);
149 }
150
151 return StatusCode::SUCCESS;
152
153}
154
155StatusCode RawDataEmcMcHitCnv::createRep(DataObject* pObj, IOpaqueAddress*& pAddr)
156{
157 // convert PixelRaw in the container into ByteStream
158 //MsgStream log(messageService(), "RawDataEmcMcHitCnv");
159
160 WriteRawEvent*& re = m_RawDataAccess->getRawEvent();
161
162 if (re == 0) {
163 //log << " get RawEvent failed !" << endreq;
164 return StatusCode::FAILURE;
165 }
166
167 SmartDataPtr<EmcMcHitCol> mcHitCol(dataProvider(), EventModel::MC::EmcMcHitCol);
168
169 if (mcHitCol == 0) {
170 //log << "no EmcMcHitCol found" << endreq;
171 return StatusCode::FAILURE;
172 }
173
174 StatusCode sc = m_emcMcHitBuilder.pack(mcHitCol, re);
175
176 return sc;
177
178}
179
const CLID & CLID_EmcMcHitCol
Definition: EventModel.cxx:242
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
const CLID & CLID_EmcMcHitCol
Definition: EventModel.cxx:242
static Identifier crystal_id(const unsigned int barrel_ec, const unsigned int theta_module, const unsigned int phi_module)
For a single crystal.
virtual StatusCode pack(EmcMcHitCol *emcMcHitCol, WriteRawEvent *&re)
virtual void unPack(vector< uint32_t >::const_iterator &, vector< uint32_t >::const_iterator &, EmcTruth_t &)
virtual RAWEVENT * currentEvent()=0
StatusCode initialize()
RawDataEmcMcHitCnv(ISvcLocator *svc)
static const CLID & classID()
StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj)
virtual StatusCode updateObj(IOpaqueAddress *, DataObject *)
override the RawDataBaseCnv version
virtual StatusCode createRep(DataObject *pObj, IOpaqueAddress *&pAddr)
Convert the transient object to the requested representation.
ObjectVector< EmcMcHit > EmcMcHitCol