ATLAS Offline Software
Loading...
Searching...
No Matches
TruthHelper::GenAccessIO Class Reference

#include <GenAccessIO.h>

Collaboration diagram for TruthHelper::GenAccessIO:

Public Member Functions

 GenAccessIO ()
StatusCode getMC (MCParticleCollection &mcParticles, const bool ifgen=false, const std::string &key="GEN_EVENT") const
StatusCode getDH (const McEventCollection *&dh) const
StatusCode getDH (const McEventCollection *&dh, const std::string &key) const
StatusCode store (McEventCollection *storee, const std::string &key) const
 GenAccessIO ()
StatusCode getMC (MCParticleCollection &mcParticles, const bool ifgen=false, const std::string &key="GEN_EVENT") const
StatusCode getDH (const McEventCollection *&dh) const
StatusCode getDH (const McEventCollection *&dh, const std::string &key) const
StatusCode store (McEventCollection *storee, const std::string &key) const

Private Attributes

ServiceHandle< StoreGateSvcm_sgSvc {"StoreGateSvc", "GenAccessIO"}

Detailed Description

Constructor & Destructor Documentation

◆ GenAccessIO() [1/2]

TruthHelper::GenAccessIO::GenAccessIO ( )
inline

Definition at line 24 of file Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h.

24 : m_sgSvc("StoreGateSvc", "GenAccessIO") {
25 if (m_sgSvc.retrieve().isFailure()) {
26 throw StatusCode::FAILURE;
27 }
28 }

◆ GenAccessIO() [2/2]

TruthHelper::GenAccessIO::GenAccessIO ( )
inline

Definition at line 27 of file PhysicsAnalysis/TruthParticleID/McParticleTools/src/GenAccessIO.h.

27 {
28 if (m_sgSvc.retrieve().isFailure()) {
29 throw StatusCode::FAILURE;
30 }
31 }

Member Function Documentation

◆ getDH() [1/4]

StatusCode TruthHelper::GenAccessIO::getDH ( const McEventCollection *& dh) const
inline

Definition at line 70 of file Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h.

70 {
71 return m_sgSvc->retrieve(dh);
72 }

◆ getDH() [2/4]

StatusCode TruthHelper::GenAccessIO::getDH ( const McEventCollection *& dh) const
inline

Definition at line 73 of file PhysicsAnalysis/TruthParticleID/McParticleTools/src/GenAccessIO.h.

73 {
74 return m_sgSvc->retrieve(dh);
75 }

◆ getDH() [3/4]

StatusCode TruthHelper::GenAccessIO::getDH ( const McEventCollection *& dh,
const std::string & key ) const
inline

Definition at line 73 of file Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h.

73 {
74 return m_sgSvc->retrieve(dh, key);
75 }

◆ getDH() [4/4]

StatusCode TruthHelper::GenAccessIO::getDH ( const McEventCollection *& dh,
const std::string & key ) const
inline

Definition at line 76 of file PhysicsAnalysis/TruthParticleID/McParticleTools/src/GenAccessIO.h.

76 {
77 return m_sgSvc->retrieve(dh, key);
78 }

◆ getMC() [1/2]

StatusCode TruthHelper::GenAccessIO::getMC ( MCParticleCollection & mcParticles,
const bool ifgen = false,
const std::string & key = "GEN_EVENT" ) const
inline

Definition at line 29 of file Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h.

