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

Go to the documentation of this file.
00001 //====================================================================
00002 //      RawDataEmcMcHitCnv.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 <assert.h>
00013 #include "GaudiKernel/SmartDataPtr.h" 
00014 #include "GaudiKernel/MsgStream.h"
00015 // for Mutil-thread by tianhl
00016 #include "GaudiKernel/ThreadGaudi.h"
00017 // for Mutil-thread by tianhl
00018 
00019 #include "EventModel/EventModel.h"
00020 #include "Identifier/Identifier.h"
00021 #include "Identifier/EmcID.h"
00022 #include "McTruth/EmcMcHit.h"
00023 #include "RawDataCnv/EventManagement/RAWEVENT.h" 
00024 #include "RawDataCnv/EventManagement/RawEvent.h" 
00025 #include "RawDataCnv/RawDataInputSvc.h" 
00026 #include "RawDataCnv/RawDataEmcMcHitCnv.h"
00027                                                                                                                              
00028 using Event::EmcMcHit;
00029 using Event::EmcMcHitCol;
00030 
00031 extern const CLID& CLID_EmcMcHitCol;
00032 
00033 // Constructor.
00034 RawDataEmcMcHitCnv::RawDataEmcMcHitCnv(ISvcLocator* svc) : 
00035 RawDataBaseCnv(PACKEDRAWEVENT_StorageType, classID(), svc) 
00036 {
00037   //init();
00038 }
00039 
00040 // Return the identification number of this converter to the 
00041 // persistency service.
00042 const CLID& RawDataEmcMcHitCnv::classID()
00043 {
00044   return CLID_EmcMcHitCol;
00045 }
00046 
00047 StatusCode RawDataEmcMcHitCnv::initialize()
00048 {
00049     std::string PackedRawDataCnvSvc_Name("PackedRawDataCnvSvc");
00050     std::string RawDataInputSvc_Name("RawDataInputSvc");
00051     std::string RawDataEmcMcHitCnv_Name("RawDataEmcMcHitCnv");
00052     
00053     // for Mutil-thread by tianhl
00054     //ConversionSvc*  pCnvSvc = 0;
00055     //if (pCnvSvc = dynamic_cast<ConversionSvc*>(conversionSvc())){
00056     SmartIF<IService> pCnvSvc(conversionSvc());
00057       if  (isGaudiThreaded(pCnvSvc->name())){
00058         PackedRawDataCnvSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
00059         RawDataInputSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
00060         RawDataEmcMcHitCnv_Name += getGaudiThreadIDfromName(pCnvSvc->name());
00061       }
00062     //}
00063 
00064   MsgStream log(messageService(), RawDataEmcMcHitCnv_Name.c_str());
00065 
00066   StatusCode sc = RawDataBaseCnv::initialize();
00067   if (StatusCode::SUCCESS != sc) {
00068     log << MSG::ERROR << "RawDataBaseCnv: Cant initialize PackedRawDataCnvSvc" << endreq;
00069     return sc;
00070   }
00071 
00072   // Check RawDataCnvSvc
00073   IService* isvc = 0;
00074   sc = serviceLocator()->service(PackedRawDataCnvSvc_Name.c_str(), isvc, true);
00075   if (sc != StatusCode::SUCCESS) {
00076     log << MSG::ERROR << "Cant get PackedRawDataCnvSvc" << endreq;
00077   }
00078 
00079   m_RawDataAccess = dynamic_cast<PackedRawDataCnvSvc*> (isvc); 
00080   if (m_RawDataAccess  == 0 ) {
00081     log << MSG::ERROR << "RawDataEmcCnv: Cant cast to RawDataCnvSvc " << endreq; 
00082     return StatusCode::FAILURE;
00083   }
00084 
00085   sc = serviceLocator()->getService(RawDataInputSvc_Name.c_str(), isvc);
00086   if (sc != StatusCode::SUCCESS ) {
00087     log << MSG::WARNING << "Cant get RawDataInputSvc " << endreq;
00088     return sc ;
00089   }
00090 
00091   m_inputSvc = dynamic_cast<RawDataInputSvc*> (isvc);
00092   if (m_inputSvc == 0 ) {
00093     log << MSG::WARNING << "Cant cast to RawDataInputSvc " << endreq;
00094     return StatusCode::FAILURE ;
00095   }
00096 
00097   return StatusCode::SUCCESS; 
00098 }
00099 
00100 
00101 StatusCode RawDataEmcMcHitCnv::updateObj(IOpaqueAddress* pAddr, DataObject* pObj) {
00102   // Purpose and Method:  This method does nothing other than announce it has
00103   //   been called.
00104 
00105   //MsgStream log(msgSvc(), "RawDataEmcMcHitCnv");
00106   //log << MSG::DEBUG << "RawDataEmcMcHitCnv::updateObj" << endreq;
00107   return Converter::updateObj(pAddr, pObj);
00108 }
00109 
00110 // Create a converted object in the Transient Data Store.
00111 StatusCode RawDataEmcMcHitCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
00112 {
00113 
00114   //This converter will create an empty EmcMcHitCol on the TDS
00115   EmcMcHitCol *emcMcHitCol = new EmcMcHitCol;
00116   pObj = emcMcHitCol;
00117    
00118   RAWEVENT *evt = m_inputSvc->currentEvent(); 
00119   if (evt == NULL) {
00120       //MsgStream log(msgSvc(), "RawDataEmcMcHitCnv");
00121       //log << MSG::ERROR << "RawDataCnv has no event!" << endreq; 
00122       return StatusCode::FAILURE;
00123   }
00124   
00125   EmcMcHit* emcMcHit;
00126   EmcTruth_t m_EmcTruth;
00127 
00128   assert((evt->getEmcTruth().size()%8) == 0);
00129 
00130   std::vector<uint32_t>::const_iterator iter = evt->getEmcTruth().begin();
00131   std::vector<uint32_t>::const_iterator eiter = evt->getEmcTruth().end();
00132 
00133   for (int emcMcHitId = 0; iter != eiter; emcMcHitId++) {
00134     // retrieve the McTruth data
00135     m_emcMcHitBuilder.unPack(iter, eiter, m_EmcTruth);
00136     // construct the identifier
00137     Identifier ident = EmcID::crystal_id(m_EmcTruth.partId, m_EmcTruth.numTheta, m_EmcTruth.numPhi);
00138     // construct the EmcMcHit
00139     emcMcHit = new EmcMcHit(ident, m_EmcTruth.trackIndex,
00140                           m_EmcTruth.x/(m_emcMcHitBuilder.m_xCoeff*1.0),
00141                           m_EmcTruth.y/(m_emcMcHitBuilder.m_yCoeff*1.0),
00142                           m_EmcTruth.z/(m_emcMcHitBuilder.m_zCoeff*1.0),
00143                           m_EmcTruth.px/(m_emcMcHitBuilder.m_pxCoeff*1.0),
00144                           m_EmcTruth.py/(m_emcMcHitBuilder.m_pyCoeff*1.0),
00145                           m_EmcTruth.pz/(m_emcMcHitBuilder.m_pzCoeff*1.0),
00146                           m_EmcTruth.totalEdep/(m_emcMcHitBuilder.m_totalEdepCoeff*1.0)  );
00147     // And add the stuff to the container
00148     emcMcHitCol->push_back(emcMcHit);
00149   }
00150 
00151   return StatusCode::SUCCESS; 
00152 
00153 }
00154 
00155 StatusCode RawDataEmcMcHitCnv::createRep(DataObject* pObj, IOpaqueAddress*& pAddr)  
00156 {
00157    // convert PixelRaw in the container into ByteStream
00158   //MsgStream log(messageService(), "RawDataEmcMcHitCnv");
00159   
00160   WriteRawEvent*& re = m_RawDataAccess->getRawEvent(); 
00161   
00162   if (re == 0) {
00163      //log << " get RawEvent failed !" << endreq;
00164      return StatusCode::FAILURE; 
00165   }
00166 
00167   SmartDataPtr<EmcMcHitCol> mcHitCol(dataProvider(), EventModel::MC::EmcMcHitCol);
00168 
00169   if (mcHitCol == 0) {
00170      //log << "no EmcMcHitCol found" << endreq;
00171      return StatusCode::FAILURE;
00172   }
00173   
00174   StatusCode sc = m_emcMcHitBuilder.pack(mcHitCol, re);
00175 
00176   return sc; 
00177 
00178 }
00179 

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