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