29 {
30 MsgStream log(Athena::getMessageSvc(), "GenAccessIO");
31
32 // Retrieve iterators for McEventCollections objects
33 SG::ConstIterator<McEventCollection> firstMEC;
34 SG::ConstIterator<McEventCollection> lastMEC;
35 if ( (m_sgSvc->retrieve(firstMEC, lastMEC)).isFailure() ) {
36 log << MSG::ERROR << "Could not retrieve iterators for McEventCollections" << endmsg;
37 }
38 const McEventCollection& mcColl = *firstMEC;
39 int icount = 0;
40 for ( ; firstMEC!= lastMEC; ++firstMEC) icount++;
41 log << MSG::DEBUG << "Number of McEventCollections= "<< icount << endmsg;
42
43 // If there is more than one then do the retrieve with the key
44 if (icount > 1) {
45 log << MSG::DEBUG << "Key = " << key << endmsg;
46 const McEventCollection* mcCollptr = nullptr;
47 return this->getDH(mcCollptr, key);
48 }
49
50 if (icount > 0) {
51 // Iterate over all McEvent records
53 for (itr = mcColl.begin(); itr!=mcColl.end(); ++itr) {
54 // Access the HepMC record which is wrapped within McEvent
55 const HepMC::GenEvent* genEvt = (*itr);
56 if (genEvt == 0) return StatusCode::FAILURE;
57 if (ifgen) {
58 for (auto it: *genEvt) {
59 if (!HepMC::is_simulation_particle(it)) mcParticles.push_back(std::move(it));
60 }
61 } else {
62 for (auto it: *genEvt) {
63 mcParticles.push_back(std::move(it));
64 }
65 }
66 }
67 }
68 return StatusCode::SUCCESS;
69 }
#define endmsg
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
StatusCode getDH(const McEventCollection *&dh) const
IMessageSvc * getMessageSvc(bool quiet=false)
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...

◆ getMC() [2/2]

StatusCode TruthHelper::GenAccessIO::getMC ( MCParticleCollection & mcParticles,
const bool ifgen = false,
const std::string & key = "GEN_EVENT" ) const
inline

Definition at line 32 of file PhysicsAnalysis/TruthParticleID/McParticleTools/src/GenAccessIO.h.

32 {
33 MsgStream log(Athena::getMessageSvc(), "GenAccessIO");
34
35 // Retrieve iterators for McEventCollections objects
36 SG::ConstIterator<McEventCollection> firstMEC;
37 SG::ConstIterator<McEventCollection> lastMEC;
38 if ( (m_sgSvc->retrieve(firstMEC, lastMEC)).isFailure() ) {
39 log << MSG::ERROR << "Could not retrieve iterators for McEventCollections" << endmsg;
40 }
41 const McEventCollection& mcColl = *firstMEC;
42 int icount = 0;
43 for ( ; firstMEC!= lastMEC; ++firstMEC) icount++;
44 log << MSG::DEBUG << "Number of McEventCollections= "<< icount << endmsg;
45
46 // If there is more than one then do the retrieve with the key
47 if (icount > 1) {
48 log << MSG::DEBUG << "Key = " << key << endmsg;
49 const McEventCollection* mcCollptr = nullptr;
50 return this->getDH(mcCollptr, key);
51 }
52
53 if (icount > 0) {
54 // Iterate over all McEvent records
56 for (itr = mcColl.begin(); itr!=mcColl.end(); ++itr) {
57 // Access the HepMC record which is wrapped within McEvent
58 const HepMC::GenEvent* genEvt = (*itr);
59 if (genEvt == 0) return StatusCode::FAILURE;
60 if (ifgen) {
61 for (auto it: *genEvt) {
62 if (!HepMC::is_simulation_particle(it)) mcParticles.push_back(std::move(it));
63 }
64 } else {
65 for (auto it: *genEvt) {
66 mcParticles.push_back(std::move(it));
67 }
68 }
69 }
70 }
71 return StatusCode::SUCCESS;
72 }

◆ store() [1/2]

StatusCode TruthHelper::GenAccessIO::store ( McEventCollection * storee,
const std::string & key ) const
inline

Definition at line 76 of file Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h.

76 {
77 return m_sgSvc->record(storee, key);
78 }

◆ store() [2/2]

StatusCode TruthHelper::GenAccessIO::store ( McEventCollection * storee,
const std::string & key ) const
inline

Definition at line 79 of file PhysicsAnalysis/TruthParticleID/McParticleTools/src/GenAccessIO.h.

79 {
80 return m_sgSvc->record(storee, key);
81 }

Member Data Documentation

◆ m_sgSvc

ServiceHandle< StoreGateSvc > TruthHelper::GenAccessIO::m_sgSvc {"StoreGateSvc", "GenAccessIO"}
private

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