artdaq_mpich_plugin  v1_00_08a
BoardReaderMain.cc
1 #include "artdaq-mpich-plugin/Application/MPISentry.hh"
2 #include "artdaq/Application/BoardReaderApp.hh"
3 #include "artdaq/Application/LoadParameterSet.hh"
4 #include "artdaq/Application/TaskType.hh"
5 #include "artdaq/BuildInfo/GetPackageBuildInfo.hh"
6 #include "artdaq/DAQdata/Globals.hh"
7 #include "artdaq/ExternalComms/MakeCommanderPlugin.hh"
8 #include "cetlib_except/exception.h"
9 
10 #include <boost/lexical_cast.hpp>
11 #include <boost/program_options.hpp>
12 
13 #include <iostream>
14 #include <memory>
15 
16 int main(int argc, char* argv[]) {
17  // initialization
18  int const wanted_threading_level{MPI_THREAD_FUNNELED};
19 
20  MPI_Comm local_group_comm;
21  std::unique_ptr<artdaq::MPISentry> mpiSentry;
22 
23  try {
24  mpiSentry.reset(new artdaq::MPISentry(&argc, &argv, wanted_threading_level, artdaq::TaskType::BoardReaderTask,
25  local_group_comm));
26  } catch (cet::exception& errormsg) {
27  TLOG_ERROR("BoardReaderMain") << errormsg;
28  TLOG_ERROR("BoardReaderMain") << "MPISentry error encountered in BoardReaderMain; exiting...";
29  throw errormsg;
30  }
31 
32  struct Config {
33  fhicl::TableFragment<artdaq::CommanderInterface::Config> commander_config;
34  fhicl::Atom<std::string> application_name{fhicl::Name{"application_name"},
35  fhicl::Comment{"Name of the application for metrics and logging"},
36  "BoardReader"};
37  fhicl::TableFragment<artdaq::PortManager::Config> portsConfig;
38  };
39 
40  fhicl::ParameterSet config_ps = LoadParameterSet<Config>(argc, argv, "BoardReaderMain",
41  "This is the BoardReader's main executable (MPI version)");
42  app_name = config_ps.get<std::string>("application_name", "BoardReader");
43  portMan->UpdateConfiguration(config_ps);
44  std::string mf_app_name = artdaq::setMsgFacAppName(app_name, config_ps.get<int>("id"));
45  artdaq::configureMessageFacility(mf_app_name.c_str());
46  TLOG_DEBUG(app_name + "Main") << "Setting application name to " << mf_app_name;
47 
48  // 23-May-2018, KAB: added lookup of the partition number from the command line arguments.
49  if (config_ps.has_key("partition_number")) {
50  artdaq::Globals::partition_number_ = config_ps.get<int>("partition_number");
51  }
52  TLOG_DEBUG(app_name + "Main") << "Setting partition number to " << artdaq::Globals::partition_number_;
53 
54  TLOG_INFO(app_name + "Main") << "artdaq version "
55  << artdaq::GetPackageBuildInfo::getPackageBuildInfo().getPackageVersion() << ", built "
56  << artdaq::GetPackageBuildInfo::getPackageBuildInfo().getBuildTimestamp();
57 
58  // create the BoardReaderApp
59  my_rank = mpiSentry->rank();
60  artdaq::BoardReaderApp br_app;
61 
62  auto commander = artdaq::MakeCommanderPlugin(config_ps, br_app);
63  TLOG_INFO(app_name + "Main") << "Running Commmander Server";
64  commander->run_server();
65  artdaq::Globals::CleanUpGlobals();
66  TLOG_INFO(app_name + "Main") << "Commandable Server ended, exiting...";
67 }
The MPISentry class initializes and finalizes the MPI context that the artdaq applciations run in...
Definition: MPISentry.hh:14
int rank() const
Get the MPI rank of the application.
Definition: MPISentry.cc:67