Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Attributes | Protected Attributes | Private Member Functions | Private Attributes | List of all members
AcousticDataFilter Class Reference

#include <AcousticDataFilter.h>

Inheritance diagram for AcousticDataFilter:
KM3NETDAQ::JDAQClient

Public Member Functions

 AcousticDataFilter (const std::string &address, const std::string &port, const std::string &name, const std::string &server, const std::string &wisdom, const std::string &output, const std::string &raw, JLOGGER::JLogger *logger, const int level)
 
virtual ~AcousticDataFilter ()
 
void Send_toa_async (ToA_Packet packet)
 
virtual void actionEnter ()
 
virtual void actionExit ()
 
virtual void actionInit (int length, const char *buffer)
 
virtual void actionConfigure (int length, const char *buffer)
 
virtual void actionStart (int length, const char *buffer)
 
virtual void actionPause (int length, const char *buffer)
 
virtual void actionContinue (int length, const char *buffer)
 
virtual void actionStop (int length, const char *buffer)
 
virtual void actionReset (int length, const char *buffer)
 
virtual void actionQuit (int length, const char *buffer)
 
virtual void actionInput (int length, const char *buffer)
 This method is called at ev_input. More...
 
virtual void actionRunning ()
 This method is repeatedly called when this client machine is in state Running and the clock interval time is non-zero. More...
 
virtual bool enter (const JArgs &args)
 Enter the state machine. More...
 
virtual bool enter ()
 Enter the state machine. More...
 
virtual bool exit ()
 Exit the state machine. More...
 
const std::string & getFullName () const
 Get full name of this run control client. More...
 
const JNET::JTaggetUniqueTag () const
 Get unique tag of this run control client. More...
 
int getEventNumber () const
 Get last event number. More...
 
bool isRunning () const
 Check if this client is in runnig state. More...
 
void replaceEvent (const JNET::JTag &oldTag, const JNET::JTag &newTag, JDAQEvent_t &event)
 Replace tag of given event in event table. More...
 
JDAQEvent_t * findEvent (const JNET::JTag &tag, const std::string &event_name)
 Find event in event table. More...
 
template<class T >
void addParameter (const char option, T &parameter)
 Add parameter to parser used in method enter(). More...
 
template<class T >
void addParameter (const char option, T &parameter, const T &value)
 Add parameter to parser used in method enter(). More...
 
long long int getClockDelay () const
 Get total delay time. More...
 
const std::string & getHostname () const
 Get hostname. More...
 
long long int getClockInterval () const
 Get interval time. More...
 
void setClockInterval (const long long int interval_us)
 Set interval time. More...
 
void resetClock ()
 Reset clock. More...
 
void setSelect ()
 Set the file descriptor mask for the select call. More...
 
virtual void setSelect (JFileDescriptorMask &mask) const
 Set the file descriptor mask for the select call. More...
 
virtual void actionSelect (const JFileDescriptorMask &mask)
 Action method following last select call. More...
 
virtual bool filter (const std::string &tag, int length, const char *buffer)
 Filter message. More...
 
void run ()
 Run as run control client following command messages via JNET::JControlHost. More...
 
void run (const int port)
 Run for ever. More...
 
void run (std::istream &in)
 Run client with commands from input stream (e.g for debugging). More...
 

Static Public Attributes

static const int DEBUG_LEVEL =1
 
static const int TIMEOUT_S = 1
 time out of update [s] More...
 

Protected Attributes

JSharedPointer< JControlHostserver
 message server More...
 
JMessageLogger logger
 message logger More...
 

Private Member Functions

const JNET::JTagclientTag () const
 
void Create_probes (std::vector< std::string > probes, std::size_t window)
 
void Create_DOMs (std::vector< std::string > doms, std::string &debug_file_path, std::size_t window, std::size_t overlap)
 
void Start_accept ()
 
void Accept_completed (pLink link, const boost::system::error_code &error)
 
void Start ()
 
void Stop ()
 
void Open_toa_file ()
 
void Send_toa (ToA_Packet packet)
 

Private Attributes

boost::atomic< bool > exit_
 
boost::atomic< bool > running_
 
std::string address_
 
std::string port_
 
std::map< std::size_t, pProbeprobes_
 
std::map< std::size_t, pDOMdoms_
 
std::vector< pLinklinks_
 
boost::thread_group server_threads_
 
boost::asio::io_service server_io_service_
 
boost::asio::io_service::work * server_work_
 
boost::asio::ip::tcp::acceptor server_acceptor_
 
boost::thread_group trigger_threads_
 
boost::asio::io_service trigger_io_service_
 
boost::asio::io_service::work * trigger_work_
 
boost::asio::io_service::strand strand_
 
std::string debug_file_path_
 
std::string toa_file_path_
 
std::ofstream toa_file_
 
std::string wisdom_file_
 

Detailed Description

Definition at line 46 of file AcousticDataFilter.h.

Constructor & Destructor Documentation

AcousticDataFilter::AcousticDataFilter ( const std::string &  address,
const std::string &  port,
const std::string &  name,
const std::string &  server,
const std::string &  wisdom,
const std::string &  output,
const std::string &  raw,
JLOGGER::JLogger logger,
const int  level 
)

Definition at line 53 of file AcousticDataFilter.cpp.

