00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "GaudiKernel/StatusCode.h"
00013 #include "GaudiKernel/Converter.h"
00014 #include "GaudiKernel/SmartDataPtr.h"
00015 #include "GaudiKernel/MsgStream.h"
00016
00017 #include "GaudiKernel/ThreadGaudi.h"
00018
00019
00020 #include "EventModel/EventModel.h"
00021 #include "EmcRawEvent/EmcDigi.h"
00022 #include "RawDataCnv/EventManagement/RAWEVENT.h"
00023 #include "RawDataCnv/EventManagement/RawEvent.h"
00024 #include "RawDataCnv/RawDataInputSvc.h"
00025 #include "RawDataCnv/PackedRawDataCnvSvc.h"
00026 #include "RawDataCnv/Util/EmcConverter.h"
00027 #include "RawDataCnv/RawDataEmcDigiCnv.h"
00028
00029
00030 extern const CLID& CLID_EmcDigiCol;
00031
00032
00033 RawDataEmcDigiCnv::RawDataEmcDigiCnv(ISvcLocator* svc) :
00034 RawDataBaseCnv(PACKEDRAWEVENT_StorageType, classID(), svc)
00035 {
00036 }
00037 RawDataEmcDigiCnv::~RawDataEmcDigiCnv(){
00038 EmcConverter::destroy();
00039 }
00040
00041
00042
00043 const CLID& RawDataEmcDigiCnv::classID()
00044 {
00045 return CLID_EmcDigiCol;
00046 }
00047
00048 StatusCode RawDataEmcDigiCnv::initialize()
00049 {
00050 std::string PackedRawDataCnvSvc_Name("PackedRawDataCnvSvc");
00051 std::string RawDataInputSvc_Name("RawDataInputSvc");
00052 std::string RawDataEmcDigiCnv_Name("RawDataEmcDigiCnv");
00053
00054
00055
00056
00057 SmartIF<IService> pCnvSvc(conversionSvc());
00058
00059 if (isGaudiThreaded(pCnvSvc->name())){
00060 PackedRawDataCnvSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
00061 RawDataInputSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
00062 RawDataEmcDigiCnv_Name += getGaudiThreadIDfromName(pCnvSvc->name());
00063
00064 }
00065
00066
00067 MsgStream log(msgSvc(), RawDataEmcDigiCnv_Name.c_str());
00068
00069 StatusCode sc = RawDataBaseCnv::initialize();
00070 if ( sc.isFailure() ) {
00071 return sc;
00072 }
00073
00074
00075 IService* isvc = 0;
00076 StatusCode status = serviceLocator()->service(PackedRawDataCnvSvc_Name.c_str(), isvc, true);
00077 m_RawDataAccess = dynamic_cast<PackedRawDataCnvSvc*> (isvc);
00078 if(m_RawDataAccess == 0 ) {
00079 log<<MSG::ERROR<< " RawDataCnv: Cant cast to RawDataCnvSvc " <<endreq;
00080 return StatusCode::FAILURE ;
00081 }
00082
00083 IService* svc ;
00084 sc = serviceLocator()->getService(RawDataInputSvc_Name.c_str(), svc);
00085
00086
00087
00088
00089 m_inputSvc = dynamic_cast<RawDataInputSvc*> (svc);
00090 if ( m_inputSvc == 0 ) {
00091 log<<MSG::WARNING<< " Cant cast to RawDataInputSvc " <<endreq;
00092 return StatusCode::FAILURE ;
00093 }
00094
00095 m_cnv = EmcConverter::instance( m_inputSvc->runMode() );
00096
00097 return StatusCode::SUCCESS;
00098 }
00099
00100
00101 StatusCode RawDataEmcDigiCnv::updateObj(IOpaqueAddress* pAddr, DataObject* pObj) {
00102
00103
00104
00105 MsgStream log(msgSvc(), "RawDataEmcDigiCnv");
00106 log << MSG::DEBUG << "RawDataEmcDigiCnv::updateObj" << endreq;
00107 return Converter::updateObj(pAddr, pObj);
00108 }
00109
00110
00111 StatusCode RawDataEmcDigiCnv::createObj(IOpaqueAddress*, DataObject*& pObj)
00112 {
00113 MsgStream log(msgSvc(), "RawDataEmcDigiCnv");
00114
00115
00116
00117 EmcDigiCol *digiCol = new EmcDigiCol;
00118 pObj = digiCol;
00119
00120 RAWEVENT *evt = m_inputSvc->currentEvent();
00121 if (evt == NULL) {
00122 cout << "RawDataEmcDigiCnv::createObj can't get event!" << endl;
00123 return StatusCode::FAILURE;
00124 }
00125
00126 const BufferHolder& emcBuf = evt->getEmcBuf();
00127
00128 return m_cnv->convert(emcBuf, digiCol);
00129 }
00130
00131 StatusCode RawDataEmcDigiCnv::createRep(DataObject*, IOpaqueAddress*&)
00132 {
00133
00134 MsgStream log(msgSvc(), "RawDataEmcDigiCnv");
00135
00136 WriteRawEvent*& re = m_RawDataAccess->getRawEvent();
00137 if (re == 0) {
00138 log << " get RawEvent failed !" << endreq;
00139 return StatusCode::FAILURE;
00140 }
00141
00142 SmartDataPtr<EmcDigiCol> digiCol(dataProvider(), EventModel::Digi::EmcDigiCol);
00143 if (digiCol == 0) {
00144 log << "no EmcDigiCol found" << endreq;
00145 return StatusCode::FAILURE;
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162 return m_cnv->convert(digiCol, re);
00163 }