00001 #ifndef HltRawCnv_CXX 00002 #define HltRawCnv_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 #include "HltEvent/HltEvent.h" //TDS object 00012 #include "HltEvent/HltRaw.h" //TDS object 00013 #include "RootEventData/THltRaw.h" // standard root object 00014 #include "RootEventData/THltEvent.h" 00015 #include "RootCnvSvc/Hlt/HltCnv.h" 00016 #include "RootCnvSvc/Hlt/HltRawCnv.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 //static CnvFactory<HltRawCnv> s_factory; 00023 //const ICnvFactory& HltRawCnvFactory = s_factory; 00024 00025 HltRawCnv::HltRawCnv(ISvcLocator* svc) 00026 : RootEventBaseCnv(classID(), svc) 00027 { 00028 // Here we associate this converter with the /Event path on the TDS. 00029 MsgStream log(msgSvc(), "HltRawCnv"); 00030 //log << MSG::DEBUG << "Constructor called for " << objType() << endreq; 00031 m_rootBranchname ="m_hltRawCol"; 00032 //declareObject(EventModel::Hlt::HltRawCol, objType(), m_rootTreename, m_rootBranchname); 00033 m_adresses.push_back(&m_hltRawCol); 00034 m_hltRawCol=0; 00035 00036 } 00037 00038 StatusCode HltRawCnv::TObjectToDataObject(DataObject*& refpObject) { 00039 // creation of TDS object from root object 00040 00041 MsgStream log(msgSvc(), "HltRawCnv"); 00042 log << MSG::DEBUG << "HltRawCnv::TObjectToDataObject" << endreq; 00043 StatusCode sc=StatusCode::SUCCESS; 00044 00045 // create the TDS location for the HltRaw Collection 00046 HltRawCol* hltRawTdsCol = new HltRawCol; 00047 refpObject=hltRawTdsCol; 00048 // sc = m_eds->registerObject(EventModel::Hlt::HltRawCol, hltRawTdsCol); 00049 // if (sc.isFailure()) { 00050 // log << "Failed to register HltRaw Collection" << endreq; 00051 // return StatusCode::FAILURE; 00052 // } 00053 00054 00055 // now convert 00056 if (!m_hltRawCol) return sc; 00057 TIter hltRawIter(m_hltRawCol); 00058 THltRaw *hltRawRoot = 0; 00059 while ((hltRawRoot = (THltRaw*)hltRawIter.Next())) { 00060 unsigned int id = hltRawRoot->getIntId(); 00061 unsigned int time = hltRawRoot->getTimeChannel(); 00062 unsigned int charge = hltRawRoot->getChargeChannel(); 00063 00064 HltRaw *hltRawTds = new HltRaw(id); 00065 m_common.m_rootHltRawMap[hltRawRoot] = hltRawTds; 00066 00067 hltRawTds->setTimeChannel(time); 00068 hltRawTds->setChargeChannel(charge); 00069 00070 hltRawTdsCol->push_back(hltRawTds); 00071 } 00072 //m_hltRawCol->Delete(); // wensp add 2005/12/30 00073 delete m_hltRawCol; 00074 m_hltRawCol = 0; 00075 return StatusCode::SUCCESS; 00076 } 00077 00078 StatusCode HltRawCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) { 00079 00080 MsgStream log(msgSvc(), "HltRawCnv"); 00081 log << MSG::DEBUG << "HltRawCnv::DataObjectToTObject" << endreq; 00082 StatusCode sc=StatusCode::SUCCESS; 00083 00084 HltRawCol * hltRawColTds=dynamic_cast<HltRawCol *> (obj); 00085 if (!hltRawColTds) { 00086 log << MSG::ERROR << "Could not downcast to HltRawCol" << endreq; 00087 return StatusCode::FAILURE; 00088 } 00089 00090 DataObject *evt; 00091 m_eds->findObject(EventModel::Hlt::Event,evt); 00092 if (evt==NULL) { 00093 log << MSG::ERROR << "Could not get HltEvent in TDS " << endreq; 00094 return StatusCode::FAILURE; 00095 } 00096 HltEvent * devtTds=dynamic_cast<HltEvent *> (evt); 00097 if (!devtTds) { 00098 log << MSG::ERROR << "HltRawCnv:Could not downcast to TDS HltEvent" << endreq; 00099 } 00100 00101 IOpaqueAddress *addr; 00102 00103 00104 m_cnvSvc->getHltCnv()->createRep(evt,addr); 00105 00106 //createRep(evt,addr); 00107 00108 THltEvent *recEvt=m_cnvSvc->getHltCnv()->getWriteObject(); 00109 00110 const TObjArray *m_hltRawCol = recEvt->getHltRawCol(); 00111 if (!m_hltRawCol) return sc; 00112 recEvt->clearHltRawCol(); //necessary in case there is I/O at the same time since array is static 00113 HltRawCol::const_iterator hltRawTds; 00114 00115 for (hltRawTds = hltRawColTds->begin(); hltRawTds != hltRawColTds->end(); hltRawTds++) { 00116 UInt_t time = (*hltRawTds)->getTimeChannel(); 00117 UInt_t charge = (*hltRawTds)->getChargeChannel(); 00118 UInt_t id = (*hltRawTds)->getIntId(); 00119 00120 THltRaw *hltRawRoot = new THltRaw(); 00121 //m_common.m_hltRawMap[(*hltRawTds)] = hltRawRoot; 00122 00123 hltRawRoot->initialize(id, time ,charge); 00124 recEvt->addHltRaw(hltRawRoot); 00125 } 00126 00127 return StatusCode::SUCCESS; 00128 } 00129 00130 #endif 00131 00132 00133 00134 00135 00136 00137 00138 00139 00140