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-2021 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 return found;
32}
33
34bool HEPRUPAttribute::to_string(std::string &att) const {
35 std::ostringstream os;
36 if ( heprup.NPRUP ) heprup.print(os);
37 for ( int i = 0, N = tags.size(); i < N; ++i )
38 if ( heprup.NPRUP == 0 || tags[i]->name != "init" ) tags[i]->print(os);
39 att = os.str();
40 return true;
41}
42
44 for ( int i = 0, N = tags.size(); i < N; ++i ) delete tags[i];
45 tags.clear();
46 hepeup.clear();
47}
48
49bool HEPEUPAttribute::from_string(const std::string &att) {
50 clear();
52 for ( int i = 0, N = tags.size(); i < N; ++i )
53 if ( tags[i]->name == "event" || tags[i]->name == "eventgroup")
54 return true;
55 return false;
56}
57
58bool HEPEUPAttribute::to_string(std::string &att) const {
59 std::ostringstream os;
60 if ( hepeup.heprup ) hepeup.print(os);
61 for ( int i = 0, N = tags.size(); i < N; ++i )
62 if ( !hepeup.heprup ||
63 (tags[i]->name != "event" && tags[i]->name != "eventgroup") )
64 tags[i]->print(os);
65 att = os.str();
66 return true;
67}
68
70 std::shared_ptr<HEPRUPAttribute> hepr =
71 event()->attribute<HEPRUPAttribute>("HEPRUP");
72 bool found = false;
73 for ( int i = 0, N = tags.size(); i < N; ++i )
74 if ( tags[i]->name == "event" || tags[i]->name == "eventgroup" ) {
75 hepeup = LHEF::HEPEUP(*tags[i], hepr->heprup);
76 found = true;
77 }
78 return found;
79}
80
81} // namespace HepMC3
82
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:409
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