BOSS 7.0.1
BESIII Offline Software System
Loading...
Searching...
No Matches
RawDataMcPaticleCnv.cxx
Go to the documentation of this file.
1//====================================================================
2// RawDataMcParticleCnv.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 "GaudiKernel/MsgStream.h"
13#include "GaudiKernel/SmartDataPtr.h"
14// for Mutil-thread by tianhl
15#include "GaudiKernel/ThreadGaudi.h"
16// for Mutil-thread by tianhl
17
18#include "EventModel/EventModel.h"
19#include "McTruth/McParticle.h"
20#include "RawDataCnv/EventManagement/RAWEVENT.h"
21#include "RawDataCnv/EventManagement/RawEvent.h"
22#include "RawDataCnv/RawDataInputSvc.h"
23#include "RawDataCnv/RawDataMcParticleCnv.h"
24
27
28
29extern const CLID& CLID_McParticleCol;
30
31// Constructor.
34{
35 //init();
36}
37
38// Return the identification number of this converter to the
39// persistency service.
41{
42 return CLID_McParticleCol;
43}
44
46{
47
48 std::string PackedRawDataCnvSvc_Name("PackedRawDataCnvSvc");
49 std::string RawDataInputSvc_Name("RawDataInputSvc");
50 std::string RawDataMcParticleCnv_Name("RawDataMcParticleCnv");
51
52 // for Mutil-thread by tianhl
53 //ConversionSvc* pCnvSvc = 0;
54 //if (pCnvSvc = dynamic_cast<ConversionSvc*>(conversionSvc())){
55 SmartIF<IService> pCnvSvc(conversionSvc());
56 if (isGaudiThreaded(pCnvSvc->name())){
57 PackedRawDataCnvSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
58 RawDataInputSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
59 RawDataMcParticleCnv_Name += getGaudiThreadIDfromName(pCnvSvc->name());
60 }
61 //}
62
63 MsgStream log(messageService(), RawDataMcParticleCnv_Name.c_str());
64
65 StatusCode sc = RawDataBaseCnv::initialize();
66 if (StatusCode::SUCCESS != sc) {
67 log << MSG::ERROR << "RawDataBaseCnv: Cant initialize PackedRawDataCnvSvc" << endreq;
68 return sc;
69 }
70
71 // Check RawDataCnvSvc
72 IService* isvc = 0;
73 sc = serviceLocator()->service(PackedRawDataCnvSvc_Name.c_str(), isvc, true);
74 if (sc != StatusCode::SUCCESS) {
75 log << MSG::ERROR << "Cant get PackedRawDataCnvSvc" << endreq;
76 }
77
78 m_RawDataAccess = dynamic_cast<PackedRawDataCnvSvc*> (isvc);
79 if (m_RawDataAccess == 0 ) {
80 log << MSG::ERROR << "RawDataMcParticleCnv: Cant cast to RawDataCnvSvc " << endreq;
81 return StatusCode::FAILURE;
82 }
83
84 sc = serviceLocator()->getService(RawDataInputSvc_Name.c_str(), isvc);
85 if (sc != StatusCode::SUCCESS ) {
86 log << MSG::WARNING << "Cant get RawDataInputSvc " << endreq;
87 return sc ;
88 }
89
90 m_inputSvc = dynamic_cast<RawDataInputSvc*> (isvc);
91 if (m_inputSvc == 0 ) {
92 log << MSG::WARNING << "Cant cast to RawDataInputSvc " << endreq;
93 return StatusCode::FAILURE ;
94 }
95
96 return StatusCode::SUCCESS;
97}
98
99
100StatusCode RawDataMcParticleCnv::updateObj(IOpaqueAddress* pAddr, DataObject* pObj) {
101 // Purpose and Method: This method does nothing other than announce it has
102 // been called.
103
104 //MsgStream log(msgSvc(), "RawDataMcParticleCnv");
105 //log << MSG::DEBUG << "RawDataMcParticleCnv::updateObj" << endreq;
106 return Converter::updateObj(pAddr, pObj);
107}
108
109// Create a converted object in the Transient Data Store.
110StatusCode RawDataMcParticleCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
111{
112 //MsgStream log(msgSvc(), "RawDataMcParticleCnv");
113
114 //This converter will create an empty McParticleCol on the TDS
115 McParticleCol *mcParticleCol = new McParticleCol;
116 pObj = mcParticleCol;
117
118 RAWEVENT *evt = m_inputSvc->currentEvent();
119 if (evt == NULL) {
120 //log << MSG::ERROR << "RawDataCnv has no event!" << endreq;
121 return StatusCode::FAILURE;
122 }
123
124 const BufferHolder& mcParBuf = evt->getMcParBuf();
125 if (mcParBuf.nBuf() == 0) {
126 //cerr << "no McParticle Data Buffer found!!!" << endl;
127 return StatusCode::FAILURE;
128 }
129 uint32_t* buf = mcParBuf(0);
130
131 uint32_t nParticle = (buf[0] >> 16);
132 //uint32_t nVertex = (buf[0] & 0xFFFF);
133 double* vPointer = (double*)(buf + nParticle*11 + 1);
134
135 for (uint32_t i = 0; i < nParticle; i++) {
136 McParticle* mcPar = new McParticle;
137 m_mcParticleBuilder.unPack((buf+1+i*11), vPointer, mcPar);
138 mcParticleCol->push_back(mcPar);
139 }
140
141 // Get primary McParticles
142 SmartRefVector<McParticle> primaryParticleCol;
143 McParticleCol::iterator iter_particle = mcParticleCol->begin();
144 for ( ; iter_particle != mcParticleCol->end(); iter_particle++) {
145 if ((*iter_particle)->primaryParticle()) {
146 McParticle* mcPart = (McParticle*)(*iter_particle);
147 primaryParticleCol.push_back(mcPart);
148 }
149 }
150
151 if (primaryParticleCol.empty()) {
152 //log << MSG::WARNING << "createObj error: no primary particle found!" << endreq;
153 }
154
155 // Add mother particle recursively
156 SmartRefVector<McParticle>::iterator iter_primary = primaryParticleCol.begin();
157 //std::cout << "primaryParticleCol.size() = " << primaryParticleCol.size() << std::endl;
158 for ( ; iter_primary != primaryParticleCol.end(); iter_primary++) {
159
160 if (!(*iter_primary)->leafParticle())
161 addMother((*iter_primary), mcParticleCol);
162 }
163
164 return StatusCode::SUCCESS;
165}
166
167StatusCode RawDataMcParticleCnv::createRep(DataObject* /*pObj*/, IOpaqueAddress*& /*pAddr*/)
168{
169 // convert PixelRaw in the container into ByteStream
170 //MsgStream log(messageService(), "RawDataMcParticleCnv");
171
172 WriteRawEvent*& re = m_RawDataAccess->getRawEvent();
173 if (re == 0) {
174 //log << " get RawEvent failed !" << endreq;
175 return StatusCode::FAILURE;
176 }
177
178 SmartDataPtr<McParticleCol> mcParticleCol(dataProvider(), EventModel::MC::McParticleCol);
179 if (mcParticleCol == 0) {
180 //log << "no McParticleCol found" << endreq;
181 return StatusCode::FAILURE;
182 }
183
184 return m_mcParticleBuilder.pack(mcParticleCol, re);
185}
186
187void RawDataMcParticleCnv::addMother(McParticle* currentParticle, McParticleCol *particleCol)
188{
189
190 if (currentParticle->leafParticle()) return;
191
192 bool found = false;
193 McParticleCol::iterator iter = particleCol->begin();
194 //std::cout << "particleCol->size() = " << particleCol->size() << std::endl;
195 for ( ; iter != particleCol->end(); iter++) {
196 if (currentParticle->vertexIndex1() == (*iter)->vertexIndex0()) {
197 found = true;
198 (*iter)->setMother(currentParticle);
199 currentParticle->addDaughter(*iter);
200 addMother((*iter), particleCol);
201 }
202 }
203
204 if (!found)
205 std::cout << "RawDataMcParticleCnv::addMother: inconsistency was found!" << std::endl;
206}
207
const CLID & CLID_McParticleCol
Definition: EventModel.cxx:207
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
const CLID & CLID_McParticleCol
Definition: EventModel.cxx:207
bool leafParticle() const
Retrieve whether this is a leaf particle.
Definition: McParticle.cxx:19
void addDaughter(const SmartRef< McParticle > d)
add a daugther particle to this particle
virtual RAWEVENT * currentEvent()=0
virtual void unPack(uint32_t *buf, double *vPointer, McParticle *mcPar)
virtual StatusCode pack(McParticleCol *mcParticleCol, WriteRawEvent *&re)
StatusCode initialize()
static const CLID & classID()
virtual StatusCode updateObj(IOpaqueAddress *pAddr, DataObject *pObj)
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.
RawDataMcParticleCnv(ISvcLocator *svc)
ObjectList< McParticle > McParticleCol