artdaq  v2_03_02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Config.hh
1 #ifndef proto_Config_hh
2 #define proto_Config_hh
3 
4 #include <iostream>
5 #include <string>
6 #include "fhiclcpp/fwd.h"
8 
9 // sources are first, sinks are second
10 // the offset_ is the index of the first sink
11 // the offset_ = sources_
12 
13 // Define the environment variable ARTDAQ_DAQRATE_USE_ART to any value
14 // to set use_artapp_ to true.
15 
16 namespace artdaq {
17 
21  class Config
22  {
23  public:
27  static const char* usage;
28 
32  enum TaskType : int
33  {
34  TaskSink = 0,
35  TaskSource = 1,
37  };
38 
48  Config(int rank, int nprocs, int buffer_count, size_t max_payload_size, int argc, char* argv[]);
49 
54  int destCount() const;
55 
60  int destStart() const;
61 
66  int srcCount() const;
67 
72  int srcStart() const;
73 
78  int getDestFriend() const;
79 
84  int getSrcFriend() const;
85 
92  int getArtArgc(int argc, char* argv[]) const;
93 
100  char** getArtArgv(int argc, char* argv[]) const;
101 
106  std::string typeName() const;
107 
111  void writeInfo() const;
112 
113  // input parameters
114  int rank_;
116 
118  int sources_;
119  int sinks_;
123 
125  int run_;
126 
129 
130  // calculated parameters
132  int offset_;
133  std::string node_name_;
134 
135  int art_argc_;
136  char** art_argv_;
137  bool use_artapp_;
138 
143  void print(std::ostream& ost) const;
144 
149  void printHeader(std::ostream& ost) const;
150 
155  fhicl::ParameterSet makeParameterSet() const;
156 
168  fhicl::ParameterSet getArtPset();
169 
175  static void throwUsage(char* argv0, const std::string& msg)
176  {
177  std::cerr << argv0 << " " << artdaq::Config::usage << "\n";
178  throw msg;
179  }
180 
187  static double getArgDetectors(int argc, char* argv[])
188  {
189  if (argc < 2) { throwUsage(argv[0], "no detectors_per_node argument"); }
190  return atof(argv[1]);
191  }
192 
199  static double getArgSinks(int argc, char* argv[])
200  {
201  if (argc < 3) { throwUsage(argv[0], "no sinks_per_node argument"); }
202  return atof(argv[2]);
203  }
204 
211  static int getArgQueueSize(int argc, char* argv[])
212  {
213  if (argc < 4) { throwUsage(argv[0], "no event_queue_size argument"); }
214  return atoi(argv[3]);
215  }
216 
223  static int getArgRun(int argc, char* argv[])
224  {
225  if (argc < 5) { throwUsage(argv[0], "no run argument"); }
226  return atoi(argv[4]);
227  }
228 
233  static std::string getProcessorName()
234  {
235  char buf[100];
236  int sz = sizeof(buf);
237  MPI_Get_processor_name(buf, &sz);
238  return std::string(buf);
239  }
240  };
241 
248  inline std::ostream& operator<<(std::ostream& ost, Config const& c)
249  {
250  c.print(ost);
251  return ost;
252  }
253 }
254 #endif /* proto_Config_hh */
size_t max_payload_size_
Maximum size of Fragments to create/transfer.
Definition: Config.hh:128
fhicl::ParameterSet getArtPset()
Get the ParameterSet to use to configure art.
Definition: Config.cc:181
TaskType
Type of the builder instance.
Definition: Config.hh:32
int source_start_
Rank of first source.
Definition: Config.hh:121
std::string node_name_
Name of this node, from MPI_Get_processor_name.
Definition: Config.hh:133
void print(std::ostream &ost) const
Dump configuration information (space delimited) to a stream.
Definition: Config.cc:132
int getSrcFriend() const
Get the corresponding source for this destination.
Definition: Config.cc:98
static const char * usage
String for command-line arguments.
Definition: Config.hh:27
int srcCount() const
Get the number of sources for this process.
Definition: Config.cc:75
int event_queue_size_
Size of the Event Queue.
Definition: Config.hh:124
int destCount() const
Get the number of destinations for this process.
Definition: Config.cc:63
TaskType type_
Type of this Builder application.
Definition: Config.hh:131
std::string typeName() const
Get the name of the type of this process.
Definition: Config.cc:87
int sources_
Count of source.
Definition: Config.hh:118
int sinks_
Count of sinks.
Definition: Config.hh:119
This Builder is a &quot;Detector&quot;.
Definition: Config.hh:36
std::ostream & operator<<(std::ostream &ost, Config const &c)
Stream a Config object to the given stream.
Definition: Config.hh:248
This Builder is a &quot;Source&quot;.
Definition: Config.hh:35
int getDestFriend() const
Get the corresponding destination for this source.
Definition: Config.cc:93
int srcStart() const
Get the rank of the first source for this process.
Definition: Config.cc:81
int total_procs_
Total number of processes.
Definition: Config.hh:115
int buffer_count_
Maximum number of simulatneous Fragments.
Definition: Config.hh:127
static int getArgRun(int argc, char *argv[])
Get the Run number from the command line.
Definition: Config.hh:223
int getArtArgc(int argc, char *argv[]) const
Gets the count of arguments after a – delimiter.
Definition: Config.cc:103
fhicl::ParameterSet makeParameterSet() const
Write a ParameterSet using configuration.
Definition: Config.cc:148
int rank_
Rank of this application.
Definition: Config.hh:114
bool use_artapp_
Whether to use art.
Definition: Config.hh:137
static double getArgSinks(int argc, char *argv[])
Get the sink count from the command line.
Definition: Config.hh:199
int detector_start_
Rank of first detector.
Definition: Config.hh:120
char ** art_argv_
Arguments used for art.
Definition: Config.hh:136
int sink_start_
Rank of first sink.
Definition: Config.hh:122
int offset_
Offset from the start rank for this type.
Definition: Config.hh:132
static void throwUsage(char *argv0, const std::string &msg)
Write the usage to cerr and throw an exception.
Definition: Config.hh:175
This Builder is a &quot;Sink&quot;.
Definition: Config.hh:34
Helper class for configuring the builder test.
Definition: Config.hh:21
static double getArgDetectors(int argc, char *argv[])
Get the detectors count from the command line.
Definition: Config.hh:187
char ** getArtArgv(int argc, char *argv[]) const
Get the array of arguments after a – delimiter.
Definition: Config.cc:114
void printHeader(std::ostream &ost) const
Write configuration parameter names to a stream.
Definition: Config.cc:119
static int getArgQueueSize(int argc, char *argv[])
Get the Queue Size from the command line.
Definition: Config.hh:211
int run_
Run Number.
Definition: Config.hh:125
int art_argc_
Count of arguments used for art.
Definition: Config.hh:135
void writeInfo() const
Write information about this Config class to a file.
Definition: Config.cc:55
static std::string getProcessorName()
Call MPI_Get_processor_name.
Definition: Config.hh:233
int detectors_
Count of detectors.
Definition: Config.hh:117
Config(int rank, int nprocs, int buffer_count, size_t max_payload_size, int argc, char *argv[])
Config Constructor.
Definition: Config.cc:26
int destStart() const
Get the rank of the first destination for this process.
Definition: Config.cc:69