HepMC3 event record library
LHEFAttributes.cc
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// This file is part of HepMC
4// Copyright (C) 2014-2023 The HepMC collaboration (see AUTHORS for details)
5//
6/**
7 * @file LHEFAttributes.cc
8 * @brief Implementation of \b class HEPRUPAttribute and HEPEUPAttribute
9 */
10
12#include "HepMC3/GenEvent.h"
13
14namespace HepMC3 {
15
17 for ( int i = 0, N = tags.size(); i < N; ++i ) delete tags[i];
18 tags.clear();
19 heprup.clear();
20}
21
22bool HEPRUPAttribute::from_string(const std::string &att) {
23 bool found = false;
24 clear();
26 for ( int i = 0, N = tags.size(); i < N; ++i ) {
27 if ( tags[i]->name == "init" ) {
28 heprup = LHEF::HEPRUP(*tags[i], 3);
29 found = true;
30 }
31 }
32 return found;
33}
34
35bool HEPRUPAttribute::to_string(std::string &att) const {
36 std::ostringstream os;
37 if ( heprup.NPRUP ) heprup.print(os);
38 for ( int i = 0, N = tags.size(); i < N; ++i ) {
39 if ( heprup.NPRUP == 0 || tags[i]->name != "init" ) tags[i]->print(os);
40 }
41 att = os.str();
42 return true;
43}
44
46 for ( int i = 0, N = tags.size(); i < N; ++i ) delete tags[i];
47 tags.clear();
48 hepeup.clear();
49}
50
51bool HEPEUPAttribute::from_string(const std::string &att) {
52 clear();
54 for ( int i = 0, N = tags.size(); i < N; ++i ) {
55 if ( tags[i]->name == "event" || tags[i]->name == "eventgroup") {
56 return true;
57 }
58 }
59 return false;
60}
61
62bool HEPEUPAttribute::to_string(std::string &att) const {
63 std::ostringstream os;
64 if ( hepeup.heprup ) hepeup.print(os);
65 for ( int i = 0, N = tags.size(); i < N; ++i ) {
66 if ( !hepeup.heprup ||
67 (tags[i]->name != "event" && tags[i]->name != "eventgroup") ) {
68 tags[i]->print(os);
69 }
70 }
71 att = os.str();
72 return true;
73}
74
76 std::shared_ptr<HEPRUPAttribute> hepr =
77 event()->attribute<HEPRUPAttribute>("HEPRUP");
78 bool found = false;
79 for ( int i = 0, N = tags.size(); i < N; ++i ) {
80 if ( tags[i]->name == "event" || tags[i]->name == "eventgroup" ) {
81 hepeup = LHEF::HEPEUP(*tags[i], hepr->heprup);
82 found = true;
83 }
84 }
85 return found;
86}
87
88} // namespace HepMC3
89
Definition of class GenEvent.
Definition of class HEPRUPAttribute and class HEPEUAttribute.
const GenEvent * event() const
Definition: Attribute.h:108
std::shared_ptr< T > attribute(const std::string &name, const int &id=0) const
Get attribute of type T.
Definition: GenEvent.h:417
virtual bool init() override
Parse the XML-tags.
LHEF::HEPEUP hepeup
The actual HEPEUP object.
virtual bool from_string(const std::string &att) override
Fill class content from string.
void clear()
Clear this object.
std::vector< LHEF::XMLTag * > tags
The parsed XML-tags.
virtual bool to_string(std::string &att) const override
Fill string from class content.
Class for storing data for LHEF run information.
virtual bool from_string(const std::string &att) override
Fill class content from string.
void clear()
Clear this object.
LHEF::HEPRUP heprup
The actual HEPRUP object.
std::vector< LHEF::XMLTag * > tags
The parsed XML-tags.
virtual bool to_string(std::string &att) const override
Fill string from class content.
void print(std::ostream &file) const
Definition: LHEF.h:2320
HEPRUP * heprup
Definition: LHEF.h:2630
void clear()
Definition: LHEF.h:2414
void print(std::ostream &file) const
Definition: LHEF.h:1765
int NPRUP
Definition: LHEF.h:1967
void clear()
Definition: LHEF.h:1862
HepMC3 main namespace.
static std::vector< XMLTag * > findXMLTags(std::string str, std::string *leftover=0)
Definition: LHEF.h:198