Belle II Software development
RCCallback Class Reference
Inheritance diagram for RCCallback:
NSMCallback AbstractNSMCallback Callback DqmMasterCallback ERecoMasterCallback ERecoRunControlCallback EventServerCallback RFMasterCallback RFRunControlCallback RoiSenderCallback

Public Member Functions

 RCCallback (int timeout=4)
 
void init (NSMCommunicator &com) override
 
virtual void boot (const std::string &, const DBObject &)
 
virtual void load (const DBObject &, const std::string &)
 
virtual void start (int, int)
 
virtual void stop ()
 
virtual void recover (const DBObject &, const std::string &)
 
virtual bool resume (int)
 
virtual bool pause ()
 
virtual void abort ()
 
virtual void monitor ()
 
virtual std::string dbdump ()
 
bool perform (NSMCommunicator &com) override
 
void timeout (NSMCommunicator &com) override
 
virtual void initialize (const DBObject &)
 
virtual void configure (const DBObject &)
 
void dump (bool isstart)
 
const NSMNodegetRuncontrol () const
 
void setState (const RCState &state)
 
void setRCConfig (const std::string &rcconfig)
 
void setDBTable (const std::string &table)
 
void setDBFile (const std::string &file)
 
const std::string & getDBTable () const
 
void setAutoReply (bool auto_reply)
 
void setDB (DBInterface *db, const std::string &table)
 
DBInterfacegetDB ()
 
void setProvider (const std::string &host, int port)
 
DBObjectgetDBObject ()
 
void setRunNumbers (int expno, int runno)
 
int getExpNumber () const
 
int getRunNumber () const
 
void setRunTypeRecord (const std::string &runtype)
 
const std::string & getRunTypeRecord () const
 
DBObject dbload (const std::string &path)
 
void configure_raw (int length, const char *data)
 
virtual void term ()
 
virtual void ok (const char *, const char *)
 
virtual void fatal (const char *, const char *)
 
virtual void error (const char *, const char *)
 
virtual void logset (const DAQLogMessage &)
 
virtual void vget (const std::string &nodename, const std::string &vname)
 
virtual void vset (NSMCommunicator &com, const NSMVar &var)
 
virtual void vlistget (NSMCommunicator &com)
 
virtual void vlistset (NSMCommunicator &com)
 
virtual void vreply (NSMCommunicator &, const std::string &, bool)
 
void reply (const NSMMessage &msg)
 
void log (LogFile::Priority pri, const char *format,...)
 
void log (LogFile::Priority pri, const std::string &msg)
 
int reset ()
 
NSMDataMap & getDataMap ()
 
NSMDatagetData (const std::string &name)
 
NSMDatagetData ()
 
void openData (const std::string &name, const std::string &format, int revision=-1)
 
void allocData (const std::string &name, const std::string &format, int revision)
 
const std::string & getCategory () const
 
void setCategory (const std::string &category)
 
int addDB (const DBObject &obj)
 
bool get (const NSMNode &node, const std::string &name, int &val, int timeout=5)
 
bool get (const NSMNode &node, const std::string &name, float &val, int timeout=5)
 
bool get (const NSMNode &node, const std::string &name, std::string &val, int timeout=5)
 
bool get (const NSMNode &node, const std::string &name, std::vector< int > &val, int timeout=5)
 
bool get (const NSMNode &node, const std::string &name, std::vector< float > &val, int timeout=5)
 
bool get (const NSMNode &node, NSMVHandler *handler, int timeout=5)
 
bool get (const DBObject &obj)
 
bool get (const std::string &name, int &val)
 
bool get (const std::string &name, float &val)
 
bool get (const std::string &name, std::string &val)
 
bool get (const std::string &name, std::vector< int > &val)
 
bool get (const std::string &name, std::vector< float > &val)
 
bool get (const std::string &node, const std::string &name, int &val)
 
bool get (const std::string &node, const std::string &name, float &val)
 
bool get (const std::string &node, const std::string &name, std::string &val)
 
bool get (const std::string &node, const std::string &name, std::vector< int > &val)
 
bool get (const std::string &node, const std::string &name, std::vector< float > &val)
 
bool get (const NSMNode &node, NSMVar &var, int timeout=5)
 
bool set (const NSMNode &node, const std::string &name, int val, int timeout=5)
 
bool set (const NSMNode &node, const std::string &name, float val, int timeout=5)
 
bool set (const NSMNode &node, const std::string &name, const std::string &val, int timeout=5)
 
bool set (const NSMNode &node, const std::string &name, const std::vector< int > &val, int timeout=5)
 
bool set (const NSMNode &node, const std::string &name, const std::vector< float > &val, int timeout=5)
 
bool set (const std::string &name, int val)
 
bool set (const std::string &name, float val)
 
bool set (const std::string &name, const std::string &val)
 
bool set (const std::string &name, const std::vector< int > &val)
 
bool set (const std::string &name, const std::vector< float > &val)
 
bool set (const std::string &node, const std::string &name, int val)
 
bool set (const std::string &node, const std::string &name, float val)
 
bool set (const std::string &node, const std::string &name, const std::string &val)
 
bool set (const std::string &node, const std::string &name, const std::vector< int > &val)
 
bool set (const std::string &node, const std::string &name, const std::vector< float > &val)
 
bool set (const NSMNode &node, const NSMVar &var, int timeout=5)
 
int wait (double timeout=5)
 
NSMCommunicatorwait (const NSMNode &node, const NSMCommand &cmd, double timeout=5)
 
bool try_wait ()
 
NSMNodegetNode ()
 
const NSMNodegetNode () const
 
void setNode (const NSMNode &node)
 
int getTimeout () const
 
void setTimeout (int timeout)
 
int add (NSMVHandler *handler, bool overwrite=true, bool isdump=true)
 
void remove (const std::string &node, const std::string &name)
 
void remove (const std::string &name)
 
void remove (const DBObject &obj)
 
StringList & getHandlerNames ()
 
NSMVHandlerList & getHandlers ()
 
NSMVHandlergetHandler (const std::string &name)
 
NSMVHandlergetHandler (const std::string &node, const std::string &name)
 
void setUseGet (const std::string &name, bool use)
 
void setUseSet (const std::string &name, bool use)
 
void setRevision (int revision)
 
int getRevision () const
 

Protected Member Functions

void notify (const NSMVar &var) override
 
void reg (const NSMCommand &cmd)
 
void addNode (const NSMNode &node)
 
const NSMNodeMap & getNodes ()
 
void setLogNode (const NSMNode &node)
 
const NSMNodegetLogNode ()
 
void readVar (const NSMMessage &msg, NSMVar &var)
 

Protected Attributes

bool m_showall
 

Private Types

typedef std::vector< NSMCommandNSMCommandList
 

Private Member Functions

void dbload (int length, const char *data)
 
int addDefaultHandlers ()
 
NSMCommandList & getCommandList ()
 
void alloc_open (NSMCommunicator &com)
 
template<typename T >
bool get_t (const NSMNode &node, const std::string &name, T &val, int timeout, NSMVar::Type type=NSMVar::NONE, int len=0)
 
template<typename T >
bool get_t (const std::string &node, const std::string &name, T &val)
 
template<typename T >
bool set_t (const std::string &node, const std::string &name, const T &val)
 
NSMVHandlergetHandler_p (const std::string &node, const std::string &name)
 

Private Attributes

RCState m_state_demand
 
DBObject m_obj
 
DBInterfacem_db
 
std::string m_table
 
std::string m_file
 
bool m_auto
 
std::string m_rcconfig
 
std::string m_rcconfig_org
 
std::string m_provider_host
 
int m_provider_port
 
int m_expno
 
int m_runno
 
NSMNode m_runcontrol
 
std::string m_runtype_record
 
NSMCommandList m_cmd_v
 
NSMNodeMap m_nodes
 
NSMData m_data
 
NSMDataMap m_datas
 
NSMNode m_lognode
 
std::string m_category
 
NSMNode m_node
 
int m_timeout
 
NSMNodeMapMap m_node_v_m
 
int m_revision
 
NSMVHandlerList m_handler
 
StringList m_hnames
 

Friends

class RCMonitor
 
class RCConfigHandler
 

Detailed Description

Definition at line 25 of file RCCallback.h.

Member Typedef Documentation

◆ NSMCommandList

typedef std::vector<NSMCommand> NSMCommandList
privateinherited

