HepMC event record
GenRunInfo.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // This file is part of HepMC
4 // Copyright (C) 2014 The HepMC collaboration (see AUTHORS for details)
5 //
6 /**
7  * @file GenRunInfo.cc
8  * @brief Implementation of \b class GenRunInfo
9  *
10  */
11 #include "HepMC/GenRunInfo.h"
12 #include "HepMC/Data/GenRunInfoData.h"
13 #include <sstream>
14 
15 namespace HepMC {
16 
17 
18 void GenRunInfo::set_weight_names(const std::vector<std::string> & names) {
19  m_weight_indices.clear();
20  m_weight_names = names;
21  for ( int i = 0, N = names.size(); i < N; ++i ) {
22  string name = names[i];
23  if ( name.empty() ) {
24  std::ostringstream oss;
25  oss << i;
26  name = oss.str();
27  m_weight_names[i] = name;
28  }
29  if ( has_weight(name) )
30  throw std::logic_error("GenRunInfo::set_weight_names: "
31  "Duplicate weight name '" + name +
32  "' found.");
33  m_weight_indices[name] = i;
34  }
35 }
36 
37 string GenRunInfo::attribute_as_string(const string &name) const {
38 
39  std::map< std::string, shared_ptr<Attribute> >::iterator i = m_attributes.find(name);
40  if( i == m_attributes.end() ) return string();
41 
42  if( !i->second ) return string();
43 
44  string ret;
45  i->second->to_string(ret);
46 
47  return ret;
48 }
49 
51 
52  // Weight names
53  data.weight_names = this->weight_names();
54 
55  // Attributes
56  typedef std::map<std::string, shared_ptr<Attribute> >::value_type att_val_t;
57 
58  FOREACH( const att_val_t& vt, this->attributes() ) {
59  std::string att;
60  vt.second->to_string(att);
61 
62  data.attribute_name. push_back(vt.first);
63  data.attribute_string.push_back(att);
64  }
65 
66  // Tools
67  FOREACH( const ToolInfo &tool, this->tools() ) {
68  data.tool_name. push_back(tool.name);
69  data.tool_version. push_back(tool.version);
70  data.tool_description.push_back(tool.description);
71  }
72 }
73 
75 
76  //this->clear();
77 
78  // Weight names
80 
81  // Attributes
82  for(unsigned int i=0; i<data.attribute_name.size(); ++i) {
84  make_shared<StringAttribute>(data.attribute_string[i]) );
85  }
86 
87  // Tools
88  for(unsigned int i=0; i<data.tool_name.size(); ++i) {
89  ToolInfo ti;
90  ti.name = data.tool_name[i];
91  ti.version = data.tool_version[i];
92  ti.description = data.tool_description[i];
93 
94  this->tools().push_back(ti);
95  }
96 }
97 } // namespace HepMC
string description
Other information about how the tool was used in the run.
void read_data(const GenRunInfoData &data)
Fill GenRunInfo based on GenRunInfoData.
Definition: GenRunInfo.cc:74
const std::vector< ToolInfo > & tools() const
The vector of tools used to produce this run.
Stores serializable run information.
const std::map< std::string, shared_ptr< Attribute > > & attributes() const
Get list of attributes.
std::map< std::string, shared_ptr< Attribute > > m_attributes
Map of attributes.
std::vector< std::string > attribute_string
Attribute serialized as string.
std::vector< std::string > tool_description
Tool descriptions.
std::vector< std::string > m_weight_names
A vector of weight names.
void add_attribute(const string &name, const shared_ptr< Attribute > &att)
add an attribute This will overwrite existing attribute if an attribute with the same name is present...
const std::vector< std::string > & weight_names() const
Get the vector of weight names.
bool has_weight(string name) const
Check if a weight name is present.
void write_data(GenRunInfoData &data) const
Fill GenRunInfoData object.
Definition: GenRunInfo.cc:50
std::vector< std::string > weight_names
Weight names.
std::map< std::string, int > m_weight_indices
A map of weight names mapping to indices.
Definition of template class SmartPointer.
string attribute_as_string(const string &name) const
Get attribute of any type as string.
Definition: GenRunInfo.cc:37
std::vector< std::string > tool_name
Tool names.
std::vector< std::string > tool_version
Tool versions.
Interrnal struct for keeping track of tools.
std::vector< std::string > attribute_name
Attribute name.
void set_weight_names(const std::vector< std::string > &names)
Set the names of the weights in this run.
Definition: GenRunInfo.cc:18