mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-16 01:51:45 +00:00
- FairMQ options:
a) move the XML parser into the FairMQ/options/FairMQParser.h b) add a routine in FairMQProgOption to check whether the necessary XML or JSON input files are there, and send an error message if not there - Policy based devices: a) rename GenericSampler to base_GenericSampler and use an alias template named GenericSampler b) in base_GenericSampler, rename template parameter to simple variables <T,U,… > and use typedef for clarity c) introduce an anonymous function container in the base_GenericSampler host class with a register task template member function and an Executetasks() d) add two new template parameters in base_GenericSampler for the anonymous function container map. parameter is K for the key type (default=int) and L for the value type (default=std::function<void()>) - Tutorial7: a) use FairMQProgOption to configure devices in tutorial7 b) introduce several template functions helper in tutorial7 to reduce code redundancy c) show examples in tutorial7 of task registration with callback and lambda expression for the sampler devices d) separate the executable build of the tutorial7 data generator to remove the Roofit banner when executing the MQdevices
This commit is contained in:
committed by
Mohammad Al-Turany
parent
6ed9cc3da1
commit
d1bba61939
@@ -14,7 +14,7 @@
|
||||
|
||||
#include "FairMQParser.h"
|
||||
#include "FairMQLogger.h"
|
||||
|
||||
#include <boost/property_tree/xml_parser.hpp>
|
||||
// WARNING : pragma commands to hide boost (1.54.0) warning
|
||||
// TODO : remove these pragma commands when boost will fix this issue in future release
|
||||
#pragma clang diagnostic push
|
||||
@@ -188,4 +188,22 @@ FairMQMap JSON::UserParser(std::stringstream& input, const std::string& deviceId
|
||||
return ptreeToMQMap(pt, deviceId, rootNode,"json");
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
FairMQMap XML::UserParser(const std::string& filename, const std::string& deviceId, const std::string& rootNode)
|
||||
{
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::read_xml(filename, pt);
|
||||
return ptreeToMQMap(pt,deviceId,rootNode,"xml");
|
||||
}
|
||||
|
||||
FairMQMap XML::UserParser(std::stringstream& input, const std::string& deviceId, const std::string& rootNode)
|
||||
{
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::read_xml(input, pt);
|
||||
return ptreeToMQMap(pt,deviceId,rootNode,"xml");
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // end FairMQParser namespace
|
@@ -32,6 +32,12 @@ struct JSON
|
||||
FairMQMap UserParser(std::stringstream& input, const std::string& deviceId, const std::string& rootNode = "fairMQOptions");
|
||||
};
|
||||
|
||||
struct XML
|
||||
{
|
||||
FairMQMap UserParser(const std::string& filename, const std::string& deviceId, const std::string& root_node="fairMQOptions");
|
||||
FairMQMap UserParser(std::stringstream& input, const std::string& deviceId, const std::string& rootNode="fairMQOptions");
|
||||
};
|
||||
|
||||
} // FairMQParser namespace
|
||||
#endif /* FAIRMQPARSER_H */
|
||||
|
||||
|
@@ -19,10 +19,11 @@
|
||||
FairMQProgOptions::FairMQProgOptions()
|
||||
: FairProgOptions()
|
||||
, fMQParserOptions("MQ-Device parser options")
|
||||
, fMQOptionsInCmd("MQ-Device options")
|
||||
, fMQOptionsInCfg("MQ-Device options")
|
||||
, fMQtree()
|
||||
, fFairMQmap()
|
||||
{
|
||||
InitOptionDescription();
|
||||
}
|
||||
|
||||
FairMQProgOptions::~FairMQProgOptions()
|
||||
@@ -30,53 +31,62 @@ FairMQProgOptions::~FairMQProgOptions()
|
||||
}
|
||||
|
||||
int FairMQProgOptions::ParseAll(const int argc, char** argv, bool AllowUnregistered)
|
||||
{
|
||||
// before parsing, define cmdline and optionally cfgfile description,
|
||||
// and also what is visible for the user
|
||||
AddToCmdLineOptions(fGenericDesc);
|
||||
AddToCmdLineOptions(fMQParserOptions);
|
||||
|
||||
// if config file option enabled then id non required in cmdline but required in configfile
|
||||
// else required in cmdline
|
||||
if (fUseConfigFile)
|
||||
{
|
||||
fCmdline_options.add_options()
|
||||
("id", po::value< std::string >(), "Device ID");
|
||||
fConfig_file_options.add_options()
|
||||
("id", po::value< std::string >()->required(), "Device ID");
|
||||
}
|
||||
else
|
||||
{
|
||||
fCmdline_options.add_options()
|
||||
("id", po::value< std::string >()->required(), "Device ID");
|
||||
}
|
||||
|
||||
fVisible_options.add_options()
|
||||
("id", po::value< std::string >()->required(), "Device ID (required value)");
|
||||
|
||||
// parse command line
|
||||
{
|
||||
// init description
|
||||
InitOptionDescription();
|
||||
// parse command line options
|
||||
if (ParseCmdLine(argc,argv,fCmdline_options,fvarmap,AllowUnregistered))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
// if txt/INI configuration file enabled then parse it
|
||||
if (fUseConfigFile && !fConfigFile.empty())
|
||||
// if txt/INI configuration file enabled then parse it as well
|
||||
if (fUseConfigFile)
|
||||
{
|
||||
AddToCfgFileOptions(fMQParserOptions,false);
|
||||
|
||||
if (ParseCfgFile(fConfigFile, fConfig_file_options, fvarmap, AllowUnregistered))
|
||||
// check if file exist
|
||||
if (fs::exists(fConfigFile))
|
||||
{
|
||||
if (ParseCfgFile(fConfigFile.string(), fConfig_file_options, fvarmap, AllowUnregistered))
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(ERROR)<<"config file '"<< fConfigFile <<"' not found";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// set log level before printing (default is 0 = DEBUG level)
|
||||
int verbose=GetValue<int>("verbose");
|
||||
SET_LOGGER_LEVEL(verbose);
|
||||
|
||||
PrintOptions();
|
||||
|
||||
|
||||
// check if one of required MQ config option is there
|
||||
auto parserOption_shptr = fMQParserOptions.options();
|
||||
bool option_exists=false;
|
||||
std::vector<std::string> MQParserKeys;
|
||||
for(const auto& p : parserOption_shptr)
|
||||
{
|
||||
MQParserKeys.push_back( p->canonical_display_name() );
|
||||
if( fvarmap.count( p->canonical_display_name() ) )
|
||||
{
|
||||
option_exists=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!option_exists)
|
||||
{
|
||||
LOG(ERROR)<<"Required option to configure the MQ device is not there.";
|
||||
LOG(ERROR)<<"Please provide the value of one of the following key:";
|
||||
for(const auto& p : MQParserKeys)
|
||||
{
|
||||
LOG(ERROR)<<p;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -84,13 +94,13 @@ int FairMQProgOptions::NotifySwitchOption()
|
||||
{
|
||||
if ( fvarmap.count("help") )
|
||||
{
|
||||
std::cout << "***** FAIRMQ Program Options ***** \n" << fVisible_options;
|
||||
LOG(INFO) << "***** FAIRMQ Program Options ***** \n" << fVisible_options;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (fvarmap.count("version"))
|
||||
{
|
||||
std::cout << "Beta version 0.1\n";
|
||||
LOG(INFO) << "Beta version 0.1\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -100,13 +110,39 @@ int FairMQProgOptions::NotifySwitchOption()
|
||||
|
||||
void FairMQProgOptions::InitOptionDescription()
|
||||
{
|
||||
fMQParserOptions.add_options()
|
||||
("config-xml-string", po::value< std::vector<std::string> >()->multitoken(), "XML input as command line string.")
|
||||
("config-xml-file", po::value< std::string >(), "XML input as file.")
|
||||
("config-json-string", po::value< std::vector<std::string> >()->multitoken(), "JSON input as command line string.")
|
||||
("config-json-file", po::value< std::string >(), "JSON input as file.")
|
||||
// Id required in command line if config txt file not enabled
|
||||
if (fUseConfigFile)
|
||||
{
|
||||
fMQOptionsInCmd.add_options()
|
||||
("id", po::value< std::string >(), "Device ID (required argument)")
|
||||
("io-threads", po::value<int>()->default_value(1), "io threads number");
|
||||
|
||||
// ("ini.config.string", po::value< std::vector<std::string> >()->multitoken(), "INI input as command line string.")
|
||||
// ("ini.config.file", po::value< std::string >(), "INI input as file.")
|
||||
;
|
||||
fMQOptionsInCfg.add_options()
|
||||
("id", po::value< std::string >()->required(), "Device ID (required argument)")
|
||||
("io-threads", po::value<int>()->default_value(1), "io threads number");
|
||||
}
|
||||
else
|
||||
{
|
||||
fMQOptionsInCmd.add_options()
|
||||
("id", po::value< std::string >()->required(), "Device ID (required argument)")
|
||||
("io-threads", po::value<int>()->default_value(1), "io threads number");
|
||||
}
|
||||
|
||||
fMQParserOptions.add_options()
|
||||
("config-xml-string", po::value< std::vector<std::string> >()->multitoken(), "XML input as command line string.")
|
||||
("config-xml-file", po::value< std::string >(), "XML input as file.")
|
||||
("config-json-string", po::value< std::vector<std::string> >()->multitoken(), "JSON input as command line string.")
|
||||
("config-json-file", po::value< std::string >(), "JSON input as file.");
|
||||
|
||||
|
||||
AddToCmdLineOptions(fGenericDesc);
|
||||
AddToCmdLineOptions(fMQOptionsInCmd);
|
||||
AddToCmdLineOptions(fMQParserOptions);
|
||||
|
||||
if (fUseConfigFile)
|
||||
{
|
||||
AddToCfgFileOptions(fMQOptionsInCfg,false);
|
||||
AddToCfgFileOptions(fMQParserOptions,false);
|
||||
}
|
||||
|
||||
}
|
@@ -74,6 +74,8 @@ public:
|
||||
|
||||
protected:
|
||||
po::options_description fMQParserOptions;
|
||||
po::options_description fMQOptionsInCfg;
|
||||
po::options_description fMQOptionsInCmd;
|
||||
pt::ptree fMQtree;
|
||||
FairMQMap fFairMQmap;
|
||||
|
||||
|
@@ -64,6 +64,10 @@ int FairProgOptions::AddToCmdLineOptions(const po::options_description& optdesc,
|
||||
|
||||
int FairProgOptions::AddToCfgFileOptions(const po::options_description& optdesc, bool visible)
|
||||
{
|
||||
//if UseConfigFile() not yet called, then enable it with required file name to be provided by command line
|
||||
if(!fUseConfigFile)
|
||||
UseConfigFile();
|
||||
|
||||
fConfig_file_options.add(optdesc);
|
||||
if(visible)
|
||||
fVisible_options.add(optdesc);
|
||||
@@ -82,8 +86,9 @@ void FairProgOptions::UseConfigFile(const std::string& filename)
|
||||
fUseConfigFile = true;
|
||||
if (filename.empty())
|
||||
{
|
||||
fCmdline_options.add_options()
|
||||
("config,c", po::value<std::string>(&fConfigFile)->required(), "Path to configuration file");
|
||||
fConfigDesc.add_options()
|
||||
("config,c", po::value<boost::filesystem::path>(&fConfigFile)->required(), "Path to configuration file (required argument)");
|
||||
AddToCmdLineOptions(fConfigDesc);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -464,6 +469,7 @@ FairProgOptions::VarValInfo_t FairProgOptions::Get_variable_value_info(const po:
|
||||
if(auto q = boost::any_cast<boost::filesystem::path>(&value))
|
||||
{
|
||||
std::string val_str = (*q).string();
|
||||
//std::string val_str = (*q).filename().generic_string();
|
||||
return std::make_tuple(val_str,std::string(" [Type=boost::filesystem::path]"),defaulted_val,empty_val);
|
||||
}
|
||||
|
||||
|
@@ -62,6 +62,7 @@ std::ostream& operator<<(std::ostream& os, const std::vector<T>& v)
|
||||
}
|
||||
|
||||
namespace po = boost::program_options;
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
class FairProgOptions
|
||||
{
|
||||
@@ -87,12 +88,6 @@ public:
|
||||
{
|
||||
val = fvarmap[key].as<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(ERROR) << "Key '"<< key <<"' not found in boost variable map";
|
||||
LOG(INFO) << "Command line / txt config file options are the following : ";
|
||||
this->PrintHelp();
|
||||
}
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
@@ -144,7 +139,7 @@ protected:
|
||||
|
||||
int fVerboseLvl;
|
||||
bool fUseConfigFile;
|
||||
std::string fConfigFile;
|
||||
boost::filesystem::path fConfigFile;
|
||||
virtual int NotifySwitchOption();
|
||||
|
||||
// UpadateVarMap() and replace() --> helper functions to modify the value of variable map after calling po::store
|
||||
|
@@ -13,29 +13,6 @@
|
||||
namespace FairMQParser
|
||||
{
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//----------- filename version
|
||||
FairMQMap XML::UserParser(const std::string& filename, const std::string& device_id, const std::string& root_node)
|
||||
{
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::read_xml(filename, pt);
|
||||
return ptreeToMQMap(pt,device_id,root_node,"xml");
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----------- stringstream version
|
||||
FairMQMap XML::UserParser(std::stringstream& input_ss, const std::string& device_id, const std::string& root_node)
|
||||
{
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::read_xml(input_ss, pt);
|
||||
return ptreeToMQMap(pt,device_id,root_node,"xml");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// other xml examples
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
boost::property_tree::ptree MQXML2::UserParser(const std::string& filename)
|
||||
|
@@ -27,15 +27,7 @@ namespace FairMQParser
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////// XML ////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// xml example 1
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
struct XML
|
||||
{
|
||||
FairMQMap UserParser(const std::string& filename, const std::string& device_id, const std::string& root_node="fairMQOptions");
|
||||
FairMQMap UserParser(std::stringstream& input_ss, const std::string& device_id, const std::string& root_node="fairMQOptions");
|
||||
};
|
||||
|
||||
|
||||
// xml example 2
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
struct MQXML2
|
||||
|
Reference in New Issue
Block a user