Definition at line 82 of file NSMCallback.h.

Constructor & Destructor Documentation

◆ RCCallback()

RCCallback ( int  timeout = 4)

Definition at line 73 of file RCCallback.cc.

74 : NSMCallback(timeout)
75{
76 reg(RCCommand::CONFIGURE);
77 reg(RCCommand::BOOT);
78 reg(RCCommand::LOAD);
79 reg(RCCommand::START);
80 reg(RCCommand::STOP);
81 reg(RCCommand::RECOVER);
82 reg(RCCommand::RESUME);
83 reg(RCCommand::PAUSE);
84 reg(RCCommand::ABORT);
85 reg(RCCommand::STATUS);
86 reg(NSMCommand::FATAL);
87 m_auto = true;
88 m_db = NULL;
89 m_showall = true;
90 m_expno = m_runno = 0;
91}

◆ ~RCCallback()

virtual ~RCCallback ( )
inlinevirtual

Definition at line 32 of file RCCallback.h.

32{}

Member Function Documentation

◆ abort()

virtual void abort ( void  )
inlinevirtual

Definition at line 43 of file RCCallback.h.

43{}

◆ add()

int add ( NSMVHandler handler,
bool  overwrite = true,
bool  isdump = true 
)
inherited

Definition at line 25 of file Callback.cc.

26{
27 if (handler) {
28 std::string hname = handler->getNode() + "@" + handler->getName();
29 if (m_handler.find(hname) != m_handler.end()) {
30 NSMVHandler* handler_old = m_handler.find(hname)->second;
31 if (handler->useSet() && overwrite) {
32 handler->set(handler_old->get());
33 }
34 delete handler_old;
35 m_handler.erase(hname);
36 }
37 handler->setDumped(isdump);
38 m_handler.insert(std::pair<std::string, NSMVHandler*>(hname, handler));
39 m_hnames.push_back(hname);
40 return m_handler.size();
41 }
42 return 0;
43}

◆ addDB()

int addDB ( const DBObject obj)
inherited

Definition at line 26 of file AbstractNSMCallback.cc.

27{
28 DBObject::NameValueList list;
29 obj.search(list, "", true);
30 int id = 0;
31 for (DBObject::NameValueList::iterator it = list.begin();
32 it != list.end(); ++it) {
33 const std::string& name(it->name);
34 if (name.size() == 0 || name.at(0) == '$') continue;
35 switch (it->type) {
36 case DBField::BOOL:
37 id = Callback::add(new NSMVHandlerInt(name, true, true, (int) * ((bool*)it->buf)));
38 set(name, (int) * ((bool*)it->buf));
39 break;
40 case DBField::CHAR:
41 id = Callback::add(new NSMVHandlerInt(name, true, true, (int) * ((char*)it->buf)));
42 set(name, (int) * ((char*)it->buf));
43 break;
44 case DBField::SHORT:
45 id = Callback::add(new NSMVHandlerInt(name, true, true, (int) * ((short*)it->buf)));
46 set(name, (int) * ((short*)it->buf));
47 break;
48 case DBField::INT:
49 id = Callback::add(new NSMVHandlerInt(name, true, true, *((int*)it->buf)));
50 set(name, (int) * ((int*)it->buf));
51 break;
52 case DBField::LONG:
53 id = Callback::add(new NSMVHandlerInt(name, true, true, (int) * ((long long*)it->buf)));
54 set(name, (int) * ((long long*)it->buf));
55 break;
56 case DBField::FLOAT:
57 id = Callback::add(new NSMVHandlerFloat(name, true, true, *((float*)it->buf)));
58 set(name, * ((float*)it->buf));
59 break;
60 case DBField::DOUBLE:
61 id = Callback::add(new NSMVHandlerFloat(name, true, true, (float) * ((double*)it->buf)));
62 set(name, (float) * ((double*)it->buf));
63 break;
64 case DBField::TEXT:
65 id = Callback::add(new NSMVHandlerText(name, true, true, *((std::string*)it->buf)));
66 set(name, *((std::string*)it->buf));
67 break;
68 default:
69 break;
70 }
71 }
72 return id;
73}

◆ addDefaultHandlers()

int addDefaultHandlers ( )
privateinherited

Definition at line 49 of file NSMCallback.cc.

50{
51 return add(new NSMVHandlerText("version", true, false, DAQ_SLC_VERSION::DAQ_SLC_VERSION), false, true);
52}

◆ addNode()

void addNode ( const NSMNode node)
protectedinherited

Definition at line 54 of file NSMCallback.cc.

55{
56 std::string name = node.getName();
57 if (m_nodes.find(name) == m_nodes.end()) {
58 m_nodes.insert(NSMNodeMap::value_type(name, node));
59 }
60}

◆ alloc_open()

void alloc_open ( NSMCommunicator com)
privateinherited

Definition at line 300 of file NSMCallback.cc.

301{
302 try {
303 if (!m_data.isAvailable() && m_data.getName().size() > 0 &&
304 m_data.getFormat().size() > 0 && m_data.getRevision() > 0) {
305 m_data.allocate(com);
306 }
307 } catch (const NSMHandlerException& e) {
308 LogFile::warning(e.what());
309 }
310 for (NSMDataMap::iterator it = m_datas.begin();
311 it != m_datas.end(); ++it) {
312 try {
313 NSMData& data(it->second);
314 if (!data.isAvailable() && data.getName().size() > 0 &&
315 data.getFormat().size() > 0) {
316 data.open(com);
317 }
318 } catch (const NSMHandlerException& e) {
319 }
320 }
321}

◆ boot()

virtual void boot ( const std::string &  ,
const DBObject  
)
inlinevirtual

Definition at line 36 of file RCCallback.h.

36{}

◆ configure()

virtual void configure ( const DBObject )
inlinevirtual

Definition at line 53 of file RCCallback.h.

53{}

◆ configure_raw()

void configure_raw ( int  length,
const char *  data 
)

Definition at line 401 of file RCCallback.cc.

402{
403 try {
404 dbload(length, data);
405 } catch (const IOException& e) {
406 throw (RCHandlerException(e.what()));
407 }
408 configure(m_obj);
409}

◆ dbdump()

std::string dbdump ( )
virtual

Definition at line 292 of file RCCallback.cc.

293{
294 std::stringstream ss;
295 StringList& hnames(getHandlerNames());
296 const NSMVHandlerList& handlers(getHandlers());
297 for (StringList::iterator it = hnames.begin();
298 it != hnames.end(); ++it) {
299 std::string hname = *it;
300 NSMVHandler& handler(*handlers.at(hname));
301 std::string vname = StringUtil::replace(hname, "@", "");
302 if (!handler.useGet()) {
303 continue;
304 }
305 if (!handler.isDumped()) {
306 continue;
307 }
308 if (vname.c_str()[0] == '.') {
309 continue;
310 }
311 NSMVar var;
312 handler.handleGet(var);
313 switch (var.getType()) {
314 case NSMVar::INT:
315 ss << vname << " : int(" << var.getInt() << ")" << std::endl;
316 break;
317 case NSMVar::FLOAT:
318 ss << vname << " : float(" << var.getFloat() << ")" << std::endl;
319 break;
320 case NSMVar::TEXT:
321 ss << vname << " : \"" << var.getText() << "\"" << std::endl;
322 break;
323 default:
324 break;
325 }
326 }
327 ss << getDBObject().sprint(true) << std::endl;
328 ss << "nodename : " << std::endl;
329 return ss.str();
330}

◆ dbload() [1/2]

DBObject dbload ( const std::string &  path)

Definition at line 347 of file RCCallback.cc.

