00001 #ifndef HltInfCnv_CXX 00002 #define HltInfCnv_CXX 1 00003 00004 #include "GaudiKernel/MsgStream.h" 00005 #include "GaudiKernel/DataObject.h" 00006 00007 #include "TClonesArray.h" 00008 00009 #include "EventModel/EventModel.h" 00010 #include "Identifier/HltID.h" 00011 #include "HltEvent/HltEvent.h" //TDS object 00012 #include "HltEvent/HltInf.h" //TDS object 00013 #include "RootEventData/THltEvent.h" // standard root object 00014 #include "RootEventData/THltInf.h" // standard root object 00015 #include "RootCnvSvc/Hlt/HltCnv.h" 00016 #include "RootCnvSvc/Hlt/HltInfCnv.h" 00017 #include "RootCnvSvc/RootAddress.h" 00018 00019 00020 // Instantiation of a static factory class used by clients to create 00021 // instances of this service 00022 00023 HltInfCnv::HltInfCnv(ISvcLocator* svc) 00024 : RootEventBaseCnv(classID(), svc), 00025 m_old(false) 00026 { 00027 // Here we associate this converter with the /Event path on the TDS. 00028 MsgStream log(msgSvc(), "HltInfCnv"); 00029 //log << MSG::DEBUG << "Constructor called for " << objType() << endreq; 00030 m_rootBranchname ="m_hltInf"; 00031 //declareObject(EventModel::MC::HltInf, objType(), m_rootTreename, m_rootBranchname); 00032 m_adresses.push_back(&m_hltInf); 00033 m_hltInf=0; 00034 } 00035 00036 StatusCode HltInfCnv::TObjectToDataObject(DataObject*& refpObject) { 00037 // creation of TDS object from root object 00038 00039 MsgStream log(msgSvc(), "HltInfCnv"); 00040 log << MSG::DEBUG << "HltInfCnv::TObjectToDataObject" << endreq; 00041 StatusCode sc=StatusCode::SUCCESS; 00042 00043 // create the TDS location for the trigger data 00044 HltInf* hltInfTds = new HltInf; 00045 refpObject=hltInfTds; 00046 00047 // now convert 00048 if(!m_hltInf) return sc; 00049 00050 int evt = m_hltInf->getEventType(); 00051 int alg = m_hltInf->getAlgProcess(); 00052 int cri = m_hltInf->getCriteriaTable(); 00053 int ver = m_hltInf->getVersion(); 00054 float etot = m_hltInf->getTotalEnergy(); 00055 hltInfTds->setEventType(evt); 00056 hltInfTds->setAlgProcess(alg); 00057 hltInfTds->setCriteriaTable(cri); 00058 hltInfTds->setVersion(ver); 00059 hltInfTds->setTotalEnergy(etot); 00060 00061 try{ 00062 uint32_t nsub= m_hltInf->getNumber(); 00063 uint32_t ncon= m_hltInf->getNCON(); 00064 uint32_t nmdc= nsub &0XFF; 00065 uint32_t ntof=(nsub>>8 )&0XFF; 00066 uint32_t nemc=(nsub>>16)&0XFF; 00067 uint32_t nmuc= nsub>>24; 00068 if(nmuc>HltID::getID_MUC_MAX()+1 || nemc>HltID::getID_EMC_MAX()+1 00069 ||ntof>HltID::getID_TOF_MAX()+1 || nmdc>HltID::getID_MDC_MAX()+1){ 00070 throw exception(); 00071 } 00072 hltInfTds->setNumber(nsub); 00073 hltInfTds->setNCON(ncon); 00074 00075 std::vector<Int_t> mdcRoot=m_hltInf->getMdcData(); 00076 if(mdcRoot.size()!=nmdc) { 00077 throw exception(); 00078 } 00079 std::vector<Int_t>::iterator it=mdcRoot.begin(); 00080 for(;it!=mdcRoot.end();it++){ 00081 uint32_t data=*it; 00082 hltInfTds->push_mdc(data); 00083 } 00084 std::vector<Int_t> tofRoot=m_hltInf->getTofData(); 00085 if(tofRoot.size()!=ntof) { 00086 throw exception(); 00087 } 00088 it=tofRoot.begin(); 00089 for(;it!=tofRoot.end();it++){ 00090 uint32_t data=*it; 00091 hltInfTds->push_tof(data); 00092 } 00093 std::vector<Int_t> emcRoot=m_hltInf->getEmcData(); 00094 if(emcRoot.size()!=nemc) { 00095 throw exception(); 00096 } 00097 it=emcRoot.begin(); 00098 for(;it!=emcRoot.end();it++){ 00099 uint32_t data=*it; 00100 hltInfTds->push_emc(data); 00101 } 00102 std::vector<Int_t> mucRoot=m_hltInf->getMucData(); 00103 if(mucRoot.size()!=nmuc) { 00104 throw exception(); 00105 } 00106 it=mucRoot.begin(); 00107 for(;it!=mucRoot.end();it++){ 00108 uint32_t data=*it; 00109 hltInfTds->push_muc(data); 00110 } 00111 std::vector<Int_t> conRoot=m_hltInf->getConData(); 00112 if(conRoot.size()!=ncon) { 00113 throw exception(); 00114 } 00115 it=conRoot.begin(); 00116 for(;it!=conRoot.end();it++){ 00117 uint32_t data=*it; 00118 hltInfTds->push_con(data); 00119 } 00120 } 00121 catch(...){ 00122 //log << MSG::ERROR << "***********************************************************" << endreq; 00123 //log << MSG::ERROR << "Input ROOT object is older version, please reconstrut again" << endreq; 00124 //log << MSG::ERROR << " or check out old RootCnvSvc! (mailto: fucd@ihep.ac.cn)" << endreq; 00125 //log << MSG::WARNING << "***** Continuing run may cause a little memory leakage ****" << endreq; 00126 //m_old=true; 00127 } 00128 00129 delete m_hltInf; 00130 m_hltInf = 0; 00131 00132 return StatusCode::SUCCESS; 00133 } 00134 00135 StatusCode HltInfCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) { 00136 00137 MsgStream log(msgSvc(), "HltInfCnv"); 00138 log << MSG::DEBUG << "HltInfCnv::DataObjectToTObject" << endreq; 00139 StatusCode sc=StatusCode::SUCCESS; 00140 00141 HltInf * hltInfCnvTds=dynamic_cast<HltInf*> (obj); 00142 if (!hltInfCnvTds) { 00143 log << MSG::ERROR << "Could not downcast to HltInf" << endreq; 00144 return StatusCode::FAILURE; 00145 } 00146 00147 DataObject *evt; 00148 m_eds->findObject(EventModel::Hlt::Event,evt); 00149 if (evt==NULL) { 00150 log << MSG::ERROR << "Could not get HltInf in TDS " << endreq; 00151 return StatusCode::FAILURE; 00152 } 00153 00154 HltEvent * devtTds=dynamic_cast<HltEvent *> (evt); 00155 if (!devtTds) { 00156 log << MSG::ERROR << "HltInfCnv:Could not downcast to TDS HltInf" << endreq; 00157 } 00158 00159 IOpaqueAddress *addr; 00160 m_cnvSvc->getHltCnv()->createRep(evt,addr); 00161 00162 THltEvent *hltInf=m_cnvSvc->getHltCnv()->getWriteObject(); 00163 00164 const TObject *tHltInf = hltInf->getHltInf(); 00165 if (!tHltInf) return sc; 00166 hltInf->clearHltInf(); 00167 00168 Int_t type = hltInfCnvTds->getEventType(); 00169 Int_t alg = hltInfCnvTds->getAlgProcess(); 00170 Int_t cri = hltInfCnvTds->getCriteriaTable(); 00171 Int_t ver = hltInfCnvTds->getVersion(); 00172 Double_t etot = hltInfCnvTds->getTotalEnergy(); 00173 Int_t nsub = hltInfCnvTds->getNumber(); 00174 Int_t ncon = hltInfCnvTds->getNCON(); 00175 00176 THltInf *hltInfRoot = new THltInf(); 00177 00178 hltInfRoot->setEventType(type); 00179 hltInfRoot->setAlgProcess(alg); 00180 hltInfRoot->setCriteriaTable(cri); 00181 hltInfRoot->setVersion(ver); 00182 hltInfRoot->setTotalEnergy(etot); 00183 hltInfRoot->setNumber(nsub); 00184 hltInfRoot->setNCON(ncon); 00185 00186 00187 std::vector<uint32_t> mdcTds=hltInfCnvTds->getDataVec(HltID::MDC); 00188 std::vector<Int_t> mdcRoot; 00189 std::vector<uint32_t>::iterator it= mdcTds.begin(); 00190 for(;it!=mdcTds.end();it++){ 00191 Int_t data=*it; 00192 mdcRoot.push_back(data); 00193 } 00194 hltInfRoot->setMdcData(mdcRoot); 00195 00196 std::vector<uint32_t> tofTds=hltInfCnvTds->getDataVec(HltID::TOF); 00197 std::vector<Int_t> tofRoot; 00198 for(it= tofTds.begin();it!=tofTds.end();it++){ 00199 Int_t data=*it; 00200 tofRoot.push_back(data); 00201 } 00202 hltInfRoot->setTofData(tofRoot); 00203 00204 std::vector<uint32_t> emcTds=hltInfCnvTds->getDataVec(HltID::EMC); 00205 std::vector<Int_t> emcRoot; 00206 for(it= emcTds.begin();it!=emcTds.end();it++){ 00207 Int_t data=*it; 00208 emcRoot.push_back(data); 00209 } 00210 hltInfRoot->setEmcData(emcRoot); 00211 00212 std::vector<uint32_t> mucTds=hltInfCnvTds->getDataVec(HltID::MUC); 00213 std::vector<Int_t> mucRoot; 00214 for(it= mucTds.begin();it!=mucTds.end();it++){ 00215 Int_t data=*it; 00216 mucRoot.push_back(data); 00217 } 00218 hltInfRoot->setMucData(mucRoot); 00219 00220 std::vector<uint32_t> conTds=hltInfCnvTds->getDataVec(HltID::CON); 00221 std::vector<Int_t> conRoot; 00222 for(it= conTds.begin();it!=conTds.end();it++){ 00223 Int_t data=*it; 00224 conRoot.push_back(data); 00225 } 00226 hltInfRoot->setConData(conRoot); 00227 00228 hltInf->addHltInf(hltInfRoot); 00229 00230 return StatusCode::SUCCESS; 00231 } 00232 #endif