Belle II Software  release-08-01-10
NSMCallback.h
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 #ifndef _Belle2_NSMCallback_hh
9 #define _Belle2_NSMCallback_hh
10 
11 #include "daq/slc/nsm/AbstractNSMCallback.h"
12 #include "daq/slc/nsm/NSMCommand.h"
13 #include "daq/slc/nsm/NSMData.h"
14 
15 #include <string>
16 #include <vector>
17 #include <map>
18 
19 namespace Belle2 {
25  class NSMCommunicator;
26  class NSMMessage;
27 
28  typedef std::map<std::string, NSMNode> NSMNodeMap;
29  typedef std::map<std::string, NSMData> NSMDataMap;
30 
32 
33  friend class NSMCommunicator;
34  friend class NSMNodeDaemon;
35 
36  public:
37  NSMCallback(int timeout = 5);
38  virtual ~NSMCallback() {}
39 
40  public:
41  virtual void init(NSMCommunicator&) {}
42  virtual void term() {}
43  virtual void timeout(NSMCommunicator&) {}
44  bool perform(NSMCommunicator& com) override;
45  virtual void ok(const char* /*node*/, const char* /*data*/) {}
46  virtual void fatal(const char* /*node*/, const char* /*data*/) {}
47  virtual void error(const char* /*node*/, const char* /*data*/) {}
48  virtual void logset(const DAQLogMessage&) {}
49  virtual void vget(const std::string& nodename,
50  const std::string& vname);
51  virtual void vset(NSMCommunicator& com, const NSMVar& var);
52  virtual void vlistget(NSMCommunicator& com);
53  virtual void vlistset(NSMCommunicator& com);
54  virtual void vreply(NSMCommunicator&, const std::string&, bool) {}
55 
56  public:
57  void reply(const NSMMessage& msg);
58  void log(LogFile::Priority pri, const char* format, ...);
59  void log(LogFile::Priority pri, const std::string& msg);
60  int reset();
61 
62  public:
63  NSMDataMap& getDataMap() { return m_datas; }
64  NSMData& getData(const std::string& name);
65  NSMData& getData() { return m_data; }
66  void openData(const std::string& name, const std::string& format,
67  int revision = -1);
68  void allocData(const std::string& name, const std::string& format,
69  int revision);
70  const std::string& getCategory() const { return m_category; }
71  void setCategory(const std::string& category) { m_category = category; }
72 
73  protected:
74  void notify(const NSMVar& var) override;
75  void reg(const NSMCommand& cmd) { m_cmd_v.push_back(cmd); }
76  void addNode(const NSMNode& node);
77  const NSMNodeMap& getNodes() { return m_nodes; }
78  void setLogNode(const NSMNode& node) { m_lognode = node; }
79  const NSMNode& getLogNode() { return m_lognode; }
80 
81  private:
82  typedef std::vector<NSMCommand> NSMCommandList;
83 
84  private:
85  int addDefaultHandlers();
86 
87  NSMCommandList& getCommandList() { return m_cmd_v; }
88  void alloc_open(NSMCommunicator& com);
89 
90  private:
91  NSMCommandList m_cmd_v;
92  NSMNodeMap m_nodes;
93  NSMData m_data;
94  NSMDataMap m_datas;
95  NSMNode m_lognode;
96  std::string m_category;
97 
98  };
99 
100  inline NSMData& NSMCallback::getData(const std::string& name)
101  {
102  if (m_datas.find(name) != m_datas.end()) {
103  return m_datas[name];
104  }
105  throw (std::out_of_range("nodata registered : " + name));
106  }
107 
108  inline void NSMCallback::openData(const std::string& name,
109  const std::string& format,
110  int revision)
111  {
112  if (m_datas.find(name) == m_datas.end()) {
113  m_datas.insert(NSMDataMap::value_type(name, NSMData(name, format, revision)));
114  }
115  }
116 
117  inline void NSMCallback::allocData(const std::string& name,
118  const std::string& format,
119  int revision)
120  {
121  m_data = NSMData(name, format, revision);
122  }
123 
125 };
126 
127 #endif
Eigen::VectorXd getNodes(int Size)
Get the vector of positions of the Chebyshev nodes The nodes are by definition between 0 and 1,...
Definition: nodes.cc:65
Abstract base class for different kinds of events.