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