MapServiceConnector::ptr_t MapServiceConnectorFactory::Create( const std::string& config_pathname,
                                                               Status&            status )
{
    // Log Entry
    BOOST_LOG_TRIVIAL(trace) << "MapServiceConnector::" << __func__ << ", Start of Method";
    
    // Load the Configuration
    Configuration options = ConfigParser(config_pathname).Load_Configuration(status);
    
    // Check if Initialized
    if( Is_Initialized() == false ){
        status = Initialize( options );
        if( status.Get_Code() != StatusCode::SUCCESS ){
            return nullptr;
        }
    }

    // Check the status
    if( status.Get_Code() != StatusCode::SUCCESS ){
        return nullptr;
    }

    // Load and return the new connector
    MapServiceConnector::ptr_t connector = std::make_shared<MapServiceConnector>( options );
    
    // Log Entry
    BOOST_LOG_TRIVIAL(trace) << "MapServiceConnector::" << __func__ << ", End of Method";

    // Return Success
    status = Status( StatusCode::SUCCESS );
    return connector;
}
//---------------------------------------------------------------------------------------------
// Config Default Parser 
void TLibParser::ConfigDefaultParser()
{
  #ifdef internaldebug
    printf("-> TLibParser::ConfigDefaultParser\r\n");
  #endif       

  ConfigParser("<customcmd>", "</customcmd>");
}
 TEST(ConfigParserTest, testParseSerializedConfig) {
     const ConfigEntry::Ptr config = ConfigParser("  { first = \"firstValue\", second=\"secondValue\", third = {\"fourth\",\"fifth\"} } ").parse();
     const String serialized = config->asString();
     const ConfigEntry::Ptr deserialized = ConfigParser(serialized).parse();
     
     ASSERT_TRUE(deserialized != NULL);
     ASSERT_TRUE(deserialized->type() == ConfigEntry::Type_Table);
     
     const ConfigTable& table = *deserialized;
     ASSERT_EQ(3u, table.count());
     ASSERT_TRUE(ConfigEntry::Type_Value == table["first"].type());
     ASSERT_TRUE(ConfigEntry::Type_Value == table["second"].type());
     ASSERT_TRUE(ConfigEntry::Type_List == table["third"].type());
     ASSERT_EQ(String("firstValue"), static_cast<const String&>(table["first"]));
     ASSERT_EQ(String("secondValue"), static_cast<const String&>(table["second"]));
     
     const ConfigList& nested = table["third"];
     ASSERT_EQ(2u, nested.count());
     ASSERT_TRUE(ConfigEntry::Type_Value == nested[0].type());
     ASSERT_TRUE(ConfigEntry::Type_Value == nested[1].type());
     ASSERT_EQ(String("fourth"), static_cast<const String&>(nested[0]));
     ASSERT_EQ(String("fifth"), static_cast<const String&>(nested[1]));
 }
