ATLAS Offline Software
Loading...
Searching...
No Matches
HepMC::GenEventBarcodes Class Reference

#include <GenEvent.h>

Inheritance diagram for HepMC::GenEventBarcodes:
Collaboration diagram for HepMC::GenEventBarcodes:

Public Member Functions

virtual bool from_string (const std::string &) override
virtual bool to_string (std::string &att) const override
ConstGenVertexPtr barcode_to_vertex (int id) const
GenVertexPtr barcode_to_vertex (int id)
ConstGenParticlePtr barcode_to_particle (int id) const
GenParticlePtr barcode_to_particle (int id)
void add (GenVertexPtr p)
void remove (GenVertexPtr p)
void add (GenParticlePtr p)
void remove (GenParticlePtr p)
std::map< int, ConstGenVertexPtrbarcode_to_vertex_map () const
std::map< int, ConstGenParticlePtrbarcode_to_particle_map () const
std::map< int, int > id_to_barcode_map () const
void fillAttribute (GenEvent *e)

Private Attributes

std::unordered_map< int, GenVertexPtrm_vertexBC
std::unordered_map< int, GenParticlePtrm_particleBC

Detailed Description

Definition at line 174 of file GenEvent.h.

Member Function Documentation

◆ add() [1/2]

void HepMC::GenEventBarcodes::add ( GenParticlePtr p)
inline

Definition at line 223 of file GenEvent.h.

223 {
224 if (!p) return;
225 auto barcode = p->attribute<HepMC3::IntAttribute>(HepMCStr::barcode);
226 if (barcode) {
227 m_particleBC[barcode->value()] = std::move(p);
228 }
229 }
std::unordered_map< int, GenParticlePtr > m_particleBC
Definition GenEvent.h:300
const std::string barcode
int barcode(const T *p)
Definition Barcode.h:15

◆ add() [2/2]

void HepMC::GenEventBarcodes::add ( GenVertexPtr p)
inline

Definition at line 204 of file GenEvent.h.

204 {
205 if (!p) return;
206 auto barcode = p->attribute<HepMC3::IntAttribute>(HepMCStr::barcode);
207 if (barcode) {
208 m_vertexBC[barcode->value()] = std::move(p);
209 }
210 }
std::unordered_map< int, GenVertexPtr > m_vertexBC
Definition GenEvent.h:299

◆ barcode_to_particle() [1/2]

GenParticlePtr HepMC::GenEventBarcodes::barcode_to_particle ( int id)
inline

Definition at line 198 of file GenEvent.h.

198 {
199 const auto it = m_particleBC.find (id);
200 if (it != m_particleBC.end()) return it->second;
201 return nullptr;
202 }

◆ barcode_to_particle() [2/2]

ConstGenParticlePtr HepMC::GenEventBarcodes::barcode_to_particle ( int id) const
inline

Definition at line 193 of file GenEvent.h.

193 {
194 const auto it = m_particleBC.find (id);
195 if (it != m_particleBC.end()) return it->second;
196 return nullptr;
197 }

◆ barcode_to_particle_map()

std::map< int, ConstGenParticlePtr > HepMC::GenEventBarcodes::barcode_to_particle_map ( ) const
inline

Definition at line 248 of file GenEvent.h.

248 {
249 std::map<int, ConstGenParticlePtr> ret;
250 for (const auto &bcpartpair: m_particleBC)
251 ret.insert({bcpartpair.first, std::const_pointer_cast<const HepMC3::GenParticle>(bcpartpair.second)});
252 return ret;
253 }

◆ barcode_to_vertex() [1/2]

GenVertexPtr HepMC::GenEventBarcodes::barcode_to_vertex ( int id)
inline

Definition at line 188 of file GenEvent.h.

188 {
189 const auto it = m_vertexBC.find (id);
190 if (it != m_vertexBC.end()) return it->second;
191 return nullptr;
192 }

◆ barcode_to_vertex() [2/2]

ConstGenVertexPtr HepMC::GenEventBarcodes::barcode_to_vertex ( int id) const
inline

Definition at line 183 of file GenEvent.h.

183 {
184 const auto it = m_vertexBC.find (id);
185 if (it != m_vertexBC.end()) return it->second;
186 return nullptr;
187 }

◆ barcode_to_vertex_map()

std::map< int, ConstGenVertexPtr > HepMC::GenEventBarcodes::barcode_to_vertex_map ( ) const
inline

Definition at line 242 of file GenEvent.h.

