artdaq  v3_12_01
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()
20  ("key,M", bpo::value<std::string>(), "Shared Memory to attach to")
21  ("events,e", "Print event information")
22  ("help,h", "produce help message");
23  bpo::variables_map vm;
24  try
25  {
26  bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm);
27  bpo::notify(vm);
28  }
29  catch (bpo::error const& e)
30  {
31  std::cerr << "Exception from command line processing in " << *argv
32  << ": " << e.what() << "\n";
33  return -1;
34  }
35  if (vm.count("help") != 0u)
36  {
37  std::cout << desc << std::endl;
38  return 1;
39  }
40 
41  fhicl::ParameterSet pset;
42  if (vm.count("key") != 0u)
43  {
44  pset.put("shared_memory_key", vm["key"].as<std::string>());
45  auto bkey = vm["key"].as<std::string>();
46  if (bkey[2] == 'e' && bkey[3] == 'e')
47  {
48  bkey[2] = 'b';
49  bkey[3] = 'b';
50  pset.put("broadcast_shared_memory_key", bkey);
51  pset.put("read_event_info", true);
52  }
53  else
54  {
55  pset.put("read_event_info", vm.count("events") > 0);
56  }
57  }
58  else
59  {
60  std::cerr << "You must specify a shared_memory_key in FHiCL or provide one on the command line!" << std::endl;
61  return -2;
62  }
63 
64  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");
65  if (pset.get<bool>("read_event_info", false))
66  {
67  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")));
68  std::cout << t.toString() << std::endl;
69  }
70  else
71  {
72  artdaq::SharedMemoryManager t(pset.get<uint32_t>("shared_memory_key"), 0, 0, 0);
73  std::cout << t.toString() << std::endl;
74  }
75 
76  return 0;
77 }
78 catch (...)
79 {
80  return -1;
81 }