/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Event/RawDataCnv/RawDataCnv-00-04-35/src/RawDataMcPaticleCnv.cxx

Go to the documentation of this file.
00001 //====================================================================
00002 //      RawDataMcParticleCnv.cxx
00003 //====================================================================
00004 //
00005 // Description: A converter class to unpack Event Filter packed raw   
00006 //              event persistent data and place it in the Transient    
00007 //              Data Store of Athena.
00008 //
00009 //--------------------------------------------------------------------
00010 
00011 // Include files.
00012 #include "GaudiKernel/MsgStream.h"
00013 #include "GaudiKernel/SmartDataPtr.h" 
00014 // for Mutil-thread by tianhl
00015 #include "GaudiKernel/ThreadGaudi.h"
00016 // for Mutil-thread by tianhl
00017 
00018 #include "EventModel/EventModel.h"
00019 #include "McTruth/McParticle.h"
00020 #include "RawDataCnv/EventManagement/RAWEVENT.h" 
00021 #include "RawDataCnv/EventManagement/RawEvent.h" 
00022 #include "RawDataCnv/RawDataInputSvc.h" 
00023 #include "RawDataCnv/RawDataMcParticleCnv.h"
00024                                                                                                                              
00025 using Event::McParticle;
00026 using Event::McParticleCol;
00027 
00028 
00029 extern const CLID& CLID_McParticleCol;
00030 
00031 // Constructor.
00032 RawDataMcParticleCnv::RawDataMcParticleCnv(ISvcLocator* svc) : 
00033 RawDataBaseCnv(PACKEDRAWEVENT_StorageType, classID(), svc) 
00034 {
00035   //init();
00036 }
00037 
00038 // Return the identification number of this converter to the 
00039 // persistency service.
00040 const CLID& RawDataMcParticleCnv::classID()
00041 {
00042   return CLID_McParticleCol;
00043 }
00044 
00045 StatusCode RawDataMcParticleCnv::initialize()
00046 {
00047 
00048     std::string PackedRawDataCnvSvc_Name("PackedRawDataCnvSvc");
00049     std::string RawDataInputSvc_Name("RawDataInputSvc");
00050     std::string RawDataMcParticleCnv_Name("RawDataMcParticleCnv");
00051     
00052     // for Mutil-thread by tianhl
00053     //ConversionSvc*  pCnvSvc = 0;
00054     //if (pCnvSvc = dynamic_cast<ConversionSvc*>(conversionSvc())){
00055     SmartIF<IService> pCnvSvc(conversionSvc());  
00056     if  (isGaudiThreaded(pCnvSvc->name())){
00057         PackedRawDataCnvSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
00058         RawDataInputSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
00059         RawDataMcParticleCnv_Name += getGaudiThreadIDfromName(pCnvSvc->name());
00060       }
00061     //}
00062     
00063   MsgStream log(messageService(), RawDataMcParticleCnv_Name.c_str());
00064 
00065   StatusCode sc = RawDataBaseCnv::initialize();
00066   if (StatusCode::SUCCESS != sc) {
00067     log << MSG::ERROR << "RawDataBaseCnv: Cant initialize PackedRawDataCnvSvc" << endreq;
00068     return sc;
00069   }
00070 
00071   // Check RawDataCnvSvc
00072   IService* isvc = 0;
00073   sc = serviceLocator()->service(PackedRawDataCnvSvc_Name.c_str(), isvc, true);
00074   if (sc != StatusCode::SUCCESS) {
00075     log << MSG::ERROR << "Cant get PackedRawDataCnvSvc" << endreq;
00076   }
00077 
00078   m_RawDataAccess = dynamic_cast<PackedRawDataCnvSvc*> (isvc); 
00079   if (m_RawDataAccess  == 0 ) {
00080     log << MSG::ERROR << "RawDataMcParticleCnv: Cant cast to RawDataCnvSvc " << endreq; 
00081     return StatusCode::FAILURE;
00082   }
00083 
00084   sc = serviceLocator()->getService(RawDataInputSvc_Name.c_str(), isvc);
00085   if (sc != StatusCode::SUCCESS ) {
00086     log << MSG::WARNING << "Cant get RawDataInputSvc " << endreq;
00087     return sc ;
00088   }
00089 
00090   m_inputSvc = dynamic_cast<RawDataInputSvc*> (isvc);
00091   if (m_inputSvc == 0 ) {
00092     log << MSG::WARNING << "Cant cast to RawDataInputSvc " << endreq;
00093     return StatusCode::FAILURE ;
00094   }
00095 
00096   return StatusCode::SUCCESS; 
00097 }
00098 
00099 
00100 StatusCode RawDataMcParticleCnv::updateObj(IOpaqueAddress* pAddr, DataObject* pObj) {
00101   // Purpose and Method:  This method does nothing other than announce it has
00102   //   been called.
00103 
00104   //MsgStream log(msgSvc(), "RawDataMcParticleCnv");
00105   //log << MSG::DEBUG << "RawDataMcParticleCnv::updateObj" << endreq;
00106   return Converter::updateObj(pAddr, pObj);
00107 }
00108 
00109 // Create a converted object in the Transient Data Store.
00110 StatusCode RawDataMcParticleCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
00111 {
00112   //MsgStream log(msgSvc(), "RawDataMcParticleCnv");
00113 
00114   //This converter will create an empty McParticleCol on the TDS
00115   McParticleCol *mcParticleCol = new McParticleCol;
00116   pObj = mcParticleCol;
00117    
00118   RAWEVENT *evt = m_inputSvc->currentEvent(); 
00119   if (evt == NULL) {
00120       //log << MSG::ERROR << "RawDataCnv has no event!" << endreq; 
00121       return StatusCode::FAILURE;
00122   }
00123 
00124   const BufferHolder& mcParBuf = evt->getMcParBuf();
00125   if (mcParBuf.nBuf() == 0) {
00126     //cerr << "no McParticle Data Buffer found!!!" << endl;
00127     return StatusCode::FAILURE;
00128   }
00129   uint32_t* buf = mcParBuf(0);
00130 
00131   uint32_t nParticle = (buf[0] >> 16);
00132   //uint32_t nVertex   = (buf[0] & 0xFFFF);
00133   double*  vPointer  = (double*)(buf + nParticle*11 + 1);
00134 
00135   for (uint32_t i = 0; i < nParticle; i++) {
00136     McParticle* mcPar = new McParticle;
00137     m_mcParticleBuilder.unPack((buf+1+i*11), vPointer, mcPar);
00138     mcParticleCol->push_back(mcPar);
00139   }
00140   
00141   // Get primary McParticles
00142   SmartRefVector<McParticle> primaryParticleCol;
00143   McParticleCol::iterator iter_particle = mcParticleCol->begin();
00144   for ( ; iter_particle != mcParticleCol->end(); iter_particle++) {
00145     if ((*iter_particle)->primaryParticle()) {
00146       McParticle* mcPart = (McParticle*)(*iter_particle);
00147       primaryParticleCol.push_back(mcPart);
00148     }
00149   }
00150 
00151   if (primaryParticleCol.empty()) {
00152     //log << MSG::WARNING << "createObj error: no primary particle found!" << endreq;
00153   }
00154 
00155   // Add mother particle recursively
00156   SmartRefVector<McParticle>::iterator iter_primary = primaryParticleCol.begin();
00157   //std::cout << "primaryParticleCol.size() = " << primaryParticleCol.size() << std::endl;
00158   for ( ; iter_primary != primaryParticleCol.end(); iter_primary++) {
00159 
00160     if (!(*iter_primary)->leafParticle())
00161       addMother((*iter_primary), mcParticleCol);
00162   }
00163 
00164   return StatusCode::SUCCESS; 
00165 }
00166 
00167 StatusCode RawDataMcParticleCnv::createRep(DataObject* /*pObj*/, IOpaqueAddress*& /*pAddr*/)
00168 {
00169    // convert PixelRaw in the container into ByteStream
00170   //MsgStream log(messageService(), "RawDataMcParticleCnv");
00171   
00172   WriteRawEvent*& re = m_RawDataAccess->getRawEvent(); 
00173   if (re == 0) {
00174      //log << " get RawEvent failed !" << endreq;
00175      return StatusCode::FAILURE; 
00176   }
00177 
00178   SmartDataPtr<McParticleCol> mcParticleCol(dataProvider(), EventModel::MC::McParticleCol);
00179   if (mcParticleCol == 0) {
00180      //log << "no McParticleCol found" << endreq;
00181      return StatusCode::FAILURE;
00182   }
00183  
00184   return m_mcParticleBuilder.pack(mcParticleCol, re);
00185 }
00186 
00187 void RawDataMcParticleCnv::addMother(McParticle* currentParticle, McParticleCol *particleCol)
00188 {
00189 
00190   if (currentParticle->leafParticle()) return;
00191 
00192   bool found = false;
00193   McParticleCol::iterator iter = particleCol->begin();
00194   //std::cout << "particleCol->size() = " << particleCol->size() << std::endl;
00195   for ( ; iter != particleCol->end(); iter++) {
00196     if (currentParticle->vertexIndex1() == (*iter)->vertexIndex0()) {
00197       found = true;
00198       (*iter)->setMother(currentParticle);
00199       currentParticle->addDaughter(*iter);
00200       addMother((*iter), particleCol);
00201     }
00202   }
00203 
00204   if (!found) 
00205     std::cout << "RawDataMcParticleCnv::addMother: inconsistency was found!" << std::endl;
00206 }
00207 

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