HepMC3 event record library: LHEFAttributes.cc Source File

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
11#include "HepMC3/LHEFAttributes.h"
12#include "HepMC3/GenEvent.h"
13
14namespace HepMC3 {
15
16 void HEPRUPAttribute::clear() {
17 for ( int i = 0, N = tags.size(); i < N; ++i ) delete tags[i];
18 tags.clear();
19 heprup.clear();
20}
21
22 bool HEPRUPAttribute::from_string(const std::string &att) {
23 bool found = false;
24 clear();
25 tags = LHEF::XMLTag::findXMLTags(att);
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
35 bool 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
45 void HEPEUPAttribute::clear() {
46 for ( int i = 0, N = tags.size(); i < N; ++i ) delete tags[i];
47 tags.clear();
48 hepeup.clear();
49}
50
51 bool HEPEUPAttribute::from_string(const std::string &att) {
52 clear();
53 tags = LHEF::XMLTag::findXMLTags(att);
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
62 bool 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
75 bool HEPEUPAttribute::init() {
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
GenEvent.h
Definition of class GenEvent.
LHEFAttributes.h
Definition of class HEPRUPAttribute and class HEPEUAttribute.
HepMC3::Attribute::event
const GenEvent * event() const
Definition Attribute.h:108
HepMC3::GenEvent::attribute
std::shared_ptr< T > attribute(const std::string &name, const int &id=0) const
Get attribute of type T.
Definition GenEvent.h:420
HepMC3::HEPEUPAttribute::init
virtual bool init() override
Parse the XML-tags.
Definition LHEFAttributes.cc:75
HepMC3::HEPEUPAttribute::hepeup
LHEF::HEPEUP hepeup
The actual HEPEUP object.
Definition LHEFAttributes.h:113
HepMC3::HEPEUPAttribute::from_string
virtual bool from_string(const std::string &att) override
Fill class content from string.
Definition LHEFAttributes.cc:51
HepMC3::HEPEUPAttribute::clear
void clear()
Clear this object.
Definition LHEFAttributes.cc:45
HepMC3::HEPEUPAttribute::tags
std::vector< LHEF::XMLTag * > tags
The parsed XML-tags.
Definition LHEFAttributes.h:116
HepMC3::HEPEUPAttribute::to_string
virtual bool to_string(std::string &att) const override
Fill string from class content.
Definition LHEFAttributes.cc:62
HepMC3::HEPRUPAttribute
Class for storing data for LHEF run information.
Definition LHEFAttributes.h:26
HepMC3::HEPRUPAttribute::from_string
virtual bool from_string(const std::string &att) override
Fill class content from string.
Definition LHEFAttributes.cc:22
HepMC3::HEPRUPAttribute::clear
void clear()
Clear this object.
Definition LHEFAttributes.cc:16
HepMC3::HEPRUPAttribute::heprup
LHEF::HEPRUP heprup
The actual HEPRUP object.
Definition LHEFAttributes.h:57
HepMC3::HEPRUPAttribute::tags
std::vector< LHEF::XMLTag * > tags
The parsed XML-tags.
Definition LHEFAttributes.h:60
HepMC3::HEPRUPAttribute::to_string
virtual bool to_string(std::string &att) const override
Fill string from class content.
Definition LHEFAttributes.cc:35
LHEF::HEPEUP
Definition LHEF.h:2136
LHEF::HEPRUP
Definition LHEF.h:1646
HepMC3
HepMC3 main namespace.
Definition AnalysisExample.h:24
LHEF::XMLTag::findXMLTags
static std::vector< XMLTag * > findXMLTags(std::string str, std::string *leftover=nullptr)
Definition LHEF.h:200