artdaq  v3_09_00
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 "fhiclcpp/make_ParameterSet.h"
9 
10 int main(int argc, char* argv[])
11 try
12 {
13  artdaq::configureMessageFacility("PrintSharedMemory");
14 
15  std::ostringstream descstr;
16  descstr << *argv
17  << " <-c <config-file>> <other-options> [<source-file>]+";
18  bpo::options_description desc(descstr.str());
19  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");
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  if ((vm.count("config") == 0u) && (vm.count("key") == 0u))
38  {
39  std::cerr << "Exception from command line processing in " << *argv
40  << ": no configuration file given.\n"
41  << "For usage and an options list, please do '"
42  << *argv << " --help"
43  << "'.\n";
44  return 2;
45  }
46 
47  fhicl::ParameterSet pset;
48  if (vm.count("key") != 0u)
49  {
50  pset.put("shared_memory_key", vm["key"].as<std::string>());
51  pset.put("buffer_count", 1);
52  pset.put("max_event_size_bytes", 1024);
53  pset.put("ReadEventInfo", vm.count("events") > 0);
54  }
55  else
56  {
57  if (getenv("FHICL_FILE_PATH") == nullptr)
58  {
59  std::cerr
60  << "INFO: environment variable FHICL_FILE_PATH was not set. Using \".\"\n";
61  setenv("FHICL_FILE_PATH", ".", 0);
62  }
63  cet::filepath_lookup_after1 lookup_policy("FHICL_FILE_PATH");
64  fhicl::make_ParameterSet(vm["config"].as<std::string>(), lookup_policy, pset);
65  }
66 
67  if (!pset.has_key("shared_memory_key"))
68  {
69  std::cerr << "You must specify a shared_memory_key in FHiCL or provide one on the command line!" << std::endl;
70  }
71 
72  if (pset.get<bool>("ReadEventInfo", false))
73  {
74  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")));
75  std::cout << t.toString() << std::endl;
76  }
77  else
78  {
79  artdaq::SharedMemoryManager t(pset.get<uint32_t>("shared_memory_key"),
80  pset.get<size_t>("buffer_count"),
81  pset.get<size_t>("max_event_size_bytes"),
82  pset.get<size_t>("stale_buffer_timeout_usec", 1000000));
83  std::cout << t.toString() << std::endl;
84  }
85 
86  return 0;
87 }
88 catch (...)
89 {
90  return -1;
91 }