Belle II Software  release-08-01-10
EventExtraInfo.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include <framework/dataobjects/EventExtraInfo.h>
10 #include <framework/utilities/HTML.h>
11 #include <stdexcept>
12 
13 using namespace Belle2;
14 
15 
16 float EventExtraInfo::getExtraInfo(const std::string& name) const
17 {
18  if (hasExtraInfo(name)) return eventExtraInfo.at(name);
19  else throw std::runtime_error("EventExtraInfo::getExtraInfo: You try to access the EventExtraInfo '" + name +
20  "', but it doesn't exist.");
21 }
22 
23 bool EventExtraInfo::hasExtraInfo(const std::string& name) const
24 {
25  return not(eventExtraInfo.find(name) == eventExtraInfo.end());
26 }
27 
28 
30 {
31  eventExtraInfo.clear();
32 }
33 
34 void EventExtraInfo::addExtraInfo(const std::string& name, float value)
35 {
36  if (hasExtraInfo(name)) {
37  throw std::out_of_range(std::string("Key with name ") + name + " already exists in EventExtraInfo.");
38  }
39  eventExtraInfo[name] = value;
40 }
41 
42 void EventExtraInfo::setExtraInfo(const std::string& name, float value)
43 {
44  eventExtraInfo[name] = value;
45 }
46 
47 std::string EventExtraInfo::getInfoHTML() const
48 {
49  std::string s;
50  for (const auto& pair : eventExtraInfo) {
51  s += HTML::escape(pair.first) + " = " + std::to_string(pair.second) + "<br />";
52  }
53  return s;
54 }
55 
56 std::vector<std::string> EventExtraInfo::getNames() const
57 {
58  std::vector<std::string> out;
59  for (const auto& pair : eventExtraInfo)
60  out.push_back(pair.first);
61  return out;
62 }
63 
64 
65 
66 std::string EventExtraInfo::getExtraStringInfo(const std::string& name) const
67 {
68  if (hasExtraStringInfo(name)) return eventExtraStringInfo.at(name);
69  else throw std::runtime_error("EventExtraInfo::getExtraStringInfo: You try to access the EventExtraInfo '" + name +
70  "', but it doesn't exist.");
71 }
72 
73 bool EventExtraInfo::hasExtraStringInfo(const std::string& name) const
74 {
75  return not(eventExtraStringInfo.find(name) == eventExtraStringInfo.end());
76 }
77 
78 
80 {
81  eventExtraStringInfo.clear();
82 }
83 
84 void EventExtraInfo::addExtraStringInfo(const std::string& name, const std::string& value)
85 {
86  if (hasExtraStringInfo(name)) {
87  throw std::out_of_range(std::string("Key with name ") + name + " already exists in EventExtraInfo.");
88  }
89  eventExtraStringInfo[name] = value;
90 }
91 
92 void EventExtraInfo::setExtraStringInfo(const std::string& name, const std::string& value)
93 {
94  eventExtraStringInfo[name] = value;
95 }
96 
97 std::vector<std::string> EventExtraInfo::getStringInfoNames() const
98 {
99  std::vector<std::string> out;
100  for (const auto& pair : eventExtraStringInfo)
101  out.push_back(pair.first);
102  return out;
103 }
104 
105 std::string EventExtraInfo::getEventType() const
106 {
107  if (hasExtraStringInfo(std::string("eventType")))
108  return getExtraStringInfo(std::string("eventType"));
109  else
110  return std::string("");
111 }
void removeExtraInfo()
Removes extra info from event.
std::string getExtraStringInfo(const std::string &name) const
Return given value if set.
std::map< std::string, std::string > eventExtraStringInfo
map variable names to values for string data type.
float getExtraInfo(const std::string &name) const
Return given value if set.
std::map< std::string, float > eventExtraInfo
map variable names to values.
bool hasExtraStringInfo(const std::string &name) const
Return whether the extra string info with the given name is set.
bool hasExtraInfo(const std::string &name) const
Return whether the extra info with the given name is set.
std::string getEventType() const
Get the event type information.
void addExtraStringInfo(const std::string &name, const std::string &value)
Sets the user-defined data of given name to the given value.
void removeExtraStringInfo()
Removes extra string info from event.
void addExtraInfo(const std::string &name, float value)
Sets the user-defined data of given name to the given value.
void setExtraStringInfo(const std::string &name, const std::string &value)
Sets the user-defined data of given name to the given value.
std::vector< std::string > getStringInfoNames() const
Grab the names in this event extra string info (for printing etc)
std::vector< std::string > getNames() const
Grab the names in this event extra info (for printing etc)
std::string getInfoHTML() const
Return a short summary of this object's contents in HTML format.
void setExtraInfo(const std::string &name, float value)
Sets the user-defined data of given name to the given value.
std::string escape(const std::string &str)
Convert &, <, > etc.
Definition: HTML.cc:159
Abstract base class for different kinds of events.