/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Event/RootCnvSvc/RootCnvSvc-02-01-12/src/Rec/RecEmcClusterCnv.cxx

Go to the documentation of this file.
00001 #ifndef RecEmcClusterCnv_CXX
00002 #define RecEmcClusterCnv_CXX  1
00003 
00004 #include "GaudiKernel/MsgStream.h"
00005 #include "GaudiKernel/DataObject.h"
00006 #include "GaudiKernel/ObjectVector.h"
00007 #include "GaudiKernel/IDataProviderSvc.h"
00008 #include "GaudiKernel/Bootstrap.h"
00009 
00010 #include "TClonesArray.h"
00011 
00012 #include "EventModel/EventModel.h"
00013 
00014 #include "ReconEvent/ReconEvent.h"
00015 #include "EmcRecEventModel/RecEmcCluster.h"
00016 
00017 #include "RootEventData/TRecEmcCluster.h" // standard root object
00018 #include "RootEventData/TRecTrackEvent.h"
00019 
00020 #include "RootCnvSvc/Rec/RecTrackCnv.h"
00021 #include "RootCnvSvc/Rec/RecEmcClusterCnv.h"
00022 #include "RootCnvSvc/RootAddress.h"
00023 
00024 #include <vector>
00025 
00026 using namespace std;
00027 
00028 // Instantiation of a static factory class used by clients to create
00029 // instances of this service
00030 //static CnvFactory<RecEmcClusterCnv> s_factory;
00031 //const ICnvFactory& RecEmcClusterCnvFactory = s_factory;
00032 
00033 RecEmcClusterCnv::RecEmcClusterCnv(ISvcLocator* svc)
00034 : RootEventBaseCnv(classID(), svc)
00035 {
00036   //cout<<"in RecEmcClusterCnv::constructor: clusterid= "<<aCluster->clID()<<endl;
00037 
00038     // Here we associate this converter with the /Event path on the TDS.
00039     MsgStream log(msgSvc(), "RecEmcClusterCnv");
00040     //log << MSG::DEBUG << "Constructor called for " << objType() << endreq;
00041     //m_rootTreename ="Rec";
00042     m_rootBranchname ="m_recEmcClusterCol";
00043     //declareObject(EventModel::Recon::RecEmcClusterCol, objType(), m_rootTreename, m_rootBranchname);
00044     m_adresses.push_back(&m_recEmcClusterCol);
00045     m_recEmcClusterCol=0;
00046 }
00047 
00048 StatusCode RecEmcClusterCnv::TObjectToDataObject(DataObject*& refpObject) {
00049   // creation of TDS object from root object
00050   MsgStream log(msgSvc(), "RecEmcClusterCnv");
00051   log << MSG::DEBUG << "RecEmcClusterCnv::TObjectToDataObject" << endreq;
00052   //cout << "RecEmcClusterCnv::TObjectToDataObject" << endl;
00053   StatusCode sc=StatusCode::SUCCESS;
00054 
00055   IDataProviderSvc* eventSvc;
00056   Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
00057 
00058   SmartDataPtr<RecEmcHitCol> emcRecHitCol(eventSvc,
00059       EventModel::Recon::RecEmcHitCol);
00060   if(!emcRecHitCol) log << MSG::INFO << "can't retrieve RecEmcHitCol" << endreq;
00061   
00062   // create the TDS location for the RecEmcCluster Collection
00063   RecEmcClusterCol* emcClusterTdsCol = new RecEmcClusterCol;
00064   refpObject=emcClusterTdsCol;
00065 
00066   // now convert
00067   if (!m_recEmcClusterCol) return sc;
00068   TIter emcClusterIter(m_recEmcClusterCol);
00069   TRecEmcCluster *emcClusterRoot = 0;
00070   while ((emcClusterRoot = (TRecEmcCluster*)emcClusterIter.Next())) {
00071     RecEmcID clusterId(emcClusterRoot->clusterId());
00072 
00073     RecEmcCluster *emcClusterTds = new RecEmcCluster();
00074     m_common.m_rootRecEmcClusterMap[emcClusterRoot] = emcClusterTds;
00075 
00076     emcClusterTds->ClusterId(clusterId);
00077 
00078     vector<int> vecShowers = emcClusterRoot->vecShowers();
00079     vector<int>::iterator iVecShower;
00080     vector<RecEmcID> vecShowerId;
00081     for(iVecShower=vecShowers.begin();
00082         iVecShower!=vecShowers.end();
00083         iVecShower++) {
00084       RecEmcID id(*iVecShower);
00085       vecShowerId.push_back(id);
00086     }
00087     emcClusterTds->ShowerIdVec(vecShowerId);
00088     
00089     if(emcRecHitCol) {
00090       vector<Int_t> vecHits = emcClusterRoot->vecHits();
00091       vector<Int_t> vecSeeds = emcClusterRoot->vecSeeds();
00092       vector<Int_t>::iterator iVecHit;
00093       
00094       //put hit map into cluster
00095       for(iVecHit=vecHits.begin();
00096           iVecHit!=vecHits.end();
00097           iVecHit++) {
00098         
00099         RecEmcID id(*iVecHit);
00100         
00101         RecEmcHitCol::iterator iHit;
00102         for(iHit=emcRecHitCol->begin();
00103             iHit!=emcRecHitCol->end();
00104             iHit++) {
00105           
00106           RecEmcID idHit((*iHit)->getCellId());
00107 
00108           if(id==idHit) {
00109             //RecEmcFraction frac(*(*iHit));
00110             //frac.Fraction(iHit->second);
00111             emcClusterTds->Insert(*(*iHit));
00112             break;
00113           }
00114         } //RecEmcHitCol
00115       } //VecHit
00116 
00117       //put seed map into cluster
00118       for(iVecHit=vecSeeds.begin();
00119           iVecHit!=vecSeeds.end();
00120           iVecHit++) {
00121         
00122         RecEmcID id(*iVecHit);
00123         
00124         RecEmcHitCol::iterator iHit;
00125         for(iHit=emcRecHitCol->begin();
00126             iHit!=emcRecHitCol->end();
00127             iHit++) {
00128           
00129           RecEmcID idHit((*iHit)->getCellId());
00130 
00131           if(id==idHit) {
00132             //RecEmcFraction frac(*(*iHit));
00133             //frac.Fraction(iHit->second);
00134             emcClusterTds->InsertSeed(*(*iHit));
00135             break;
00136           }
00137         } //RecEmcHitCol
00138       } //VecHit
00139 
00140     }
00141     
00142     emcClusterTdsCol->push_back(emcClusterTds);
00143   }
00144 
00145 
00146     return StatusCode::SUCCESS;
00147 }
00148 
00149 StatusCode RecEmcClusterCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
00150 
00151   MsgStream log(msgSvc(), "RecEmcClusterCnv");
00152   log << MSG::DEBUG << "RecEmcClusterCnv::DataObjectToTObject" << endreq;
00153   //cout<<"RecEmcClusterCnv::DataObjectToTObject"<<endl;
00154   StatusCode sc=StatusCode::SUCCESS;
00155  
00156   RecEmcClusterCol * emcClusterColTds=dynamic_cast<RecEmcClusterCol *> (obj);
00157   if (!emcClusterColTds) {
00158     log << MSG::ERROR << "Could not downcast to RecEmcClusterCol" << endreq;
00159     return StatusCode::FAILURE;
00160   }
00161 
00162   DataObject *evt;
00163   m_eds->findObject(EventModel::Recon::Event,evt);
00164   if (evt==NULL) {
00165     log << MSG::ERROR << "Could not get RecEvent in TDS "  << endreq;
00166     return StatusCode::FAILURE;
00167   }
00168   ReconEvent * devtTds=dynamic_cast<ReconEvent *> (evt);
00169   if (!devtTds) {
00170     log << MSG::ERROR << "RecEmcClusterCnv:Could not downcast to TDS DstEvent" << endreq;
00171   }
00172   IOpaqueAddress *addr;
00173 
00174   m_cnvSvc->getRecTrackCnv()->createRep(evt,addr); 
00175   TRecTrackEvent *recEvt=m_cnvSvc->getRecTrackCnv()->getWriteObject();
00176 
00177   const TObjArray *m_emcClusterCol = recEvt->getEmcClusterCol();
00178   if (!m_emcClusterCol) return sc;
00179 
00180   //necessary in case there is I/O at the same time since array is static
00181   recEvt->clearEmcClusterCol(); 
00182 
00183   RecEmcClusterCol::const_iterator emcClusterTds;
00184 
00185   for(emcClusterTds = emcClusterColTds->begin();
00186       emcClusterTds != emcClusterColTds->end();
00187       emcClusterTds++) {
00188     Int_t clusterId = (*emcClusterTds)->getClusterId();
00189     
00190     vector<Int_t> vecHits;
00191     RecEmcHitMap::const_iterator iHitMap;
00192     for(iHitMap=(*emcClusterTds)->Begin();
00193         iHitMap!=(*emcClusterTds)->End();
00194         iHitMap++) {
00195       vecHits.push_back(iHitMap->first);
00196     }
00197 
00198     vector<Int_t> vecSeeds;
00199     RecEmcHitMap::const_iterator iSeedMap;
00200     for(iSeedMap=(*emcClusterTds)->BeginSeed();
00201         iSeedMap!=(*emcClusterTds)->EndSeed();
00202         iSeedMap++) {
00203       vecSeeds.push_back(iSeedMap->first);
00204     }
00205 
00206     vector<RecEmcID> vecShowerId=(*emcClusterTds)->getShowerIdVec();
00207     vector<RecEmcID>::iterator iShowerId;
00208     vector<Int_t> vecShowers;
00209     for(iShowerId=vecShowerId.begin();
00210         iShowerId!=vecShowerId.end();
00211         iShowerId++) {
00212        vecShowers.push_back(*iShowerId);
00213     }
00214 
00215     //cout<<"clusterId="<<RecEmcID(clusterId)<<endl;
00216 
00217     TRecEmcCluster *emcClusterRoot = new TRecEmcCluster();
00218     //m_common.m_recEmcClusterMap[(*emcClusterTds)] = emcClusterRoot;
00219 
00220     emcClusterRoot->setClusterId(clusterId);
00221     emcClusterRoot->setVecHits(vecHits);
00222     emcClusterRoot->setVecSeeds(vecSeeds);
00223     emcClusterRoot->setVecShowers(vecShowers);
00224 
00225     recEvt->addEmcCluster(emcClusterRoot);
00226   }
00227   
00228   return StatusCode::SUCCESS;
00229 }
00230 #endif

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