00001 #ifndef RecEmcHitCnv_CXX 00002 #define RecEmcHitCnv_CXX 1 00003 00004 #include "GaudiKernel/MsgStream.h" 00005 #include "GaudiKernel/DataObject.h" 00006 #include "GaudiKernel/ObjectVector.h" 00007 00008 #include "TClonesArray.h" 00009 00010 #include "EventModel/EventModel.h" 00011 00012 #include "ReconEvent/ReconEvent.h" 00013 #include "EmcRecEventModel/RecEmcHit.h" 00014 00015 #include "RootEventData/TRecEmcHit.h" // standard root object 00016 #include "RootEventData/TRecTrackEvent.h" 00017 00018 #include "RootCnvSvc/Rec/RecTrackCnv.h" 00019 #include "RootCnvSvc/Rec/RecEmcHitCnv.h" 00020 #include "RootCnvSvc/RootAddress.h" 00021 00022 #include <vector> 00023 00024 using namespace std; 00025 00026 // Instantiation of a static factory class used by clients to create 00027 // instances of this service 00028 //static CnvFactory<RecEmcHitCnv> s_factory; 00029 //const ICnvFactory& RecEmcHitCnvFactory = s_factory; 00030 00031 RecEmcHitCnv::RecEmcHitCnv(ISvcLocator* svc) 00032 : RootEventBaseCnv(classID(), svc) 00033 { 00034 //cout<<"in RecEmcHitCnv::constructor: hitid= "<<aHit->clID()<<endl; 00035 00036 // Here we associate this converter with the /Event path on the TDS. 00037 MsgStream log(msgSvc(), "RecEmcHitCnv"); 00038 //log << MSG::DEBUG << "Constructor called for " << objType() << endreq; 00039 m_rootTreename ="Rec"; 00040 m_rootBranchname ="m_recEmcHitCol"; 00041 //declareObject(EventModel::Recon::RecEmcHitCol, objType(), m_rootTreename, m_rootBranchname); 00042 m_adresses.push_back(&m_recEmcHitCol); 00043 m_recEmcHitCol=0; 00044 } 00045 00046 StatusCode RecEmcHitCnv::TObjectToDataObject(DataObject*& refpObject) { 00047 00048 // creation of TDS object from root object 00049 MsgStream log(msgSvc(), "RecEmcHitCnv"); 00050 log << MSG::DEBUG << "RecEmcHitCnv::TObjectToDataObject" << endreq; 00051 //cout<<"RecEmcHitCnv::TObjectToDataObject"<<endl; 00052 StatusCode sc=StatusCode::SUCCESS; 00053 00054 // create the TDS location for the RecEmcHit Collection 00055 RecEmcHitCol* emcHitTdsCol = new RecEmcHitCol; 00056 refpObject=emcHitTdsCol; 00057 00058 // now convert 00059 if (!m_recEmcHitCol) return sc; 00060 TIter emcHitIter(m_recEmcHitCol); 00061 TRecEmcHit *emcHitRoot = 0; 00062 while ((emcHitRoot = (TRecEmcHit*)emcHitIter.Next())) { 00063 RecEmcID cellId(emcHitRoot->cellId()); 00064 double energy = emcHitRoot->energy(); 00065 double time = emcHitRoot->time(); 00066 00067 //cout<<"cellId="<<cellId<<"\tenergy="<<energy<<"\ttime="<<time<<endl; 00068 00069 RecEmcHit *emcHitTds = new RecEmcHit(); 00070 m_common.m_rootRecEmcHitMap[emcHitRoot] = emcHitTds; 00071 00072 emcHitTds->Assign(cellId,energy,time); 00073 00074 emcHitTdsCol->push_back(emcHitTds); 00075 } 00076 00077 delete m_recEmcHitCol; 00078 m_recEmcHitCol = 0; 00079 00080 return StatusCode::SUCCESS; 00081 } 00082 00083 StatusCode RecEmcHitCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) { 00084 00085 MsgStream log(msgSvc(), "RecEmcHitCnv"); 00086 log << MSG::DEBUG << "RecEmcHitCnv::DataObjectToTObject" << endreq; 00087 //cout<<"RecEmcHitCnv::DataObjectToTObject"<<endl; 00088 StatusCode sc=StatusCode::SUCCESS; 00089 00090 RecEmcHitCol * emcHitColTds=dynamic_cast<RecEmcHitCol *> (obj); 00091 if (!emcHitColTds) { 00092 log << MSG::ERROR << "Could not downcast to RecEmcHitCol" << endreq; 00093 return StatusCode::FAILURE; 00094 } 00095 00096 DataObject *evt; 00097 m_eds->findObject(EventModel::Recon::Event,evt); 00098 if (evt==NULL) { 00099 log << MSG::ERROR << "Could not get RecEvent in TDS " << endreq; 00100 return StatusCode::FAILURE; 00101 } 00102 ReconEvent * devtTds=dynamic_cast<ReconEvent *> (evt); 00103 if (!devtTds) { 00104 log << MSG::ERROR << "RecEmcHitCnv:Could not downcast to TDS DstEvent" << endreq; 00105 } 00106 IOpaqueAddress *addr; 00107 00108 m_cnvSvc->getRecTrackCnv()->createRep(evt,addr); 00109 TRecTrackEvent *recEvt=m_cnvSvc->getRecTrackCnv()->getWriteObject(); 00110 00111 const TObjArray *m_emcHitCol = recEvt->getEmcHitCol(); 00112 if (!m_emcHitCol) return sc; 00113 00114 //necessary in case there is I/O at the same time since array is static 00115 recEvt->clearEmcHitCol(); 00116 00117 RecEmcHitCol::const_iterator emcHitTds; 00118 00119 for(emcHitTds = emcHitColTds->begin(); 00120 emcHitTds != emcHitColTds->end(); 00121 emcHitTds++) { 00122 Int_t cellId = (*emcHitTds)->getCellId(); 00123 Double_t energy = (*emcHitTds)->getEnergy(); 00124 Double_t time = (*emcHitTds)->getTime(); 00125 00126 TRecEmcHit *emcHitRoot = new TRecEmcHit(); 00127 //m_common.m_recEmcHitMap[(*emcHitTds)] = emcHitRoot; 00128 emcHitRoot->setCellId(cellId); 00129 emcHitRoot->setEnergy(energy); 00130 emcHitRoot->setTime(time); 00131 00132 recEvt->addEmcHit(emcHitRoot); 00133 } 00134 00135 return StatusCode::SUCCESS; 00136 } 00137 #endif