BOSS 6.6.4.p01
BESIII Offline Software System
Loading...
Searching...
No Matches
RawDataTofMcHitCnv.cxx
Go to the documentation of this file.
1//====================================================================
2// RawDataTofMcHitCnv.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
22#include "Identifier/TofID.h"
23#include "McTruth/TofMcHit.h"
28
30
31
32using Event::TofMcHit;
34
35
36extern const CLID& CLID_TofMcHitCol;
37
38// Constructor.
41{
42 //init();
43}
44
45// Return the identification number of this converter to the
46// persistency service.
48{
49 return CLID_TofMcHitCol;
50}
51
53{
54
55 std::string PackedRawDataCnvSvc_Name("PackedRawDataCnvSvc");
56 std::string RawDataInputSvc_Name("RawDataInputSvc");
57 std::string RawDataTofMcHitCnv_Name("RawDataTofMcHitCnv");
58
59 // for Mutil-thread by tianhl
60 //ConversionSvc* pCnvSvc = 0;
61 //if (pCnvSvc = dynamic_cast<ConversionSvc*>(conversionSvc())){
62 SmartIF<IService> pCnvSvc(conversionSvc());
63 if (isGaudiThreaded(pCnvSvc->name())){
64 PackedRawDataCnvSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
65 RawDataInputSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
66 RawDataTofMcHitCnv_Name += getGaudiThreadIDfromName(pCnvSvc->name());
67 }
68 //}
69
70 MsgStream log(messageService(), RawDataTofMcHitCnv_Name.c_str());
71
72 StatusCode sc = RawDataBaseCnv::initialize();
73 if (StatusCode::SUCCESS != sc) {
74 log << MSG::ERROR << "RawDataBaseCnv: Cant initialize PackedRawDataCnvSvc" << endreq;
75 return sc;
76 }
77
78 // Check RawDataCnvSvc
79 IService* isvc = 0;
80 sc = serviceLocator()->service(PackedRawDataCnvSvc_Name.c_str(), isvc, true);
81 if (sc != StatusCode::SUCCESS) {
82 log << MSG::ERROR << "Cant get PackedRawDataCnvSvc" << endreq;
83 }
84
85 m_RawDataAccess = dynamic_cast<PackedRawDataCnvSvc*> (isvc);
86 if (m_RawDataAccess == 0 ) {
87 log << MSG::ERROR << "RawDataTofCnv: Cant cast to RawDataCnvSvc " << endreq;
88 return StatusCode::FAILURE;
89 }
90
91 sc = serviceLocator()->getService(RawDataInputSvc_Name.c_str(), isvc);
92 if (sc != StatusCode::SUCCESS ) {
93 log << MSG::WARNING << "Cant get RawDataInputSvc " << endreq;
94 return sc ;
95 }
96
97 m_inputSvc = dynamic_cast<RawDataInputSvc*> (isvc);
98 if (m_inputSvc == 0 ) {
99 log << MSG::WARNING << "Cant cast to RawDataInputSvc " << endreq;
100 return StatusCode::FAILURE ;
101 }
102
103 return StatusCode::SUCCESS;
104}
105
106
107StatusCode RawDataTofMcHitCnv::updateObj(IOpaqueAddress* pAddr, DataObject* pObj) {
108 // Purpose and Method: This method does nothing other than announce it has
109 // been called.
110
111 //MsgStream log(msgSvc(), "RawDataTofMcHitCnv");
112 //log << MSG::DEBUG << "RawDataTofMcHitCnv::updateObj" << endreq;
113 return Converter::updateObj(pAddr, pObj);
114}
115
116// Create a converted object in the Transient Data Store.
117StatusCode RawDataTofMcHitCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
118{
119 //MsgStream log(msgSvc(), "RawDataTofMcHitCnv");
120
121 //This converter will create an empty TofMcHitCol on the TDS
122 TofMcHitCol *tofMcHitCol = new TofMcHitCol;
123 pObj = tofMcHitCol;
124
125 RAWEVENT *evt = m_inputSvc->currentEvent();
126 if (evt == NULL) {
127 //log << MSG::ERROR << "RawDataCnv has no event!" << endreq;
128 return StatusCode::FAILURE;
129 }
130
131 assert((evt->getTofTruth().size())%9 == 0);
132
133 TofTruth_t m_TofTruth;
134 TofMcHit* tofMcHit;
135
136 std::vector<uint32_t>::const_iterator iter = evt->getTofTruth().begin();
137 std::vector<uint32_t>::const_iterator eiter = evt->getTofTruth().end();
138
139 for (int tofMcHitId = 0; iter != eiter; tofMcHitId++) {
140 // retrieve the TofTruth data
141 m_tofMcHitBuilder.unPack(iter, eiter, m_TofTruth);
142 // construct the identifier
143 unsigned int layer = 0;
144 unsigned int barrel_ec = m_TofTruth.partId;
145 if (TofID::is_barrel(barrel_ec) && m_TofTruth.scinNb > TofID::getPHI_BARREL_MAX()) {
146 layer = 1;
147 m_TofTruth.scinNb -= (TofID::getPHI_BARREL_MAX() + 1);
148 }
149
150
151
152
153
154
155
156
157 Identifier ident;
158
159 if(barrel_ec==0 || barrel_ec==1 || barrel_ec==2 ) //Old-Tof
160 {
161 ident = TofID::cell_id(barrel_ec, layer, m_TofTruth.scinNb, 0);
162 }
163 else //MRPC Part
164 {
165 int help = BesTofDigitizerEcV4::Calculate_Readoutstrip_number_continuum(m_TofTruth.x*mm, m_TofTruth.y*mm, barrel_ec, m_TofTruth.scinNb);
167 ident = TofID::cell_id_mrpc_mc( barrel_ec, scinNum);
168 }
169
170
171
172
173
174
175
176 //construct the TofMcHit
177 tofMcHit = new TofMcHit(ident, m_TofTruth.trackIndex,
178 m_TofTruth.x/(m_tofMcHitBuilder.m_xCoeff*1.0),
179 m_TofTruth.y/(m_tofMcHitBuilder.m_yCoeff*1.0),
180 m_TofTruth.z/(m_tofMcHitBuilder.m_zCoeff*1.0),
181 m_TofTruth.px/(m_tofMcHitBuilder.m_pxCoeff*1.0),
182 m_TofTruth.py/(m_tofMcHitBuilder.m_pyCoeff*1.0),
183 m_TofTruth.pz/(m_tofMcHitBuilder.m_pzCoeff*1.0),
184 m_TofTruth.trackLength/(m_tofMcHitBuilder.m_trackLengthCoeff*1.0),
185 m_TofTruth.time/(m_tofMcHitBuilder.m_timeCoeff*1.0) );
186 // And add the stuff to the container
187 tofMcHitCol->push_back(tofMcHit);
188 }
189
190 return StatusCode::SUCCESS;
191
192}
193
194StatusCode RawDataTofMcHitCnv::createRep(DataObject* pObj, IOpaqueAddress*& pAddr)
195{
196 // convert PixelRaw in the container into ByteStream
197 //MsgStream log(messageService(), "RawDataTofMcHitCnv");
198
199 WriteRawEvent*& re = m_RawDataAccess->getRawEvent();
200
201 if (re == 0) {
202 //log << " get RawEvent failed !" << endreq;
203 return StatusCode::FAILURE;
204 }
205
206 SmartDataPtr<TofMcHitCol> mcHitCol(dataProvider(), EventModel::MC::TofMcHitCol);
207
208 if (mcHitCol == 0) {
209 //log << "no TofMcHitCol found" << endreq;
210 return StatusCode::FAILURE;
211 }
212
213 StatusCode sc = m_tofMcHitBuilder.pack(mcHitCol, re);
214
215 return sc;
216
217}
218
unsigned const long PACKEDRAWEVENT_StorageType
Definition: ClassID_temp.h:17
const CLID & CLID_TofMcHitCol
Definition: EventModel.cxx:214
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
std::string help()
Definition: HelloServer.cpp:35
const CLID & CLID_TofMcHitCol
Definition: EventModel.cxx:214
static G4int Produce_unique_identifier(G4int module_mrpc_f, G4int readoutstripnumber_f)
static G4int Calculate_Readoutstrip_number_continuum(G4double x_mm, G4double y_mm, G4int partId_f, G4int module_mrpc_f)
virtual RAWEVENT * currentEvent()=0
virtual WriteRawEvent *& getRawEvent()
const int_vector & getTofTruth() const
Definition: RAWEVENT.h:98
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:156
static value_type getPHI_BARREL_MAX()
Definition: TofID.cxx:237
static bool is_barrel(const Identifier &id)
Test for barrel.
Definition: TofID.cxx:78
static Identifier cell_id_mrpc_mc(int partID, int scinNum)
Definition: TofID.cxx:189
virtual void unPack(vector< uint32_t >::const_iterator &, vector< uint32_t >::const_iterator &, TofTruth_t &)
uint64_t m_trackLengthCoeff
uint64_t m_timeCoeff
virtual StatusCode pack(TofMcHitCol *tofMcHitCol, WriteRawEvent *&re)
_EXTERN_ std::string TofMcHitCol
Definition: EventModel.h:45
ObjectVector< TofMcHit > TofMcHitCol
Definition: TofMcHit.h:100