Example #4
0
void runGridpPb(const char *config = "config.txt"){
        //
        // run analysis 
        //

        TGrid::Connect("alien://");

        // Create Lookup with sample information
        TMap sampleinfos;
        Generate_Sample_Lookup(sampleinfos);

        ConfigParser(config);

        // Configure alien plugin
        AliAnalysisAlien *plugin = CreateGridHandler();
        if(!CreateTrainDir(plugin, sampleinfos)){
                printf("Cannot setup output directory\n");
                return;
        }
        if(!MakeSample(plugin, sampleinfos)){
                printf("Cannot create data sample\n");
                return;
        }
        if(!g_plugin_mode.CompareTo("full")){
                // full mode, creating config files for the merging stage
                GenerateMergeConfigs();
        }

        AliAnalysisManager *mgr = new AliAnalysisManager("tpctofanalysis");
        mgr->SetGridHandler(plugin);
        
        SetupTrain(sampleinfos);

        // Run train
        if (!mgr->InitAnalysis()) return;
        mgr->PrintStatus();
        // Start analysis in grid.
        mgr->StartAnalysis("grid");
} 
Example #5
0
namespace eNetworks
{

ConfigParser::ConfigParser(const std::string& _ConfigFile) : ConfigMap(), ConfigFile(_ConfigFile), M_parsed(false)
{
}

void ConfigParser::ParseConfigFile()
{
   ifstream ifsConfigFile(ConfigFile.c_str()); // Opening Configuration file
   if (!ifsConfigFile.is_open())
   {
   	debug << "ConifgParser Error: Could not open " << ConfigFile << endb;
   	exit(0);
   }

   unsigned int intCurrentLine = 0;
   string strCurrentLine;
   while(getline(ifsConfigFile, strCurrentLine))
   {    
   	intCurrentLine++; // start with line 1.

   	if (strCurrentLine == "")
   	   continue;

   	// replace this with a strip function.
   	while(strCurrentLine[0] == ' ')
   	{
   	   strCurrentLine = strCurrentLine.substr(1);
   	}

   	// Comment line. Ignore.
   	if (strCurrentLine[0] == '#')
   	   continue;

   	if (!IsItem(strCurrentLine.substr(0, strCurrentLine.find(" "))))
   	{
   	   // handle error "Unrecognizable configuration"
   	   debug << "Line " << intCurrentLine << ": Unrecognizable configuration." << endb;
   	   continue;
   	}

   	string strItem = strCurrentLine.substr(0, strCurrentLine.find(" "));
   	strCurrentLine = strCurrentLine.substr(strItem.length()+1);

   	// replace this with a strip function.
        while(strCurrentLine[0] == ' ')
        {
           strCurrentLine = strCurrentLine.substr(1);
        }

   	if (strCurrentLine[0] != '=')
   	{
   	   // handle error "Expected '=' Token."
   	   debug << "Line " << intCurrentLine << ": Expected \'=\' Token." << endb;
   	   continue;
   	}
   	strCurrentLine = strCurrentLine.substr(1);

        // replace this with a strip function.
        while(strCurrentLine[0] == ' ')
        {
           strCurrentLine = strCurrentLine.substr(1);
        }
   	
   	if (strCurrentLine[0] != '\"')
   	{
   	   // handle error "Expected '\"' Token."
   	   debug << "Line " << intCurrentLine << ": Expected \'\"\' Token (0x01)." << endb;
   	   continue;
   	}

   	// Format is ITEM = "CONFIGURATION"
   	string strConfiguration = strCurrentLine.substr(1);
   	if (strConfiguration.find('\"') != string::npos)
   	{
   	   for (unsigned int i = 0; i < strConfiguration.length(); i++)
   	   {
   	   	if ('\"' == strConfiguration[i] && '\\' != strConfiguration[i-1])
   	   	   strConfiguration = strConfiguration.substr(0, i);
   	   }
   	}
   	else
  	{
   	   // handle error "Expected '\"' Token"
   	   debug << "Line " << intCurrentLine << ": Expected \'\"\' Token (0x02)." << endb;
   	   continue;
   	}
   	SetConfiguration(strItem, strConfiguration);
   }
 
   ifsConfigFile.close();
   M_parsed = true;
}


bool ConfigParser::IsItem(const string& Item)
{
   ConfigMapType::iterator iterConfigMap = ConfigMap.find(Item);

   if (ConfigMap.end() == iterConfigMap)
   	return false;

   // else
   return true;
}

std::string ConfigParser::GetConfiguration(const string& Item)
{
   ConfigMapType::iterator iterConfigMap = ConfigMap.find(Item);

   if (ConfigMap.end() == iterConfigMap)
    return "";
   // else
   return iterConfigMap->second;
}

void ConfigParser::SetConfiguration(const string& Item, const string& Configuration)
{
   ConfigMapType::iterator iterConfigMap = ConfigMap.find(Item);

   if (ConfigMap.end() != iterConfigMap)
   	iterConfigMap->second = Configuration;
}

bool ConfigParser::InsertItem(const string& Item, const string& Configuration)
{
   return ConfigMap.insert(ConfigMapType::value_type(Item,Configuration)).second;
}

ConfigParser ConfigFile = ConfigParser();

} // namespace eNetworks