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