Пример #1
0
//--------------------------------------------------------------------------------------------------
void runSimpleFileCataloger(const char *dir  = "/mnt/hadoop/cms/store/user/paus/fabstoec/Summer11Private/TTH_HToGG_M-120_TuneZ2_7TeV-pythia6/Summer11-PU32_8CM_START42_V13C-v4/GEN-SIM-RECO",
			    const char *file = "")
{
  // -----------------------------------------------------------------------------------------------
  // This script runs a full cataloging action on the given directory
  // -----------------------------------------------------------------------------------------------
  reset();
  catalogFile(dir,file);
  return;
}
VLanguageSyntaxTesterCatalog::VLanguageSyntaxTesterCatalog(XBOX::VFilePath& inFilePath)
:fFilePath(inFilePath)
,fCatalogBag(NULL)
{
	VErrorDB4D err = VE_OK;

	if ( fFilePath.IsValid() )
	{
		fCatalogBag = new VValueBag();

		VFile catalogFile(fFilePath);

		if ( catalogFile.Exists() )
		{
			CDB4DManager*		dB4DBaseManager = VComponentManager::RetainComponentOfType<CDB4DManager>();
			if (NULL != dB4DBaseManager)
			{
				sLONG flags = DB4D_Open_As_XML_Definition | DB4D_Open_No_Respart | DB4D_Open_StructOnly | DB4D_Open_Allow_Temporary_Convert_For_ReadOnly;

				CDB4DBase* dB4DBase = dB4DBaseManager->OpenBase(catalogFile, flags, NULL /* outErr */, XBOX::FA_READ);
				if (NULL != dB4DBase)
				{
					CDB4DBaseContext* dB4DBaseContext = dB4DBase->NewContext(nil, nil);
					if (NULL != dB4DBaseContext)
					{
						std::vector<XBOX::VRefPtr<CDB4DEntityModel> > entityModels;

						err = dB4DBase->RetainAllEntityModels(entityModels, dB4DBaseContext, true);
						if (err == VE_OK)
						{
							for( std::vector<XBOX::VRefPtr<CDB4DEntityModel> >::iterator oneEntityModel = entityModels.begin() ; oneEntityModel != entityModels.end() ; ++oneEntityModel)
							{			
								VValueBag* resolvedRepresentation = (*oneEntityModel)->CreateDefinition();
								fCatalogBag->AddElement(LS_TESTER_CATALOG_DATACLASSES, resolvedRepresentation);
								ReleaseRefCountable( &resolvedRepresentation);
							}
						}
						dB4DBaseContext->Release();
					}
					dB4DBase->Release();
				}
				dB4DBaseManager->Release();
			}
		}
	}
}
Пример #3
0
int main(){

    std::ifstream catalogFile("catalog.json");

    Json::Value root;   // will contains the root value after parsing.
    Json::Reader reader;
    bool parsingSuccessful = reader.parse( catalogFile, root );
    if ( !parsingSuccessful ){
        // report to the user the failure and their locations in the document.
        std::cout  << "Failed to parse configuration\n"
                   << reader.getFormattedErrorMessages();
        return 1;
    }

    //parsing songs
    Json::Value songs = root["songs"];
    for ( int index = 0; index < songs.size(); ++index ){  // Iterates over the sequence elements.
        printSongInfo(songs[index]);
    }
    return 0;
}
Пример #4
0
//! Execute catalog_pruner.
void executeCatalogPruner( const rapidjson::Document& config )
{
    // Verify config parameters. Exception is thrown if any of the parameters are missing.
    const CatalogPrunerInput input = checkCatalogPrunerInput( config );

    std::cout << std::endl;
    std::cout << "******************************************************************" << std::endl;
    std::cout << "                              Parser                              " << std::endl;
    std::cout << "******************************************************************" << std::endl;
    std::cout << std::endl;

    // Parse catalog and store TLE objects.
    std::ifstream catalogFile( input.catalogPath.c_str( ) );
    std::string catalogLine;

    // Check if catalog is 2-line or 3-line version.
    std::getline( catalogFile, catalogLine );
    const int tleLines = getTleCatalogType( catalogLine );

    // Reset file stream to start of file.
    catalogFile.seekg( 0, std::ios::beg );

    int numberOfPrunedObjects = 0;

    // Loop over file and apply filters to generate pruned catalog.
    if ( tleLines == 3 )
    {
        std::cout << "3-line catalog detected ..." << std::endl;

        std::ofstream prunedCatalogFile( input.prunedCatalogPath.c_str( ) );

        while ( std::getline( catalogFile, catalogLine ) )
        {
            if ( catalogLine.substr( 0, 1 ).compare( "0" ) != 0 )
            {
                // TODO: print catalog line in error message.
                throw std::runtime_error( "ERROR: Catalog malformed!" );
            }
            const std::string line0 = catalogLine;

            // Check regex name filter.
            // If regex can't be match, continue.
            boost::xpressive::sregex line0RegexFilter
                = boost::xpressive::sregex::compile( input.nameRegex.c_str( ) );
            if ( !boost::xpressive::regex_search( line0, line0RegexFilter ) )
            {
                std::getline( catalogFile, catalogLine );
                std::getline( catalogFile, catalogLine );
                continue;
            }

            std::getline( catalogFile, catalogLine );
            if ( catalogLine.substr( 0, 1 ).compare( "1" ) != 0 )
            {
                // Print catalog line in error message.
                throw std::runtime_error( "ERROR: Catalog malformed!" );
            }
            removeNewline( catalogLine );
            const std::string line1 = catalogLine;

            std::getline( catalogFile, catalogLine );
            if ( catalogLine.substr( 0, 1 ).compare( "2" ) != 0 )
            {
                // Print catalog line in error message.
                throw std::runtime_error( "ERROR: Catalog malformed!" );
            }
            removeNewline( catalogLine );
            const std::string line2 = catalogLine;

            // Create TLE object from catalog lines.
            const Tle tle( line0, line1, line2 );

            // Apply filters.
            const OrbitalElements orbitalElements( tle );

            // Apply semi-major axis filter.
            const double semiMajorAxis = orbitalElements.RecoveredSemiMajorAxis( ) * kXKMPER;
            if ( ( semiMajorAxis < input.semiMajorAxisMinimum + kXKMPER )
                 || ( semiMajorAxis > input.semiMajorAxisMaximum + kXKMPER ) )
            {
                continue;
            }

            // Apply eccentricity filter.
            const double eccentricity = orbitalElements.Eccentricity( );
            if ( ( eccentricity < input.eccentricityMinimum )
                 || ( eccentricity > input.eccentricityMaximum ) )
            {
                continue;
            }

            // Apply inclination filter.
            const double inclination = orbitalElements.Inclination( ) / kPI * 180.0;
            if ( ( inclination < input.inclinationMinimum )
                 || ( inclination > input.inclinationMaximum ) )
            {
                continue;
            }

            // Check if the number of objects in the pruned catalog has reached the cutoff set by
            // the user. If not, increment the counter.
            if ( input.catalogCutoff != 0 && numberOfPrunedObjects == input.catalogCutoff )
            {
                std::cout << "Cutoff reached ..." << std::endl;
                break;
            }

            numberOfPrunedObjects++;

            // This point is reached if TLE is not filtered: write catalog lines to pruned catalog.
            prunedCatalogFile << line0 << std::endl;
            prunedCatalogFile << line1 << std::endl;
            prunedCatalogFile << line2 << std::endl;
        }

        prunedCatalogFile.close( );
    }
    else if ( tleLines == 2 )
    {
        std::cout << "2-line catalog detected ... " << std::endl;
        std::cout << "WARNING: regex name filter will be skipped!" << std::endl;

        std::ofstream prunedCatalogFile( input.prunedCatalogPath.c_str( ) );

        while ( std::getline( catalogFile, catalogLine ) )
        {
            if ( catalogLine.substr( 0, 1 ).compare( "1" ) != 0 )
            {
                // Print catalog line in error message.
                throw std::runtime_error( "ERROR: Catalog malformed!" );
            }
            removeNewline( catalogLine );
            const std::string line1 = catalogLine;

            std::getline( catalogFile, catalogLine );
            if ( catalogLine.substr( 0, 1 ).compare( "2" ) != 0 )
            {
                // Print catalog line in error message.
                throw std::runtime_error( "ERROR: Catalog malformed!" );
            }
            removeNewline( catalogLine );
            const std::string line2 = catalogLine;

            // Create TLE object from catalog lines.
            const Tle tle( line1, line2 );

            // Apply filters.
            const OrbitalElements orbitalElements( tle );

            // Apply semi-major axis filter.
            const double semiMajorAxis = orbitalElements.RecoveredSemiMajorAxis( ) * kXKMPER;
            if ( ( semiMajorAxis < input.semiMajorAxisMinimum + kXKMPER )
                 || ( semiMajorAxis > input.semiMajorAxisMaximum + kXKMPER ) )
            {
                continue;
            }

            // Apply eccentricity filter.
            const double eccentricity = orbitalElements.Eccentricity( );
            if ( ( eccentricity < input.eccentricityMinimum )
                 || ( eccentricity > input.eccentricityMaximum ) )
            {
                continue;
            }

            // Apply inclination filter.
            const double inclination = orbitalElements.Inclination( ) / kPI * 180.0;
            if ( ( inclination < input.inclinationMinimum )
                 || ( inclination > input.inclinationMaximum ) )
            {
                continue;
            }

            // Check if the number of objects in the pruned catalog has reached the cutoff set by
            // the user. If not, increment the counter.
            if ( input.catalogCutoff != 0 && numberOfPrunedObjects == input.catalogCutoff )
            {
                std::cout << "Cutoff reached ..." << std::endl;
                break;
            }

            numberOfPrunedObjects++;

            // This point is reached if TLE is not filtered: write catalog lines to pruned catalog.
            prunedCatalogFile << line1 << std::endl;
            prunedCatalogFile << line2 << std::endl;
        }

        prunedCatalogFile.close( );
    }
    else
    {
        throw std::runtime_error( "ERROR: # of lines per TLE must be 2 or 3!" );
    }

    std::cout << "Number of objects in pruned catalog: " << numberOfPrunedObjects << std::endl;

    catalogFile.close( );
}