15 #include "GaudiKernel/DataSvc.h"
24 const size_t max_e_buffer_size=512;
25 char buf_e[max_e_buffer_size];
30 m_file.getline(buf_e,max_e_buffer_size);
31 if( strlen(buf_e) == 0 )
return false;
32 std::stringstream st_e(buf_e);
37 if (!(st_e>>attr))
break;
38 if (attr==
' ')
continue;
42 eventline=
static_cast<bool>(st_e>>
im>>pm);
46 HepMC::HEPEVT_Wrapper::set_event_number(
im);
47 HepMC::HEPEVT_Wrapper::set_number_entries(pm);
52 static constexpr
size_t max_p_buffer_size=512;
53 static constexpr
size_t max_v_buffer_size=512;
54 char buf_p[max_p_buffer_size];
55 char buf_v[max_v_buffer_size];
56 std::array<int, 6> intcodes {};
57 std::array<double, 5> fltcodes1 {};
58 std::array<double, 4> fltcodes2 {};
59 m_file.getline(buf_p,max_p_buffer_size);
60 if( strlen(buf_p) == 0 )
return false;
61 m_file.getline(buf_v,max_v_buffer_size);
62 if( strlen(buf_v) == 0 )
return false;
63 std::stringstream st_p(buf_p);
64 std::stringstream st_v(buf_v);
65 if (!
static_cast<bool>(st_p>>intcodes[0]>>intcodes[1]>>intcodes[2]>>intcodes[3]>>intcodes[4]>>intcodes[5]>>fltcodes1[0]>>fltcodes1[1]>>fltcodes1[2]>>fltcodes1[3]>>fltcodes1[4])) {
return false;}
66 if (!
static_cast<bool>(st_v>>fltcodes2[0]>>fltcodes2[1]>>fltcodes2[2]>>fltcodes2[3])) {
return false;}
67 HepMC::HEPEVT_Wrapper::set_status(
i,intcodes[0]);
68 HepMC::HEPEVT_Wrapper::set_id(
i,intcodes[1]);
69 HepMC::HEPEVT_Wrapper::set_parents(
i,intcodes[2],
std::max(intcodes[2],intcodes[3]));
70 HepMC::HEPEVT_Wrapper::set_children(
i,intcodes[4],intcodes[5]);
71 HepMC::HEPEVT_Wrapper::set_momentum(
i,fltcodes1[0],fltcodes1[1],fltcodes1[2],fltcodes1[3]);
72 HepMC::HEPEVT_Wrapper::set_mass(
i,fltcodes1[4]);
73 HepMC::HEPEVT_Wrapper::set_position(
i,fltcodes2[0],fltcodes2[1],fltcodes2[2],fltcodes2[3]);
88 msg(MSG::INFO) <<
">>> ReadHepEvtFromAscii from Initialize" <<
endmsg;
93 msg(MSG::ERROR) <<
"Could not find StoreGateSvc" <<
endmsg;
100 HepMC::HEPEVT_Wrapper::set_sizeof_int(4);
101 HepMC::HEPEVT_Wrapper::set_sizeof_real(8);
102 HepMC::HEPEVT_Wrapper::set_max_number_entries(10000);
107 if( !
m_file.is_open() )
return StatusCode::FAILURE;
109 return StatusCode::SUCCESS;
113 msg(MSG::INFO) <<
">>> ReadHepEvtFromAscii from execute" <<
endmsg;
125 msg(MSG::ERROR) <<
"Could not record McEventCollection" <<
endmsg;
130 HepMC::GenEvent*
evt =
new HepMC::GenEvent();
131 HepMC::HEPEVT_Wrapper::zero_everything();
134 if (!fileok)
return StatusCode::FAILURE;
137 HepMC::HEPEVT_Wrapper::HEPEVT_to_GenEvent(
evt);
139 HepMC::IO_HEPEVT hepio;
140 hepio.set_print_inconsistency_errors(0);
141 hepio.fill_next_event(
evt);
146 for (
auto p:
evt->particles() ){
148 for (
auto ip =
evt->particles_begin();
ip !=
evt->particles_end(); ++
ip ){
151 HepMC::FourVector newMomentum(0.,0.,0.,0.);
152 newMomentum.setPx(
p->momentum().px() * 1000. );
153 newMomentum.setPy(
p->momentum().py() * 1000. );
154 newMomentum.setPz(
p->momentum().pz() * 1000. );
155 newMomentum.setE(
p->momentum().e() * 1000. );
156 p->set_momentum(newMomentum);
163 return StatusCode::SUCCESS;
167 msg(MSG::INFO) <<
">>> ReadHepEvtFromAscii from finalize" <<
endmsg;
171 return StatusCode::SUCCESS;