ATLAS Offline Software
Loading...
Searching...
No Matches
ReadHepEvtFromAscii Class Reference

#include <ReadHepEvtFromAscii.h>

Inheritance diagram for ReadHepEvtFromAscii:
Collaboration diagram for ReadHepEvtFromAscii:

Public Member Functions

 ReadHepEvtFromAscii (const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize () override
virtual StatusCode execute () override
virtual StatusCode finalize () override
virtual StatusCode sysInitialize () override
 Override sysInitialize.
virtual const DataObjIDColl & extraOutputDeps () const override
 Return the list of extra output dependencies.
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const

Protected Member Functions

void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

bool read_hepevt_particle (int i)
bool read_hepevt_event_header ()
 This class is only needed for HepMC2-based builds.
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

std::string m_key
std::string m_input_file
std::ifstream m_file
DataObjIDColl m_extendedExtraObjects
StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default)
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default)
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared

Detailed Description

Definition at line 10 of file ReadHepEvtFromAscii.h.

Member Typedef Documentation

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< Algorithm > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ ReadHepEvtFromAscii()

ReadHepEvtFromAscii::ReadHepEvtFromAscii ( const std::string & name,
ISvcLocator * pSvcLocator )

Definition at line 77 of file ReadHepEvtFromAscii.cxx.

78 : AthAlgorithm(name, pSvcLocator)
79{
80 // Set users' request
81 declareProperty("McEventKey", m_key = "GEN_EVENT");
82 declareProperty("HepEvtFile", m_input_file = "events.ascii");
83}
AthAlgorithm()
Default constructor:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)

Member Function Documentation

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< Algorithm > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ execute()

StatusCode ReadHepEvtFromAscii::execute ( )
overridevirtual

Definition at line 104 of file ReadHepEvtFromAscii.cxx.

104 {
105
106 msg(MSG::INFO) << ">>> ReadHepEvtFromAscii from execute" << endmsg;
107
108 McEventCollection* mcEvtColl;
109
110 if ( evtStore()->contains<McEventCollection>(m_key) && evtStore()->retrieve(mcEvtColl, m_key).isSuccess() ) {
111 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "found an McEventCollecion in store" << endmsg;
112 } else {
113 // McCollection doesn't exist. Create it (empty)
114 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "create new McEventCollecion in store" << endmsg;
115 mcEvtColl = new McEventCollection;
116 StatusCode status = evtStore()->record( mcEvtColl, m_key );
117 if (status.isFailure()) {
118 msg(MSG::ERROR) << "Could not record McEventCollection" << endmsg;
119 return status;
120 }
121 }
122
123 HepMC::GenEvent* evt = new HepMC::GenEvent();
124 HepMC::HEPEVT_Wrapper::zero_everything();
125 bool fileok=read_hepevt_event_header();
126 for (int i=1; (i<=HepMC::HEPEVT_Wrapper::number_entries())&&fileok; i++) fileok=read_hepevt_particle(i);
127 if (!fileok) return StatusCode::FAILURE;
128
129#ifdef HEPMC3
130 HepMC::HEPEVT_Wrapper::HEPEVT_to_GenEvent(evt);
131#else
132 HepMC::IO_HEPEVT hepio;
133 hepio.set_print_inconsistency_errors(0);
134 hepio.fill_next_event(evt);
135#endif
136
137 // Convert GeV to MeV
138#ifdef HEPMC3
139 for ( auto p: evt->particles() ){
140#else
141 for ( auto ip = evt->particles_begin(); ip != evt->particles_end(); ++ip ){
142 auto p=*ip;
143#endif
144 HepMC::FourVector newMomentum(0.,0.,0.,0.);
145 newMomentum.setPx( p->momentum().px() * 1000. );
146 newMomentum.setPy( p->momentum().py() * 1000. );
147 newMomentum.setPz( p->momentum().pz() * 1000. );
148 newMomentum.setE( p->momentum().e() * 1000. );
149 p->set_momentum(newMomentum);
150
151 }
153 mcEvtColl->push_back(evt);
154
155 // End of execution for each event
156 return StatusCode::SUCCESS;
157}
#define endmsg
bool msgLvl(const MSG::Level lvl) const
MsgStream & msg() const
value_type push_back(value_type pElem)
Add an element to the end of the collection.
bool read_hepevt_event_header()
This class is only needed for HepMC2-based builds.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
::StatusCode StatusCode
StatusCode definition for legacy code.
void fillBarcodesAttribute(GenEvent *)
Definition GenEvent.h:628
status
Definition merge.py:16
retrieve(aClass, aKey=None)
Definition PyKernel.py:110

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< Algorithm > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ extraOutputDeps()

const DataObjIDColl & AthAlgorithm::extraOutputDeps ( ) const
overridevirtualinherited

Return the list of extra output dependencies.

This list is extended to include symlinks implied by inheritance relations.

Definition at line 50 of file AthAlgorithm.cxx.

51{
52 // If we didn't find any symlinks to add, just return the collection
53 // from the base class. Otherwise, return the extended collection.
54 if (!m_extendedExtraObjects.empty()) {
56 }
57 return Algorithm::extraOutputDeps();
58}
DataObjIDColl m_extendedExtraObjects

◆ finalize()

StatusCode ReadHepEvtFromAscii::finalize ( )
overridevirtual

Definition at line 158 of file ReadHepEvtFromAscii.cxx.

158 {
159
160 msg(MSG::INFO) << ">>> ReadHepEvtFromAscii from finalize" << endmsg;
161
162 if(m_file.is_open()) m_file.close();
163 // End of finalization step
164 return StatusCode::SUCCESS;
165
166}

◆ initialize()

StatusCode ReadHepEvtFromAscii::initialize ( )
overridevirtual

Definition at line 85 of file ReadHepEvtFromAscii.cxx.

85 {
86
87 msg(MSG::INFO) << ">>> ReadHepEvtFromAscii from Initialize" << endmsg;
88
89#ifdef HEPMC3
90//These things are not present
91#else
92
93 HepMC::HEPEVT_Wrapper::set_sizeof_int(4);
94 HepMC::HEPEVT_Wrapper::set_sizeof_real(8);
95 HepMC::HEPEVT_Wrapper::set_max_number_entries(10000);
96
97#endif
98 // Initialize input file
99 m_file=std::ifstream(m_input_file.c_str());
100 if( !m_file.is_open() ) return StatusCode::FAILURE;
101 // Initialization terminated
102 return StatusCode::SUCCESS;
103}

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< Algorithm > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ msg()

MsgStream & AthCommonMsg< Algorithm >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msgLvl()

bool AthCommonMsg< Algorithm >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< Algorithm > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ read_hepevt_event_header()

bool ReadHepEvtFromAscii::read_hepevt_event_header ( )
private

This class is only needed for HepMC2-based builds.

Definition at line 22 of file ReadHepEvtFromAscii.cxx.

23{
24 const size_t max_e_buffer_size=512;
25 char buf_e[max_e_buffer_size];
26 bool eventline=false;
27 int im=0, pm=0;
28 while(!eventline)
29 {
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);
33 char attr=' ';
34 eventline=false;
35 while (!eventline)
36 {
37 if (!(st_e>>attr)) break;
38 if (attr==' ') continue;
39 else eventline=false;
40 if (attr=='E')
41 {
42 eventline=static_cast<bool>(st_e>>im>>pm);
43 }
44 }
45 }
46 HepMC::HEPEVT_Wrapper::set_event_number(im);
47 HepMC::HEPEVT_Wrapper::set_number_entries(pm);
48 return eventline;
49}

