8#ifndef NIDAS_CORE_NIDASAPP_H
9#define NIDAS_CORE_NIDASAPP_H
23namespace nidas {
namespace core {
27class SampleOutputBase;
60 if (i < (
int)args.size())
121 const std::string& syntax =
"",
122 const std::string&
usage =
"",
123 const std::string& default_ =
"",
124 bool required =
false);
163 addFlag(
const std::string& flag);
181 args.push_back(
this);
197 usage(
const std::string& indent =
" ",
bool brief =
false);
264 accept(
const std::string& flag);
627 if (right._width != 0)
822 nidas_app_arglist_t::const_iterator
it;
823 for (it = arglist.begin(); it != arglist.end(); ++
it)
825 (*it)->acceptShortFlag(!require);
857 startArgs(
int argc,
const char*
const argv[]);
939 parseArgs(
int argc,
const char*
const argv[]);
979 parseInputs(
const std::vector<std::string>& inputs,
980 std::string default_input =
"",
981 int default_port = 0);
1189 usage(
const std::string& indent,
bool brief);
1196 usage(
const std::string& indent =
" ");
1223 addSignal(
int signum,
void (*callback)(
int signum) = 0,
bool nolog=
false);
1310 std::list<std::string>&
1469 nidas::util::auto_ptr<nidas::util::SocketAddress>
_sockAddr;
1522 const std::vector<std::string>& args) :
1526 for (
unsigned int i = 0; i < args.size(); ++
i)
1542 return std::vector<std::string>(
vargv.begin()+optindex,
vargv.end());
1547 for (
int i = 0; i <
argc; ++
i)
A Dataset is a named collection of parameters, that are used in data processing.
Definition Datasets.h:48
Implementation of an IOChannel using an nidas::util::FileSet.
Definition FileSet.h:42
A NidasAppArg is command-line argument which can be handled by NidasApp.
Definition NidasApp.h:76
const std::string & getFlag()
Return the command-line flag which this argument consumed.
Definition NidasApp.cc:137
NidasAppArg(const std::string &flags, const std::string &syntax="", const std::string &usage="", const std::string &default_="", bool required=false)
Construct a NidasAppArg from a list of accepted short and long flags, the syntax for any arguments to...
Definition NidasApp.cc:78
NidasAppArg & operator=(const NidasAppArg &)
std::string _default
Definition NidasApp.h:296
std::string getUsageFlags()
Return the string of flags accepted by this NidasAppArg according to the acceptShortFlag() setting.
Definition NidasApp.cc:316
virtual ~NidasAppArg()
Definition NidasApp.cc:95
bool asBool()
An argument is true if it is a stand-alone flag and was specified in the arguments,...
Definition NidasApp.cc:165
void setUsageString(const std::string &text)
Definition NidasApp.h:267
bool accept(const std::string &flag)
Return true if the given command-line flag matches one of this argument's flags.
Definition NidasApp.cc:274
std::string _value
Definition NidasApp.h:298
std::string _flags
Definition NidasApp.h:293
void addFlag(const std::string &flag)
Add a flag which this argument should accept.
Definition NidasApp.cc:145
bool isRequired()
Return whether this argument is required.
Definition NidasApp.cc:109
std::string _usage
Definition NidasApp.h:295
const std::string & getValue()
If this argument has been parsed from a command line list (specified() returns true),...
Definition NidasApp.cc:125
int asInt()
Parse the argument value as an integer, where the value could be the default if no value has been exp...
Definition NidasApp.cc:187
float asFloat()
Same as asInt(), except parse the argument value as a float.
Definition NidasApp.cc:214
virtual bool parse(const ArgVector &argv, int *argi=0)
If argv[argi] matches this argument, then set the flag that was found and also the value if this argu...
Definition NidasApp.cc:242
std::string _syntax
Definition NidasApp.h:294
void setRequired(bool isRequired=true)
Set whether this argument is required.
Definition NidasApp.cc:101
std::string usage(const std::string &indent=" ", bool brief=false)
Render the usage string for this particular argument, taking into account which flags are enabled.
Definition NidasApp.cc:349
bool _enableShortFlag
Definition NidasApp.h:299
bool _required
Definition NidasApp.h:300
std::string getDefault()
Definition NidasApp.h:286
bool single()
Return true for arguments which are only a single argument.
Definition NidasApp.cc:266
void setDefault(const std::string &dvalue)
Definition NidasApp.h:280
std::string _arg
Definition NidasApp.h:297
bool specified()
Return true if this argument has been filled in from a command-line argument list,...
Definition NidasApp.cc:117
NidasAppArg(const NidasAppArg &)
void setFlags(const std::string &flags)
Completely replace the flags which this argument should accept.
Definition NidasApp.cc:157
void acceptShortFlag(bool enable)
Set whether short flags are enabled or not.
Definition NidasApp.h:153
The NidasApp class throws a NidasAppException when command-line options do not parse.
Definition NidasApp.h:34
NidasAppException(const std::string &what)
Definition NidasApp.h:36
NidasApp handles common options for NIDAS applications.
Definition NidasApp.h:576
NidasAppInputFilesArg InputFiles
Definition NidasApp.h:671
bool _deleteProject
Definition NidasApp.h:1485
SampleMatcher & sampleMatcher()
Use this method to access the SampleMatcher instance for this NidasApp.
Definition NidasApp.h:1300
bool _allowUnrecognized
Definition NidasApp.h:1495
bool briefHelp()
Return true if brief help requested, such as with -h.
Definition NidasApp.h:1239
std::string _appname
Definition NidasApp.h:1451
int _argi
Definition NidasApp.h:1490
bool _brief
Definition NidasApp.h:1475
std::string getName()
Definition NidasApp.h:711
static NidasApp * getApplicationInstance()
Return the current application instance.
Definition NidasApp.cc:658
nidas::util::UTime parseTime(const std::string &optarg)
Definition NidasApp.cc:764
nidas_app_arglist_t _app_arguments
Definition NidasApp.h:1487
void enableArguments(const nidas_app_arglist_t &arglist)
Add the list of NidasAppArg pointers to the set of arguments accepted by this NidasApp instance.
Definition NidasApp.cc:694
void parseUsername(const std::string &username)
Definition NidasApp.cc:1546
nidas::core::Dataset getDataset(const std::string &datasetname)
Derive a path to an XML datasets file according to the current environment settings,...
Definition NidasApp.cc:1582
void setProcessName(const std::string &argv0)
Set the name of this particular process, usually argv[0].
Definition NidasApp.cc:665
bool helpRequested()
Return true when a help option was parsed, meaning the usage info has been requested.
Definition NidasApp.h:1230
NidasApp(const std::string &name)
Construct a NidasApp instance and give it a name to be used for the usage info.
Definition NidasApp.cc:448
static void setInterrupted(bool interrupted)
Set the global interrupted state for NidasApp.
Definition NidasApp.cc:1163
std::string getHostName()
Return the hostname passed to the Hostname argument, if any, otherwise return the current hostname as...
Definition NidasApp.cc:1631
NidasAppArg FormatHexId
Definition NidasApp.h:668
std::string _username
Definition NidasApp.h:1477
NidasAppArg StartTime
Definition NidasApp.h:665
nidas::util::Exception getException()
Return the current exception.
Definition NidasApp.cc:1155
static NidasApp * application_instance
Definition NidasApp.h:1449
NidasAppArg ProcessData
Definition NidasApp.h:664
std::string getShortHostName()
Like getHostName(), but any '.
Definition NidasApp.cc:1658
bool allowUnrecognized()
Return whether unrecognized flags are allowed or not.
Definition NidasApp.cc:1372
void startArgs(const ArgVector &args)
Set the list of command-line argument strings to be parsed and handled by successive calls to nextArg...
Definition NidasApp.cc:788
ArgVector parseArgs(const ArgVector &args)
Parse all arguments accepted by this NidasApp in the command-line argument list args,...
Definition NidasApp.cc:966
NidasAppArg FormatSampleId
Definition NidasApp.h:669
int outputFileLength()
Return the output file length in seconds.
Definition NidasApp.h:1014
std::string getProcessName()
Get the process name, as set by setProcessName(), or else return the app name from getName().
Definition NidasApp.cc:672
void setException(const nidas::util::Exception &ex)
Like setInterrupted(true), but also allows an exception to be stored which can be tested and retrieve...
Definition NidasApp.cc:1137
NidasAppArg DebugDaemon
Definition NidasApp.h:675
NidasAppArg LogShow
Definition NidasApp.h:659
std::string getUserName()
Return the username passed to the Username argument, if enabled, otherwise return an empty string.
Definition NidasApp.h:1346
bool _processData
Definition NidasApp.h:1455
NidasAppArg * parseNext()
Parse the next recognized argument from the list set in startArgs().
Definition NidasApp.cc:824
void parseLogLevel(const std::string &optarg)
This is an alias for parseLogConfig(), since the LogConfig string syntax is backwards compatible with...
Definition NidasApp.h:957
std::string usage(const std::string &indent, bool brief)
Return a usage string describing the arguments accepted by this application, rendering each argument ...
Definition NidasApp.cc:1245
bool nextArg(std::string &arg)
If the next argument to be parsed does not start with '-', then copy it into arg and remove it from t...
Definition NidasApp.cc:809
void setupLogScheme()
Definition NidasApp.cc:603
int _outputFileLength
Definition NidasApp.h:1472
int logLevel()
Return LogScheme::logLevel() for the current log scheme.
Definition NidasApp.cc:1354
IdFormat getIdFormat()
Definition NidasApp.h:1251
void setupDaemon()
Call setupDaemon(daemon_mode), where daemon_mode is true only if DebugDaemon is false.
Definition NidasApp.cc:1420
bool hasException()
See setException().
Definition NidasApp.cc:1147
uid_t getUserID()
Return the userid of the username passed to the Username argument, otherwise 0.
Definition NidasApp.h:1356
NidasAppArg Help
Definition NidasApp.h:663
bool inputsProvided()
Definition NidasApp.h:986
NidasAppArg LogFields
Definition NidasApp.h:661
void setupProcess()
Setup a process with the user and group specified by the Username argument, and attempt to set relate...
Definition NidasApp.cc:1469
bool processData()
Return the current process-data setting for this NidasApp.
Definition NidasApp.h:1046
NidasAppArg OutputFiles
Definition NidasApp.h:672
std::string _argv0
Definition NidasApp.h:1453
void parseInputs(const std::vector< std::string > &inputs, std::string default_input="", int default_port=0)
Parse one or more input URLs from a list of non-option command-line arguments.
Definition NidasApp.cc:980
std::string _hostname
Definition NidasApp.h:1479
void requireLongFlag(const nidas_app_arglist_t &arglist, bool require=true)
Call acceptShortFlag(false) on the given list of NidasApp instances, meaning only the long flag will ...
Definition NidasApp.h:820
uid_t _userid
Definition NidasApp.h:1481
void parseOutput(const std::string &optarg)
Parse an output specifier in the form <strptime-filename-pattern>[<length>[smh]].
Definition NidasApp.cc:1048
bool _help
Definition NidasApp.h:1474
nidas::util::Exception _exception
Definition NidasApp.h:1493
NidasAppArg Hostname
Definition NidasApp.h:674
gid_t _groupid
Definition NidasApp.h:1483
nidas::util::UTime getEndTime()
Return the EndTime as a UTime.
Definition NidasApp.h:1110
void setupDaemonLogging()
Call setupDaemonLogging(daemon_mode), where daemon_mode is true only if DebugDaemon is false.
Definition NidasApp.cc:1389
std::string outputFileName()
Return just the output file pattern specified by an output option, without the file length specifier.
Definition NidasApp.h:1005
nidas::util::UTime _startTime
Definition NidasApp.h:1463
NidasAppArg Clipping
Definition NidasApp.h:678
void setProcessData(bool process)
Set the process-data setting in this NidasApp.
Definition NidasApp.h:1037
int checkPidFile()
Create a pid file for this process and return 0.
Definition NidasApp.cc:1667
NidasAppArg ConfigsArg
Definition NidasApp.h:676
NidasAppArg XmlHeaderFile
Definition NidasApp.h:658
NidasAppArg PidFile
It is not enough to enable this arg in an app, the app must must call checkPidFile() as well.
Definition NidasApp.h:685
std::list< std::string > & dataFileNames()
Return the list of filenames parsed from the input URLs with parseInputs().
Definition NidasApp.h:1311
Project * getProject()
Return a pointer to the application-wide Project instance.
Definition NidasApp.cc:1262
ArgVector _argv
Definition NidasApp.h:1489
nidas::util::auto_ptr< nidas::util::SocketAddress > _sockAddr
Definition NidasApp.h:1469
NidasAppArg LogConfig
Definition NidasApp.h:660
NidasAppArg SampleRanges
Definition NidasApp.h:667
nidas::util::UTime _endTime
Definition NidasApp.h:1465
void setApplicationInstance()
An instance of NidasApp can be set as an application-wide instance, like an application context,...
Definition NidasApp.cc:650
nidas_app_arglist_t loggingArgs()
This is a convenience method to return all of the logging-related options in a list,...
Definition NidasApp.cc:1212
void setIdFormat(IdFormat idt)
Store the format in which sample IDs should be shown.
Definition NidasApp.cc:1295
NidasAppArg Version
Definition NidasApp.h:670
void setFileSetTimes(const nidas::util::UTime &start, const nidas::util::UTime &end, nidas::core::FileSet *fset)
Definition NidasApp.cc:1731
NidasAppArg LogParam
Definition NidasApp.h:662
void requireArguments(const nidas_app_arglist_t &arglist)
Add arguments to this NidasApp same as enableArguments() but also set them as required.
Definition NidasApp.cc:702
std::string _xmlFileName
Definition NidasApp.h:1457
NidasAppArg Username
Definition NidasApp.h:673
void parseLogConfig(const std::string &optarg)
Parse a LogConfig from the given argument using the LogConfig string syntax, and add that LogConfig t...
Definition NidasApp.cc:742
NidasAppArg SorterLength
Definition NidasApp.h:679
std::string getConfigsXML()
Derive the path to the XML file which lists project configs.
Definition NidasApp.cc:411
ArgVector unparsedArgs()
Definition NidasApp.cc:780
static std::ostream & formatSampleId(std::ostream &out, IdFormat idfmt, dsm_sample_id_t sid)
Write the sensor-plus-sample ID part of sid to stream out using the format specified in idfmt.
Definition NidasApp.cc:1303
std::list< std::string > _dataFileNames
Definition NidasApp.h:1467
void setOutputClipping(const nidas::util::UTime &start, const nidas::util::UTime &end, nidas::core::SampleOutputBase *output)
If Clipping has been enabled, call setTimeClippingWindow() on the given output using start and end.
Definition NidasApp.cc:1714
std::string _outputFileName
Definition NidasApp.h:1471
void lockMemory()
Attempt mlockall() for this process, first adding the CAP_IPC_LOCK capability if possible.
Definition NidasApp.cc:1445
std::string formatId(dsm_sample_id_t sid)
A more convenient form of formatSampleId() which just returns a string, and also includes the DSM id ...
Definition NidasApp.cc:1343
nidas::util::LogScheme _logscheme
NidasApp keeps track of the LogScheme built up from arguments.
Definition NidasApp.h:1498
nidas::util::UTime getStartTime()
Return the StartTime as a UTime.
Definition NidasApp.h:1097
NidasAppArg DatasetName
Definition NidasApp.h:677
IdFormat _idFormat
Definition NidasApp.h:1459
NidasAppArg EndTime
Definition NidasApp.h:666
~NidasApp()
If this instance is the current application instance, then the application instance is reset to null ...
Definition NidasApp.cc:626
id_format_t
The four possible output formats for sensor-plus-sample IDs:
Definition NidasApp.h:590
@ OCTAL_ID
Definition NidasApp.h:591
@ AUTO_ID
Definition NidasApp.h:591
@ HEX_ID
Definition NidasApp.h:591
@ DECIMAL_ID
Definition NidasApp.h:591
@ NOFORMAT_ID
Definition NidasApp.h:591
bool _hasException
Definition NidasApp.h:1492
std::string xmlHeaderFile()
Definition NidasApp.h:1052
nidas::util::SocketAddress * socketAddress()
If parseInputs() parsed a network socket specifier, then this method returns a pointer to the corresp...
Definition NidasApp.h:1322
float getSorterLength(float min, float max)
Return sorter length value, or throw std::invalid_argument.
Definition NidasApp.cc:1700
static void addSignal(int signum, void(*callback)(int signum)=0, bool nolog=false)
Add the given signal signum to the list of signals handled by the NidasApp signal handler,...
Definition NidasApp.cc:1183
uid_t getGroupID()
Return the groupid of the username passed to the Username argument, otherwise 0.
Definition NidasApp.h:1366
nidas_app_arglist_t getArguments()
Return the list of arguments which are supported by this NidasApp, in other words,...
Definition NidasApp.cc:734
void resetLogging()
Reset logging to the NidasApp default.
Definition NidasApp.cc:1380
SampleMatcher _sampleMatcher
Definition NidasApp.h:1461
void checkRequiredArguments()
Verify that all NidasAppArg arguments required by this NidasApp have been specified,...
Definition NidasApp.cc:715
Match samples according to DSM and Sample ID ranges, and configure the ranges with criteria in text f...
Definition SampleMatcher.h:21
Implementation of portions of SampleOutput.
Definition SampleOutput.h:160
Definition Exception.h:35
virtual const char * what() const
Definition Exception.h:98
Exception(const std::string &type, const std::string &n, const std::string &m)
Definition Exception.h:41
A LogScheme is a vector of LogConfig's and the vector of fields to show in log messages.
Definition Logger.h:680
An interface for a socket address.
Definition SocketAddress.h:36
A class for parsing, formatting and doing operations on time, based on Unix time conventions,...
Definition UTime.h:95
void setupSignals()
Definition dmd_mmat_test.cc:286
Sample * getSample(sampleType type, unsigned int len)
A convienence method for getting a sample of an enumerated type from a pool.
Definition Sample.cc:70
std::vector< NidasAppArg * > nidas_app_arglist_t
Lists of arguments can be manipulated together by putting them into this container type.
Definition NidasApp.h:49
nidas_app_arglist_t operator|(nidas_app_arglist_t arglist1, nidas_app_arglist_t arglist2)
Combine two arglists into a single arglist without any duplicates.
Definition NidasApp.cc:1221
std::vector< std::string > ArgVector
Convenience typedef for handling the command-line argv as a vector of strings.
Definition NidasApp.h:55
std::string expectArg(const ArgVector &args, int i)
Definition NidasApp.h:58
unsigned int dsm_sample_id_t
Definition Sample.h:64
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31
static bool interrupted
Definition nidas_udp_relay.cc:76
static n_u::SerialPort port
Definition sing.cc:68
Convert vector<string> args to dynamically allocated (argc, argv) pair which will be freed when the i...
Definition NidasApp.h:1520
char ** argv
Definition NidasApp.h:1554
ArgVector unparsedArgs(int optindex)
Given the opt index after getopt() finishes, return a vector of any remaining arguments,...
Definition NidasApp.h:1540
int argc
Definition NidasApp.h:1555
~NidasAppArgv()
Definition NidasApp.h:1545
std::vector< char * > vargv
Definition NidasApp.h:1553
NidasAppArgv(const std::string &argv0, const std::vector< std::string > &args)
Definition NidasApp.h:1521
NidasAppArgv(const NidasAppArgv &)
NidasAppArgv & operator=(const NidasAppArgv &)