BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
RawDataTofMcHitCnv.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Identifier/TofID.h"
4#include "McTruth/TofMcHit.h"
5#include "RawDataCnv/EventManagement/McTruthDataStructure.h"
6#include "RawDataCnv/EventManagement/TofMcHitBuilder.h"
7
8#include "RawDataBaseCnv.h"
9
10extern const CLID& CLID_TofMcHitCol;
11
13private:
14 /// TofMcHitBuilder for packing or unpacking data
15 TofMcHitBuilder m_tofMcHitBuilder;
16
17public:
18 RawDataTofMcHitCnv( ISvcLocator* svc ) : RawDataBaseCnv( svc, classID() ) {}
19
20 static const CLID& classID() { return CLID_TofMcHitCol; }
21
22 StatusCode createObj( IOpaqueAddress* pAddr, DataObject*& pObj ) {
23 MsgStream log( msgSvc(), "RawDataTofMcHitCnv" );
24
25 // This converter will create an empty TofMcHitCol on the TDS
26 TofMcHitCol* tofMcHitCol = new TofMcHitCol;
27 pObj = tofMcHitCol;
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 assert( ( evt->getTofTruth().size() ) % 9 == 0 );
37
38 TofTruth_t m_TofTruth;
39 TofMcHit* tofMcHit;
40
41 std::vector<uint32_t>::const_iterator iter = evt->getTofTruth().begin();
42 std::vector<uint32_t>::const_iterator eiter = evt->getTofTruth().end();
43
44 for ( int tofMcHitId = 0; iter != eiter; tofMcHitId++ )
45 {
46 // retrieve the TofTruth data
47 m_tofMcHitBuilder.unPack( iter, eiter, m_TofTruth );
48 // construct the identifier
49 Identifier ident;
50 unsigned int barrel_ec = m_TofTruth.partId;
51 // for scintillator
52 if ( barrel_ec >= 0 && barrel_ec <= 2 )
53 {
54 unsigned int layer = 0;
55 if ( m_TofTruth.scinNb > TofID::getPHI_BARREL_MAX() )
56 {
57 layer = 1;
58 m_TofTruth.scinNb -= ( TofID::getPHI_BARREL_MAX() + 1 );
59 }
60 ident = TofID::cell_id( barrel_ec, layer, m_TofTruth.scinNb, 0 );
61 }
62 // for ETF(MRPC)
63 else if ( barrel_ec >= 3 )
64 {
65 unsigned int endcap = 0;
66 if ( barrel_ec == 4 ) { endcap = 1; }
67 ident = TofID::cell_id( 3, endcap, m_TofTruth.scinNb, m_TofTruth.strip, 0 );
68 }
69 else
70 { log << MSG::ERROR << "barrel_ec is not correct! barrel_ec=" << barrel_ec << endmsg; }
71
72 // construct the TofMcHit
73 tofMcHit = new TofMcHit(
74 ident, m_TofTruth.trackIndex, m_TofTruth.x / ( m_tofMcHitBuilder.m_xCoeff * 1.0 ),
75 m_TofTruth.y / ( m_tofMcHitBuilder.m_yCoeff * 1.0 ),
76 m_TofTruth.z / ( m_tofMcHitBuilder.m_zCoeff * 1.0 ),
77 m_TofTruth.px / ( m_tofMcHitBuilder.m_pxCoeff * 1.0 ),
78 m_TofTruth.py / ( m_tofMcHitBuilder.m_pyCoeff * 1.0 ),
79 m_TofTruth.pz / ( m_tofMcHitBuilder.m_pzCoeff * 1.0 ),
80 m_TofTruth.trackLength / ( m_tofMcHitBuilder.m_trackLengthCoeff * 1.0 ),
81 m_TofTruth.time / ( m_tofMcHitBuilder.m_timeCoeff * 1.0 ) );
82 // And add the stuff to the container
83 tofMcHitCol->push_back( tofMcHit );
84 }
85
86 return StatusCode::SUCCESS;
87 }
88
89 StatusCode createRep( DataObject* pObj, IOpaqueAddress*& pAddr ) {
90 // convert PixelRaw in the container into ByteStream
91 // MsgStream log(msgSvc(), "RawDataTofMcHitCnv");
92
93 WriteRawEvent*& re = m_cnvSvc->getRawEvent();
94
95 if ( re == 0 )
96 {
97 // log << " get RawEvent failed !" << endmsg;
98 return StatusCode::FAILURE;
99 }
100
101 SmartDataPtr<TofMcHitCol> mcHitCol( dataProvider(), EventModel::MC::TofMcHitCol );
102
103 if ( mcHitCol == 0 )
104 {
105 // log << "no TofMcHitCol found" << endmsg;
106 return StatusCode::FAILURE;
107 }
108
109 StatusCode sc = m_tofMcHitBuilder.pack( mcHitCol, re );
110
111 return sc;
112 }
113};
const CLID & CLID_TofMcHitCol
eformat::write::FullEventFragment WriteRawEvent
ObjectVector< TofMcHit > TofMcHitCol
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
const CLID & CLID_TofMcHitCol
IMessageSvc * msgSvc()
IRawDataCnvSvc * m_cnvSvc
IRawDataInputSvc * m_inputSvc
RawDataBaseCnv(long storageType, const CLID &clid, ISvcLocator *svc)
static const CLID & classID()
RawDataTofMcHitCnv(ISvcLocator *svc)
StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj)
StatusCode createRep(DataObject *pObj, IOpaqueAddress *&pAddr)
static Identifier cell_id(int barrel_ec, int layer, int phi_module, int end)
For a single crystal.
Definition TofID.cxx:126
static value_type getPHI_BARREL_MAX()
Definition TofID.cxx:167