348{
349 DBObject obj;
350 std::string pathin, table, config;
351 LogFile::debug(path);
352 if (path.find("db://") != std::string::npos) {
353 pathin = StringUtil::replace(path, "db://", "");
354 StringList s = StringUtil::split(pathin, '/');
355 if (s.size() > 1) {
356 table = s[0];
357 config = s[1];
358 } else {
359 table = m_table;
360 config = s[0];
361 }
362 } else if (path.find("file://") != std::string::npos) {
363 pathin = StringUtil::replace(path, "file:/", "");
364 return obj;
365 }
366 if (table.size() > 0 && config.size() > 0) {
367 if (getDB()) {
368 DBInterface& db(*getDB());
369 try {
370 obj = DBObjectLoader::load(db, table, config, false);
371 if (obj.getName().size() > 0) {
372 config = obj.getName();
373 }
374 db.close();
375 } catch (const DBHandlerException& e) {
376 db.close();
377 throw (e);
378 }
379 } else if (m_provider_host.size() > 0 && m_provider_port > 0) {
380 TCPSocket socket(m_provider_host, m_provider_port);
381 try {
382 socket.connect();
383 TCPSocketWriter writer(socket);
384 writer.writeInt(1);
385 writer.writeString(table + "/" + config);
386 TCPSocketReader reader(socket);
387 obj.readObject(reader);
388 socket.close();
389 if (obj.getName().size() > 0) {
390 config = obj.getName();
391 }
392 } catch (const IOException& e) {
393 socket.close();
394 throw (IOException("Socket connection error : %s ", e.what()));
395 }
396 }
397 }
398 return obj;
399}

◆ dbload() [2/2]

void dbload ( int  length,
const char *  data 
)
private

Definition at line 411 of file RCCallback.cc.

412{
413 const NSMNode& node(getNode());
414 m_rcconfig = node.getName() + "@RC:" + m_rcconfig_org;
415 LogFile::debug("Loading '%s'", m_rcconfig.c_str());
416 if (m_file.size() > 0) {
417 StringList files = StringUtil::split(m_file, ',');
418 ConfigFile conf;
419 for (size_t i = 0; i < files.size(); i++) {
420 conf.read(files[i]);
421 }
422 m_obj = DBObjectLoader::load(conf);
423 m_obj.print(m_showall);
424 } else if (getDB()) {
425 DBInterface& db(*getDB());
426 std::string rcconfig = "";
427 DBObject obj1, obj2;
428 if (m_runtype_record.size()) {
429 rcconfig = node.getName() + "@RC:start:" + m_runtype_record + ":";
430 obj1 = DBObjectLoader::load(db, m_table + "record", rcconfig, m_showall);
431 }
432 obj2 = DBObjectLoader::load(db, m_table, m_rcconfig, m_showall);
433 if (obj1.getDate() < obj2.getDate()) {
434 m_obj = obj2;
435 } else {
436 m_obj = obj1;
437 m_rcconfig = rcconfig;
438 }
439 db.close();
440 m_obj.print(m_showall);
441 } else if (m_provider_host.size() > 0 && m_provider_port > 0) {
442 TCPSocket socket(m_provider_host, m_provider_port);
443 try {
444 DBObject obj1, obj2;
445 std::string rcconfig = "";
446 if (m_runtype_record.size() > 0) {
447 rcconfig = node.getName() + "@RC:start:" + m_runtype_record + ":";
448 socket.connect();
449 TCPSocketWriter writer(socket);
450 writer.writeInt(1);
451 writer.writeString(m_table + "record/" + rcconfig);
452 TCPSocketReader reader(socket);
453 obj1.readObject(reader);
454 socket.close();
455 }
456 socket.connect();
457 TCPSocketWriter writer(socket);
458 writer.writeInt(1);
459 writer.writeString(m_table + "/" + m_rcconfig);
460 TCPSocketReader reader(socket);
461 obj2.readObject(reader);
462 if (obj1.getDate() < obj2.getDate()) {
463 m_obj = obj2;
464 } else {
465 m_obj = obj1;
466 m_rcconfig = rcconfig;
467 }
468 m_obj.print(m_showall);
469 } catch (const IOException& e) {
470 socket.close();
471 throw (IOException("Socket connection error : %s ", e.what()));
472 }
473 socket.close();
474 }
475 reset();
476 add(new NSMVHandlerText("runtype", true, true, ""), false, true);
477 add(new NSMVHandlerText("dbtable", true, false, m_table), false, true);
478 add(new NSMVHandlerText("rcstate", true, false, RCState::NOTREADY_S.getLabel()), false, true);
479 add(new NSMVHandlerText("rcrequest", true, false, ""), false, true);
480 add(new RCConfigHandler(*this, "rcconfig", m_obj.getName()));
481 addDB(m_obj);
482}

◆ dump()

void dump ( bool  isstart)

Definition at line 237 of file RCCallback.cc.

238{
239 std::string runtype;
240 get("runtype", runtype);
241 std::string rcconfig = getNode().getName() + "@RC:"
242 + (isstart ? "start:" : "end:") + runtype
243 + StringUtil::form(":%05d:%04d", m_expno, m_runno);
244 std::stringstream ss;
245 ss << dbdump() << std::endl;
246 ss << "config : " << rcconfig << std::endl;
247 LogFile::debug(ss.str());
248 ConfigFile file(ss);
249 DBObject obj = DBObjectLoader::load(file);
250 obj.print();
251 std::string table = m_table + "record";
252 if (getDB()) {
253 try {
254 DBInterface& db(*getDB());
255 DBObjectLoader::createDB(db, table, obj);
256 } catch (const IOException& e) {
257 throw (DBHandlerException("Failed to connect to database error : %s ", e.what()));
258 }
259 } else if (m_provider_host.size() > 0 && m_provider_port > 0) {
260 TCPSocket socket(m_provider_host, m_provider_port);
261 try {
262 socket.connect();
263 TCPSocketWriter writer(socket);
264 writer.writeInt(2);
265 writer.writeString(table);
266 writer.writeObject(obj);
267 } catch (const IOException& e) {
268 socket.close();
269 throw (DBHandlerException("Failed to connect to dbprovider error : %s ", e.what()));
270 }
271 socket.close();
272 }
273}

◆ error()

virtual void error ( const char *  ,
const char *   
)
inlinevirtualinherited

Definition at line 47 of file NSMCallback.h.

47{}

◆ fatal()

virtual void fatal ( const char *  ,
const char *   
)
inlinevirtualinherited

Definition at line 46 of file NSMCallback.h.

46{}

◆ get() [1/18]

bool get ( const DBObject obj)
inherited

Definition at line 300 of file AbstractNSMCallback.cc.

301{
302 DBObject::NameValueList list;
303 obj.search(list);
304 for (DBObject::NameValueList::iterator it = list.begin();
305 it != list.end(); ++it) {
306 const std::string& name(it->name);
307 if (name.size() == 0 || name.at(0) == '$') continue;
308 int vi = 0;
309 float vf = 0;
310 std::string vs;
311 switch (it->type) {
312 case DBField::BOOL:
313 if (get(name, vi)) *((bool*)it->buf) = (bool)vi;
314 break;
315 case DBField::CHAR:
316 if (get(name, vi)) *((char*)it->buf) = (char)vi;
317 break;
318 case DBField::SHORT:
319 if (get(name, vi)) *((short*)it->buf) = (short)vi;
320 break;
321 case DBField::INT:
322 if (get(name, vi)) *((int*)it->buf) = (int)vi;
323 break;
324 case DBField::LONG:
325 if (get(name, vi)) *((long long*)it->buf) = vi;
326 break;
327 case DBField::FLOAT:
328 if (get(name, vf)) *((float*)it->buf) = vf;
329 break;
330 case DBField::DOUBLE:
331 if (get(name, vf)) *((double*)it->buf) = vf;
332 break;
333 case DBField::TEXT:
334 if (get(name, vs)) *((std::string*)it->buf) = vs;
335 break;
336 default:
337 break;
338 }
339 }
340 return true;
341}

◆ get() [2/18]

bool get ( const NSMNode node,
const std::string &  name,
float &  val,
int  timeout = 5 
)
inherited

Definition at line 246 of file AbstractNSMCallback.cc.

248{
249 return get_t(node, name, val, timeout, NSMVar::FLOAT, 0);
250}

◆ get() [3/18]

bool get ( const NSMNode node,
const std::string &  name,
int &  val,
int  timeout = 5 
)
inherited

Definition at line 240 of file AbstractNSMCallback.cc.

242{
243 return get_t(node, name, val, timeout, NSMVar::INT, 0);
244}

◆ get() [4/18]

bool get ( const NSMNode node,
const std::string &  name,
std::string &  val,
int  timeout = 5 
)
inherited

Definition at line 252 of file AbstractNSMCallback.cc.

254{
255 return get_t(node, name, val, timeout, NSMVar::TEXT, 1);
256}

◆ get() [5/18]

bool get ( const NSMNode node,
const std::string &  name,
std::vector< float > &  val,
int  timeout = 5 
)
inherited

Definition at line 264 of file AbstractNSMCallback.cc.

