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