Belle II Software  release-05-01-25
EventExtraInfo.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2014 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Thomas Keck *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <analysis/dataobjects/EventExtraInfo.h>
12 #include <framework/utilities/HTML.h>
13 #include <stdexcept>
14 
15 using namespace Belle2;
16 
17 
18 float EventExtraInfo::getExtraInfo(const std::string& name) const
19 {
20  return eventExtraInfo.at(name);
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 }
Belle2::EventExtraInfo::addExtraInfo
void addExtraInfo(const std::string &name, float value)
Sets the user-defined data of given name to the given value.
Definition: EventExtraInfo.cc:34
Belle2::EventExtraInfo::getNames
std::vector< std::string > getNames() const
Grab the names in this event extra info (for printing etc)
Definition: EventExtraInfo.cc:56
Belle2::EventExtraInfo::getInfoHTML
std::string getInfoHTML() const
Return a short summary of this object's contents in HTML format.
Definition: EventExtraInfo.cc:47
Belle2::EventExtraInfo::hasExtraInfo
bool hasExtraInfo(const std::string &name) const
Return wether the extra info with the given name is set.
Definition: EventExtraInfo.cc:23
Belle2::EventExtraInfo::setExtraInfo
void setExtraInfo(const std::string &name, float value)
Sets the user-defined data of given name to the given value.
Definition: EventExtraInfo.cc:42
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::HTML::escape
std::string escape(const std::string &str)
Convert &, <, > etc.
Definition: HTML.cc:153
Belle2::EventExtraInfo::eventExtraInfo
std::map< std::string, float > eventExtraInfo
map variable names to values.
Definition: EventExtraInfo.h:70
Belle2::EventExtraInfo::getExtraInfo
float getExtraInfo(const std::string &name) const
Return given value if set.
Definition: EventExtraInfo.cc:18
Belle2::EventExtraInfo::removeExtraInfo
void removeExtraInfo()
Removes extra info from event.
Definition: EventExtraInfo.cc:29