$treeview $search $mathjax $extrastylesheet
artdaq_core
v3_06_01
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "artdaq-core/Core/SimpleQueueReader.hh" 00002 00003 #include <chrono> // for milliseconds 00004 #include <cstddef> // for std::size_t 00005 #include <iostream> 00006 #include <string> 00007 #include <thread> // std::this_thread::sleep_for 00008 #include "trace.h" // TRACE 00009 00010 namespace artdaq { 00011 int simpleQueueReaderApp(int argc, char** argv) 00012 { 00013 try 00014 { 00015 size_t eec(0); 00016 if (argc == 2) 00017 { 00018 std::istringstream ins(argv[1]); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) 00019 ins >> eec; 00020 } 00021 SimpleQueueReader reader(eec); 00022 reader.run(); 00023 return 0; 00024 } 00025 catch (std::string const& msg) 00026 { 00027 std::cerr << "simpleQueueReaderApp failed: " 00028 << msg; 00029 return 1; 00030 } 00031 catch (...) 00032 { 00033 return 1; 00034 } 00035 } 00036 00037 SimpleQueueReader:: 00038 SimpleQueueReader(std::size_t eec) 00039 : queue_(getGlobalQueue()) 00040 , expectedEventCount_(eec) 00041 { 00042 queue_.setReaderIsReady(); 00043 TLOG(50) << "SimpleQueueReader ctor done (after queue_.setReaderIsReady())"; 00044 } 00045 00046 void SimpleQueueReader::run() 00047 { 00048 std::size_t eventsSeen = 0; 00049 auto doPrint = getenv("VERBOSE_QUEUE_READING"); 00050 while (true) 00051 { 00052 RawEvent_ptr rawEventPtr; 00053 if (queue_.deqNowait(rawEventPtr)) 00054 { 00055 // If we got a null pointer, we're done... 00056 if (!rawEventPtr) { break; } 00057 ++eventsSeen; 00058 // Otherwise, do our work ... 00059 if (doPrint != nullptr) { std::cout << *rawEventPtr << std::endl; } 00060 } 00061 else 00062 { 00063 std::this_thread::sleep_for(std::chrono::milliseconds(250)); 00064 } 00065 } 00066 if ((expectedEventCount_ != 0u) && eventsSeen != expectedEventCount_) 00067 { 00068 throw cet::exception("SimpleQueueReader") // NOLINT(cert-err60-cpp) 00069 << "Wrong number of events in SimpleQueueReader (" 00070 << eventsSeen << " != " << expectedEventCount_ << ").\n"; 00071 } 00072 } 00073 } // namespace artdaq