artdaq_mpich_plugin  v1_00_13
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 {
18  // initialization
19  int const wanted_threading_level{MPI_THREAD_FUNNELED};
20 
21  MPI_Comm local_group_comm;
22  std::unique_ptr<artdaq::MPISentry> mpiSentry;
23 
24  try
25  {
26  mpiSentry.reset(new artdaq::MPISentry(&argc, &argv, wanted_threading_level, artdaq::TaskType::BoardReaderTask,
27  local_group_comm));
28  }
29  catch (cet::exception& errormsg)
30  {
31  TLOG_ERROR("BoardReaderMain") << errormsg;
32  TLOG_ERROR("BoardReaderMain") << "MPISentry error encountered in BoardReaderMain; exiting...";
33  throw errormsg;
34  }
35 
36  struct Config
37  {
38  fhicl::TableFragment<artdaq::CommanderInterface::Config> commander_config;
39  fhicl::Atom<std::string> application_name{fhicl::Name{"application_name"},
40  fhicl::Comment{"Name of the application for metrics and logging"},
41  "BoardReader"};
42  fhicl::TableFragment<artdaq::PortManager::Config> portsConfig;
43  };
44 
45  fhicl::ParameterSet config_ps = LoadParameterSet<Config>(argc, argv, "BoardReaderMain",
46  "This is the BoardReader's main executable (MPI version)");
47  app_name = config_ps.get<std::string>("application_name", "BoardReader");
48  portMan->UpdateConfiguration(config_ps);
49  std::string mf_app_name = artdaq::setMsgFacAppName(app_name, config_ps.get<int>("id"));
50  artdaq::configureMessageFacility(mf_app_name.c_str());
51  TLOG_DEBUG(app_name + "Main") << "Setting application name to " << mf_app_name;
52 
53  // 23-May-2018, KAB: added lookup of the partition number from the command line arguments.
54  if (config_ps.has_key("partition_number"))
55  {
56  artdaq::Globals::partition_number_ = config_ps.get<int>("partition_number");
57  }
58  TLOG_DEBUG(app_name + "Main") << "Setting partition number to " << artdaq::Globals::partition_number_;
59 
60  TLOG_INFO(app_name + "Main") << "artdaq version "
61  << artdaq::GetPackageBuildInfo::getPackageBuildInfo().getPackageVersion() << ", built "
62  << artdaq::GetPackageBuildInfo::getPackageBuildInfo().getBuildTimestamp();
63 
64  // create the BoardReaderApp
65  my_rank = mpiSentry->rank();
66  artdaq::BoardReaderApp br_app;
67 
68  auto commander = artdaq::MakeCommanderPlugin(config_ps, br_app);
69  TLOG_INFO(app_name + "Main") << "Running Commmander Server";
70  commander->run_server();
71  artdaq::Globals::CleanUpGlobals();
72  TLOG_INFO(app_name + "Main") << "Commandable Server ended, exiting...";
73 }
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:74