61  : KM3NETDAQ::JDAQClient(name,server,logger,level),\
64 {
65  DEBUG_MSG("Constructor",0);
66 
67  replaceEvent(KM3NETDAQ::RC_CMD, clientTag(), ev_configure);
68 
69  address_=address;
70  port_=port;
71  exit_=false;
72  running_=false;
73  wisdom_file_=wisdom;
74  toa_file_path_=output;
75  debug_file_path_=raw;
76 
77 }
boost::atomic< bool > exit_
boost::asio::io_service trigger_io_service_
boost::asio::io_service::strand strand_
JSharedPointer< JControlHost > server
message server
Definition: JDAQClient.hh:635
const JNET::JTag & clientTag() const
boost::atomic< bool > running_
Run control client base class.
Definition: JDAQClient.hh:88
boost::asio::ip::tcp::acceptor server_acceptor_
boost::asio::io_service server_io_service_
std::string debug_file_path_
void replaceEvent(const JNET::JTag &oldTag, const JNET::JTag &newTag, JDAQEvent_t &event)
Replace tag of given event in event table.
Definition: JDAQClient.hh:294
static const JNET::JTag RC_CMD
Definition: JDAQTags.hh:44
#define DEBUG_MSG(str, lev)
AcousticDataFilter::~AcousticDataFilter ( )
virtual

Definition at line 79 of file AcousticDataFilter.cpp.

80 {
81  DEBUG_MSG("Destructor",0);
82  Stop();
83 }
#define DEBUG_MSG(str, lev)

Member Function Documentation

void AcousticDataFilter::Send_toa_async ( ToA_Packet  packet)
inline

Definition at line 62 of file AcousticDataFilter.h.

62 {strand_.post(boost::bind(&AcousticDataFilter::Send_toa,this,packet));};
boost::asio::io_service::strand strand_
void Send_toa(ToA_Packet packet)
virtual void AcousticDataFilter::actionEnter ( )
inlinevirtual

Definition at line 64 of file AcousticDataFilter.h.

64 {};
virtual void AcousticDataFilter::actionExit ( )
inlinevirtual

Definition at line 65 of file AcousticDataFilter.h.

65 {exit_=true;};
boost::atomic< bool > exit_
void AcousticDataFilter::actionInit ( int  length,
const char *  buffer 
)
virtual

Definition at line 147 of file AcousticDataFilter.cpp.

148 {
149  DEBUG_MSG("SM:Init",2);
150  FILE* pfile;
151  pfile=fopen(wisdom_file_.c_str(),"r");
152  if (pfile!=NULL)
153  {
154  if (fftwf_import_wisdom_from_file(pfile)==1)
155  {
156  DEBUG_MSG("SM:Init wisdom imported",2);
157  }
158  fclose(pfile);
159  }
160 }
#define DEBUG_MSG(str, lev)
void AcousticDataFilter::actionConfigure ( int  length,
const char *  buffer 
)
virtual

Definition at line 175 of file AcousticDataFilter.cpp.

176 {
177 
178  DEBUG_MSG("SM:Configure",2);
179  Parser dummy(std::string(buffer, length),';');
180  DEBUG_MSG("SM:Cerco",2);
181 
182  std::string l_debug_file_path;
183  std::string l_window;
184  std::string l_overlap;
185  std::vector<std::string> l_toa_path;
186  std::vector<std::string> l_dbg_path;
187  std::vector<std::string> l_probes;
188  std::vector<std::string> l_dom_configuration;
189 
190  l_window=dummy.Find("ADF_analysis_window_size")[0];
191  l_overlap=dummy.Find("ADF_analysis_window_overlap")[0];
192  l_probes=dummy.Find("ADF_waveform");
193  l_dom_configuration=dummy.Find("ADF_DOM_configuration");
194 
195  l_toa_path=dummy.Find("ADF_TOA_path");
196  if (l_toa_path.size()!=0) toa_file_path_=l_toa_path[0];
197  l_dbg_path=dummy.Find("ADF_DBG_path");
198  if (l_dbg_path.size()!=0) debug_file_path_=l_dbg_path[0];
199 
200  DEBUG_MSG("SM:Configure. win="<<l_window,2);
201  DEBUG_MSG("SM:Configure. ovr="<<l_overlap,2);
202  DEBUG_MSG("SM:Configure. TOA_path="<<toa_file_path_,2);
203  DEBUG_MSG("SM:Configure. DBG_path="<<debug_file_path_,2);
204 
205  DEBUG_MSG("SM:Configure. n dom="<<l_dom_configuration.size(),2);
206  DEBUG_MSG("SM:Configure. n pro="<<l_probes.size(),2);
207 
208  Create_probes(l_probes,atoi(l_window.c_str()));
209  Create_DOMs(l_dom_configuration,debug_file_path_,atoi(l_window.c_str()),atoi(l_overlap.c_str()));
210 
211  Start();
212 
213 }
void Create_probes(std::vector< std::string > probes, std::size_t window)
std::string debug_file_path_
void Create_DOMs(std::vector< std::string > doms, std::string &debug_file_path, std::size_t window, std::size_t overlap)
#define DEBUG_MSG(str, lev)
void AcousticDataFilter::actionStart ( int  length,
const char *  buffer 
)
virtual

Definition at line 215 of file AcousticDataFilter.cpp.

216 {
217  DEBUG_MSG("SM start",2);
218  running_=true;
219  strand_.post(boost::bind(&AcousticDataFilter::Start_accept,this));
220 }
boost::asio::io_service::strand strand_
boost::atomic< bool > running_
#define DEBUG_MSG(str, lev)
void AcousticDataFilter::actionPause ( int  length,
const char *  buffer 
)
virtual

Definition at line 329 of file AcousticDataFilter.cpp.

