File indexing completed on 2025-01-18 10:17:18
0001
0002
0003
0004
0005
0006 #include <JANA/JApplication.h>
0007 #include <JANA/JLogger.h>
0008
0009 #include "GroupedEventProcessor.h"
0010 #include "GroupedEventSource.h"
0011 #include "BlockingGroupedEventSource.h"
0012
0013
0014
0015 void producer_thread(BlockingGroupedEventSource* evt_src, JApplication* app, int starting_event_number = 1) {
0016
0017 int event_number = starting_event_number;
0018 std::vector<TridasEvent*> event_batch;
0019
0020 for (int group_number = 1; group_number < 6; ++group_number) {
0021
0022
0023
0024 for (int i=1; i<=5; ++i) {
0025 auto event = new TridasEvent;
0026 event->event_number = event_number++;
0027 event->run_number = 22;
0028 event->should_keep = false;
0029 event_batch.push_back(event);
0030 }
0031
0032
0033
0034
0035 LOG << "Calling SubmitAndWait for events " << event_number-5 << ".." << event_number-1 << LOG_END;
0036
0037
0038 evt_src->SubmitAndWait(event_batch);
0039
0040
0041 LOG << "SubmitAndWait returned! Producer thread may now access results for events "
0042 << event_number-5 << ".." << event_number-1 << LOG_END;
0043
0044
0045
0046
0047
0048 for (int i=0; i<5; ++i) {
0049 assert(event_batch[i]->should_keep);
0050 delete event_batch[i];
0051 }
0052 event_batch.clear();
0053 }
0054
0055
0056 app->Quit();
0057 }
0058
0059
0060
0061 extern "C"{
0062 void InitPlugin(JApplication *app) {
0063
0064 InitJANAPlugin(app);
0065
0066 app->SetParameterValue("jana:extended_report", false);
0067
0068 app->Add(new GroupedEventProcessor());
0069
0070 auto evt_src = new BlockingGroupedEventSource();
0071
0072 app->Add(evt_src);
0073
0074
0075 new std::thread([=](){ producer_thread(evt_src, app); });
0076
0077
0078 new std::thread([=](){ producer_thread(evt_src, app, 100); });
0079
0080
0081 }
0082 }