2 #include "artdaq/DAQrate/infoFilename.hh"
3 #include "artdaq-core/Data/Fragment.hh"
4 #include "fhiclcpp/ParameterSet.h"
5 #include "fhiclcpp/make_ParameterSet.h"
13 #include <sys/types.h>
16 #include <boost/program_options.hpp>
17 namespace bpo = boost::program_options;
26 artdaq::Config::Config(
int rank,
int total_procs,
int buffer_count,
size_t max_payload_size,
int argc,
char* argv[]):
28 , total_procs_(total_procs)
29 , detectors_(getArgDetectors(argc, argv))
30 , sources_(detectors_)
31 , sinks_(getArgSinks(argc, argv))
33 , source_start_(detectors_)
34 , sink_start_(detectors_ + sources_)
35 , event_queue_size_(getArgQueueSize(argc, argv))
36 , run_(getArgRun(argc, argv))
37 , buffer_count_(buffer_count)
38 , max_payload_size_(max_payload_size)
39 , type_((rank_ < detectors_) ? TaskDetector : ((rank_ < (detectors_ + sources_)) ? TaskSource : TaskSink))
40 , offset_(rank_ - ((type_ == TaskDetector) ? detector_start_ : (type_ == TaskSource) ? source_start_ : sink_start_))
41 , node_name_(getProcessorName())
42 , art_argc_(getArtArgc(argc, argv))
43 , art_argv_(getArtArgv(argc - art_argc_, argv))
44 , use_artapp_(getenv(
"ARTDAQ_DAQRATE_USE_ART") != 0)
50 <<
"total_workers " << total_workers <<
"\n";
51 throw "total_procs != total_workers";
58 std::ofstream ostr(fname.c_str());
60 ostr << *
this <<
"\n";
65 if (type_ == TaskSink) {
throw "No destCount for a sink"; }
66 return type_ == TaskDetector ? sources_ : sinks_;
71 if (type_ == TaskSink) {
throw "No destStart for a sink"; }
72 return type_ == TaskDetector ? source_start_ : sink_start_;
77 if (type_ == TaskDetector) {
throw "No srcCount for a detector"; }
78 return type_ == TaskSink ? sources_ : detectors_;
83 if (type_ == TaskDetector) {
throw "No srcStart for a detector"; }
84 return type_ == TaskSink ? source_start_ : detector_start_;
89 static const char* names[] = {
"Sink",
"Source",
"Detector"};
95 return offset_ + destStart();
100 return offset_ + srcStart();
107 for (; pos < argc; ++pos)
109 if (strcmp(argv[pos],
"--") == 0) {
break; }
121 ost <<
"Rank TotalNodes "
122 <<
"DetectorsPerNode SourcesPerNode SinksPerNode "
123 <<
"BuilderNodes DetectorNodes Sources Sinks Detectors "
124 <<
"DetectorStart SourceStart SinkStart "
138 << detector_start_ <<
" "
139 << source_start_ <<
" "
140 << sink_start_ <<
" "
141 << event_queue_size_ <<
" "
150 std::stringstream ss;
151 if (type_ != TaskDetector)
154 int count = type_ == TaskSource ? detectors_ : sources_;
155 int start = type_ == TaskSource ? detector_start_ : source_start_;
156 for (
int ii = 0; ii < count; ++ii)
158 ss <<
"s" << ii + start <<
": { transferPluginType: MPI source_rank: " << ii + start <<
" max_fragment_size_words: " << max_payload_size_ <<
" buffer_count: " << buffer_count_ <<
"}";
163 if (type_ != TaskSink)
165 ss <<
" destinations: {";
166 int count = type_ == TaskDetector ? sources_ : sinks_;
167 int start = type_ == TaskDetector ? source_start_ : sink_start_;
168 for (
int ii = 0; ii < count; ++ii)
170 ss <<
"d" << ii + start <<
": { transferPluginType: MPI destination_rank: " << ii + start <<
" max_fragment_size_words: " << max_payload_size_ <<
" buffer_count: " << buffer_count_ <<
"}";
176 fhicl::ParameterSet ps;
177 fhicl::make_ParameterSet(ss.str(), ps);
183 std::ostringstream descstr;
184 descstr <<
"-- <-c <config-file>>";
185 bpo::options_description desc(descstr.str());
187 (
"config,c", bpo::value<std::string>(),
"Configuration file.");
188 bpo::variables_map vm;
191 bpo::store(bpo::command_line_parser(art_argc_, art_argv_).
192 options(desc).allow_unregistered().run(), vm);
195 catch (bpo::error
const& e)
197 std::cerr <<
"Exception from command line processing in Config::getArtPset: " << e.what() <<
"\n";
198 throw "cmdline parsing error.";
200 if (!vm.count(
"config"))
202 std::cerr <<
"Expected \"-- -c <config-file>\" fhicl file specification.\n";
203 throw "cmdline parsing error.";
205 fhicl::ParameterSet pset;
206 cet::filepath_lookup lookup_policy(
"FHICL_FILE_PATH");
207 fhicl::make_ParameterSet(vm[
"config"].as<std::string>(), lookup_policy, pset);
208 auto ps = pset.get<fhicl::ParameterSet>(
"daq");
209 buffer_count_ = ps.get<
int>(
"buffer_count", buffer_count_);
210 max_payload_size_ = ps.get<
size_t>(
"max_fragment_size_words", max_payload_size_);
fhicl::ParameterSet getArtPset()
Get the ParameterSet to use to configure art.
void print(std::ostream &ost) const
Dump configuration information (space delimited) to a stream.
int getSrcFriend() const
Get the corresponding source for this destination.
static const char * usage
String for command-line arguments.
int srcCount() const
Get the number of sources for this process.
int destCount() const
Get the number of destinations for this process.
std::string typeName() const
Get the name of the type of this process.
int sources_
Count of source.
int sinks_
Count of sinks.
int getDestFriend() const
Get the corresponding destination for this source.
int srcStart() const
Get the rank of the first source for this process.
int total_procs_
Total number of processes.
int getArtArgc(int argc, char *argv[]) const
Gets the count of arguments after a – delimiter.
fhicl::ParameterSet makeParameterSet() const
Write a ParameterSet using configuration.
char ** getArtArgv(int argc, char *argv[]) const
Get the array of arguments after a – delimiter.
void printHeader(std::ostream &ost) const
Write configuration parameter names to a stream.
void writeInfo() const
Write information about this Config class to a file.
int detectors_
Count of detectors.
Config(int rank, int nprocs, int buffer_count, size_t max_payload_size, int argc, char *argv[])
Config Constructor.
int destStart() const
Get the rank of the first destination for this process.
std::string infoFilename(std::string const &prefix, int rank, int run)
Generate a filename using the given parameters.