330 {
331  DEBUG_MSG("SM: pause",2);
332  running_=false;
333 }
boost::atomic< bool > running_
#define DEBUG_MSG(str, lev)
void AcousticDataFilter::actionContinue ( int  length,
const char *  buffer 
)
virtual

Definition at line 335 of file AcousticDataFilter.cpp.

336 {
337  DEBUG_MSG("SM: continue",2);
338  running_=true;
339 }
boost::atomic< bool > running_
#define DEBUG_MSG(str, lev)
void AcousticDataFilter::actionStop ( int  length,
const char *  buffer 
)
virtual

Definition at line 341 of file AcousticDataFilter.cpp.

342 {
343  DEBUG_MSG("SM:Stop",2);
344  Stop();
345 }
#define DEBUG_MSG(str, lev)
void AcousticDataFilter::actionReset ( int  length,
const char *  buffer 
)
virtual

Definition at line 162 of file AcousticDataFilter.cpp.

163 {
164  DEBUG_MSG("SM:Reset",2);
165  FILE* pfile;
166  pfile=fopen(wisdom_file_.c_str(),"w");
167  if (pfile!=NULL)
168  {
169 DEBUG_MSG("SM:Reset wisdom saved",2);
170  fftwf_export_wisdom_to_file(pfile);
171  fclose(pfile);
172  }
173 }
#define DEBUG_MSG(str, lev)
void AcousticDataFilter::actionQuit ( int  length,
const char *  buffer 
)
virtual

Definition at line 347 of file AcousticDataFilter.cpp.

348 {
349  DEBUG_MSG("SM:Quit",2);
350  Stop();
351 }
#define DEBUG_MSG(str, lev)
virtual void AcousticDataFilter::actionInput ( int  length,
const char *  buffer 
)
inlinevirtual

This method is called at ev_input.

Parameters
lengthlength of data
bufferpointer to data

Reimplemented from KM3NETDAQ::JDAQClient.

Definition at line 74 of file AcousticDataFilter.h.

74 {};
virtual void AcousticDataFilter::actionRunning ( )
inlinevirtual

This method is repeatedly called when this client machine is in state Running and the clock interval time is non-zero.

This implementation does nothing but may be redefined by the derived class. Care has to be taken so that the time needed to execute this method should be less than the specified clock interval time (see method setClockInterval()).

Reimplemented from KM3NETDAQ::JDAQClient.

Definition at line 75 of file AcousticDataFilter.h.

75 {};
const JNET::JTag& AcousticDataFilter::clientTag ( ) const
inlineprivate

Definition at line 79 of file AcousticDataFilter.h.

79 { return KM3NETDAQ::RC_AFILTER; };
static const JNET::JTag RC_AFILTER
Definition: JDAQTags.hh:55
void AcousticDataFilter::Create_probes ( std::vector< std::string >  probes,
std::size_t  window 
)
private

Definition at line 222 of file AcousticDataFilter.cpp.

223 {
224  DEBUG_MSG("Create probes",1);
225 
226  for(int t=0;t<probes.size();++t)
227  {
228  std::istringstream l_iss(probes.at(t));
229  std::string l_line;
230  uint32_t l_id;
231  uint32_t l_samples;
232  real_type* l_buffer;
233 
234  std::getline(l_iss, l_line,' ');
235  l_id=atoi(l_line.c_str());
236  DEBUG_MSG("id probe="<<l_id,1);
237  std::getline(l_iss, l_line,' ');
238  l_samples=atoi(l_line.c_str());
239  DEBUG_MSG("n samples="<<l_samples,1);
240  l_buffer=(real_type*)malloc(l_samples*sizeof(real_type));
241  for (uint32_t i=0; i<l_samples; ++i)
242  {
243  std::getline(l_iss, l_line,' ');
244  real_type l_dummy=atof(l_line.c_str());
245  DEBUG_MSG("sample="<<l_dummy,0);
246  l_buffer[i]=l_dummy;
247  }
248  DEBUG_MSG("creating probes",1);
249  pProbe l_probe = boost::make_shared<KM3::TOALIB::CTOAFinder::probeSignalT>(*(new KM3::TOALIB::CTOAFinder::probeSignalT(window)));
250  DEBUG_MSG("copying data",1);
251  l_probe->copyFromBuffer(l_buffer,l_samples);
252  DEBUG_MSG("insert probe",1);
253  probes_.insert(probe_entry(l_id,l_probe));
254  }
255  DEBUG_MSG("Probes creation finished",1);
256 }
std::map< std::size_t, pProbe > probes_
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:468
boost::shared_ptr< KM3::TOALIB::CTOAFinder::probeSignalT > pProbe
std::pair< std::size_t, pProbe > probe_entry
#define DEBUG_MSG(str, lev)
void AcousticDataFilter::Create_DOMs ( std::vector< std::string >  doms,
std::string &  debug_file_path,
std::size_t  window,
std::size_t  overlap 
)
private

Definition at line 258 of file AcousticDataFilter.cpp.

259 {
260  DEBUG_MSG("Create DOM",1);
261 
262  for(int t=0;t<dom_configuration.size();++t)
263  {
264  std::istringstream l_iss(dom_configuration.at(t));
265  std::string l_line;
266  uint32_t l_dom_id;
267  uint32_t l_probe_id;
268  uint32_t l_threshold;
269  uint32_t l_waveforms;
270  uint32_t l_test;
271 
272  std::getline(l_iss, l_line,' ');
273  l_dom_id=atoi(l_line.c_str());
274  DEBUG_MSG("DOM id="<<l_dom_id,1);
275  pDOM l_dom = boost::make_shared<KM3NeT_DOM>(*(new KM3NeT_DOM( trigger_io_service_,\
276  boost::bind(&AcousticDataFilter::Send_toa_async, this, _1),\
277  debug_file_path,\
278  window,\
279  overlap)));
280  doms_.insert(dom_entry(l_dom_id,l_dom));
281  std::getline(l_iss, l_line,' ');
282  l_waveforms=atoi(l_line.c_str());
283  DEBUG_MSG("n waveforms="<<l_waveforms,1);
284  for (uint32_t i=0; i<l_waveforms; ++i)
285  {
286  std::getline(l_iss, l_line,' ');
287  l_probe_id=atoi(l_line.c_str());
288  std::getline(l_iss, l_line,' ');
289  l_threshold=atoi(l_line.c_str());
290  DEBUG_MSG("adding probe "<<l_probe_id<<" with threshold "<<l_threshold<<" to DOM "<<l_dom_id,1);
291  l_dom->Add_probe(probes_.find(l_probe_id)->second,l_probe_id,l_threshold);
292  }
293  std::getline(l_iss, l_line,' ');
294  l_test=atoi(l_line.c_str());
295  DEBUG_MSG("setting test id="<<l_test,1);
296  l_dom->Set_test(l_test);
297  }
298  DEBUG_MSG("DOMs creation finished",1);
299 }
void Send_toa_async(ToA_Packet packet)
boost::asio::io_service trigger_io_service_
std::map< std::size_t, pProbe > probes_
boost::shared_ptr< KM3NeT_DOM > pDOM
Definition: KM3NeT_DOM.h:65
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:468
std::map< std::size_t, pDOM > doms_
#define DEBUG_MSG(str, lev)
std::pair< std::size_t, pDOM > dom_entry
void AcousticDataFilter::Start_accept ( )
private

Definition at line 128 of file AcousticDataFilter.cpp.

129 {
130  DEBUG_MSG("Start accept",2);
132  links_.push_back(l_link);
133  server_acceptor_.async_accept(l_link->Socket(), boost::bind(&AcousticDataFilter::Accept_completed, this, l_link, boost::asio::placeholders::error));
134 }
std::vector< pLink > links_
std::map< std::size_t, pDOM > doms_
void Accept_completed(pLink link, const boost::system::error_code &error)
boost::asio::ip::tcp::acceptor server_acceptor_
boost::asio::io_service server_io_service_
#define DEBUG_MSG(str, lev)
void AcousticDataFilter::Accept_completed ( pLink  link,
const boost::system::error_code &  error 
)
private

Definition at line 136 of file AcousticDataFilter.cpp.

137 {
138  DEBUG_MSG("Accept completed",2);
139 
140  if (!error)
141  {
142  link->Start_reading();
143  strand_.post(boost::bind(&AcousticDataFilter::Start_accept,this));
144  }
145 }
boost::asio::io_service::strand strand_
#define DEBUG_MSG(str, lev)
void AcousticDataFilter::Start ( )
private

Definition at line 85 of file AcousticDataFilter.cpp.

86 {
87  DEBUG_MSG("Start",2);
88  server_work_ = new boost::asio::io_service::work(server_io_service_);
89  trigger_work_ = new boost::asio::io_service::work(trigger_io_service_);
90 
91  boost::asio::ip::tcp::resolver l_resolver(server_io_service_);
92  boost::asio::ip::tcp::resolver::query l_query(address_,port_);
93  boost::asio::ip::tcp::endpoint l_endpoint = *l_resolver.resolve(l_query);
94  server_acceptor_.open(l_endpoint.protocol());
95  server_acceptor_.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
96  server_acceptor_.bind(l_endpoint);
97  server_acceptor_.listen();
98 
99  for (std::size_t i=0; i<SERVER_THREAD_POOL; ++i) { server_threads_.create_thread(boost::bind(&boost::asio::io_service::run,&server_io_service_)); }
100  for (std::size_t i=0; i<TRIGGER_THREAD_POOL; ++i) { trigger_threads_.create_thread(boost::bind(&boost::asio::io_service::run,&trigger_io_service_)); }
101 }
boost::asio::io_service trigger_io_service_
boost::asio::io_service::work * server_work_
boost::thread_group trigger_threads_
#define TRIGGER_THREAD_POOL
boost::thread_group server_threads_
boost::asio::ip::tcp::acceptor server_acceptor_
boost::asio::io_service server_io_service_
#define SERVER_THREAD_POOL
boost::asio::io_service::work * trigger_work_
#define DEBUG_MSG(str, lev)
void AcousticDataFilter::Stop ( )
private

Definition at line 103 of file AcousticDataFilter.cpp.

104 {
105  DEBUG_MSG("Stop",2);
106 
107  server_acceptor_.close();
108  delete server_work_;
109 
111  for (i=links_.begin(); i!=links_.end(); ++i){ (*i)->Disconnect(); }
112  server_io_service_.stop();
113  server_threads_.join_all();
114  server_io_service_.reset();
115 
116  delete trigger_work_;
117  trigger_io_service_.stop();
118  trigger_threads_.join_all();
119  trigger_io_service_.reset();
120 
121  links_.clear();
122  doms_.clear();
123  probes_.clear();
124 
125  if (toa_file_.is_open()) toa_file_.close();
126 }
boost::asio::io_service trigger_io_service_
std::map< std::size_t, pProbe > probes_
boost::asio::io_service::work * server_work_
boost::thread_group trigger_threads_
std::vector< pLink > links_
std::map< std::size_t, pDOM > doms_
boost::thread_group server_threads_
boost::asio::ip::tcp::acceptor server_acceptor_
boost::asio::io_service server_io_service_
boost::asio::io_service::work * trigger_work_
#define DEBUG_MSG(str, lev)
void AcousticDataFilter::Open_toa_file ( )
private

Definition at line 320 of file AcousticDataFilter.cpp.

321 {
322  std::string l_file=toa_file_path_;
323  std::time_t seconds = std::time(0);
324  l_file+="TOA_"+std::to_string((long long unsigned int)seconds)+".bin";
325  toa_file_.open(l_file.c_str(),std::ofstream::binary);
326  DEBUG_MSG("Toa file opened at "<<seconds,1);
327 }
std::string to_string(const T &value)
Convert value to string.
#define DEBUG_MSG(str, lev)
void AcousticDataFilter::Send_toa ( ToA_Packet  packet)
private

Definition at line 301 of file AcousticDataFilter.cpp.

302 {
303  if (!running_) return;
304 
305  DEBUG_MSG("Sent toa from ID="<<packet.Header.DOM_Identifier,3);
306 
307  if (!toa_file_.is_open()) Open_toa_file();
308 
309  if (toa_file_.tellp()>MAX_TOA_SIZE)
310  {
311  DEBUG_MSG("Toa file closed",1);
312  toa_file_.close();
313  Open_toa_file();
314  }
315 
316  if (toa_file_.is_open()) toa_file_.write((char*)&packet,sizeof(ToA_Packet));
317 
318 }
boost::atomic< bool > running_
#define MAX_TOA_SIZE
DAQ_Common_Header Header
#define DEBUG_MSG(str, lev)
virtual bool KM3NETDAQ::JDAQClient::enter ( const JArgs args)
inlinevirtualinherited

Enter the state machine.

This overloaded method enter reproduces the constructor. All necessary input is parsed from the list of arguments. In case of an error, the state machine is not entered.

Parameters
argsarray of command line arguments

Definition at line 143 of file JDAQClient.hh.

144  {
145  using namespace std;
146 
147  string server;
148  string logger;
149  int level;
150  bool use_cout;
151 
152  try {
153 
154  parser['H'] = make_field(server) = "localhost";
155  parser['M'] = make_field(logger) = "localhost";
156  parser['d'] = make_field(level) = 0;
157  parser['c'] = make_field(use_cout);
158 
159  if (parser.read(args) != 0) {
160  return false;
161  }
162  }
163  catch(const exception &error) {
164  cerr << error.what() << endl;
165  return false;
166  }
167 
168  try {
169 
170  JLogger* out = NULL;
171 
172  if (use_cout)
173  out = new JStreamLogger(cout);
174  else
175  out = new JControlHostLogger(logger);
176 
177  this->logger = JMessageLogger(out, getName(), level);
178 
179  this->server.reset(new JControlHost(server));
180 
181  return enter();
182  }
183  catch(const JControlHostException& error) {
184  cerr << error << endl;
185  return false;
186  }
187  }
JParser parser
parser method enter()
Definition: JDAQClient.hh:834
ControlHost class.
Message logging based on std::ostream.
Interface for logging messages.
Definition: JLogger.hh:22
Message logging based on ControlHost.
JSharedPointer< JControlHost > server
message server
Definition: JDAQClient.hh:635
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
virtual bool enter()
Enter the state machine.
Definition: JDAQClient.hh:195
Exception for ControlHost.
Definition: JException.hh:432
int read(const int argc, const char *const argv[])
Parse the program&#39;s command line options.
Definition: JParser.hh:1673
const char * getName()
Get ROOT name of given data type.
JMessageLogger logger
message logger
Definition: JDAQClient.hh:636
virtual bool KM3NETDAQ::JDAQClient::enter ( )
inlinevirtualinherited

Enter the state machine.

This method activates the subscription to JNET::JControlHost messages. In case of an error, the state machine is not entered.

Reimplemented in KM3NETDAQ::JDAQDriver.

Definition at line 195 of file JDAQClient.hh.

196  {
197  using namespace std;
198 
199  if (server.is_valid() && logger.is_valid()) {
200 
201  try {
202 
203  server->Subscribe(getSubscription(eventTable));
204  server->SendMeAlways();
205  server->MyId(getFullName());
206 
207  return CHSM::machine::enter();
208  }
209  catch(const JControlHostException& error) {
210  JErrorStream(logger) << error;
211  }
212 
213  } else {
214  cerr << "Message server or logger not properly initialised." << endl;
215  }
216 
217  return false;
218  }
JNET::JSubscriptionList getSubscription(const JEventTable &event_table)
Convert event table to ControlHost subscription.
Definition: JEventTable.hh:125
JSharedPointer< JControlHost > server
message server
Definition: JDAQClient.hh:635
Exception for ControlHost.
Definition: JException.hh:432
bool is_valid() const
Check validity of logger object.
JEventTable eventTable
event table
Definition: JDAQClient.hh:828
JMessageLogger logger
message logger
Definition: JDAQClient.hh:636
const std::string & getFullName() const
Get full name of this run control client.
Definition: JDAQClient.hh:248
virtual bool KM3NETDAQ::JDAQClient::exit ( )
inlinevirtualinherited

Exit the state machine.

This method releases the various resources.

Definition at line 225 of file JDAQClient.hh.

226  {
227  try {
228  if (server.is_valid()) server.reset(NULL);
229  }
230  catch(const JControlHostException& error) {
231  }
232 
233  try {
234  if (logger.is_valid()) logger.reset(NULL);
235  }
236  catch(const JControlHostException& error) {
237  }
238 
239  return CHSM::machine::exit();
240  }
void reset(JLogger *__logger=NULL)
Reset logger.
JSharedPointer< JControlHost > server
message server
Definition: JDAQClient.hh:635
Exception for ControlHost.
Definition: JException.hh:432
bool is_valid() const
Check validity of logger object.
JMessageLogger logger
message logger
Definition: JDAQClient.hh:636
const std::string& KM3NETDAQ::JDAQClient::getFullName ( ) const
inlineinherited

Get full name of this run control client.

Returns
full name

Definition at line 248 of file JDAQClient.hh.

249  {
250  return full_name;
251  }
std::string full_name
Definition: JDAQClient.hh:830
const JNET::JTag& KM3NETDAQ::JDAQClient::getUniqueTag ( ) const
inlineinherited

Get unique tag of this run control client.

Returns
unique tag

Definition at line 259 of file JDAQClient.hh.

260  {
261  return unique_tag;
262  }
int KM3NETDAQ::JDAQClient::getEventNumber ( ) const
inlineinherited

Get last event number.

Returns
event number

Definition at line 270 of file JDAQClient.hh.

271  {
272  return event_number;
273  }
int event_number
number of last event
Definition: JDAQClient.hh:835
bool KM3NETDAQ::JDAQClient::isRunning ( ) const
inlineinherited

Check if this client is in runnig state.

Returns
true if running; else false

Definition at line 281 of file JDAQClient.hh.

282  {
283  return Main.RunControl.Operational.Running.active();
284  }
void KM3NETDAQ::JDAQClient::replaceEvent ( const JNET::JTag oldTag,
const JNET::JTag newTag,
JDAQEvent_t event 
)
inlineinherited

Replace tag of given event in event table.

Parameters
oldTagold tag
newTagnew tag
eventevent

Definition at line 294 of file JDAQClient.hh.

297  {
298  eventTable.replace(oldTag, newTag, event);
299  }
Structure to store the ToT mean and standard deviation of the hits produced by a nanobeacon in a sour...
JEventTable eventTable
event table
Definition: JDAQClient.hh:828
void replace(const JNET::JTag &oldTag, const JNET::JTag &newTag, JDAQEvent_t &event)
Replace entry in table.
Definition: JEventTable.hh:93
JDAQEvent_t* KM3NETDAQ::JDAQClient::findEvent ( const JNET::JTag tag,
const std::string &  event_name 
)
inlineinherited

Find event in event table.

Parameters
tagtag
event_nameevent name
Returns
pointer to event or NULL

Definition at line 309 of file JDAQClient.hh.

310  {
311  JEventTable::const_iterator i = eventTable.find(tag, event_name);
312 
313  if (i != eventTable.end())
314  return i->second;
315  else
316  return NULL;
317  }
const_iterator find(const JNET::JTag &tag, const std::string &event_name) const
Find entry.
Definition: JEventTable.hh:112
JEventTable eventTable
event table
Definition: JDAQClient.hh:828
template<class T >
void KM3NETDAQ::JDAQClient::addParameter ( const char  option,
T &  parameter 
)
inlineinherited

Add parameter to parser used in method enter().

Parameters
optionoption
parameterparameter

Definition at line 327 of file JDAQClient.hh.

328  {
329  parser[option] = make_field(parameter);
330  }
JParser parser
parser method enter()
Definition: JDAQClient.hh:834
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
template<class T >
void KM3NETDAQ::JDAQClient::addParameter ( const char  option,
T &  parameter,
const T &  value 
)
inlineinherited

Add parameter to parser used in method enter().

Parameters
optionoption
parameterparameter
valuedefault value

Definition at line 341 of file JDAQClient.hh.

342  {
343  parser[option] = make_field(parameter) = value;
344  }
JParser parser
parser method enter()
Definition: JDAQClient.hh:834
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
long long int KM3NETDAQ::JDAQClient::getClockDelay ( ) const
inlineinherited

Get total delay time.

Returns
delay time [us]

Definition at line 352 of file JDAQClient.hh.

353  {
354  return clock.getDelay();
355  }
long long int getDelay() const
Get total delay time.
Definition: JTimekeeper.hh:78
JTimekeeper clock
central clock
Definition: JDAQClient.hh:832
const std::string& KM3NETDAQ::JDAQClient::getHostname ( ) const
inlineinherited

Get hostname.

Returns
host name

Definition at line 363 of file JDAQClient.hh.

364  {
365  return hostname;
366  }
std::string hostname
Definition: JDAQClient.hh:829
long long int KM3NETDAQ::JDAQClient::getClockInterval ( ) const
inlineinherited

Get interval time.

Returns
interval time [us]

Definition at line 374 of file JDAQClient.hh.

375  {
376  return clock.getInterval();
377  }
JTimekeeper clock
central clock
Definition: JDAQClient.hh:832
long long int getInterval() const
Get interval time.
Definition: JTimekeeper.hh:67
void KM3NETDAQ::JDAQClient::setClockInterval ( const long long int  interval_us)
inlineinherited

Set interval time.

Parameters
interval_usinterval time [us]

Definition at line 385 of file JDAQClient.hh.

386  {
387  clock.setInterval(interval_us);
388  }
JTimekeeper clock
central clock
Definition: JDAQClient.hh:832
void setInterval(const long long int interval_us)
Set interval time.
Definition: JTimekeeper.hh:89
void KM3NETDAQ::JDAQClient::resetClock ( )
inlineinherited

Reset clock.

Definition at line 394 of file JDAQClient.hh.

395  {
396  clock.reset();
397  }
void reset(const long long int t0)
Reset time.
Definition: JTimekeeper.hh:100
JTimekeeper clock
central clock
Definition: JDAQClient.hh:832
void KM3NETDAQ::JDAQClient::setSelect ( )
inlineinherited

Set the file descriptor mask for the select call.

Definition at line 403 of file JDAQClient.hh.

404  {
405  select.reset();
406 
408 
410  }
JSelectReader select
select call
Definition: JDAQClient.hh:833
JSharedPointer< JControlHost > server
message server
Definition: JDAQClient.hh:635
JFileDescriptorMask & getReaderMask()
Get reader mask.
void setReaderMask(const JAbstractFile &file)
Set reader mask.
void reset()
Reset.
void setSelect()
Set the file descriptor mask for the select call.
Definition: JDAQClient.hh:403
virtual void KM3NETDAQ::JDAQClient::setSelect ( JFileDescriptorMask mask) const
inlinevirtualinherited

Set the file descriptor mask for the select call.

This implementation does nothing but may be redefined by the derived class.

Parameters
maskfile descriptor mask

Reimplemented in KM3NETDAQ::JDataWriter, and KM3NETDAQ::MonitorRouter.

Definition at line 419 of file JDAQClient.hh.

420  {}
virtual void KM3NETDAQ::JDAQClient::actionSelect ( const JFileDescriptorMask mask)
inlinevirtualinherited

Action method following last select call.

This implementation does nothing but may be redefined by the derived class.

Parameters
maskfile descriptor mask

Reimplemented in KM3NETDAQ::DataQueue, KM3NETDAQ::JDataWriter, and KM3NETDAQ::MonitorRouter.

Definition at line 429 of file JDAQClient.hh.

430  {}
virtual bool KM3NETDAQ::JDAQClient::filter ( const std::string &  tag,
int  length,
const char *  buffer 
)
inlinevirtualinherited

Filter message.

The filter method can be overloaded so that a specific action is made before the corresponding message is processed by the state machine. The message is ignored if true is returned, else it is normally processed.

Parameters
tagtag
lengthnumber of characters
buffermessage
Returns
skip message or not

Definition at line 477 of file JDAQClient.hh.

478  {
479  return false;
480  }
void KM3NETDAQ::JDAQClient::run ( )
inlineinherited

Run as run control client following command messages via JNET::JControlHost.

This method can be called once the state machine is entered. It returns when the state machine is exited. If the clock interval is non-zero, the method actionRunning() is repeatedly called when this client machine is in state Running. The file descriptor mask can be set to interrupt the timeout of the select call and clock method wait() in this calling sequence (see methods setSelect() and actionSelect()).

Definition at line 493 of file JDAQClient.hh.

494  {
495  using namespace std;
496 
497  while (active()) {
498 
499  try {
500 
501  setSelect();
502 
503  if (select(JTimeval(TIMEOUT_S,0)) > 0) {
504 
505  if (select.hasReaderMask(*server)) {
506  update();
507  }
508 
510 
511  } else {
512 
513  continue;
514  }
515 
516 
517  if (isRunning() && clock.getInterval() != 0LL) {
518 
519  long long int numberOfCalls = 0;
520 
521  clock.reset();
522 
523  do {
524 
525  ++numberOfCalls;
526 
527  setSelect();
528 
529  if (clock.wait(select.getReaderMask())) {
530 
531  if (select.hasReaderMask(*server)) {
532  update();
533  }
534 
536 
537  } else {
538 
539  try {
540  actionRunning();
541  }
542  catch(const exception& error) {
543  logger.error(error.what());
544  }
545  }
546 
547  } while (isRunning());
548 
549  if (numberOfCalls != 0) {
550  JNoticeStream(logger) << "Delay per call " << clock.getDelay() / numberOfCalls / 1000 << " ms";
551  }
552  }
553  }
554  catch(const exception& error) {
555  JErrorStream(logger) << "method run(): " << error.what();
556  }
557  }
558  }
long long int getDelay() const
Get total delay time.
Definition: JTimekeeper.hh:78
JSelectReader select
select call
Definition: JDAQClient.hh:833
void reset(const long long int t0)
Reset time.
Definition: JTimekeeper.hh:100
JSharedPointer< JControlHost > server
message server
Definition: JDAQClient.hh:635
JFileDescriptorMask & getReaderMask()
Get reader mask.
JTimekeeper clock
central clock
Definition: JDAQClient.hh:832
void wait() const
Wait until the number of time intervals has elapsed since the last call to the reset method...
Definition: JTimekeeper.hh:145
Auxiliary class for time values.
Definition: JTimeval.hh:26
virtual void actionRunning()
This method is repeatedly called when this client machine is in state Running and the clock interval ...
Definition: JDAQClient.hh:440
bool isRunning() const
Check if this client is in runnig state.
Definition: JDAQClient.hh:281
void update()
Update state machine.
Definition: JDAQClient.hh:643
long long int getInterval() const
Get interval time.
Definition: JTimekeeper.hh:67
static const int TIMEOUT_S
time out of update [s]
Definition: JDAQClient.hh:631
JMessageLogger logger
message logger
Definition: JDAQClient.hh:636
void error(const JMessage_t &message)
void setSelect()
Set the file descriptor mask for the select call.
Definition: JDAQClient.hh:403
virtual void actionSelect(const JFileDescriptorMask &mask)
Action method following last select call.
Definition: JDAQClient.hh:429
bool hasReaderMask(const JAbstractFile &file) const
Has reader file.
void KM3NETDAQ::JDAQClient::run ( const int  port)
inlineinherited

Run for ever.

This method can be used when the run control client is started before the run control (e.g. at boot time of the host processor). This method should be called before the state machine is entered. It launches a server which accepts a JNET::JControlHost connection from a designated application e.g. the JDAQClientStarter.cc program. The state machine is entered using the available data in the JNET::JControlHost message. After the state machine is exited, it accepts a new a JNET::JControlHost connection.

Parameters
portport number

Definition at line 573 of file JDAQClient.hh.

574  {
576 
577  for ( ; ; ) {
578 
579  JControlHost* ps = server.AcceptClient();
580 
581  ps->Connected();
582 
583  JNET::JPrefix prefix;
584 
585  ps->WaitHead(prefix);
586 
587  const int length = prefix.getSize();
588 
589  char* buffer = new char[length];
590 
591  ps->GetFullData(buffer, length);
592  ps->PutFullData(prefix.toString(), buffer, length);
593 
594  delete ps;
595 
596  enter(JArgs(std::string(buffer, length)));
597 
598  delete [] buffer;
599 
600  run();
601 
602  exit();
603  }
604  }
ControlHost prefix.
Definition: JPrefix.hh:31
ControlHost class.
int Connected()
Send version.
JSharedPointer< JControlHost > server
message server
Definition: JDAQClient.hh:635
void run()
Run as run control client following command messages via JNET::JControlHost.
Definition: JDAQClient.hh:493
int getSize() const
Get size.
Definition: JPrefix.hh:63
virtual bool enter()
Enter the state machine.
Definition: JDAQClient.hh:195
virtual bool exit()
Exit the state machine.
Definition: JDAQClient.hh:225
int WaitHead(JPrefix &prefix)
Wait for header.
std::string toString() const
Convert tag to string.
Definition: JTag.hh:167
int GetFullData(void *buffer, int length)
Receive data.
Light-weight wrapper class around server socket.
int PutFullData(const JTag &tag, const void *buffer, const int length)
Send data.
void KM3NETDAQ::JDAQClient::run ( std::istream &  in)
inlineinherited

Run client with commands from input stream (e.g for debugging).

Example input format:

<tag> <event name>[#data];
<tag> <event name>[#data];
Parameters
ininput stream

Definition at line 618 of file JDAQClient.hh.

619  {
620  using std::string;
621 
622  string tag;
623  string buffer;
624 
625  while (in >> tag && getline(in, buffer, ';')) {
626  update(tag, buffer.length(), buffer.data());
627  }
628  }
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:468
void update()
Update state machine.
Definition: JDAQClient.hh:643

Member Data Documentation

const int AcousticDataFilter::DEBUG_LEVEL =1
static

Definition at line 49 of file AcousticDataFilter.h.

boost::atomic<bool> AcousticDataFilter::exit_
private

Definition at line 90 of file AcousticDataFilter.h.

boost::atomic<bool> AcousticDataFilter::running_
private

Definition at line 91 of file AcousticDataFilter.h.

std::string AcousticDataFilter::address_
private

Definition at line 92 of file AcousticDataFilter.h.

std::string AcousticDataFilter::port_
private

Definition at line 93 of file AcousticDataFilter.h.

std::map<std::size_t,pProbe> AcousticDataFilter::probes_
private

Definition at line 95 of file AcousticDataFilter.h.

std::map<std::size_t,pDOM> AcousticDataFilter::doms_
private

Definition at line 96 of file AcousticDataFilter.h.

std::vector<pLink> AcousticDataFilter::links_
private

Definition at line 97 of file AcousticDataFilter.h.

boost::thread_group AcousticDataFilter::server_threads_
private

Definition at line 99 of file AcousticDataFilter.h.

boost::asio::io_service AcousticDataFilter::server_io_service_
private

Definition at line 100 of file AcousticDataFilter.h.

boost::asio::io_service::work* AcousticDataFilter::server_work_
private

Definition at line 101 of file AcousticDataFilter.h.

boost::asio::ip::tcp::acceptor AcousticDataFilter::server_acceptor_
private

Definition at line 102 of file AcousticDataFilter.h.

boost::thread_group AcousticDataFilter::trigger_threads_
private

Definition at line 103 of file AcousticDataFilter.h.

boost::asio::io_service AcousticDataFilter::trigger_io_service_
private

Definition at line 104 of file AcousticDataFilter.h.

boost::asio::io_service::work* AcousticDataFilter::trigger_work_
private

Definition at line 105 of file AcousticDataFilter.h.

boost::asio::io_service::strand AcousticDataFilter::strand_
private

Definition at line 106 of file AcousticDataFilter.h.

std::string AcousticDataFilter::debug_file_path_
private

Definition at line 108 of file AcousticDataFilter.h.

std::string AcousticDataFilter::toa_file_path_
private

Definition at line 109 of file AcousticDataFilter.h.

std::ofstream AcousticDataFilter::toa_file_
private

Definition at line 110 of file AcousticDataFilter.h.

std::string AcousticDataFilter::wisdom_file_
private

Definition at line 111 of file AcousticDataFilter.h.

const int KM3NETDAQ::JDAQClient::TIMEOUT_S = 1
staticinherited

time out of update [s]

Definition at line 631 of file JDAQClient.hh.

JSharedPointer<JControlHost> KM3NETDAQ::JDAQClient::server
protectedinherited

message server

Definition at line 635 of file JDAQClient.hh.

JMessageLogger KM3NETDAQ::JDAQClient::logger
protectedinherited

message logger

Definition at line 636 of file JDAQClient.hh.


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