BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
RawDataMcParticleCnv.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "McTruth/McParticle.h"
4#include "RawDataCnv/EventManagement/McParticleBuilder.h"
5#include "RawDataCnv/EventManagement/McTruthDataStructure.h"
6#include "RawDataCnv/EventManagement/RAWEVENT.h"
7#include "RawDataCnv/EventManagement/RawEventDef.h"
8
9#include "RawDataBaseCnv.h"
10
11extern const CLID& CLID_McParticleCol;
12
14private:
15 McParticleBuilder m_mcParticleBuilder;
16
17public:
18 RawDataMcParticleCnv( ISvcLocator* svc ) : RawDataBaseCnv( svc, classID() ) {}
19
20 static const CLID& classID() { return CLID_McParticleCol; }
21
22 StatusCode createObj( IOpaqueAddress* pAddr, DataObject*& pObj ) {
23 // MsgStream log(msgSvc(), "RawDataMcParticleCnv");
24
25 // This converter will create an empty McParticleCol on the TDS
26 McParticleCol* mcParticleCol = new McParticleCol;
27 pObj = mcParticleCol;
28
29 RAWEVENT* evt = m_inputSvc->currentEvent();
30 if ( evt == NULL )
31 {
32 // log << MSG::ERROR << "RawDataCnv has no event!" << endmsg;
33 return StatusCode::FAILURE;
34 }
35
36 const BufferHolder& mcParBuf = evt->getMcParBuf();
37 if ( mcParBuf.nBuf() == 0 )
38 {
39 // cerr << "no McParticle Data Buffer found!!!" << endl;
40 return StatusCode::FAILURE;
41 }
42 uint32_t* buf = mcParBuf( 0 );
43
44 uint32_t nParticle = ( buf[0] >> 16 );
45 // uint32_t nVertex = (buf[0] & 0xFFFF);
46 double* vPointer = (double*)( buf + nParticle * 11 + 1 );
47
48 for ( uint32_t i = 0; i < nParticle; i++ )
49 {
50 McParticle* mcPar = new McParticle;
51 m_mcParticleBuilder.unPack( ( buf + 1 + i * 11 ), vPointer, mcPar );
52 mcParticleCol->push_back( mcPar );
53 }
54
55 // Get primary McParticles
56 SmartRefVector<McParticle> primaryParticleCol;
57 McParticleCol::iterator iter_particle = mcParticleCol->begin();
58 for ( ; iter_particle != mcParticleCol->end(); iter_particle++ )
59 {
60 if ( ( *iter_particle )->primaryParticle() )
61 {
62 McParticle* mcPart = (McParticle*)( *iter_particle );
63 primaryParticleCol.push_back( mcPart );
64 }
65 }
66
67 if ( primaryParticleCol.empty() )
68 {
69 // log << MSG::WARNING << "createObj error: no primary particle found!" << endmsg;
70 }
71
72 // Add mother particle recursively
73 SmartRefVector<McParticle>::iterator iter_primary = primaryParticleCol.begin();
74 // std::cout << "primaryParticleCol.size() = " << primaryParticleCol.size() << std::endl;
75 for ( ; iter_primary != primaryParticleCol.end(); iter_primary++ )
76 {
77
78 if ( !( *iter_primary )->leafParticle() ) addMother( ( *iter_primary ), mcParticleCol );
79 }
80
81 return StatusCode::SUCCESS;
82 }
83
84 StatusCode createRep( DataObject* /*pObj*/, IOpaqueAddress*& /*pAddr*/ ) {
85 // convert PixelRaw in the container into ByteStream
86 // MsgStream log(msgSvc(), "RawDataMcParticleCnv");
87
88 WriteRawEvent*& re = m_cnvSvc->getRawEvent();
89 if ( re == 0 )
90 {
91 // log << " get RawEvent failed !" << endmsg;
92 return StatusCode::FAILURE;
93 }
94
95 SmartDataPtr<McParticleCol> mcParticleCol( dataProvider(), EventModel::MC::McParticleCol );
96 if ( mcParticleCol == 0 )
97 {
98 // log << "no McParticleCol found" << endmsg;
99 return StatusCode::FAILURE;
100 }
101
102 return m_mcParticleBuilder.pack( mcParticleCol, re );
103 }
104
105 void addMother( McParticle* currentParticle, McParticleCol* particleCol ) {
106
107 if ( currentParticle->leafParticle() ) return;
108
109 bool found = false;
110 McParticleCol::iterator iter = particleCol->begin();
111 // std::cout << "particleCol->size() = " << particleCol->size() << std::endl;
112 for ( ; iter != particleCol->end(); iter++ )
113 {
114 if ( currentParticle->vertexIndex1() == ( *iter )->vertexIndex0() )
115 {
116 found = true;
117 ( *iter )->setMother( currentParticle );
118 currentParticle->addDaughter( *iter );
119 addMother( ( *iter ), particleCol );
120 }
121 }
122
123 if ( !found )
124 std::cout << "RawDataMcParticleCnv::addMother: inconsistency was found!" << std::endl;
125 }
126};
const CLID & CLID_McParticleCol
ObjectList< McParticle > McParticleCol
eformat::write::FullEventFragment WriteRawEvent
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
const CLID & CLID_McParticleCol
The Monte Carlo particle kinematics information.
IRawDataCnvSvc * m_cnvSvc
IRawDataInputSvc * m_inputSvc
RawDataBaseCnv(long storageType, const CLID &clid, ISvcLocator *svc)
void addMother(McParticle *currentParticle, McParticleCol *particleCol)
static const CLID & classID()
StatusCode createRep(DataObject *, IOpaqueAddress *&)
StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj)
RawDataMcParticleCnv(ISvcLocator *svc)