266{
267 return get_t(node, name, val, timeout, NSMVar::FLOAT, 1);
268}

◆ get() [6/18]

bool get ( const NSMNode node,
const std::string &  name,
std::vector< int > &  val,
int  timeout = 5 
)
inherited

Definition at line 258 of file AbstractNSMCallback.cc.

260{
261 return get_t(node, name, val, timeout, NSMVar::INT, 1);
262}

◆ get() [7/18]

bool get ( const NSMNode node,
NSMVar var,
int  timeout = 5 
)
inherited

Definition at line 176 of file AbstractNSMCallback.cc.

178{
179 if (node.getName().size() > 0) {
180 const std::string name = var.getName();
181 NSMCommunicator::send(NSMMessage(node, NSMCommand::VGET, name));
182 if (timeout < 0) return true;
183 double t0 = Time().get();
184 double t = t0;
185 double tout = timeout;
186 while (true) {
187 double t1 = (tout - (t - t0) > 0 ? tout - (t - t0) : 0);
188 NSMCommunicator& com(wait(NSMNode(), NSMCommand::UNKNOWN, t1));
189 NSMMessage msg = com.getMessage();
190 NSMCommand cmd(msg.getRequestName());
191 if (cmd == NSMCommand::VSET) {
192 if (msg.getLength() > 0 && msg.getData() != NULL &&
193 node.getName() == msg.getData() &&
194 var.getName() == (msg.getData() + msg.getParam(2) + 1)) {
195 readVar(msg, var);
196 return true;
197 }
198 } else if (cmd == NSMCommand::VGET || cmd == NSMCommand::VLISTGET ||
199 cmd == NSMCommand::OK || cmd == NSMCommand::ERROR || cmd == NSMCommand::FATAL) {
200 perform(com);
201 } else {
202 com.pushQueue(msg);
203 }
204 t = Time().get();
205 }
206 }
207 return false;
208}

◆ get() [8/18]

bool get ( const NSMNode node,
NSMVHandler handler,
int  timeout = 5 
)
inherited

Definition at line 141 of file AbstractNSMCallback.cc.

143{
144 if (handler && node.getName().size() > 0) {
145 NSMVar var(handler->get());
146 add(handler);
147 const std::string name = handler->getName();//var.getName();
148 NSMCommunicator::send(NSMMessage(node, NSMCommand::VGET, name));
149 if (timeout < 0) return true;
150 double t0 = Time().get();
151 double t = t0;
152 double tout = timeout;
153 while (true) {
154 double t1 = (tout - (t - t0) > 0 ? tout - (t - t0) : 0);
155 NSMCommunicator& com(wait(NSMNode(), NSMCommand::UNKNOWN, t1));
156 NSMMessage msg = com.getMessage();
157 NSMCommand cmd(msg.getRequestName());
158 if (cmd == NSMCommand::VSET) {
159 if (node.getName() == msg.getData() &&
160 var.getName() == (msg.getData() + msg.getParam(2) + 1)) {
161 readVar(msg, var);
162 return handler->handleSet(var);
163 }
164 } else if (cmd == NSMCommand::VGET || cmd == NSMCommand::VLISTGET ||
165 cmd == NSMCommand::OK || cmd == NSMCommand::ERROR || cmd == NSMCommand::FATAL) {
166 perform(com);
167 } else {
168 com.pushQueue(msg);
169 }
170 t = Time().get();
171 }
172 }
173 return false;
174}

◆ get() [9/18]

bool get ( const std::string &  name,
float &  val 
)
inlineinherited

Definition at line 52 of file AbstractNSMCallback.h.

52{ return get("", name, val); }

◆ get() [10/18]

bool get ( const std::string &  name,
int &  val 
)
inlineinherited

Definition at line 51 of file AbstractNSMCallback.h.

51{ return get("", name, val); }

◆ get() [11/18]

bool get ( const std::string &  name,
std::string &  val 
)
inlineinherited

Definition at line 53 of file AbstractNSMCallback.h.

53{ return get("", name, val); }

◆ get() [12/18]

bool get ( const std::string &  name,
std::vector< float > &  val 
)
inlineinherited

Definition at line 55 of file AbstractNSMCallback.h.

55{ return get("", name, val); }

◆ get() [13/18]

bool get ( const std::string &  name,
std::vector< int > &  val 
)
inlineinherited

Definition at line 54 of file AbstractNSMCallback.h.

54{ return get("", name, val); }

◆ get() [14/18]

bool get ( const std::string &  node,
const std::string &  name,
float &  val 
)
inlineinherited

Definition at line 62 of file AbstractNSMCallback.h.

62{ return get_t(node, name, val); }

◆ get() [15/18]

bool get ( const std::string &  node,
const std::string &  name,
int &  val 
)
inlineinherited

Definition at line 61 of file AbstractNSMCallback.h.

61{ return get_t(node, name, val); }

◆ get() [16/18]

bool get ( const std::string &  node,
const std::string &  name,
std::string &  val 
)
inlineinherited

Definition at line 63 of file AbstractNSMCallback.h.

63{ return get_t(node, name, val); }

◆ get() [17/18]

bool get ( const std::string &  node,
const std::string &  name,
std::vector< float > &  val 
)
inlineinherited

Definition at line 65 of file AbstractNSMCallback.h.

65{ return get_t(node, name, val); }

◆ get() [18/18]

bool get ( const std::string &  node,
const std::string &  name,
std::vector< int > &  val 
)
inlineinherited

Definition at line 64 of file AbstractNSMCallback.h.

64{ return get_t(node, name, val); }

◆ get_t() [1/2]

bool get_t ( const NSMNode node,
const std::string &  name,
T &  val,
int  timeout,
NSMVar::Type  type = NSMVar::NONE,
int  len = 0 
)
inlineprivateinherited

Definition at line 99 of file AbstractNSMCallback.h.

101 {
102 NSMVar var(name);
103 var.setNode(node.getName());
104 if (get(node, var, timeout)) {
105 if (type == NSMVar::NONE ||
106 (type == var.getType() &&
107 ((len == 0 && var.getLength() == 0) ||
108 (len > 0 && var.getLength() > 0)))) {
109 var >> val;
110 return true;
111 }
112 }
113 return false;
114 }

◆ get_t() [2/2]

bool get_t ( const std::string &  node,
const std::string &  name,
T &  val 
)
inlineprivateinherited

Definition at line 116 of file AbstractNSMCallback.h.

117 {
118 NSMVHandler* handler = getHandler_p(node, name);
119 if (handler) {
120 NSMVar var;
121 handler->handleGet(var);
122 var >> val;
123 return true;
124 }
125 return false;
126 }

◆ getCategory()

const std::string & getCategory ( ) const
inlineinherited

Definition at line 70 of file NSMCallback.h.

70{ return m_category; }

◆ getCommandList()

NSMCommandList & getCommandList ( )
inlineprivateinherited

Definition at line 87 of file NSMCallback.h.

87{ return m_cmd_v; }

◆ getData()

NSMData & getData ( )
inlineinherited

Definition at line 65 of file NSMCallback.h.

65{ return m_data; }

◆ getDataMap()

NSMDataMap & getDataMap ( )
inlineinherited

Definition at line 63 of file NSMCallback.h.

63{ return m_datas; }

◆ getDB()

DBInterface * getDB ( )
inline

Definition at line 65 of file RCCallback.h.

65{ return m_db; }

◆ getDBObject()

DBObject & getDBObject ( )
inline

Definition at line 71 of file RCCallback.h.

71{ return m_obj; }

◆ getDBTable()

const std::string & getDBTable ( ) const
inline

Definition at line 62 of file RCCallback.h.

62{ return m_table; }

◆ getExpNumber()

int getExpNumber ( ) const
inline

Definition at line 77 of file RCCallback.h.

77{ return m_expno; }

◆ getHandler() [1/2]

NSMVHandler & getHandler ( const std::string &  name)
inlineinherited

Definition at line 42 of file Callback.h.

43 {
44 return getHandler("", name);
45 }

◆ getHandler() [2/2]

NSMVHandler & getHandler ( const std::string &  node,
const std::string &  name 
)
inherited

Definition at line 56 of file Callback.cc.

58{
59 NSMVHandler* p = getHandler_p(node, name);
60 if (p != NULL) return *p;
61 throw (std::out_of_range(StringUtil::form("no handler for %s:%s",
62 node.c_str(), name.c_str())));
63}

