Belle II Software  release-06-02-00
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 <analysis/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  return eventExtraInfo.at(name);
19 }
20 
21 bool EventExtraInfo::hasExtraInfo(const std::string& name) const
22 {
23  return not(eventExtraInfo.find(name) == eventExtraInfo.end());
24 }
25 
26 
28 {
29  eventExtraInfo.clear();
30 }
31 
32 void EventExtraInfo::addExtraInfo(const std::string& name, float value)
33 {
34  if (hasExtraInfo(name)) {
35  throw std::out_of_range(std::string("Key with name ") + name + " already exists in EventExtraInfo.");
36  }
37  eventExtraInfo[name] = value;
38 }
39 
40 void EventExtraInfo::setExtraInfo(const std::string& name, float value)
41 {
42  eventExtraInfo[name] = value;
43 }
44 
45 std::string EventExtraInfo::getInfoHTML() const
46 {
47  std::string s;
48  for (const auto& pair : eventExtraInfo) {
49  s += HTML::escape(pair.first) + " = " + std::to_string(pair.second) + "<br />";
50  }
51  return s;
52 }
53 
54 std::vector<std::string> EventExtraInfo::getNames() const
55 {
56  std::vector<std::string> out;
57  for (const auto& pair : eventExtraInfo)
58  out.push_back(pair.first);
59  return out;
60 }
void removeExtraInfo()
Removes extra info from event.
float getExtraInfo(const std::string &name) const
Return given value if set.
std::map< std::string, float > eventExtraInfo
map variable names to values.
bool hasExtraInfo(const std::string &name) const
Return whether the extra info with the given name is set.
void addExtraInfo(const std::string &name, float value)
Sets the user-defined data of given name to the given value.
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:160
Abstract base class for different kinds of events.