Belle II Software  release-05-01-25
Callback.cc
1 #include "daq/slc/nsm/Callback.h"
2 
3 #include "daq/slc/base/StringUtil.h"
4 
5 using namespace Belle2;
6 
7 int Callback::reset()
8 {
9  for (NSMVHandlerList::iterator it = m_handler.begin();
10  it != m_handler.end(); it++) {
11  if (it->second != NULL) delete it->second;
12  }
13  m_handler = NSMVHandlerList();
14  m_hnames = StringList();
15  return ++m_revision;
16 }
17 
18 int Callback::add(NSMVHandler* handler, bool overwrite, bool isdump)
19 {
20  if (handler) {
21  std::string hname = handler->getNode() + "@" + handler->getName();
22  if (m_handler.find(hname) != m_handler.end()) {
23  NSMVHandler* handler_old = m_handler.find(hname)->second;
24  if (handler->useSet() && overwrite) {
25  handler->set(handler_old->get());
26  }
27  delete handler_old;
28  m_handler.erase(hname);
29  }
30  handler->setDumped(isdump);
31  m_handler.insert(std::pair<std::string, NSMVHandler*>(hname, handler));
32  m_hnames.push_back(hname);
33  return m_handler.size();
34  }
35  return 0;
36 }
37 
38 void Callback::remove(const std::string& node, const std::string& name)
39 {
40  std::string hname = node + "@" + node;
41  if (m_handler.find(hname) != m_handler.end()) {
42  NSMVHandler* handler_old = m_handler.find(hname)->second;
43  delete handler_old;
44  m_handler.erase(hname);
45  return;
46  }
47 }
48 
49 NSMVHandler& Callback::getHandler(const std::string& node,
50  const std::string& name)
51 {
52  NSMVHandler* p = getHandler_p(node, name);
53  if (p != NULL) return *p;
54  throw (std::out_of_range(StringUtil::form("no handler for %s:%s",
55  node.c_str(), name.c_str())));
56 }
57 
58 NSMVHandler* Callback::getHandler_p(const std::string& node, const std::string& name)
59 {
60  std::string hname = node + "@" + name;
61  if (m_handler.find(hname) != m_handler.end()) {
62  return m_handler.find(hname)->second;
63  }
64  hname = "@" + name;
65  if (m_handler.find(hname) != m_handler.end()) {
66  return m_handler.find(hname)->second;
67  }
68  return NULL;
69 }
70 
71 void Callback::remove(const DBObject& obj)
72 {
73  DBObject::NameValueList list;
74  obj.search(list, "", true);
75  for (DBObject::NameValueList::iterator it = list.begin();
76  it != list.end(); it++) {
77  const std::string& name(it->name);
78  if (name.size() == 0 || name.at(0) == '$') continue;
79  switch (it->type) {
80  case DBField::OBJECT:
81  break;
82  default:
83  remove(name);
84  break;
85  }
86  }
87 }
Belle2::NSMVHandler
Definition: NSMVHandler.h:15
Belle2::DBObject
Definition: DBObject.h:14
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19