artdaq  v3_10_02
PrintSharedMemory.cc
1 
2 #include <boost/program_options.hpp>
3 #include <sstream>
4 namespace bpo = boost::program_options;
5 
6 #include "artdaq-core/Core/SharedMemoryEventReceiver.hh"
7 #include "artdaq/DAQdata/Globals.hh"
8 #include "artdaq-utilities/Plugins/MakeParameterSet.hh"
9 
10 int main(int argc, char* argv[]) try
11 {
12  artdaq::configureMessageFacility("PrintSharedMemory");
13 
14  std::ostringstream descstr;
15  descstr << *argv
16  << " <-c <config-file>> <other-options> [<source-file>]+";
17  bpo::options_description desc(descstr.str());
18  desc.add_options()("config,c", bpo::value<std::string>(), "Configuration file.")("events,e", "Print event information")("key,M", bpo::value<std::string>(), "Shared Memory to attach to")("help,h", "produce help message");
19  bpo::variables_map vm;
20  try
21  {
22  bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm);
23  bpo::notify(vm);
24  }
25  catch (bpo::error const& e)
26  {
27  std::cerr << "Exception from command line processing in " << *argv
28  << ": " << e.what() << "\n";
29  return -1;
30  }
31  if (vm.count("help") != 0u)
32  {
33  std::cout << desc << std::endl;
34  return 1;
35  }
36  if ((vm.count("config") == 0u) && (vm.count("key") == 0u))
37  {
38  std::cerr << "Exception from command line processing in " << *argv
39  << ": no configuration file given.\n"
40  << "For usage and an options list, please do '"
41  << *argv << " --help"
42  << "'.\n";
43  return 2;
44  }
45 
46  fhicl::ParameterSet pset;
47  if (vm.count("key") != 0u)
48  {
49  pset.put("shared_memory_key", vm["key"].as<std::string>());
50  pset.put("buffer_count", 1);
51  pset.put("max_event_size_bytes", 1024);
52  pset.put("ReadEventInfo", vm.count("events") > 0);
53  }
54  else
55  {
56  if (getenv("FHICL_FILE_PATH") == nullptr)
57  {
58  std::cerr
59  << "INFO: environment variable FHICL_FILE_PATH was not set. Using \".\"\n";
60  setenv("FHICL_FILE_PATH", ".", 0);
61  }
62  cet::filepath_lookup_after1 lookup_policy("FHICL_FILE_PATH");
63  pset = artdaq::make_pset(vm["config"].as<std::string>(), lookup_policy);
64  }
65 
66  if (!pset.has_key("shared_memory_key"))
67  {
68  std::cerr << "You must specify a shared_memory_key in FHiCL or provide one on the command line!" << std::endl;
69  }
70 
71  if (pset.get<bool>("ReadEventInfo", false))
72  {
73  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")));
74  std::cout << t.toString() << std::endl;
75  }
76  else
77  {
78  artdaq::SharedMemoryManager t(pset.get<uint32_t>("shared_memory_key"),
79  pset.get<size_t>("buffer_count"),
80  pset.get<size_t>("max_event_size_bytes"),
81  pset.get<size_t>("stale_buffer_timeout_usec", 1000000));
82  std::cout << t.toString() << std::endl;
83  }
84 
85  return 0;
86 }
87 catch (...)
88 {
89  return -1;
90 }