00001
00002 #include <OnXSvc/Win32.h>
00003
00004
00005 #include "SoHepMCEventCnv.h"
00006
00007
00008 #include <Lib/smanip.h>
00009 #include <Lib/Interfaces/ISession.h>
00010
00011
00012 #include <GaudiKernel/ISvcLocator.h>
00013 #include <GaudiKernel/IParticlePropertySvc.h>
00014 #include <GaudiKernel/Converter.h>
00015 #include <GaudiKernel/CnvFactory.h>
00016 #include <GaudiKernel/MsgStream.h>
00017 #include <GaudiKernel/ParticleProperty.h>
00018
00019
00020 #include <OnXSvc/IUserInterfaceSvc.h>
00021 #include <OnXSvc/ISoConversionSvc.h>
00022 #include <OnXSvc/ClassID.h>
00023
00024 #include "Types.h"
00025
00026
00027 #include <Event/HepMCEvent.h>
00028 #include <HepMC/GenEvent.h>
00029
00030 DECLARE_CONVERTER_FACTORY( SoHepMCEventCnv );
00031
00033 SoHepMCEventCnv::SoHepMCEventCnv(
00034 ISvcLocator* aSvcLoc
00035 )
00036 :Converter(So_TechnologyType,SoHepMCEventCnv::classID(),aSvcLoc)
00037 ,fSoCnvSvc(0)
00038 ,fUISvc(0)
00039 ,fParticlePropertySvc(0)
00042 {
00043 }
00045 StatusCode SoHepMCEventCnv::initialize(
00046 )
00047
00048
00049 {
00050 StatusCode status = Converter::initialize();
00051 if( status.isFailure() ) return status;
00052 status = serviceLocator()->service("SoConversionSvc",fSoCnvSvc);
00053 if(status.isFailure()) return status;
00054 status = serviceLocator()->service("OnXSvc",fUISvc);
00055 if(status.isFailure()) return status;
00056 status =
00057 serviceLocator()->service("ParticlePropertySvc",fParticlePropertySvc);
00058 if(status.isFailure()) return status;
00059 return status;
00060 }
00062 StatusCode SoHepMCEventCnv::finalize()
00063
00064
00065 {
00066
00067
00068
00069 return StatusCode::SUCCESS;
00070 }
00072 long SoHepMCEventCnv::repSvcType() const
00075 {
00076 return i_repSvcType();
00077 }
00079 StatusCode SoHepMCEventCnv::createRep(
00080 DataObject* aObject
00081 ,IOpaqueAddress*&
00082 )
00083
00084
00085 {
00086 MsgStream log(messageService(), "SoHepMCEventCnv");
00087 log << MSG::INFO << "SoHEPMcEventCnv createReps" << endreq;
00088
00089 if(!fUISvc) {
00090 log << MSG::INFO << " UI service not found" << endreq;
00091 return StatusCode::SUCCESS;
00092 }
00093
00094 if(!fParticlePropertySvc) {
00095 log << MSG::INFO << " ParticleProperty service not found" << endreq;
00096 return StatusCode::SUCCESS;
00097 }
00098
00099 ISession* session = fUISvc->session();
00100 if(!session) {
00101 log << MSG::INFO << " can't get ISession." << endreq;
00102 return StatusCode::FAILURE;
00103 }
00104
00105 SoRegion* soRegion = fUISvc->currentSoRegion();
00106 if(!soRegion) {
00107 log << MSG::INFO << " can't get viewing region." << endreq;
00108 return StatusCode::FAILURE;
00109 }
00110
00111 if(!aObject) {
00112 log << MSG::INFO << " NULL object." << endreq;
00113 return StatusCode::FAILURE;
00114 }
00115
00116 LHCb::HepMCEvents* mcEvents = dynamic_cast<LHCb::HepMCEvents*>(aObject);
00117 if(!mcEvents) {
00118 log << MSG::INFO << " bad object type." << endreq;
00119 return StatusCode::FAILURE;
00120 }
00121
00122 log << MSG::INFO << " number of events : " << mcEvents->size() << endreq;
00123
00124 LHCb::HepMCEvents::iterator it;
00125 for(it = mcEvents->begin(); it != mcEvents->end(); it++) {
00126 HepMC::GenEvent* genEvent = (*it)->pGenEvt();
00127
00128 log << MSG::INFO
00129 << " number of particles : " << genEvent->particles_size()
00130 << " number of vertices : " << genEvent->vertices_size()
00131 << endreq;
00132 for ( HepMC::GenEvent::particle_const_iterator p
00133 = genEvent->particles_begin();
00134 p != genEvent->particles_end(); ++p ) {
00135
00136
00137 HepMC::GenParticle* genParticle = (*p);
00138 GenParticleType::represent(genParticle,
00139 session,soRegion,
00140 fParticlePropertySvc);
00141
00142 }
00143
00144 }
00145
00146 return StatusCode::SUCCESS;
00147 }
00149 const CLID& SoHepMCEventCnv::classID(
00150 )
00151
00152
00153 {
00154 return LHCb::HepMCEvents::classID();
00155 }
00157 const unsigned char SoHepMCEventCnv::storageType(
00158 )
00159
00160
00161 {
00162 return So_TechnologyType;
00163 }