Belle II Software  release-06-00-14
DQMHistAnalysisOutputNSM.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 <dqm/analysis/modules/DQMHistAnalysisOutputNSM.h>
10 
11 #include <daq/slc/nsm/NSMNotConnectedException.h>
12 #include <daq/slc/runcontrol/RCNode.h>
13 
14 #include <daq/slc/system/PThread.h>
15 
16 #include <daq/slc/base/ConfigFile.h>
17 #include <daq/slc/base/StringUtil.h>
18 
19 namespace Belle2 {
27 
28  public:
34  DQMHistAnalysisCallback(const std::string& nodename,
35  const std::string& rcnodename)
36  : NSMCallback(5), m_rcnode(rcnodename)
37  {
38  setNode(NSMNode(nodename));
39  }
40  virtual ~DQMHistAnalysisCallback() throw() {}
41 
42  public:
46  virtual void timouet(NSMCommunicator&) throw()
47  {
48  try {
49  } catch (const NSMNotConnectedException& e) {
50  printf("node %s is not online\n", m_rcnode.getName().c_str());
51  } catch (const NSMHandlerException& e) {
52  printf("NSM error %s\n", e.what());
53  } catch (const IOException& e) {
54  printf("timeout\n");
55  }
56  }
57 
58  private:
61 
62  };
63 
65 }
66 
67 using namespace std;
68 using namespace Belle2;
69 
70 //-----------------------------------------------------------------
71 // Register the Module
72 //-----------------------------------------------------------------
73 REG_MODULE(DQMHistAnalysisOutputNSM)
74 
75 //-----------------------------------------------------------------
76 // Implementation
77 //-----------------------------------------------------------------
78 
81 {
82  //Parameter definition
83  addParam("NSMNodeName", m_nodename, "NSM node name for DQM Hist analyser", string("DQMH"));
84  addParam("RunControlName", m_rcnodename, "NSM node name of the run control", string(""));
85  B2DEBUG(1, "DQMHistAnalysisOutputNSM: Constructor done.");
86 }
87 
88 
89 DQMHistAnalysisOutputNSMModule::~DQMHistAnalysisOutputNSMModule() { }
90 
91 void DQMHistAnalysisOutputNSMModule::initialize()
92 {
93  ConfigFile config("slowcontrol");
94  if (m_callback != nullptr) delete m_callback;
95  m_callback = new DQMHistAnalysisCallback(m_nodename, m_rcnodename);
96  int port = config.getInt("nsm.port");
97  std::string host = config.get("nsm.host");
98  PThread(new NSMNodeDaemon(m_callback, host, port));
99  sleep(1);
100  B2INFO("DQMHistAnalysisOutputNSM: initialized.");
101 }
102 
103 void DQMHistAnalysisOutputNSMModule::beginRun()
104 {
105  //B2INFO("DQMHistAnalysisOutputNSM: beginRun called.");
106 }
107 
108 void DQMHistAnalysisOutputNSMModule::event()
109 {
110  static bool initialized = false;
111  ParamTypeList& parnames(getParNames());
112  IntValueList& vints(getIntValues());
113  FloatValueList& vfloats(getFloatValues());
114  TextList& texts(getTexts());
115  if (!initialized) {
116  for (ParamTypeList::iterator i = parnames.begin(); i != parnames.end(); ++i) {
117  std::string pname = i->first;
118  std::string vname = StringUtil::replace(pname, "/", ".");
119  switch (i->second) {
120  case c_ParamINT:
121  m_callback->add(new NSMVHandlerInt(vname, true, false, vints[pname]));
122  break;
123  case c_ParamFLOAT:
124  m_callback->add(new NSMVHandlerFloat(vname, true, false, vfloats[pname]));
125  break;
126  case c_ParamTEXT:
127  m_callback->add(new NSMVHandlerText(vname, true, false, texts[pname]));
128  break;
129  }
130  }
131  initialized = true;
132  } else {
133  for (ParamTypeList::iterator i = parnames.begin(); i != parnames.end(); ++i) {
134  std::string pname = i->first;
135  std::string vname = StringUtil::replace(pname, "/", ".");
136  switch (i->second) {
137  case c_ParamINT:
138  m_callback->set(vname, vints[pname]);
139  break;
140  case c_ParamFLOAT:
141  m_callback->set(vname, vfloats[pname]);
142  break;
143  case c_ParamTEXT:
144  m_callback->set(vname, texts[pname]);
145  break;
146  }
147  }
148  }
149 }
150 
151 void DQMHistAnalysisOutputNSMModule::endRun()
152 {
153  B2INFO("DQMHistAnalysisOutputNSM : endRun called");
154 }
155 
156 
157 void DQMHistAnalysisOutputNSMModule::terminate()
158 {
159  B2INFO("terminate called");
160 }
161 
The class for the NSM callback.
DQMHistAnalysisCallback(const std::string &nodename, const std::string &rcnodename)
The constructor.
virtual void timouet(NSMCommunicator &)
The timeout function for the NSM communication.
std::map< std::string, int > IntValueList
The type of list of integer module parameter.
std::map< std::string, float > FloatValueList
The type of list of float module parameter.
std::map< std::string, EParamType > ParamTypeList
The type of list of module parameter types.
std::map< std::string, std::string > TextList
The type of list of string module parameter.
Class definition for the output module of Sequential ROOT I/O.
The module to output values to NSM network.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.