/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Event/RootCnvSvc/RootCnvSvc-02-01-12/src/Digi/MucDigiCnv.cxx

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

Generated on Tue Nov 29 22:58:38 2016 for BOSS_7.0.2 by  doxygen 1.4.7