artdaq  v3_12_02
PrintSharedMemory.cc
1 #include "artdaq-core/Core/SharedMemoryEventReceiver.hh"
2 #include "artdaq-core/Utilities/configureMessageFacility.hh"
3 #include "artdaq/DAQdata/Globals.hh"
4 
5 #include <boost/program_options.hpp>
6 namespace bpo = boost::program_options;
7 
8 #include <sstream>
9 
10 int main(int argc, char* argv[])
11 try
12 {
13  artdaq::configureMessageFacility("PrintSharedMemory");
14 
15  std::ostringstream descstr;
16  descstr << *argv
17  << " [-M <shared memory>] <-e>";
18  bpo::options_description desc(descstr.str());
19  desc.add_options()("key,M", bpo::value<std::string>(), "Shared Memory to attach to")("events,e", "Print event information")("help,h", "produce help message");
20  bpo::variables_map vm;
21  try
22  {
23  bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm);
24  bpo::notify(vm);
25  }
26  catch (bpo::error const& e)
27  {
28  std::cerr << "Exception from command line processing in " << *argv
29  << ": " << e.what() << "\n";
30  return -1;
31  }
32  if (vm.count("help") != 0u)
33  {
34  std::cout << desc << std::endl;
35  return 1;
36  }
37 
38  fhicl::ParameterSet pset;
39  if (vm.count("key") != 0u)
40  {
41  pset.put("shared_memory_key", vm["key"].as<std::string>());
42  auto bkey = vm["key"].as<std::string>();
43  if (bkey[2] == 'e' && bkey[3] == 'e')
44  {
45  bkey[2] = 'b';
46  bkey[3] = 'b';
47  pset.put("broadcast_shared_memory_key", bkey);
48  pset.put("read_event_info", true);
49  }
50  else
51  {
52  pset.put("read_event_info", vm.count("events") > 0);
53  }
54  }
55  else
56  {
57  std::cerr << "You must specify a shared_memory_key in FHiCL or provide one on the command line!" << std::endl;
58  return -2;
59  }
60 
61  TLOG() << "Going to read shared memory " << std::showbase << std::hex << pset.get<uint32_t>("shared_memory_key") << " Event Mode: " << std::boolalpha << pset.get<bool>("read_event_info");
62  if (pset.get<bool>("read_event_info", false))
63  {
64  artdaq::SharedMemoryEventReceiver t(pset.get<uint32_t>("shared_memory_key"), pset.get<uint32_t>("broadcast_shared_memory_key", pset.get<uint32_t>("shared_memory_key")));
65  std::cout << t.toString() << std::endl;
66  }
67  else
68  {
69  artdaq::SharedMemoryManager t(pset.get<uint32_t>("shared_memory_key"), 0, 0, 0);
70  std::cout << t.toString() << std::endl;
71  }
72 
73  return 0;
74 }
75 catch (...)
76 {
77  return -1;
78 }