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-2019 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 
14 namespace HepMC3 {
15 
16 
18  for ( int i = 0, N = tags.size(); i < N; ++i ) delete tags[i];
19  tags.clear();
20  heprup.clear();
21 }
22 
23 bool HEPRUPAttribute::from_string(const std::string &att) {
24  bool found = false;
25  clear();
27  for ( int i = 0, N = tags.size(); i < N; ++i )
28  if ( tags[i]->name == "init" ) {
29  heprup = LHEF::HEPRUP(*tags[i], 3);
30  found = true;
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  att = os.str();
41  return true;
42 }
43 
45  for ( int i = 0, N = tags.size(); i < N; ++i ) delete tags[i];
46  tags.clear();
47  hepeup.clear();
48 }
49 
50 bool HEPEUPAttribute::from_string(const std::string &att) {
51  clear();
53  for ( int i = 0, N = tags.size(); i < N; ++i )
54  if ( tags[i]->name == "event" || tags[i]->name == "eventgroup")
55  return true;
56  return false;
57 }
58 
59 bool HEPEUPAttribute::to_string(std::string &att) const {
60  std::ostringstream os;
61  if ( hepeup.heprup ) hepeup.print(os);
62  for ( int i = 0, N = tags.size(); i < N; ++i )
63  if ( !hepeup.heprup ||
64  ( tags[i]->name != "event" && tags[i]->name != "eventgroup" ) )
65  tags[i]->print(os);
66  att = os.str();
67  return true;
68 }
69 
71  std::shared_ptr<HEPRUPAttribute> hepr =
72  event()->attribute<HEPRUPAttribute>("HEPRUP");
73  bool found = false;
74  for ( int i = 0, N = tags.size(); i < N; ++i )
75  if ( tags[i]->name == "event" || tags[i]->name == "eventgroup" ) {
76  hepeup = LHEF::HEPEUP(*tags[i], hepr->heprup);
77  found = true;
78  }
79  return found;
80 }
81 
82 } // namespace HepMC3
83 
virtual bool to_string(std::string &att) const override
Fill string from class content.
Definition of class HEPRUPAttribute and class HEPEUAttribute.
static std::vector< XMLTag * > findXMLTags(std::string str, std::string *leftover=0)
Definition: LHEF.h:198
void print(std::ostream &file) const
Definition: LHEF.h:2320
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.
int NPRUP
Definition: LHEF.h:1967
virtual bool from_string(const std::string &att) override
Fill class content from string.
void print(std::ostream &file) const
Definition: LHEF.h:1765
const GenEvent * event() const
Definition: Attribute.h:109
LHEF::HEPRUP heprup
The actual HEPRUP object.
std::vector< LHEF::XMLTag * > tags
The parsed XML-tags.
LHEF::HEPEUP hepeup
The actual HEPEUP object.
void clear()
Definition: LHEF.h:1862
std::shared_ptr< T > attribute(const std::string &name, const int &id=0) const
Get attribute of type T.
Definition: GenEvent.h:389
void clear()
Clear this object.
void clear()
Definition: LHEF.h:2414
virtual bool init() override
Parse the XML-tags.
std::vector< LHEF::XMLTag * > tags
The parsed XML-tags.
Definition of class GenEvent.
Annotation for function names.
Definition: attr.h:36
void clear()
Clear this object.
HEPRUP * heprup
Definition: LHEF.h:2630