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