◆ getHandler_p()

NSMVHandler * getHandler_p ( const std::string &  node,
const std::string &  name 
)
privateinherited

Definition at line 65 of file Callback.cc.

66{
67 std::string hname = node + "@" + name;
68 if (m_handler.find(hname) != m_handler.end()) {
69 return m_handler.find(hname)->second;
70 }
71 hname = "@" + name;
72 if (m_handler.find(hname) != m_handler.end()) {
73 return m_handler.find(hname)->second;
74 }
75 return NULL;
76}

◆ getHandlerNames()

StringList & getHandlerNames ( )
inlineinherited

Definition at line 40 of file Callback.h.

40{ return m_hnames; }

◆ getHandlers()

NSMVHandlerList & getHandlers ( )
inlineinherited

Definition at line 41 of file Callback.h.

41{ return m_handler; }

◆ getLogNode()

const NSMNode & getLogNode ( )
inlineprotectedinherited

Definition at line 79 of file NSMCallback.h.

79{ return m_lognode; }

◆ getNode() [1/2]

NSMNode & getNode ( )
inlineinherited

Definition at line 78 of file AbstractNSMCallback.h.

78{ return m_node; }

◆ getNode() [2/2]

const NSMNode & getNode ( ) const
inlineinherited

Definition at line 79 of file AbstractNSMCallback.h.

79{ return m_node; }

◆ getNodes()

const NSMNodeMap & getNodes ( )
inlineprotectedinherited

Definition at line 77 of file NSMCallback.h.

77{ return m_nodes; }

◆ getRevision()

int getRevision ( ) const
inlineinherited

Definition at line 59 of file Callback.h.

59{ return m_revision; }

◆ getRuncontrol()

const NSMNode & getRuncontrol ( ) const
inline

Definition at line 57 of file RCCallback.h.

57{ return m_runcontrol; }

◆ getRunNumber()

int getRunNumber ( ) const
inline

Definition at line 78 of file RCCallback.h.

78{ return m_runno; }

◆ getRunTypeRecord()

const std::string & getRunTypeRecord ( ) const
inline

Definition at line 80 of file RCCallback.h.

80{ return m_runtype_record; }

◆ getTimeout()

int getTimeout ( ) const
inlineinherited

Definition at line 81 of file AbstractNSMCallback.h.

81{ return m_timeout; }

◆ init()

void init ( NSMCommunicator com)
overridevirtual

Reimplemented from NSMCallback.

Definition at line 93 of file RCCallback.cc.

94{
95 LogFile::debug("init");
96 dbload(0, 0);
97 try {
98 initialize(m_obj);
99 } catch (const RCHandlerException& e) {
100 LogFile::fatal("Failed to initialize. %s. terminating process (84)", e.what());
101 term();
102 exit(1);
103 }
104 LogFile::debug("init done");
105 setState(RCState::NOTREADY_S);
106 tabort = Date().get();
107}

◆ initialize()

virtual void initialize ( const DBObject )
inlinevirtual

Definition at line 52 of file RCCallback.h.

52{}

◆ load()

virtual void load ( const DBObject ,
const std::string &   
)
inlinevirtual

Reimplemented in RoiSenderCallback.

Definition at line 37 of file RCCallback.h.

37{}

◆ log() [1/2]

void log ( LogFile::Priority  pri,
const char *  format,
  ... 
)
inherited

Definition at line 77 of file NSMCallback.cc.

78{
79 va_list ap;
80 char ss[1024 * 10];
81 va_start(ap, format);
82 vsnprintf(ss, sizeof(ss), format, ap);
83 va_end(ap);
84 log(pri, std::string(ss));
85}

◆ log() [2/2]

void log ( LogFile::Priority  pri,
const std::string &  msg 
)
inherited

Definition at line 87 of file NSMCallback.cc.

