Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDAQDemoClient.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <fstream>
4 #include <iomanip>
5 
6 #include "Jeep/JParser.hh"
7 #include "Jeep/JMessage.hh"
8 #include "Jeep/JArgs.hh"
9 
11 
12 
13 using namespace KM3NETDAQ;
14 
15 
16 /**
17  * \file
18  * Run control demo client class.
19  *
20  * The various action methods could be implemented in this class.
21  * Note that process with extension /- will deliberately crash during the configure transition
22  * and process with extension /+ will sleep forever during the exit transition.
23  * \author mdejong
24  */
26  public JDAQClient
27 {
28 public:
29  /**
30  * Constructor.
31  *
32  * \param name name of client
33  * \param tag tag
34  */
35  JDAQDemoClient(const std::string& name, const std::string& tag = "") :
36  JDAQClient(name)
37  {
38  addParameter('U', extension, std::string(""));
39 
40  if (tag != "") {
41  replaceEvent(RC_CMD, tag, ev_init);
42  replaceEvent(RC_CMD, tag, ev_configure);
43  replaceEvent(RC_CMD, tag, ev_start);
44  replaceEvent(RC_CMD, tag, ev_pause);
45  replaceEvent(RC_CMD, tag, ev_stop);
46  replaceEvent(RC_CMD, tag, ev_reset);
47  replaceEvent(RC_CMD, tag, ev_quit);
48  replaceEvent(RC_CMD, tag, ev_off);
49  }
50  }
51 
52  virtual void actionEnter()
53  {
54  JDebugStream(this->logger) << "Extension <" << extension << ">";
55  }
56 
57  virtual void actionExit()
58  {
59  logger.debug("actionExit()");
60 
61  if (getName() == "JDAQDemoClient/+") {
62 
63  // sleep forever
64 
65  sleep(std::numeric_limits<unsigned int>::max());
66  }
67  }
68 
69  virtual void actionInit(int length, const char* buffer)
70  {
71  JDebugStream(logger) << std::string(buffer,length);
72  }
73 
74  virtual void actionConfigure(int length, const char* buffer)
75  {
76  if (getName() == "JDAQDemoClient/-") {
77 
78  // terminate process
79 
80  logger.error("Termination of process.");
81  ::exit(-1);
82 
83  } else
84  JDebugStream(logger) << std::string(buffer,length);
85  }
86 
87  virtual void actionStart(int length, const char* buffer)
88  {
89  JNoticeStream(logger) << "Start run " << getRunNumber();
90  }
91 
92  virtual void actionPause(int length, const char* buffer)
93  {
94  JDebugStream(logger) << std::string(buffer,length);
95  }
96 
97  virtual void actionContinue(int length, const char* buffer)
98  {
99  JDebugStream(logger) << std::string(buffer,length);
100  }
101 
102  virtual void actionStop(int length, const char* buffer)
103  {
104  JDebugStream(logger) << std::string(buffer,length);
105  }
106 
107  virtual void actionReset(int length, const char* buffer)
108  {
109  JDebugStream (logger) << std::string(buffer,length);
110  }
111 
112  virtual void actionQuit(int length, const char* buffer)
113  {
114  JDebugStream (logger) << std::string(buffer,length);
115  }
116 
117  //virtual void actionInput(int length, const char* buffer)
118  //{}
119 
120  std::string extension;
121 };
122 
123 
124 /**
125  * Run control demo client.
126  */
127 int main(int argc, char* argv[])
128 {
129  using namespace std;
130 
131  string server;
132  string logger;
133  string file_name;
134  string client_name;
135  string tag;
136  int port;
137  int debug;
138 
139  try {
140 
141  JParser<> zap("Run control demo client.");
142 
143  zap['H'] = make_field(server) = "";
144  zap['M'] = make_field(server) = "";
145  zap['f'] = make_field(file_name) = "";
146  zap['u'] = make_field(client_name) = "%";
147  zap['t'] = make_field(tag) = "";
148  zap['P'] = make_field(port) = -1;
149  zap['d'] = make_field(debug) = 2;
150 
151  zap(argc, argv);
152  }
153  catch(const exception &error) {
154  FATAL(error.what() << endl);
155  }
156 
157 
158  using namespace KM3NETDAQ;
159 
160  JDAQDemoClient demo(getProcessName(client_name, argv[0]), tag);
161 
162  if (debug >= JEEP::debug_t) {
163  demo.debug(CHSM::machine::D_all);
164  }
165 
166  if (port == -1) {
167 
168  demo.enter(JEEP::JArgs(argc, argv));
169 
170  if (file_name == "")
171 
172  demo.run();
173 
174  else {
175 
176  ifstream in(file_name.c_str());
177 
178  demo.run(in);
179 
180  in.close();
181  }
182 
183  } else {
184 
185  demo.run(port);
186  }
187 }
Utility class to parse command line options.
Definition: JParser.hh:1410
debug
Definition: JMessage.hh:27
std::string extension
virtual void actionEnter()
std::string getProcessName(const std::string &name, const std::string &process)
Get process name of run control client.
virtual void actionExit()
void run()
Run as run control client following command messages via JNET::JControlHost.
Definition: JDAQClient.hh:493
virtual void actionQuit(int length, const char *buffer)
virtual void actionConfigure(int length, const char *buffer)
virtual void actionInit(int length, const char *buffer)
virtual void actionPause(int length, const char *buffer)
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
Level specific message streamers.
int debug
debug level
Definition: JSirene.cc:59
Data structure to store command line arguments.
Definition: JArgs.hh:24
General purpose messaging.
virtual void actionStart(int length, const char *buffer)
#define FATAL(A)
Definition: JMessage.hh:65
JDAQDemoClient(const std::string &name, const std::string &tag="")
Constructor.
virtual void actionContinue(int length, const char *buffer)
Run control client base class.
Definition: JDAQClient.hh:88
Utility class to parse command line options.
virtual void actionReset(int length, const char *buffer)
virtual bool enter(const JArgs &args)
Enter the state machine.
Definition: JDAQClient.hh:143
const char * getName()
Get ROOT name of given data type.
virtual void actionStop(int length, const char *buffer)
static const JNET::JTag RC_CMD
Definition: JDAQTags.hh:44
int main(int argc, char *argv[])
Definition: Main.cpp:15