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