00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <assert.h>
00013 #include <vector>
00014 #include "GaudiKernel/MsgStream.h"
00015 #include "GaudiKernel/SmartDataPtr.h"
00016
00017 #include "GaudiKernel/ThreadGaudi.h"
00018
00019
00020 #include "EventModel/EventModel.h"
00021 #include "Identifier/Identifier.h"
00022 #include "Identifier/MucID.h"
00023 #include "McTruth/MucMcHit.h"
00024 #include "RawDataCnv/EventManagement/RAWEVENT.h"
00025 #include "RawDataCnv/EventManagement/RawEvent.h"
00026 #include "RawDataCnv/RawDataInputSvc.h"
00027 #include "RawDataCnv/RawDataMucMcHitCnv.h"
00028
00029
00030 using Event::MucMcHit;
00031 using Event::MucMcHitCol;
00032
00033
00034
00035 extern const CLID& CLID_MucMcHitCol;
00036
00037
00038 RawDataMucMcHitCnv::RawDataMucMcHitCnv(ISvcLocator* svc) :
00039 RawDataBaseCnv(PACKEDRAWEVENT_StorageType, classID(), svc)
00040 {
00041
00042 }
00043
00044
00045
00046 const CLID& RawDataMucMcHitCnv::classID()
00047 {
00048 return CLID_MucMcHitCol;
00049 }
00050
00051 StatusCode RawDataMucMcHitCnv::initialize()
00052 {
00053 std::string PackedRawDataCnvSvc_Name("PackedRawDataCnvSvc");
00054 std::string RawDataInputSvc_Name("RawDataInputSvc");
00055 std::string RawDataMucMcHitCnv_Name("RawDataMucMcHitCnv");
00056
00057
00058
00059
00060 SmartIF<IService> pCnvSvc(conversionSvc());
00061 if (isGaudiThreaded(pCnvSvc->name())){
00062 PackedRawDataCnvSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
00063 RawDataInputSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
00064 RawDataMucMcHitCnv_Name += getGaudiThreadIDfromName(pCnvSvc->name());
00065 }
00066
00067
00068
00069 MsgStream log(messageService(), RawDataMucMcHitCnv_Name.c_str());
00070
00071 StatusCode sc = RawDataBaseCnv::initialize();
00072 if (StatusCode::SUCCESS != sc) {
00073 log << MSG::ERROR << "RawDataBaseCnv: Cant initialize PackedRawDataCnvSvc" << endreq;
00074 return sc;
00075 }
00076
00077
00078 IService* isvc = 0;
00079 sc = serviceLocator()->service(PackedRawDataCnvSvc_Name.c_str(), isvc, true);
00080 if (sc != StatusCode::SUCCESS) {
00081 log << MSG::ERROR << "Cant get PackedRawDataCnvSvc" << endreq;
00082 }
00083
00084 m_RawDataAccess = dynamic_cast<PackedRawDataCnvSvc*> (isvc);
00085 if (m_RawDataAccess == 0 ) {
00086 log << MSG::ERROR << "RawDataMucCnv: Cant cast to RawDataCnvSvc " << endreq;
00087 return StatusCode::FAILURE;
00088 }
00089
00090 sc = serviceLocator()->getService(RawDataInputSvc_Name.c_str(), isvc);
00091 if (sc != StatusCode::SUCCESS ) {
00092 log << MSG::WARNING << "Cant get RawDataInputSvc " << endreq;
00093 return sc ;
00094 }
00095
00096 m_inputSvc = dynamic_cast<RawDataInputSvc*> (isvc);
00097 if (m_inputSvc == 0 ) {
00098 log << MSG::WARNING << "Cant cast to RawDataInputSvc " << endreq;
00099 return StatusCode::FAILURE ;
00100 }
00101
00102 return StatusCode::SUCCESS;
00103 }
00104
00105
00106 StatusCode RawDataMucMcHitCnv::updateObj(IOpaqueAddress* pAddr, DataObject* pObj) {
00107
00108
00109
00110
00111
00112 return Converter::updateObj(pAddr, pObj);
00113 }
00114
00115
00116 StatusCode RawDataMucMcHitCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
00117 {
00118
00119
00120
00121 MucMcHitCol *mucMcHitCol = new MucMcHitCol;
00122 pObj = mucMcHitCol;
00123
00124 RAWEVENT *evt = m_inputSvc->currentEvent();
00125 if (evt == NULL) {
00126
00127 return StatusCode::FAILURE;
00128 }
00129
00130 assert((evt->getMucTruth().size()%7) == 0);
00131
00132 MucMcHit* mucMcHit;
00133 MucTruth_t m_MucTruth;
00134
00135 std::vector<uint32_t>::const_iterator iter = evt->getMucTruth().begin();
00136 std::vector<uint32_t>::const_iterator eiter = evt->getMucTruth().end();
00137
00138 for (int mucMcHitId = 0; iter != eiter; mucMcHitId++) {
00139
00140 m_mucMcHitBuilder.unPack(iter, eiter, m_MucTruth);
00141
00142 const Identifier ident = MucID::channel_id
00143 (m_MucTruth.partId, m_MucTruth.segId, m_MucTruth.gapId, m_MucTruth.stripId);
00144
00145 mucMcHit = new MucMcHit(ident, m_MucTruth.trackIndex%1000,
00146 m_MucTruth.x/(m_mucMcHitBuilder.m_xCoeff*1.0),
00147 m_MucTruth.y/(m_mucMcHitBuilder.m_yCoeff*1.0),
00148 m_MucTruth.z/(m_mucMcHitBuilder.m_zCoeff*1.0),
00149 m_MucTruth.px/(m_mucMcHitBuilder.m_pxCoeff*1.0),
00150 m_MucTruth.py/(m_mucMcHitBuilder.m_pyCoeff*1.0),
00151 m_MucTruth.pz/(m_mucMcHitBuilder.m_pzCoeff*1.0) );
00152
00153 mucMcHitCol->push_back(mucMcHit);
00154 }
00155
00156 return StatusCode::SUCCESS;
00157
00158 }
00159
00160 StatusCode RawDataMucMcHitCnv::createRep(DataObject* pObj, IOpaqueAddress*& pAddr)
00161 {
00162
00163
00164
00165 WriteRawEvent*& re = m_RawDataAccess->getRawEvent();
00166
00167 if (re == 0) {
00168
00169 return StatusCode::FAILURE;
00170 }
00171
00172 SmartDataPtr<MucMcHitCol> mcHitCol(dataProvider(), EventModel::MC::MucMcHitCol);
00173
00174 if (mcHitCol == 0) {
00175
00176 return StatusCode::FAILURE;
00177 }
00178
00179 StatusCode sc = m_mucMcHitBuilder.pack(mcHitCol, re);
00180
00181 return sc;
00182
00183 }
00184