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

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

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