mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
merge MQ parameters in the variable_map container of FairMQProgramOptions class
This commit is contained in:
@@ -22,17 +22,21 @@ FairMQProgOptions::FairMQProgOptions()
|
||||
, fMQParserOptions("MQ-Device parser options")
|
||||
, fMQOptionsInCfg("MQ-Device options")
|
||||
, fMQOptionsInCmd("MQ-Device options")
|
||||
, fMQtree()
|
||||
, fFairMQMap()
|
||||
, fHelpTitle("***** FAIRMQ Program Options ***** ")
|
||||
, fVersion("Beta version 0.1")
|
||||
, fMQKeyMap()
|
||||
{
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
FairMQProgOptions::~FairMQProgOptions()
|
||||
{
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
void FairMQProgOptions::ParseAll(const int argc, char** argv, bool allowUnregistered)
|
||||
{
|
||||
|
||||
@@ -175,6 +179,83 @@ void FairMQProgOptions::ParseAll(const int argc, char** argv, bool allowUnregist
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
int FairMQProgOptions::Store(const FairMQMap& channels)
|
||||
{
|
||||
fFairMQMap = channels;
|
||||
UpdateMQValues();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
// replace FairMQChannelMap, and update variable map accordingly
|
||||
int FairMQProgOptions::UpdateChannelMap(const FairMQMap& channels)
|
||||
{
|
||||
fFairMQMap=channels;
|
||||
UpdateMQValues();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
// read FairMQChannelMap and insert/update corresponding values in variable map
|
||||
// create key for variable map as follow : channelName.index.memberName
|
||||
void FairMQProgOptions::UpdateMQValues()
|
||||
{
|
||||
|
||||
for(const auto& p : fFairMQMap)
|
||||
{
|
||||
int index = 0;
|
||||
for(const auto& channel : p.second)
|
||||
{
|
||||
std::string typeKey = p.first + "." + std::to_string(index) + ".type";
|
||||
std::string methodKey = p.first + "." + std::to_string(index) + ".method";
|
||||
std::string addressKey = p.first + "." + std::to_string(index) + ".address";
|
||||
std::string propertyKey = p.first + "." + std::to_string(index) + ".property";
|
||||
std::string sndBufSizeKey = p.first + "." + std::to_string(index) + ".sndBufSize";
|
||||
std::string rcvBufSizeKey = p.first + "." + std::to_string(index) + ".rcvBufSize";
|
||||
std::string rateLoggingKey = p.first + "." + std::to_string(index) + ".rateLogging";
|
||||
|
||||
fMQKeyMap[typeKey] = std::make_tuple(p.first,index,"type");
|
||||
fMQKeyMap[methodKey] = std::make_tuple(p.first,index,"method");
|
||||
fMQKeyMap[addressKey] = std::make_tuple(p.first,index,"address");
|
||||
fMQKeyMap[propertyKey] = std::make_tuple(p.first,index,"property");
|
||||
fMQKeyMap[sndBufSizeKey] = std::make_tuple(p.first,index,"sndBufSize");
|
||||
fMQKeyMap[rcvBufSizeKey] = std::make_tuple(p.first,index,"rcvBufSize");
|
||||
fMQKeyMap[rateLoggingKey] = std::make_tuple(p.first,index,"rateLogging");
|
||||
|
||||
UpdateVarMap<std::string>(typeKey,channel.GetType());
|
||||
UpdateVarMap<std::string>(methodKey,channel.GetMethod());
|
||||
UpdateVarMap<std::string>(addressKey,channel.GetAddress());
|
||||
UpdateVarMap<std::string>(propertyKey,channel.GetProperty());
|
||||
UpdateVarMap<int>(sndBufSizeKey,channel.GetSndBufSize());
|
||||
UpdateVarMap<int>(rcvBufSizeKey,channel.GetRcvBufSize());
|
||||
UpdateVarMap<int>(rateLoggingKey,channel.GetRateLogging());
|
||||
|
||||
/*
|
||||
LOG(DEBUG) << "Update MQ parameters of variable map";
|
||||
LOG(DEBUG) << "key = " << typeKey <<"\t value = " << GetValue<std::string>(typeKey);
|
||||
LOG(DEBUG) << "key = " << methodKey <<"\t value = " << GetValue<std::string>(methodKey);
|
||||
LOG(DEBUG) << "key = " << addressKey <<"\t value = " << GetValue<std::string>(addressKey);
|
||||
LOG(DEBUG) << "key = " << propertyKey <<"\t value = " << GetValue<std::string>(propertyKey);
|
||||
LOG(DEBUG) << "key = " << sndBufSizeKey << "\t value = " << GetValue<int>(sndBufSizeKey);
|
||||
LOG(DEBUG) << "key = " << rcvBufSizeKey <<"\t value = " << GetValue<int>(rcvBufSizeKey);
|
||||
LOG(DEBUG) << "key = " << rateLoggingKey <<"\t value = " << GetValue<int>(rateLoggingKey);
|
||||
*/
|
||||
index++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
int FairMQProgOptions::NotifySwitchOption()
|
||||
{
|
||||
if (fVarMap.count("help"))
|
||||
@@ -192,6 +273,8 @@ int FairMQProgOptions::NotifySwitchOption()
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
void FairMQProgOptions::InitOptionDescription()
|
||||
{
|
||||
// Id required in command line if config txt file not enabled
|
||||
@@ -248,3 +331,72 @@ void FairMQProgOptions::InitOptionDescription()
|
||||
AddToCfgFileOptions(fMQParserOptions, false);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
int FairMQProgOptions::UpdateChannelMap(const std::string& channelName, int index, const std::string& member, const std::string& val)
|
||||
{
|
||||
if(member == "type")
|
||||
{
|
||||
fFairMQMap.at(channelName).at(index).UpdateType(val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(member == "method")
|
||||
{
|
||||
fFairMQMap.at(channelName).at(index).UpdateMethod(val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(member == "address")
|
||||
{
|
||||
fFairMQMap.at(channelName).at(index).UpdateAddress(val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(member == "property")
|
||||
{
|
||||
fFairMQMap.at(channelName).at(index).UpdateProperty(val);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//if we get there it means something is wrong
|
||||
LOG(ERROR) << "update of FairMQChannel map failed for the following key: "
|
||||
<< channelName<<"."<<index<<"."<<member;
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
int FairMQProgOptions::UpdateChannelMap(const std::string& channelName, int index, const std::string& member, int val)
|
||||
{
|
||||
|
||||
if(member == "sndBufSize")
|
||||
{
|
||||
fFairMQMap.at(channelName).at(index).UpdateSndBufSize(val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(member == "rcvBufSize")
|
||||
{
|
||||
fFairMQMap.at(channelName).at(index).UpdateRcvBufSize(val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(member == "rateLogging")
|
||||
{
|
||||
fFairMQMap.at(channelName).at(index).UpdateRateLogging(val);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//if we get there it means something is wrong
|
||||
LOG(ERROR) << "update of FairMQChannel map failed for the following key: "
|
||||
<< channelName<<"."<<index<<"."<<member;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user