Psyllid  v1.12.4
Project 8 Data Acquisisition Software
test_event_builder.cc
Go to the documentation of this file.
1 /*
2  * test_event_builder.cc
3  *
4  * Created on: Dec 29, 2015
5  * Author: nsoblath
6  *
7  * Trigger ids: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16, 17, 18, 19
8  * Sequence of triggers: 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1
9  *
10  * Pretrigger: 2
11  * Skip tolerance: 1
12  *
13  * Triggered events should be: 1-8, 9-15, 17-19
14  */
15 
16 
17 #include "diptera.hh"
18 #include "event_builder.hh"
19 #include "producer.hh"
20 
21 #include "logger.hh"
22 
23 #include <array>
24 
25 using std::array;
26 
27 using midge::stream;
28 
29 LOGGER( plog, "test_event_builder" );
30 
31 namespace psyllid
32 {
33  class test_producer :
34  public midge::_producer< test_producer, typelist_1( trigger_flag ) >
35  {
36  public:
38  f_length( 10 )
39  {}
40 
41  virtual ~test_producer() {}
42 
43  public:
44  accessible( uint64_t, length );
45 
46  public:
47  void initialize()
48  {
49  out_buffer< 0 >().initialize( f_length );
50  return;
51  }
52 
53  void execute()
54  {
55  // this line produces a warning in clang and some versions of gcc; it's a known bug in the compilers
56  array< bool, 20 > t_flags = { 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1 };
57 
58  out_stream< 0 >().set( stream::s_start );
59 
60  for( uint64_t t_id = 0; t_id < t_flags.size(); ++t_id )
61  {
62  trigger_flag* t_flag_data = out_stream< 0 >().data();
63 
64  t_flag_data->set_id( t_id );
65  t_flag_data->set_flag( t_flags[ t_id ] );
66 
67  LDEBUG( plog, "Sending: " << t_id << ", " << t_flags[t_id] );
68 
69  out_stream< 0 >().set( stream::s_run );
70  }
71 
72  out_stream< 0 >().set( stream::s_stop );
73  out_stream< 0 >().set( stream::s_exit );
74 
75  return;
76  }
77 
78  void finalize()
79  {
80  out_buffer< 0 >().finalize();
81  return;
82  }
83 
84 
85  };
86 }
87 
88 
89 using namespace psyllid;
90 
91 int main()
92 {
93  LINFO( plog, "Preparing" );
94 
95  ::midge::diptera* t_root = new ::midge::diptera();
96 
97  test_producer* t_test_prod = new test_producer();
98  t_test_prod->set_name( "tp" );
99  t_root->add( t_test_prod );
100 
101  event_builder* t_event_builder = new event_builder();
102  t_event_builder->set_name( "eb" );
103  t_event_builder->set_pretrigger( 2 );
104  t_event_builder->set_skip_tolerance( 1 );
105  t_root->add( t_event_builder );
106 
107  t_root->join( "tp.out_0:eb.in_0" );
108 
109  LINFO( plog, "Expecting the following events: 1-8, 9-15, 17-19" );
110 
111  LINFO( plog, "Starting execution" );
112 
113  t_root->run( "tp:eb" );
114 
115  LINFO( plog, "All done!" );
116 
117  delete t_root;
118 
119  return 0;
120 }
121 
accessible(uint64_t, length)
static scarab::logger plog("batch_executor")
A transformer that considers a sequence of triggered packets and decides what constitutes a contiguou...
static scarab::logger plog("test_event_builder")
int main()
LOGGER(plog, "egg_writer")