88{
89 LogFile::put(pri, msg);
90 try {
91 if (getLogNode().getName().size() > 0) {
92 NSMCommunicator::send(NSMMessage(getLogNode().getName(),
93 DAQLogMessage(getNode().getName(),
94 pri, getCategory(), msg)));
95 }
96 } catch (const NSMHandlerException& e) {
97 LogFile::error(e.what());
98 }
99}
TString getName(const TObject *obj)
human-readable name (e.g.
Definition: ObjectInfo.cc:45

◆ logset()

virtual void logset ( const DAQLogMessage )
inlinevirtualinherited

Definition at line 48 of file NSMCallback.h.

48{}

◆ monitor()

virtual void monitor ( )
inlinevirtual

Definition at line 44 of file RCCallback.h.

44{}

◆ notify()

void notify ( const NSMVar var)
overrideprotectedvirtualinherited

Implements AbstractNSMCallback.

Definition at line 155 of file NSMCallback.cc.

156{
157 std::string vname = var.getName();
158 NSMVar var_out = var;
159 if (var_out.getNode().size() == 0) {
160 var_out.setNode(getNode().getName());
161 }
162
163 if (m_node_v_m.find(vname) != m_node_v_m.end()) {
164 try {
165 NSMNodeMap& node_v(m_node_v_m[vname]);
166 for (NSMNodeMap::iterator inode = node_v.begin();
167 inode != node_v.end();) {
168 NSMNode& node(inode->second);
169 if (NSMCommunicator::send(NSMMessage(node, var_out))) {
170 ++inode;
171 } else {
172 node_v.erase(inode++);
173 }
174 }
175 } catch (const IOException& e) {
176 LogFile::error(e.what());
177 }
178 }
179}

◆ ok()

virtual void ok ( const char *  ,
const char *   
)
inlinevirtualinherited

Definition at line 45 of file NSMCallback.h.

45{}

◆ pause()

virtual bool pause ( )
inlinevirtual

Definition at line 42 of file RCCallback.h.

42{ return true; }

◆ perform()

bool perform ( NSMCommunicator com)
overridevirtual

Reimplemented from NSMCallback.

Definition at line 109 of file RCCallback.cc.

110{
111 NSMMessage msg(com.getMessage());
112 const RCCommand cmd = msg.getRequestName();
113 const RCState state_org(getNode().getState());
114 RCState state(getNode().getState());
115 if (NSMCallback::perform(com)) return true;
116 if (cmd.isAvailable(state) == NSMCommand::DISABLED) {
117 return false;
118 }
119 addNode(NSMNode(msg.getNodeName()));
120 try {
121 set("rcrequest", msg.getRequestName());
122 } catch (const std::exception& e) {
123 LogFile::error(e.what());
124 }
125 RCState tstate(cmd.nextTState());
126 try {
127 if (tstate != Enum::UNKNOWN) {
128 log(LogFile::DEBUG, "RC request %s from %s", msg.getRequestName(), msg.getNodeName());
129 setState(tstate);
130 std::string nodename = getNode().getName();
131 bool ismaster = nodename == "RUNCONTROL" ||
132 (StringUtil::find(nodename, "RC_") && !StringUtil::find(nodename, "HLT"));
133 if (cmd == RCCommand::CONFIGURE) {
134 m_runcontrol.setName(msg.getNodeName());
135 configure_raw(msg.getLength(), msg.getData());
136 } else if (cmd == RCCommand::BOOT) {
137 m_runcontrol.setName(msg.getNodeName());
138 get(m_obj);
139 std::string opt = msg.getLength() > 0 ? msg.getData() : "";
140 boot(opt, m_obj);
141 } else if (cmd == RCCommand::LOAD) {
142 m_expno = 0;
143 m_runno = 0;
144 m_runcontrol.setName(msg.getNodeName());
145 std::string runtype = (msg.getLength() > 0 ? msg.getData() : "");
146 if (runtype.size() == 0) {
147 get("runtype", runtype);
148 } else {
149 set("runtype", runtype);
150 }
151 get(m_obj);
152 load(m_obj, runtype);
153 } else if (cmd == RCCommand::START) {
154 m_runcontrol.setName(msg.getNodeName());
155 m_expno = (msg.getNParams() > 0) ? msg.getParam(0) : 0;
156 m_runno = (msg.getNParams() > 1) ? msg.getParam(1) : 0;
157 if (ismaster) {
158 log(LogFile::NOTICE, "Run start by %s (exp=%05d, run=%06d)",
159 msg.getNodeName(), m_runno, m_expno);
160 }
161 start(m_expno, m_runno);
162 } else if (cmd == RCCommand::STOP) {
163 if (ismaster) {
164 log(LogFile::NOTICE, "Run stop by %s (exp=%05d, run=%06d)",
165 msg.getNodeName(), m_runno, m_expno);
166 }
167 stop();
168 } else if (cmd == RCCommand::RESUME) {
169 if (ismaster) {
170 log(LogFile::NOTICE, "Run resume by %s (exp=%05d, run=%06d)",
171 msg.getNodeName(), m_runno, m_expno);
172 }
173 if (!resume(msg.getParam(0))) {
174 setState(RCState::NOTREADY_S);
175 return true;
176 }
177 } else if (cmd == RCCommand::PAUSE) {
178 if (ismaster) {
179 log(LogFile::NOTICE, "Run pause by %s (exp=%05d, run=%06d)",
180 msg.getNodeName(), m_runno, m_expno);
181 }
182 if (!pause()) {
183 setState(RCState::NOTREADY_S);
184 return true;
185 }
186 }
187 try {
188 if (cmd == RCCommand::ABORT) {
189 double t = Date().get();
190 if (t - tabort > 3) {
191 if (ismaster) {
192 log(LogFile::NOTICE, "Run abort by %s (exp=%05d, run=%06d)",
193 msg.getNodeName(), m_runno, m_expno);
194 }
195 m_runcontrol.setName(msg.getNodeName());
196 abort();
197 }
198 tabort = t;
199 } else if (cmd == RCCommand::RECOVER) {
200 std::string runtype;
201 get("runtype", runtype);
202 recover(m_obj, runtype);
203 }
204 } catch (const RCHandlerException& e) {
205 log(LogFile::FATAL, "Failed to recover/abort : %s", e.what());
206 }
207 }
208 RCState State = cmd.nextState();
209 if (getNode().getState() == tstate &&
210 State != Enum::UNKNOWN && m_auto) {
211 setState(State);
212 }
213 State = getNode().getState();
214 if (State != Enum::UNKNOWN) {
215 if ((cmd == RCCommand::START &&
216 (State == RCState::RUNNING_S || State == RCState::STARTING_TS)) ||
217 ((cmd == RCCommand::STOP || cmd == RCCommand::ABORT)
218 && state_org == RCState::RUNNING_S)) {
219 try {
220 dump(cmd == RCCommand::START);
221 } catch (const DBHandlerException& e) {
222 LogFile::error(e.what());
223 }
224 }
225 }
226 } catch (const RCHandlerFatalException& e) {
227 log(LogFile::FATAL, e.what());
228 } catch (const RCHandlerException& e) {
229 log(LogFile::ERROR, e.what());
230 setState(RCState::ERROR_ES);
231 } catch (const std::exception& e) {
232 log(LogFile::FATAL, "Unknown exception: %s. terminating process (193)", e.what());
233 }
234 return true;
235}

◆ readVar()

void readVar ( const NSMMessage msg,
NSMVar var 
)
protectedinherited

Definition at line 129 of file AbstractNSMCallback.cc.

130{
131 const int* pars = msg.getParams();
132 const char* node = msg.getData();
133 const char* name = (msg.getData() + pars[2] + 1);
134 const char* value = (msg.getData() + pars[2] + 1 + pars[3] + 1);
135 var = NSMVar(name, (NSMVar::Type)pars[0], pars[1], value);
136 var.setNode(node);
137 var.setId(pars[4]);
138 var.setDate(pars[5]);
139}

◆ recover()

virtual void recover ( const DBObject ,
const std::string &   
)
inlinevirtual

Definition at line 40 of file RCCallback.h.

40{}

◆ reg()

void reg ( const NSMCommand cmd)
inlineprotectedinherited

Definition at line 75 of file NSMCallback.h.

75{ m_cmd_v.push_back(cmd); }

◆ remove() [1/3]

void remove ( const DBObject obj)
inherited

Definition at line 78 of file Callback.cc.

79{
80 DBObject::NameValueList list;
81 obj.search(list, "", true);
82 for (DBObject::NameValueList::iterator it = list.begin();
83 it != list.end(); ++it) {
84 const std::string& name(it->name);
85 if (name.size() == 0 || name.at(0) == '$') continue;
86 switch (it->type) {
87 case DBField::OBJECT:
88 break;
89 default:
90 remove(name);
91 break;
92 }
93 }
94}

◆ remove() [2/3]

void remove ( const std::string &  name)
inlineinherited

Definition at line 38 of file Callback.h.

38{ remove("", name); }

◆ remove() [3/3]

void remove ( const std::string &  node,
const std::string &  name 
)
inherited

Definition at line 45 of file Callback.cc.

46{
47 std::string hname = node + "@" + node;
48 if (m_handler.find(hname) != m_handler.end()) {
49 NSMVHandler* handler_old = m_handler.find(hname)->second;
50 delete handler_old;
51 m_handler.erase(hname);
52 return;
53 }
54}

◆ reply()

void reply ( const NSMMessage msg)
inherited

Definition at line 62 of file NSMCallback.cc.

63{
64 NSMMessage msg_out = msg;
65 for (NSMNodeMap::iterator it = m_nodes.begin();
66 it != m_nodes.end();) {
67 NSMNode& node(it->second);
68 msg_out.setNodeName(node.getName());
69 if (NSMCommunicator::send(msg_out)) {
70 ++it;
71 } else {
72 m_nodes.erase(it++);
73 }
74 }
75}

◆ reset()

int reset ( )
inherited

Definition at line 40 of file NSMCallback.cc.

41{
42 int revision = Callback::reset();
43
44 addDefaultHandlers();
45
46 return revision;
47}

◆ resume()

virtual bool resume ( int  )
inlinevirtual

Definition at line 41 of file RCCallback.h.

41{ return true; }

◆ set() [1/16]

bool set ( const NSMNode node,
const NSMVar var,
int  timeout = 5 
)
inherited

Definition at line 210 of file AbstractNSMCallback.cc.

212{
213 if (node.getName().size() > 0) {
214 NSMCommunicator::send(NSMMessage(node, var));
215 if (timeout < 0) return true;
216 double t0 = Time().get();
217 double t = t0;
218 double tout = timeout;
219 while (true) {
220 double t1 = (tout - (t - t0) > 0 ? tout - (t - t0) : 0);
221 NSMCommunicator& com(wait(node, NSMCommand::VREPLY, t1));
222 NSMMessage msg(com.getMessage());
223 NSMCommand cmd(msg.getRequestName());
224 if (cmd == NSMCommand::VREPLY && var.getName() == msg.getData()) {
225 bool ret = msg.getParam(0) > 0;
226 perform(com);
227 return ret;
228 } else if (cmd == NSMCommand::VGET || cmd == NSMCommand::VLISTGET ||
229 cmd == NSMCommand::OK || cmd == NSMCommand::ERROR || cmd == NSMCommand::FATAL) {
230 perform(com);
231 } else {
232 com.pushQueue(msg);
233 }
234 t = Time().get();
235 }
236 }
237 return false;
238}

◆ set() [2/16]

bool set ( const NSMNode node,
const std::string &  name,
const std::string &  val,
int  timeout = 5 
)
inherited

Definition at line 282 of file AbstractNSMCallback.cc.

284{
285 return set(node, NSMVar(name, val), timeout);
286}

◆ set() [3/16]

bool set ( const NSMNode node,
const std::string &  name,
const std::vector< float > &  val,
int  timeout = 5 
)
inherited

Definition at line 294 of file AbstractNSMCallback.cc.

296{
297 return set(node, NSMVar(name, val), timeout);
298}

◆ set() [4/16]

bool set ( const NSMNode node,
const std::string &  name,
const std::vector< int > &  val,
int  timeout = 5 
)
inherited

Definition at line 288 of file AbstractNSMCallback.cc.

290{
291 return set(node, NSMVar(name, val), timeout);
292}

◆ set() [5/16]

bool set ( const NSMNode node,
const std::string &  name,
float  val,
int  timeout = 5 
)
inherited

Definition at line 276 of file AbstractNSMCallback.cc.

278{
279 return set(node, NSMVar(name, val), timeout);
280}

◆ set() [6/16]

bool set ( const NSMNode node,
const std::string &  name,
int  val,
int  timeout = 5 
)
inherited

Definition at line 270 of file AbstractNSMCallback.cc.

272{
273 return set(node, NSMVar(name, val), timeout);
274}

◆ set() [7/16]

bool set ( const std::string &  name,
const std::string &  val 
)
inlineinherited

Definition at line 58 of file AbstractNSMCallback.h.

58{ return set("", name, val); }

◆ set() [8/16]

bool set ( const std::string &  name,
const std::vector< float > &  val 
)
inlineinherited

Definition at line 60 of file AbstractNSMCallback.h.

60{ return set("", name, val); }

◆ set() [9/16]

bool set ( const std::string &  name,
const std::vector< int > &  val 
)
inlineinherited

Definition at line 59 of file AbstractNSMCallback.h.

59{ return set("", name, val); }

◆ set() [10/16]

bool set ( const std::string &  name,
float  val 
)
inlineinherited

Definition at line 57 of file AbstractNSMCallback.h.

57{ return set("", name, val); }

◆ set() [11/16]

bool set ( const std::string &  name,
int  val 
)
inlineinherited

Definition at line 56 of file AbstractNSMCallback.h.

56{ return set("", name, val); }

◆ set() [12/16]

bool set ( const std::string &  node,
const std::string &  name,
const std::string &  val 
)
inlineinherited

Definition at line 68 of file AbstractNSMCallback.h.

68{ return set_t(node, name, val); }

◆ set() [13/16]

bool set ( const std::string &  node,
const std::string &  name,
const std::vector< float > &  val 
)
inlineinherited

Definition at line 70 of file AbstractNSMCallback.h.

70{ return set_t(node, name, val); }

◆ set() [14/16]

bool set ( const std::string &  node,
const std::string &  name,
const std::vector< int > &  val 
)
inlineinherited

Definition at line 69 of file AbstractNSMCallback.h.

69{ return set_t(node, name, val); }

◆ set() [15/16]

bool set ( const std::string &  node,
const std::string &  name,
float  val 
)
inlineinherited

Definition at line 67 of file AbstractNSMCallback.h.

67{ return set_t(node, name, val); }

◆ set() [16/16]

bool set ( const std::string &  node,
const std::string &  name,
int  val 
)
inlineinherited

Definition at line 66 of file AbstractNSMCallback.h.

66{ return set_t(node, name, val); }

◆ set_t()

bool set_t ( const std::string &  node,
const std::string &  name,
const T &  val 
)
inlineprivateinherited

Definition at line 128 of file AbstractNSMCallback.h.

129 {
130 NSMVHandler* handler = getHandler_p(node, name);
131 if (handler) {
132 handler->set(val);
133 if (node.size() == 0) {
134 notify(handler->get());
135 }
136 return true;
137 }
138 return false;
139 }

◆ setAutoReply()

void setAutoReply ( bool  auto_reply)
inline

Definition at line 63 of file RCCallback.h.

63{ m_auto = auto_reply; }

◆ setCategory()

void setCategory ( const std::string &  category)
inlineinherited

Definition at line 71 of file NSMCallback.h.

71{ m_category = category; }

◆ setDBFile()

void setDBFile ( const std::string &  file)
inline

Definition at line 61 of file RCCallback.h.

61{ m_file = file; }

◆ setDBTable()

void setDBTable ( const std::string &  table)
inline

Definition at line 60 of file RCCallback.h.

60{ m_table = table; }

◆ setLogNode()

void setLogNode ( const NSMNode node)
inlineprotectedinherited

Definition at line 78 of file NSMCallback.h.

78{ m_lognode = node; }

◆ setNode()

void setNode ( const NSMNode node)
inlineinherited

Definition at line 80 of file AbstractNSMCallback.h.

80{ m_node = node; }

◆ setProvider()

void setProvider ( const std::string &  host,
int  port 
)
inline

Definition at line 66 of file RCCallback.h.

67 {
68 m_provider_host = host;
69 m_provider_port = port;
70 }

◆ setRCConfig()

void setRCConfig ( const std::string &  rcconfig)
inline

Definition at line 59 of file RCCallback.h.

59{ m_rcconfig_org = rcconfig; }

◆ setRevision()

void setRevision ( int  revision)
inlineinherited

Definition at line 58 of file Callback.h.

58{ m_revision = revision; }

◆ setRunNumbers()

void setRunNumbers ( int  expno,
int  runno 
)
inline

Definition at line 72 of file RCCallback.h.

73 {
74 m_expno = expno;
75 m_runno = runno;
76 }

◆ setRunTypeRecord()

void setRunTypeRecord ( const std::string &  runtype)
inline

Definition at line 79 of file RCCallback.h.

79{ m_runtype_record = runtype; }

◆ setState()

void setState ( const RCState state)

Definition at line 332 of file RCCallback.cc.

333{
334 RCState state_org = getNode().getState();
335 if (state_org != state) {
336 LogFile::debug("state transit : %s >> %s",
337 state_org.getLabel(), state.getLabel());
338 try {
339 getNode().setState(state);
340 set("rcstate", state.getLabel());
341 } catch (const std::exception& e) {
342 LogFile::error(e.what());
343 }
344 }
345}

◆ setTimeout()

void setTimeout ( int  timeout)
inlineinherited

Definition at line 82 of file AbstractNSMCallback.h.

82{ m_timeout = timeout; }

◆ setUseGet()

void setUseGet ( const std::string &  name,
bool  use 
)
inlineinherited

Definition at line 48 of file Callback.h.

49 {
50 getHandler(name).setUseGet(use);
51 }

◆ setUseSet()

void setUseSet ( const std::string &  name,
bool  use 
)
inlineinherited

Definition at line 52 of file Callback.h.

53 {
54 getHandler(name).setUseSet(use);
55 }

◆ start()

virtual void start ( int  ,
int   
)
inlinevirtual

Definition at line 38 of file RCCallback.h.

38{}

◆ stop()

virtual void stop ( void  )
inlinevirtual

Definition at line 39 of file RCCallback.h.

39{}

◆ term()

virtual void term ( )
inlinevirtualinherited

Definition at line 42 of file NSMCallback.h.

42{}

◆ timeout()

void timeout ( NSMCommunicator com)
overridevirtual

Reimplemented from NSMCallback.

Definition at line 275 of file RCCallback.cc.

276{
277 try {
278 monitor();
279 } catch (const RCHandlerFatalException& e) {
280 LogFile::fatal(e.what());
281 setState(RCState::ERROR_ES);
282 reply(NSMMessage(NSMCommand::FATAL, e.what()));
283 } catch (const RCHandlerException& e) {
284 LogFile::error(e.what());
285 setState(RCState::ERROR_ES);
286 reply(NSMMessage(NSMCommand::ERROR, e.what()));
287 } catch (const std::exception& e) {
288 LogFile::fatal("Unknown exception: %s. terminating process (249)", e.what());
289 }
290}

◆ try_wait()

bool try_wait ( )
inherited

Definition at line 119 of file AbstractNSMCallback.cc.

120{
121 try {
122 perform(wait(NSMNode(), NSMCommand::UNKNOWN, 0));
123 } catch (const std::exception& e) {
124 return false;
125 }
126 return true;
127}

◆ vget()

void vget ( const std::string &  nodename,
const std::string &  vname 
)
virtualinherited

Definition at line 181 of file NSMCallback.cc.

182{
183 NSMNode node(nodename);
184 NSMVar var(vname);
185 try {
186 NSMVHandler* handler_p = getHandler_p(nodename, vname);
187 if (handler_p) {
188 NSMVHandler& handler(*handler_p);
189 handler.handleGet(var);
190 var.setNode(getNode().getName());
191 var.setName(vname);
192 //var.setId(i + 1);
193 var.setDate(Date());
194 NSMCommunicator::send(NSMMessage(node, var));
195 if (m_node_v_m.find(vname) == m_node_v_m.end()) {
196 m_node_v_m.insert(NSMNodeMapMap::value_type(vname, NSMNodeMap()));
197 }
198 NSMNodeMap& node_v(m_node_v_m[vname]);
199 if (node_v.find(nodename) == node_v.end()) {
200 node_v.insert(NSMNodeMap::value_type(nodename, NSMNode(nodename)));
201 std::string filename = ("/tmp/nsmvget." + StringUtil::tolower(getNode().getName()));
202 std::ofstream fout(filename.c_str(), std::ios::app);
203 fout << nodename << " " << vname << std::endl;
204 }
205 }
206 } catch (const NSMHandlerException& e) {
207 LogFile::error(e.what());
208 }
209}

◆ vlistget()

void vlistget ( NSMCommunicator com)
virtualinherited

Definition at line 240 of file NSMCallback.cc.

241{
242 std::stringstream ss;
243 int i = 0;
244 int count = 0;
245 for (NSMVHandlerList::iterator it = m_handler.begin();
246 it != m_handler.end(); ++it) {
247 NSMVHandler& handler(*it->second);
248 if (handler.getNode().size() == 0) {
249 ss << handler.getName() << ":"
250 << handler.get().getTypeLabel() << ":"
251 << (int)handler.useGet() << ":"
252 << (int)handler.useSet() << ":"
253 << i << "\n";
254 count++;
255 }
256 i++;
257 }
258 std::string nodename = com.getMessage().getNodeName();
259 NSMNode node(nodename);
260 try {
261 NSMCommunicator::send(NSMMessage(node, NSMCommand::VLISTSET,
262 count, ss.str()));
263 } catch (const NSMHandlerException& e) {
264 LogFile::error(e.what());
265 }
266}

◆ vlistset()

void vlistset ( NSMCommunicator com)
virtualinherited

Definition at line 275 of file NSMCallback.cc.

276{
277 std::string data = com.getMessage().getData();
278 StringList s = StringUtil::split(data, '\n');
279 std::vector<vlistentry_t> vlist;
280 size_t length = 0;
281 for (size_t i = 0; i < s.size(); i++) {
282 StringList ss = StringUtil::split(s[i], ':');
283 if (ss.size() > 4) {
284 vlistentry_t en = { ss[0],
285 ss[1], ss[2] == "1", ss[3] == "1"
286 };
287 vlist.push_back(en);
288 if (length < ss[0].size()) length = ss[0].size();
289 }
290 }
291 for (size_t i = 0; i < vlist.size(); i++) {
292 vlistentry_t& en(vlist[i]);
293 std::cout << StringUtil::form(StringUtil::form("%%-%ds ", length).c_str(), en.name.c_str())
294 << " : " << en.type << " "
295 << (en.useGet ? "get " : "")
296 << (en.useSet ? "set " : "") << std::endl;
297 }
298}

◆ vreply()

virtual void vreply ( NSMCommunicator ,
const std::string &  ,
bool   
)
inlinevirtualinherited

Definition at line 54 of file NSMCallback.h.

54{}

◆ vset()

void vset ( NSMCommunicator com,
const NSMVar var 
)
virtualinherited

Definition at line 211 of file NSMCallback.cc.

212{
213 try {
214 NSMMessage msg(com.getMessage());
215 NSMVHandler* handler_p = getHandler_p(var.getNode(), var.getName());
216 if (handler_p) {
217 NSMVHandler& handler(*handler_p);
218 if (var.getName() == handler.getName() &&
219 (var.getNode() == handler.getNode() ||
220 (var.getNode().size() == 0 && handler.getNode() == getNode().getName()) ||
221 (handler.getNode().size() == 0 && var.getNode() == getNode().getName())) &&
222 handler.useSet()) {
223 NSMNode node(msg.getNodeName());
224 bool result = false;
225 if ((result = handler.handleSet(var)) &&
226 (var.getNode().size() == 0 || var.getNode() == getNode().getName())) {
227 notify(var);
228 }
229 if (var.getNode().size() == 0) {
230 NSMCommunicator::send(NSMMessage(node, NSMCommand::VREPLY,
231 result, var.getName()));
232 }
233 }
234 }
235 } catch (const NSMHandlerException& e) {
236 LogFile::error(e.what());
237 }
238}

◆ wait() [1/2]

NSMCommunicator & wait ( const NSMNode node,
const NSMCommand cmd,
double  timeout = 5 
)
inherited

Definition at line 75 of file AbstractNSMCallback.cc.

78{
79 double t0 = Time().get();
80 double t = t0;
81 while (true) {
82 double t1 = (timeout - (t - t0) > 0 ? timeout - (t - t0) : 0);
83 NSMCommunicator& com(NSMCommunicator::select(t1));
84 NSMMessage msg = com.getMessage();
85 const std::string reqname = msg.getRequestName();
86 if ((cmd == NSMCommand::UNKNOWN || cmd == reqname) &&
87 (node.getName().size() == 0 || msg.getNodeName() == node.getName())) {
88 return com;
89 }
90 com.pushQueue(msg);
91 t = Time().get();
92 }
93}

◆ wait() [2/2]

int wait ( double  timeout = 5)
inherited

Definition at line 95 of file AbstractNSMCallback.cc.

96{
97 double t0 = Time().get();
98 double t = t0;
99 int count = 0;
100 try {
101 while (true) {
102 double t1 = (timeout - (t - t0) > 0 ? timeout - (t - t0) : 0);
103 if (t1 == 0) break;
104 NSMCommunicator& com(NSMCommunicator::select(t1));
105 NSMMessage msg = com.getMessage();
106 NSMCommand cmd(msg.getRequestName());
107 if (cmd == NSMCommand::VGET || cmd == NSMCommand::VLISTGET) {
108 perform(com);
109 } else {
110 com.pushQueue(msg);
111 }
112 t = Time().get();
113 }
114 } catch (const TimeoutException& e) {
115 }
116 return count;
117}

Friends And Related Function Documentation

◆ RCConfigHandler

friend class RCConfigHandler
friend

Definition at line 28 of file RCCallback.h.

◆ RCMonitor

friend class RCMonitor
friend

Definition at line 27 of file RCCallback.h.

Member Data Documentation

◆ m_auto

bool m_auto
private

Definition at line 95 of file RCCallback.h.

◆ m_category

std::string m_category
privateinherited

Definition at line 96 of file NSMCallback.h.

◆ m_cmd_v

NSMCommandList m_cmd_v
privateinherited

Definition at line 91 of file NSMCallback.h.

◆ m_data

NSMData m_data
privateinherited

Definition at line 93 of file NSMCallback.h.

◆ m_datas

NSMDataMap m_datas
privateinherited

Definition at line 94 of file NSMCallback.h.

◆ m_db

DBInterface* m_db
private

Definition at line 92 of file RCCallback.h.

◆ m_expno

int m_expno
private

Definition at line 100 of file RCCallback.h.

◆ m_file

std::string m_file
private

Definition at line 94 of file RCCallback.h.

◆ m_handler

NSMVHandlerList m_handler
privateinherited

Definition at line 66 of file Callback.h.

◆ m_hnames

StringList m_hnames
privateinherited

Definition at line 67 of file Callback.h.

◆ m_lognode

NSMNode m_lognode
privateinherited

Definition at line 95 of file NSMCallback.h.

◆ m_node

NSMNode m_node
privateinherited

Definition at line 89 of file AbstractNSMCallback.h.

◆ m_node_v_m

NSMNodeMapMap m_node_v_m
privateinherited

Definition at line 91 of file AbstractNSMCallback.h.

◆ m_nodes

NSMNodeMap m_nodes
privateinherited

Definition at line 92 of file NSMCallback.h.

◆ m_obj

DBObject m_obj
private

Definition at line 91 of file RCCallback.h.

◆ m_provider_host

std::string m_provider_host
private

Definition at line 98 of file RCCallback.h.

◆ m_provider_port

int m_provider_port
private

Definition at line 99 of file RCCallback.h.

◆ m_rcconfig

std::string m_rcconfig
private

Definition at line 96 of file RCCallback.h.

◆ m_rcconfig_org

std::string m_rcconfig_org
private

Definition at line 97 of file RCCallback.h.

◆ m_revision

int m_revision
privateinherited

Definition at line 65 of file Callback.h.

◆ m_runcontrol

NSMNode m_runcontrol
private

Definition at line 102 of file RCCallback.h.

◆ m_runno

int m_runno
private

Definition at line 101 of file RCCallback.h.

◆ m_runtype_record

std::string m_runtype_record
private

Definition at line 103 of file RCCallback.h.

◆ m_showall

bool m_showall
protected

Definition at line 106 of file RCCallback.h.

◆ m_state_demand

RCState m_state_demand
private

Definition at line 90 of file RCCallback.h.

◆ m_table

std::string m_table
private

Definition at line 93 of file RCCallback.h.

◆ m_timeout

int m_timeout
privateinherited

Definition at line 90 of file AbstractNSMCallback.h.


The documentation for this class was generated from the following files: