Psyllid  v1.12.4
Project 8 Data Acquisisition Software
tf_roach_monitor.cc
Go to the documentation of this file.
1 /*
2  * tf_roach_monitor.cc
3  *
4  * Created on: Sept 23, 2016
5  * Author: nsoblath
6  */
7 
8 #include "tf_roach_monitor.hh"
9 
10 #include "psyllid_error.hh"
11 
12 #include "logger.hh"
13 #include "time.hh"
14 
15 #include <limits>
16 
17 using midge::stream;
18 
19 namespace psyllid
20 {
21  REGISTER_NODE_AND_BUILDER( roach_time_monitor, "roach-time-monitor", roach_time_monitor_binding );
22  REGISTER_NODE_AND_BUILDER( roach_freq_monitor, "roach-freq-monitor", roach_freq_monitor_binding );
23 
24  LOGGER( plog, "tf_roach_monitor" );
25 
26 
27  //****************
28  // Time Monitor
29  //****************
30 
32  f_last_pkt_in_batch( 0 ),
33  f_packet_count( 0 ),
34  f_acquisition_count( 0 )
35  {
36  }
37 
39  {
40  }
41 
43  {
44  f_last_pkt_in_batch = std::numeric_limits< uint64_t >::max();
45  return;
46  }
47 
48  void roach_time_monitor::execute( midge::diptera* a_midge )
49  {
50  try
51  {
52  midge::enum_t t_time_command = stream::s_none;
53 
54  time_data* t_time_data = nullptr;
55 
56  uint64_t t_current_pkt_in_batch = 0;
57 
58  while( ! is_canceled() )
59  {
60  t_time_command = in_stream< 0 >().get();
61  if( t_time_command == stream::s_error ) break;
62  if( t_time_command == stream::s_none ) continue;
63 
64  LTRACE( plog, "ROACH time monitor reading stream 0 (time) at index " << in_stream< 0 >().get_current_index() );
65 
66  if( t_time_command == stream::s_exit )
67  {
68  LDEBUG( plog, "ROACH time monitor is exiting" );
69 
70  break;
71  }
72 
73  if( t_time_command == stream::s_stop )
74  {
75  LDEBUG( plog, "ROACH time monitor is stopping" );
76 
77  continue;
78  }
79 
80  if( t_time_command == stream::s_start )
81  {
82  LDEBUG( plog, "ROACH time monitor is starting" );
83 
84  continue;
85  }
86 
87  t_time_data = in_stream< 0 >().data();
88 
89  if( t_time_command == stream::s_run )
90  {
92  t_current_pkt_in_batch = t_time_data->get_pkt_in_batch();
93 
94  if( f_last_pkt_in_batch + 1 != t_current_pkt_in_batch )
95  {
97  LWARN( plog, "[Time] Packet-count discontinuity: last packet = " << f_last_pkt_in_batch << " current packet = " << t_current_pkt_in_batch );
98  }
99  f_last_pkt_in_batch = t_current_pkt_in_batch;
100 
101  continue;
102  }
103 
104  }
105 
106  return;
107  }
108  catch(...)
109  {
110  if( a_midge ) a_midge->throw_ex( std::current_exception() );
111  else throw;
112  }
113  }
114 
116  {
117  LINFO( plog, "ROACH Time Monitor statistics:\n" <<
118  "\tPacket count:\t" << f_packet_count << '\n' <<
119  "\tAcq'n count:\t" << f_acquisition_count << '\n' <<
120  "\tLast pkt in batch:\t" << f_last_pkt_in_batch );
121  return;
122  }
123 
124 
127  {
128  }
129 
131  {
132  }
133 
134  void roach_time_monitor_binding::do_apply_config( roach_time_monitor*, const scarab::param_node& ) const
135  {
136  return;
137  }
138 
139  void roach_time_monitor_binding::do_dump_config( const roach_time_monitor*, scarab::param_node& ) const
140  {
141  return;
142  }
143 
144 
145 
146  //****************
147  // Freq Monitor
148  //****************
149 
151  f_last_pkt_in_batch( 0 ),
152  f_packet_count( 0 ),
153  f_acquisition_count( 0 )
154  {
155  }
156 
158  {
159  }
160 
162  {
163  f_last_pkt_in_batch = std::numeric_limits< uint64_t >::max();
164  return;
165  }
166 
167  void roach_freq_monitor::execute( midge::diptera* a_midge )
168  {
169  try
170  {
171  midge::enum_t t_freq_command = stream::s_none;
172 
173  freq_data* t_freq_data = nullptr;
174 
175  uint64_t t_current_pkt_in_batch = 0;
176 
177  while( ! is_canceled() )
178  {
179  t_freq_command = in_stream< 0 >().get();
180  if( t_freq_command == stream::s_error ) break;
181  if( t_freq_command == stream::s_none ) continue;
182 
183  LTRACE( plog, "ROACH freq monitor reading stream 0 (freq) at index " << in_stream< 0 >().get_current_index() );
184 
185  if( t_freq_command == stream::s_exit )
186  {
187  LDEBUG( plog, "ROACH freq monitor is exiting" );
188 
189  break;
190  }
191 
192  if( t_freq_command == stream::s_stop )
193  {
194  LDEBUG( plog, "ROACH freq monitor is stopping" );
195 
196  continue;
197  }
198 
199  if( t_freq_command == stream::s_start )
200  {
201  LDEBUG( plog, "ROACH freq monitor is starting" );
202 
203  continue;
204  }
205 
206  t_freq_data = in_stream< 0 >().data();
207 
208  if( t_freq_command == stream::s_run )
209  {
210  ++f_packet_count;
211  t_current_pkt_in_batch = t_freq_data->get_pkt_in_batch();
212 
213  if( f_last_pkt_in_batch + 1 != t_current_pkt_in_batch )
214  {
216  LWARN( plog, "[Time] Packet-count discontinuity: last packet = " << f_last_pkt_in_batch << " current packet = " << t_current_pkt_in_batch );
217  }
218  f_last_pkt_in_batch = t_current_pkt_in_batch;
219 
220  continue;
221  }
222 
223  }
224 
225  return;
226  }
227  catch(...)
228  {
229  if( a_midge ) a_midge->throw_ex( std::current_exception() );
230  else throw;
231  }
232  }
233 
235  {
236  LINFO( plog, "ROACH Time Monitor statistics:\n" <<
237  "\tPacket count:\t" << f_packet_count << '\n' <<
238  "\tAcq'n count:\t" << f_acquisition_count << '\n' <<
239  "\tLast pkt in batch:\t" << f_last_pkt_in_batch );
240  return;
241  }
242 
243 
246  {
247  }
248 
250  {
251  }
252 
253  void roach_freq_monitor_binding::do_apply_config( roach_freq_monitor*, const scarab::param_node& ) const
254  {
255  return;
256  }
257 
258  void roach_freq_monitor_binding::do_dump_config( const roach_freq_monitor*, scarab::param_node& ) const
259  {
260  return;
261  }
262 
263 
264 
265 } /* namespace psyllid */
virtual void execute(midge::diptera *a_midge=nullptr)
virtual void do_dump_config(const roach_freq_monitor *a_node, scarab::param_node &a_config) const
static scarab::logger plog("batch_executor")
virtual void do_apply_config(roach_time_monitor *a_node, const scarab::param_node &a_config) const
A consumer to check the continuity of the freq-packet stream from a ROACH.
virtual void do_apply_config(roach_freq_monitor *a_node, const scarab::param_node &a_config) const
virtual void do_dump_config(const roach_time_monitor *a_node, scarab::param_node &a_config) const
A consumer to check the continuity of the time-packet stream from a ROACH.
uint32_t get_pkt_in_batch() const
REGISTER_NODE_AND_BUILDER(data_producer, "data-producer", data_producer_binding)
virtual void execute(midge::diptera *a_midge=nullptr)
LOGGER(plog, "egg_writer")