00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "GaudiKernel/MsgStream.h"
00013 #include "GaudiKernel/SmartDataPtr.h"
00014
00015 #include "GaudiKernel/ThreadGaudi.h"
00016
00017
00018 #include "EventModel/EventModel.h"
00019 #include "Identifier/HltID.h"
00020 #include "HltEvent/HltRaw.h"
00021 #include "RawDataCnv/EventManagement/RAWEVENT.h"
00022 #include "RawDataCnv/EventManagement/RawEvent.h"
00023 #include "RawDataCnv/RawDataAddress.h"
00024 #include "RawDataCnv/RawDataInputSvc.h"
00025 #include "RawDataCnv/RawDataHltRawCnv.h"
00026
00027
00028 extern const CLID& CLID_HltRawCol;
00029
00030
00031 RawDataHltRawCnv::RawDataHltRawCnv(ISvcLocator* svc) :
00032 RawDataBaseCnv(PACKEDRAWEVENT_StorageType, classID(), svc)
00033 {
00034
00035 }
00036 RawDataHltRawCnv::~RawDataHltRawCnv(){
00037 }
00038
00039
00040
00041 const CLID& RawDataHltRawCnv::classID()
00042 {
00043 return CLID_HltRawCol;
00044 }
00045
00046 StatusCode RawDataHltRawCnv::initialize()
00047 {
00048 std::string PackedRawDataCnvSvc_Name("PackedRawDataCnvSvc");
00049 std::string RawDataInputSvc_Name("RawDataInputSvc");
00050 std::string RawDataHltRawCnv_Name("RawDataHltRawCnv");
00051
00052
00053
00054
00055 SmartIF<IService> pCnvSvc(conversionSvc());
00056 if (isGaudiThreaded(pCnvSvc->name())){
00057 PackedRawDataCnvSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
00058 RawDataInputSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
00059 RawDataHltRawCnv_Name += getGaudiThreadIDfromName(pCnvSvc->name());
00060 }
00061
00062
00063 MsgStream log(messageService(), RawDataHltRawCnv_Name.c_str());
00064 StatusCode sc = RawDataBaseCnv::initialize();
00065 if (StatusCode::SUCCESS != sc) {
00066
00067 return sc;
00068 }
00069
00070
00071 IService* isvc = 0;
00072 StatusCode status = serviceLocator()->service(PackedRawDataCnvSvc_Name.c_str(), isvc, true);
00073
00074 m_RawDataAccess = dynamic_cast<PackedRawDataCnvSvc*> (isvc);
00075 if(m_RawDataAccess == 0 ) {
00076 log<<MSG::ERROR<< " RawDataCnv: Cant cast to RawDataCnvSvc " <<endreq;
00077 return StatusCode::FAILURE ;
00078 }
00079
00080 if(m_RawDataAccess)
00081 log << MSG::INFO << "RawDataCnvSvc retrieved "<< endreq;
00082
00083 IService* svc ;
00084 sc = serviceLocator()->getService(RawDataInputSvc_Name.c_str(), svc);
00085 if(sc != StatusCode::SUCCESS ) {
00086 log<<MSG::WARNING << " Cant get RawDataInputSvc " <<endreq;
00087 return sc ;
00088 }
00089
00090 m_inputSvc = dynamic_cast<RawDataInputSvc*> (svc);
00091 if(m_inputSvc == 0 ) {
00092 log<<MSG::WARNING<< " Cant cast to RawDataInputSvc " <<endreq;
00093 return StatusCode::FAILURE ;
00094 }
00095
00096 return StatusCode::SUCCESS;
00097 }
00098
00099
00100 StatusCode RawDataHltRawCnv::updateObj(IOpaqueAddress* pAddr, DataObject* pObj) {
00101
00102
00103
00104
00105
00106 return Converter::updateObj(pAddr, pObj);
00107 }
00108
00109
00110 StatusCode RawDataHltRawCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
00111 {
00112
00113 RawDataAddress *pEFAddr;
00114 uint32_t TEData[2];
00115
00116
00117
00118 HltRawCol *digiCol = new HltRawCol;
00119 pObj = digiCol;
00120
00121 RAWEVENT *evt = m_inputSvc->currentEvent();
00122 if (evt == NULL) {
00123 cout << "RawDataHltRawCnv::createObj can't get event!" << endl;
00124 return StatusCode::FAILURE;
00125 }
00126
00127 int digiId = 0;
00128 const BufferHolder& hltBuf = evt->getHltBuf();
00129 uint32_t nbuf = hltBuf.nBuf();
00130
00131 uint32_t REId = 0, TEId = 0;
00132 uint32_t nmdc=0,ntof=0,nemc=0,nmuc=0;
00133 for (uint32_t i = 0; i < nbuf; i++) {
00134 uint32_t* buf = hltBuf(i);
00135 uint32_t bufSize = hltBuf.bufSize(i);
00136 for (uint32_t j = 0; j < bufSize; j++, digiId++) {
00137
00138 m_hltBuilder.unPack(buf[j], digiId, REId, TEData[0], TEData[1]);
00139 TEId = m_hltBuilder.getTEID(REId);
00140 if ( TEId == 0xFFFFFFFF ) continue;
00141
00142
00143
00144 for (uint32_t k=0; k< 2;k++){
00145
00146 if(k==0||(k==1&&TEData[k])){
00147 if(k==1) TEId+=1;
00148 if(HltID::is_number(HltID::convert(TEId))) {
00149 nmdc=TEData[k]&0xFF;
00150 ntof=(TEData[k]>>8)&0xFF;
00151 nemc=(TEData[k]>>16)&0xFF;
00152 nmuc=(TEData[k]>>24)&0xFF;
00153
00154 }
00155 HltRaw* hltRaw = new HltRaw(HltID::convert(TEId,nmdc,ntof,nemc,nmuc));
00156 hltRaw->setIntChannel(TEData[k]);
00157
00158 hltRaw->setChargeChannel(TEData[k]);
00159
00160 digiCol->push_back ( hltRaw );
00161 }
00162 }
00163 }
00164 }
00165 return StatusCode::SUCCESS;
00166 }
00167
00168 StatusCode RawDataHltRawCnv::createRep(DataObject* pObj, IOpaqueAddress*& pAddr)
00169 {
00170
00171
00172
00173 WriteRawEvent*& re = m_RawDataAccess->getRawEvent();
00174 if(re == 0) {
00175
00176 return StatusCode::FAILURE;
00177 }
00178
00179 SmartDataPtr<HltRawCol> digiCol(dataProvider(), EventModel::Hlt::HltRawCol);
00180 if (digiCol == 0) {
00181
00182 return StatusCode::FAILURE;
00183 }
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 return m_hltBuilder.pack(digiCol, re);
00199 }
00200
00201