artdaq  v2_02_03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
EventStore_t.cc
1 #include "artdaq/DAQrate/EventStore.hh"
2 #include <fhiclcpp/ParameterSet.h>
3 
4 #include <thread>
5 
6 #define BOOST_TEST_MODULE(EventStore_t)
7 #include "boost/test/auto_unit_test.hpp"
8 
9 BOOST_AUTO_TEST_SUITE(EventStore_test)
10 
11  /* This is responsible for taking the completed RawEvents passed via the
12  GlobalQueue from the EventStore and holding onto them until the EndOfData
13  signal is received. At that point it will push all of the events back onto
14  the GlobalQueue so that the unit test can pull them off and examine them.
15  */
16  int bogusApp(int, char**)
17  {
18  artdaq::RawEventQueue& queue(artdaq::getGlobalQueue());
19  artdaq::RawEvent_ptr incomingEvent;
20  std::vector<artdaq::RawEvent_ptr> receivedEvents;
21 
22  while (1)
23  {
24  queue.deqWait(incomingEvent);
25  if (incomingEvent == nullptr)
26  {
27  for (std::vector<artdaq::RawEvent_ptr>::iterator it = receivedEvents.begin();
28  it != receivedEvents.end(); ++it)
29  {
30  queue.enqNowait(*it);
31  }
32 
33  queue.enqNowait(artdaq::RawEvent_ptr(0));
34  return 0;
35  }
36 
37  receivedEvents.emplace_back(incomingEvent);
38  }
39  }
40 
41 
42  BOOST_AUTO_TEST_CASE(Trivial)
43  {
44  /* This will create an event store configured to build RawEvents that consist
45  of four Fragments. We'll insert the Fragments out of order to spice things
46  up.
47  */
48  std::unique_ptr<artdaq::EventStore> eventStore;
49  artdaq::EventStore::ART_CMDLINE_FCN* bogusReader = &bogusApp;
50  fhicl::ParameterSet pset;
51  eventStore.reset(new artdaq::EventStore(pset, 4, 1, 0, nullptr, bogusReader));
52 
53  int sequenceID[8] = {1, 2, 1, 2, 1, 2, 2, 1};
54  int fragmentID[8] = {1, 2, 3, 4, 1, 2, 3, 4};
55  std::unique_ptr<artdaq::Fragment> testFragment;
56  for (int i = 0; i < 8; i++)
57  {
58  testFragment.reset(new artdaq::Fragment(sequenceID[i], fragmentID[i]));
59  eventStore->insert(std::move(testFragment));
60  }
61  int readerReturnValue;
62  eventStore->endOfData(readerReturnValue);
63 
64  artdaq::RawEventQueue& queue(artdaq::getGlobalQueue());
65 
66  artdaq::RawEvent_ptr r1;
67  artdaq::RawEvent_ptr r2;
68  artdaq::RawEvent_ptr r3;
69  artdaq::RawEvent_ptr r4;
70 
71  BOOST_REQUIRE_EQUAL(queue.deqNowait(r1), true);
72  BOOST_REQUIRE_EQUAL(queue.deqNowait(r2), true);
73  BOOST_REQUIRE_EQUAL(queue.deqNowait(r3), true);
74  BOOST_REQUIRE_EQUAL(queue.deqNowait(r4), false);
75 
76  BOOST_REQUIRE_EQUAL(r1->numFragments(), (size_t) 4);
77  BOOST_REQUIRE_EQUAL(r2->numFragments(), (size_t) 4);
78  }
79 
80  BOOST_AUTO_TEST_CASE(SequenceMod)
81  {
82  /* Verify that the EventStore will correctly group Fragments with different
83  sequence numbers into groups when configured to do so.
84  */
85  std::unique_ptr<artdaq::EventStore> eventStore;
86  artdaq::EventStore::ART_CMDLINE_FCN* bogusReader = &bogusApp;
87  fhicl::ParameterSet pset;
88  eventStore.reset(new artdaq::EventStore(pset, 4, 1, 0, nullptr, bogusReader));
89  eventStore->setSeqIDModulus(4);
90 
91  int sequenceID[8] = {1, 5, 4, 6, 7, 2, 8, 3};
92  int fragmentID[8] = {1, 2, 3, 4, 1, 2, 3, 4};
93  std::unique_ptr<artdaq::Fragment> testFragment;
94  for (int i = 0; i < 8; i++)
95  {
96  testFragment.reset(new artdaq::Fragment(sequenceID[i], fragmentID[i]));
97  eventStore->insert(std::move(testFragment));
98  }
99  int readerReturnValue;
100  eventStore->endOfData(readerReturnValue);
101 
102  artdaq::RawEventQueue& queue(artdaq::getGlobalQueue());
103 
104  artdaq::RawEvent_ptr r1;
105  artdaq::RawEvent_ptr r2;
106  artdaq::RawEvent_ptr r3;
107  artdaq::RawEvent_ptr r4;
108 
109  BOOST_REQUIRE_EQUAL(queue.deqNowait(r1), true);
110  BOOST_REQUIRE_EQUAL(queue.deqNowait(r2), true);
111  BOOST_REQUIRE_EQUAL(queue.deqNowait(r3), true);
112  BOOST_REQUIRE_EQUAL(queue.deqNowait(r4), false);
113 
114  BOOST_REQUIRE_EQUAL(r1->numFragments(), (size_t) 4);
115  BOOST_REQUIRE_EQUAL(r2->numFragments(), (size_t) 4);
116 
117  /* The EventStore doesn't order anything so things should come out the same
118  order they went in.
119  */
120  std::unique_ptr<std::vector<artdaq::Fragment>> fragments1 = r1->releaseProduct();
121  int sequenceIDb[8] = {5, 6, 7, 8};
122  for (int i = 0; i < 4; i++)
123  {
124  BOOST_REQUIRE_EQUAL(sequenceIDb[i], (int)fragments1->at(i).sequenceID());
125  }
126 
127  std::unique_ptr<std::vector<artdaq::Fragment>> fragments2 = r2->releaseProduct();
128  int sequenceIDc[8] = {1, 4, 2, 3};
129  for (int i = 0; i < 4; i++)
130  {
131  BOOST_REQUIRE_EQUAL(sequenceIDc[i], (int)fragments2->at(i).sequenceID());
132  }
133  }
134 
135 BOOST_AUTO_TEST_SUITE_END()
void insert(FragmentPtr pfrag, bool printWarningWhenFragmentIsDropped=true)
Give ownership of the Fragment to the EventStore.
Definition: EventStore.cc:94
bool endOfData(int &readerReturnValue)
Indicate that the end of input has been reached to the art thread.
Definition: EventStore.cc:247
The EventStore class collects Fragment objects, until it receives a complete event, at which point the event is handed over to the art thread.
Definition: EventStore.hh:48
int( ART_CMDLINE_FCN)(int, char **)
An art function that accepts standard C main arguments.
Definition: EventStore.hh:55
void setSeqIDModulus(unsigned int seqIDModulus)
Set the parameter that will be used to determine which sequence IDs get grouped together into events...
Definition: EventStore.cc:262