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-2020 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 
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();
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 
34 bool 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 
49 bool 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 
58 bool 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 
HepMC3::HEPEUPAttribute::init
virtual bool init() override
Parse the XML-tags.
Definition: LHEFAttributes.cc:69
GenEvent.h
Definition of class GenEvent.
HepMC3::HEPEUPAttribute::clear
void clear()
Clear this object.
Definition: LHEFAttributes.cc:43
HepMC3
HepMC3 main namespace.
Definition: AnalysisExample.h:19
HepMC3::HEPRUPAttribute::heprup
LHEF::HEPRUP heprup
The actual HEPRUP object.
Definition: LHEFAttributes.h:57
LHEFAttributes.h
Definition of class HEPRUPAttribute and class HEPEUAttribute.
LHEF::HEPRUP::print
void print(std::ostream &file) const
Definition: LHEF.h:1765
LHEF::HEPRUP::NPRUP
int NPRUP
Definition: LHEF.h:1967
HepMC3::HEPRUPAttribute::clear
void clear()
Clear this object.
Definition: LHEFAttributes.cc:16
HepMC3::HEPEUPAttribute::tags
std::vector< LHEF::XMLTag * > tags
The parsed XML-tags.
Definition: LHEFAttributes.h:116
LHEF::HEPEUP
Definition: LHEF.h:2117
LHEF::HEPRUP
Definition: LHEF.h:1627
HepMC3::Attribute::event
const GenEvent * event() const
Definition: Attribute.h:108
HepMC3::HEPRUPAttribute::from_string
virtual bool from_string(const std::string &att) override
Fill class content from string.
Definition: LHEFAttributes.cc:22
HepMC3::HEPEUPAttribute::to_string
virtual bool to_string(std::string &att) const override
Fill string from class content.
Definition: LHEFAttributes.cc:58
HepMC3::HEPRUPAttribute
Class for storing data for LHEF run information.
Definition: LHEFAttributes.h:26
LHEF::HEPRUP::clear
void clear()
Definition: LHEF.h:1862
LHEF::HEPEUP::heprup
HEPRUP * heprup
Definition: LHEF.h:2630
LHEF::XMLTag::findXMLTags
static std::vector< XMLTag * > findXMLTags(std::string str, std::string *leftover=0)
Definition: LHEF.h:198
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:49
HepMC3::HEPRUPAttribute::to_string
virtual bool to_string(std::string &att) const override
Fill string from class content.
Definition: LHEFAttributes.cc:34
HepMC3::HEPRUPAttribute::tags
std::vector< LHEF::XMLTag * > tags
The parsed XML-tags.
Definition: LHEFAttributes.h:60
LHEF::HEPEUP::print
void print(std::ostream &file) const
Definition: LHEF.h:2320
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:390
LHEF::HEPEUP::clear
void clear()
Definition: LHEF.h:2414