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

Go to the documentation of this file.
00001 
00002 //====================================================================
00003 //      RawDataTofMcHitCnv.cxx
00004 //====================================================================
00005 //
00006 // Description: A converter class to unpack Event Filter packed raw   
00007 //              event persistent data and place it in the Transient    
00008 //              Data Store of Athena.
00009 //
00010 //--------------------------------------------------------------------
00011 
00012 // Include files.
00013 #include <assert.h>
00014 #include <vector>
00015 #include "GaudiKernel/MsgStream.h"
00016 #include "GaudiKernel/SmartDataPtr.h" 
00017 // for Mutil-thread by tianhl
00018 #include "GaudiKernel/ThreadGaudi.h"
00019 // for Mutil-thread by tianhl
00020 
00021 #include "EventModel/EventModel.h"
00022 #include "Identifier/Identifier.h"
00023 #include "Identifier/TofID.h"
00024 #include "McTruth/TofMcHit.h"
00025 #include "RawDataCnv/EventManagement/RAWEVENT.h" 
00026 #include "RawDataCnv/EventManagement/RawEvent.h" 
00027 #include "RawDataCnv/RawDataInputSvc.h" 
00028 #include "RawDataCnv/RawDataTofMcHitCnv.h"
00029 
00030 using Event::TofMcHit;
00031 using Event::TofMcHitCol;
00032 
00033 extern const CLID& CLID_TofMcHitCol;
00034 
00035 // Constructor.
00036 RawDataTofMcHitCnv::RawDataTofMcHitCnv(ISvcLocator* svc) : 
00037 RawDataBaseCnv(PACKEDRAWEVENT_StorageType, classID(), svc) 
00038 {
00039   //init();
00040 }
00041 
00042 // Return the identification number of this converter to the 
00043 // persistency service.
00044 const CLID& RawDataTofMcHitCnv::classID()
00045 {
00046   return CLID_TofMcHitCol;
00047 }
00048 
00049 StatusCode RawDataTofMcHitCnv::initialize()
00050 {
00051 
00052     std::string PackedRawDataCnvSvc_Name("PackedRawDataCnvSvc");
00053     std::string RawDataInputSvc_Name("RawDataInputSvc");
00054     std::string RawDataTofMcHitCnv_Name("RawDataTofMcHitCnv");
00055     
00056     // for Mutil-thread by tianhl
00057     //ConversionSvc*  pCnvSvc = 0;
00058     //if (pCnvSvc = dynamic_cast<ConversionSvc*>(conversionSvc())){
00059     SmartIF<IService> pCnvSvc(conversionSvc());
00060       if  (isGaudiThreaded(pCnvSvc->name())){
00061         PackedRawDataCnvSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
00062         RawDataInputSvc_Name += getGaudiThreadIDfromName(pCnvSvc->name());
00063         RawDataTofMcHitCnv_Name += getGaudiThreadIDfromName(pCnvSvc->name());
00064       }
00065       //}
00066     
00067   MsgStream log(messageService(), RawDataTofMcHitCnv_Name.c_str());
00068 
00069   StatusCode sc = RawDataBaseCnv::initialize();
00070   if (StatusCode::SUCCESS != sc) {
00071     log << MSG::ERROR << "RawDataBaseCnv: Cant initialize PackedRawDataCnvSvc" << endreq;
00072     return sc;
00073   }
00074 
00075   // Check RawDataCnvSvc
00076   IService* isvc = 0;
00077   sc = serviceLocator()->service(PackedRawDataCnvSvc_Name.c_str(), isvc, true);
00078   if (sc != StatusCode::SUCCESS) {
00079     log << MSG::ERROR << "Cant get PackedRawDataCnvSvc" << endreq;
00080   }
00081 
00082   m_RawDataAccess = dynamic_cast<PackedRawDataCnvSvc*> (isvc); 
00083   if (m_RawDataAccess  == 0 ) {
00084     log << MSG::ERROR << "RawDataTofCnv: Cant cast to RawDataCnvSvc " << endreq; 
00085     return StatusCode::FAILURE;
00086   }
00087 
00088   sc = serviceLocator()->getService(RawDataInputSvc_Name.c_str(), isvc);
00089   if (sc != StatusCode::SUCCESS ) {
00090     log << MSG::WARNING << "Cant get RawDataInputSvc " << endreq;
00091     return sc ;
00092   }
00093 
00094   m_inputSvc = dynamic_cast<RawDataInputSvc*> (isvc);
00095   if (m_inputSvc == 0 ) {
00096     log << MSG::WARNING << "Cant cast to RawDataInputSvc " << endreq;
00097     return StatusCode::FAILURE ;
00098   }
00099 
00100   return StatusCode::SUCCESS; 
00101 }
00102 
00103 
00104 StatusCode RawDataTofMcHitCnv::updateObj(IOpaqueAddress* pAddr, DataObject* pObj) {
00105   // Purpose and Method:  This method does nothing other than announce it has
00106   //   been called.
00107 
00108   //MsgStream log(msgSvc(), "RawDataTofMcHitCnv");
00109   //log << MSG::DEBUG << "RawDataTofMcHitCnv::updateObj" << endreq;
00110   return Converter::updateObj(pAddr, pObj);
00111 }
00112 
00113 // Create a converted object in the Transient Data Store.
00114 StatusCode RawDataTofMcHitCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
00115 {
00116   MsgStream log(msgSvc(), "RawDataTofMcHitCnv");
00117 
00118   //This converter will create an empty TofMcHitCol on the TDS
00119   TofMcHitCol *tofMcHitCol = new TofMcHitCol;
00120   pObj = tofMcHitCol;
00121    
00122   RAWEVENT *evt = m_inputSvc->currentEvent(); 
00123   if (evt == NULL) {
00124       //log << MSG::ERROR << "RawDataCnv has no event!" << endreq; 
00125       return StatusCode::FAILURE;
00126   }
00127   
00128   assert((evt->getTofTruth().size())%9 == 0);
00129 
00130   TofTruth_t m_TofTruth;
00131   TofMcHit* tofMcHit;
00132 
00133   std::vector<uint32_t>::const_iterator iter = evt->getTofTruth().begin();
00134   std::vector<uint32_t>::const_iterator eiter = evt->getTofTruth().end();
00135 
00136   for (int tofMcHitId = 0; iter != eiter; tofMcHitId++) {
00137     // retrieve the TofTruth data
00138     m_tofMcHitBuilder.unPack(iter, eiter, m_TofTruth);
00139     // construct the identifier
00140     Identifier ident;
00141     unsigned int barrel_ec = m_TofTruth.partId;
00142     // for scintillator
00143     if( barrel_ec>=0 && barrel_ec<=2 ) {
00144       unsigned int layer = 0;
00145       if( m_TofTruth.scinNb > TofID::getPHI_BARREL_MAX() ) {
00146         layer = 1;
00147         m_TofTruth.scinNb -= ( TofID::getPHI_BARREL_MAX() + 1 );
00148       }
00149       ident = TofID::cell_id( barrel_ec, layer, m_TofTruth.scinNb, 0 );
00150     }
00151     // for ETF(MRPC)
00152     else if( barrel_ec>=3 ) {
00153       unsigned int endcap = 0;
00154       if( barrel_ec==4 ) { endcap = 1; }
00155       ident = TofID::cell_id( 3, endcap, m_TofTruth.scinNb, m_TofTruth.strip, 0 );
00156     }
00157     else {
00158       log << MSG::ERROR << "barrel_ec is not correct! barrel_ec=" << barrel_ec << endreq; 
00159     }
00160 
00161     //construct the TofMcHit
00162     tofMcHit = new TofMcHit(ident, m_TofTruth.trackIndex,
00163                       m_TofTruth.x/(m_tofMcHitBuilder.m_xCoeff*1.0),
00164                       m_TofTruth.y/(m_tofMcHitBuilder.m_yCoeff*1.0),
00165                       m_TofTruth.z/(m_tofMcHitBuilder.m_zCoeff*1.0),
00166                       m_TofTruth.px/(m_tofMcHitBuilder.m_pxCoeff*1.0),
00167                       m_TofTruth.py/(m_tofMcHitBuilder.m_pyCoeff*1.0),
00168                       m_TofTruth.pz/(m_tofMcHitBuilder.m_pzCoeff*1.0),
00169                       m_TofTruth.trackLength/(m_tofMcHitBuilder.m_trackLengthCoeff*1.0),
00170                       m_TofTruth.time/(m_tofMcHitBuilder.m_timeCoeff*1.0) );
00171     // And add the stuff to the container
00172     tofMcHitCol->push_back(tofMcHit);
00173   }
00174 
00175   return StatusCode::SUCCESS; 
00176 
00177 }
00178 
00179 StatusCode RawDataTofMcHitCnv::createRep(DataObject* pObj, IOpaqueAddress*& pAddr)  
00180 {
00181    // convert PixelRaw in the container into ByteStream
00182   //MsgStream log(messageService(), "RawDataTofMcHitCnv");
00183   
00184   WriteRawEvent*& re = m_RawDataAccess->getRawEvent(); 
00185   
00186   if (re == 0) {
00187      //log << " get RawEvent failed !" << endreq;
00188      return StatusCode::FAILURE; 
00189   }
00190 
00191   SmartDataPtr<TofMcHitCol> mcHitCol(dataProvider(), EventModel::MC::TofMcHitCol);
00192 
00193   if (mcHitCol == 0) {
00194      //log << "no TofMcHitCol found" << endreq;
00195      return StatusCode::FAILURE;
00196   }
00197   
00198   StatusCode sc = m_tofMcHitBuilder.pack(mcHitCol, re);
00199 
00200   return sc; 
00201 
00202 }
00203 

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