◆ read_hepevt_particle()

bool ReadHepEvtFromAscii::read_hepevt_particle ( int i)
private

Definition at line 50 of file ReadHepEvtFromAscii.cxx.

51{
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]));/* Pythia writes second mother 0*/
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]);
74 return true;
75}

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< Algorithm > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< Algorithm > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ sysInitialize()

StatusCode AthAlgorithm::sysInitialize ( )
overridevirtualinherited

Override sysInitialize.

Override sysInitialize from the base class.

Loop through all output handles, and if they're WriteCondHandles, automatically register them and this Algorithm with the CondSvc

Scan through all outputHandles, and if they're WriteCondHandles, register them with the CondSvc

Reimplemented from AthCommonDataStore< AthCommonMsg< Algorithm > >.

Reimplemented in AthAnalysisAlgorithm, AthFilterAlgorithm, AthHistogramAlgorithm, and PyAthena::Alg.

Definition at line 66 of file AthAlgorithm.cxx.

66 {
68
69 if (sc.isFailure()) {
70 return sc;
71 }
72 ServiceHandle<ICondSvc> cs("CondSvc",name());
73 for (auto h : outputHandles()) {
74 if (h->isCondition() && h->mode() == Gaudi::DataHandle::Writer) {
75 // do this inside the loop so we don't create the CondSvc until needed
76 if ( cs.retrieve().isFailure() ) {
77 ATH_MSG_WARNING("no CondSvc found: won't autoreg WriteCondHandles");
78 return StatusCode::SUCCESS;
79 }
80 if (cs->regHandle(this,*h).isFailure()) {
81 sc = StatusCode::FAILURE;
82 ATH_MSG_ERROR("unable to register WriteCondHandle " << h->fullKey()
83 << " with CondSvc");
84 }
85 }
86 }
87 return sc;
88}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
static Double_t sc
virtual StatusCode sysInitialize() override
Override sysInitialize.
AthCommonDataStore(const std::string &name, T... args)
virtual std::vector< Gaudi::DataHandle * > outputHandles() const override

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< Algorithm > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< Algorithm > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
std::vector< SG::VarHandleKeyArray * > m_vhka

Member Data Documentation

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< Algorithm > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default)

Definition at line 393 of file AthCommonDataStore.h.

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< Algorithm > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default)

Definition at line 390 of file AthCommonDataStore.h.

◆ m_extendedExtraObjects

DataObjIDColl AthAlgorithm::m_extendedExtraObjects
privateinherited

Definition at line 79 of file AthAlgorithm.h.

◆ m_file

std::ifstream ReadHepEvtFromAscii::m_file
private

Definition at line 22 of file ReadHepEvtFromAscii.h.

◆ m_input_file

std::string ReadHepEvtFromAscii::m_input_file
private

Definition at line 21 of file ReadHepEvtFromAscii.h.

◆ m_key

std::string ReadHepEvtFromAscii::m_key
private

Definition at line 20 of file ReadHepEvtFromAscii.h.

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< Algorithm > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< Algorithm > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.


The documentation for this class was generated from the following files: