BOSS 7.0.1
BESIII Offline Software System
Loading...
Searching...
No Matches
RawDataTofMcHitCnv.cxx
Go to the documentation of this file.
1
2//====================================================================
3// RawDataTofMcHitCnv.cxx
4//====================================================================
5//
6// Description: A converter class to unpack Event Filter packed raw
7// event persistent data and place it in the Transient
8// Data Store of Athena.
9//
10//--------------------------------------------------------------------
11
12// Include files.
13#include <assert.h>
14#include <vector>
15#include "GaudiKernel/MsgStream.h"
16#include "GaudiKernel/SmartDataPtr.h"
17// for Mutil-thread by tianhl
18#include "GaudiKernel/ThreadGaudi.h"
19// for Mutil-thread by tianhl
20
21#include "EventModel/EventModel.h"
22#include "Identifier/Identifier.h"
23#include "Identifier/TofID.h"
24#include "McTruth/TofMcHit.h"
25#include "RawDataCnv/EventManagement/RAWEVENT.h"
26#include "RawDataCnv/EventManagement/RawEvent.h"
27#include "RawDataCnv/RawDataInputSvc.h"
28#include "RawDataCnv/RawDataTofMcHitCnv.h"
29
30using Event::TofMcHit;
32
33extern const CLID& CLID_TofMcHitCol;
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_TofMcHitCol;
47}
48
50{
51
52 std::string PackedRawDataCnvSvc_Name("PackedRawDataCnvSvc");
53 std::string RawDataInputSvc_Name("RawDataInputSvc");
54 std::string RawDataTofMcHitCnv_Name("RawDataTofMcHitCnv");
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 RawDataTofMcHitCnv_Name += getGaudiThreadIDfromName(pCnvSvc->name());
64 }
65 //}
66
67 MsgStream log(messageService(), RawDataTofMcHitCnv_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 << "RawDataTofCnv: Cant cast to RawDataCnvSvc " << endreq;
85 return StatusCode::FAILURE;
86 }
87
88 sc = serviceLocator()->getService(RawDataInputSvc_Name.c_str(), isvc);
89 if (sc != StatusCode::SUCCESS ) {
90 log << MSG::WARNING << "Cant get RawDataInputSvc " << endreq;
91 return sc ;
92 }
93
94 m_inputSvc = dynamic_cast<RawDataInputSvc*> (isvc);
95 if (m_inputSvc == 0 ) {
96 log << MSG::WARNING << "Cant cast to RawDataInputSvc " << endreq;
97 return StatusCode::FAILURE ;
98 }
99
100 return StatusCode::SUCCESS;
101}
102
103
104StatusCode RawDataTofMcHitCnv::updateObj(IOpaqueAddress* pAddr, DataObject* pObj) {
105 // Purpose and Method: This method does nothing other than announce it has
106 // been called.
107
108 //MsgStream log(msgSvc(), "RawDataTofMcHitCnv");
109 //log << MSG::DEBUG << "RawDataTofMcHitCnv::updateObj" << endreq;
110 return Converter::updateObj(pAddr, pObj);
111}
112
113// Create a converted object in the Transient Data Store.
114StatusCode RawDataTofMcHitCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
115{
116 MsgStream log(msgSvc(), "RawDataTofMcHitCnv");
117
118 //This converter will create an empty TofMcHitCol on the TDS
119 TofMcHitCol *tofMcHitCol = new TofMcHitCol;
120 pObj = tofMcHitCol;
121
122 RAWEVENT *evt = m_inputSvc->currentEvent();
123 if (evt == NULL) {
124 //log << MSG::ERROR << "RawDataCnv has no event!" << endreq;
125 return StatusCode::FAILURE;
126 }
127
128 assert((evt->getTofTruth().size())%9 == 0);
129
130 TofTruth_t m_TofTruth;
131 TofMcHit* tofMcHit;
132
133 std::vector<uint32_t>::const_iterator iter = evt->getTofTruth().begin();
134 std::vector<uint32_t>::const_iterator eiter = evt->getTofTruth().end();
135
136 for (int tofMcHitId = 0; iter != eiter; tofMcHitId++) {
137 // retrieve the TofTruth data
138 m_tofMcHitBuilder.unPack(iter, eiter, m_TofTruth);
139 // construct the identifier
140 Identifier ident;
141 unsigned int barrel_ec = m_TofTruth.partId;
142 // for scintillator
143 if( barrel_ec>=0 && barrel_ec<=2 ) {
144 unsigned int layer = 0;
145 if( m_TofTruth.scinNb > TofID::getPHI_BARREL_MAX() ) {
146 layer = 1;
147 m_TofTruth.scinNb -= ( TofID::getPHI_BARREL_MAX() + 1 );
148 }
149 ident = TofID::cell_id( barrel_ec, layer, m_TofTruth.scinNb, 0 );
150 }
151 // for ETF(MRPC)
152 else if( barrel_ec>=3 ) {
153 unsigned int endcap = 0;
154 if( barrel_ec==4 ) { endcap = 1; }
155 ident = TofID::cell_id( 3, endcap, m_TofTruth.scinNb, m_TofTruth.strip, 0 );
156 }
157 else {
158 log << MSG::ERROR << "barrel_ec is not correct! barrel_ec=" << barrel_ec << endreq;
159 }
160
161 //construct the TofMcHit
162 tofMcHit = new TofMcHit(ident, m_TofTruth.trackIndex,
163 m_TofTruth.x/(m_tofMcHitBuilder.m_xCoeff*1.0),
164 m_TofTruth.y/(m_tofMcHitBuilder.m_yCoeff*1.0),
165 m_TofTruth.z/(m_tofMcHitBuilder.m_zCoeff*1.0),
166 m_TofTruth.px/(m_tofMcHitBuilder.m_pxCoeff*1.0),
167 m_TofTruth.py/(m_tofMcHitBuilder.m_pyCoeff*1.0),
168 m_TofTruth.pz/(m_tofMcHitBuilder.m_pzCoeff*1.0),
169 m_TofTruth.trackLength/(m_tofMcHitBuilder.m_trackLengthCoeff*1.0),
170 m_TofTruth.time/(m_tofMcHitBuilder.m_timeCoeff*1.0) );
171 // And add the stuff to the container
172 tofMcHitCol->push_back(tofMcHit);
173 }
174
175 return StatusCode::SUCCESS;
176
177}
178
179StatusCode RawDataTofMcHitCnv::createRep(DataObject* pObj, IOpaqueAddress*& pAddr)
180{
181 // convert PixelRaw in the container into ByteStream
182 //MsgStream log(messageService(), "RawDataTofMcHitCnv");
183
184 WriteRawEvent*& re = m_RawDataAccess->getRawEvent();
185
186 if (re == 0) {
187 //log << " get RawEvent failed !" << endreq;
188 return StatusCode::FAILURE;
189 }
190
191 SmartDataPtr<TofMcHitCol> mcHitCol(dataProvider(), EventModel::MC::TofMcHitCol);
192
193 if (mcHitCol == 0) {
194 //log << "no TofMcHitCol found" << endreq;
195 return StatusCode::FAILURE;
196 }
197
198 StatusCode sc = m_tofMcHitBuilder.pack(mcHitCol, re);
199
200 return sc;
201
202}
203
const CLID & CLID_TofMcHitCol
Definition: EventModel.cxx:218
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
const CLID & CLID_TofMcHitCol
Definition: EventModel.cxx:218
virtual RAWEVENT * currentEvent()=0
StatusCode initialize()
static const CLID & classID()
RawDataTofMcHitCnv(ISvcLocator *svc)
virtual StatusCode updateObj(IOpaqueAddress *, DataObject *)
override the RawDataBaseCnv version
StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj)
virtual StatusCode createRep(DataObject *pObj, IOpaqueAddress *&pAddr)
Convert the transient object to the requested representation.
static Identifier cell_id(int barrel_ec, int layer, int phi_module, int end)
For a single crystal.
Definition: TofID.cxx:143
static value_type getPHI_BARREL_MAX()
Definition: TofID.cxx:217
virtual void unPack(vector< uint32_t >::const_iterator &, vector< uint32_t >::const_iterator &, TofTruth_t &)
virtual StatusCode pack(TofMcHitCol *tofMcHitCol, WriteRawEvent *&re)
ObjectVector< TofMcHit > TofMcHitCol