Exemple #1
0
		bool importDatabase() {
			IO::XMLArchive ar;
			if ( _inputFile == "-" )
				ar.open(cin.rdbuf());
			else if ( !ar.open(_inputFile.c_str()) ) {
				cout << "Error: could not open input file '" << _inputFile << "'" << endl;
				return false;
			}

			cout << "Parsing file '" << _inputFile << "'..." << endl;

			Util::StopWatch timer;
			DataModel::ObjectPtr doc;
			ar >> doc;
			ar.close();

			if ( doc == NULL ) {
				cerr << "Error: no valid object found in file '" << _inputFile << "'" << endl;
				return false;
			}

			ObjectDispatcher dispatcher(connection(), _operation, commandline().hasOption("test"), ObjectCounter(doc.get()).count(), 78);
			cout << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ROUTING TABLE" << endl;
			dispatcher.setRoutingTable(_routingTable);
			cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << endl;

			unsigned int totalCount = ObjectCounter(doc.get()).count();

			cout << "Time needed to parse XML: " << Core::Time(timer.elapsed()).toString("%T.%f") << endl;
			cout << "Document object type: " << doc->className() << endl;
			cout << "Total number of objects: " << totalCount << endl;

			if ( connection() )
				cout << "Dispatching " << doc->className() << " to " << connection()->masterAddress() << endl;
			timer.restart();

			dispatcher(doc.get());
			sync();
			cout << endl;

			cout << "While dispatching " << dispatcher.count() << "/" << totalCount << " objects " << dispatcher.errors() << " errors occured" << endl;
			cout << "Time needed to dispatch " << dispatcher.count() << " objects: " << Core::Time(timer.elapsed()).toString("%T.%f") << endl;

			return true;
		}
Exemple #2
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void ObjectCache::updateObjects(Seiscomp::DataModel::DatabaseQuery* query) {

	if ( !query ) {
		SEISCOMP_ERROR("Provided query instance is broken, no cache update performed");
		return;
	}

	// Make a deep copy of the tuple, free the original, store a fresh version
	// of the newly fetched objects...
	Tuple copy = _cache;

	clear();

	Util::StopWatch sw;
	for (size_t i = 0; i < copy.size(); ++i) {
		PO obj = query->getObject(copy[i].second->typeInfo(), copy[i].second->publicID());
		if ( obj )
			addObject(copy[i].first, obj);
	}
	SEISCOMP_INFO("All objects from the cache have been updated: %s",
	    Seiscomp::Core::Time(sw.elapsed()).toString("%T.%f").c_str());
}
Exemple #3
0
DataModel::Origin* relocate(Seismology::LocatorInterface *locator, DataModel::Origin* origin) {
	if ( !locator )
		throw Core::GeneralException("No locator type set.");

	DataModel::Origin* newOrg = NULL;
	std::string errorMsg;

	try {
		Util::StopWatch stopWatch;
		newOrg = locator->relocate(origin);
		double elapsed = stopWatch.elapsed();
		SEISCOMP_DEBUG("Locator took %fms", elapsed*1E3);
		if ( newOrg )
			return newOrg;

		errorMsg = "The Relocation failed for some reason.";
	}
	catch ( Core::GeneralException& e ) {
		errorMsg = e.what();
	}

	// if no initial location is supported throw the error
	// after the first try
	if ( !locator->supports(Seismology::LocatorInterface::InitialLocation) )
		throw Core::GeneralException(errorMsg);

	Seismology::LocatorInterface::PickList picks;
	for ( size_t i = 0; i < origin->arrivalCount(); ++i ) {
		DataModel::Arrival* arrival = origin->arrival(i);
		try {
			if ( arrival->weight() < 0.5 ) continue;
		}
		catch ( ... ) {}

		DataModel::Pick* pick = locator->getPick(arrival);
		if ( !pick )
			throw Core::GeneralException("pick '" + arrival->pickID() + "' not found");

		picks.push_back(Seismology::LocatorInterface::PickItem(pick,
		                                                       Seismology::LocatorInterface::F_ALL));
	}

	if ( picks.empty() )
		throw Core::GeneralException("No picks given to relocate");

	std::sort(picks.begin(), picks.end(), comparePick());
	DataModel::SensorLocation *sloc = locator->getSensorLocation(picks.front().pick.get());
	if ( !sloc )
		throw Core::GeneralException("station '" + picks.front().pick->waveformID().networkCode() +
		                             "." + picks.front().pick->waveformID().stationCode() + "' not found");

	DataModel::OriginPtr tmp = DataModel::Origin::Create();
	*tmp = *origin;
	for ( size_t i = 0; i < origin->arrivalCount(); ++i ) {
		DataModel::ArrivalPtr ar = new DataModel::Arrival(*origin->arrival(i));
		tmp->add(ar.get());
	}

	tmp->setLatitude(sloc->latitude());
	tmp->setLongitude(sloc->longitude());
	tmp->setDepth(DataModel::RealQuantity(11.0));
	tmp->setTime(picks.front().pick->time());

	Util::StopWatch stopWatch;
	newOrg = locator->relocate(tmp.get());
	double elapsed = stopWatch.elapsed();
	SEISCOMP_DEBUG("Locator took %fms", elapsed*1E3);

	if ( newOrg )
		return newOrg;

	throw Core::GeneralException(errorMsg);
}