242 {
243 std::map<int, ConstGenVertexPtr> ret;
244 for (const auto &bcvertpair: m_vertexBC)
245 ret.insert({bcvertpair.first, std::const_pointer_cast<const HepMC3::GenVertex>(bcvertpair.second)});
246 return ret;
247 }

◆ fillAttribute()

void HepMC::GenEventBarcodes::fillAttribute ( GenEvent * e)
inline

Definition at line 262 of file GenEvent.h.

262 {
263 const auto eventAttributes = e->attributes(); // this makes a copy
264 const auto barcodeAttributeIt = eventAttributes.find(HepMCStr::barcode);
265 const bool hasBarcodeAttribute = barcodeAttributeIt != eventAttributes.end();
266
267 const auto &particles = e->particles();
268 for (size_t i = 1; i <= particles.size(); i++) {
269 if (hasBarcodeAttribute && barcodeAttributeIt->second.count(i) > 0) {
270 const auto &ptr = barcodeAttributeIt->second.at(i);
271 if (ptr->is_parsed()) {
272 m_particleBC[static_cast<HepMC3::IntAttribute*>(ptr.get())->value()] = ptr->particle();
273 }
274 else {
275 m_particleBC[std::atoi(ptr->unparsed_string().c_str())] = ptr->particle();
276 }
277 } else {
279 }
280 }
281 const auto &vertices = e->vertices();
282 for (size_t i = 1; i <= vertices.size(); i++) {
283 if (hasBarcodeAttribute && barcodeAttributeIt->second.count(-i) > 0) {
284 const auto &ptr = barcodeAttributeIt->second.at(-i);
285 if (ptr->is_parsed()) {
286 m_vertexBC[static_cast<HepMC3::IntAttribute*>(ptr.get())->value()] = ptr->vertex();
287 }
288 else {
289 m_vertexBC[std::atoi(ptr->unparsed_string().c_str())] = ptr->vertex();
290 }
291 } else {
292 m_vertexBC[-i] = vertices[i-1];
293 }
294 }
295 set_is_parsed(true);
296 }
void * ptr(T *p)
Definition SGImplSvc.cxx:74

◆ from_string()

virtual bool HepMC::GenEventBarcodes::from_string ( const std::string & )
inlineoverridevirtual

Definition at line 177 of file GenEvent.h.

177{ return false; }

◆ id_to_barcode_map()

std::map< int, int > HepMC::GenEventBarcodes::id_to_barcode_map ( ) const
inline

Definition at line 254 of file GenEvent.h.

254 {
255 std::map<int, int> ret;
256 for (const auto &bcvertpair: m_vertexBC) ret.insert({bcvertpair.second->id(), bcvertpair.first});
257 for (const auto &bcpartpair: m_particleBC) ret.insert({bcpartpair.second->id(), bcpartpair.first});
258 return ret;
259 }

◆ remove() [1/2]

void HepMC::GenEventBarcodes::remove ( GenParticlePtr p)
inline

Definition at line 231 of file GenEvent.h.

231 {
232 if (!p) return;
233 auto barcode = p->attribute<HepMC3::IntAttribute>(HepMCStr::barcode);
234 if (barcode) {
235 const auto it = m_particleBC.find (barcode->value());
236 if (it != m_particleBC.end()) {
237 m_particleBC.erase (it);
238 }
239 }
240 }

◆ remove() [2/2]

void HepMC::GenEventBarcodes::remove ( GenVertexPtr p)
inline

Definition at line 212 of file GenEvent.h.

212 {
213 if (!p) return;
214 auto barcode = p->attribute<HepMC3::IntAttribute>(HepMCStr::barcode);
215 if (barcode) {
216 const auto it = m_vertexBC.find (barcode->value());
217 if (it != m_vertexBC.end()) {
218 m_vertexBC.erase (it);
219 }
220 }
221 }

◆ to_string()

virtual bool HepMC::GenEventBarcodes::to_string ( std::string & att) const
inlineoverridevirtual

Definition at line 178 of file GenEvent.h.

179 {
180 att = "GenEventBarcodes";
181 return true;
182 }

Member Data Documentation

◆ m_particleBC

std::unordered_map<int, GenParticlePtr> HepMC::GenEventBarcodes::m_particleBC
private

Definition at line 300 of file GenEvent.h.

◆ m_vertexBC

std::unordered_map<int, GenVertexPtr> HepMC::GenEventBarcodes::m_vertexBC
private

Definition at line 299 of file GenEvent.h.


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