Exemple #1
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void App::handleTimeout() {

	if ( !_config.playback || _inputFileXML.empty() ) {
		_flush();
		return;
	}


	// The following is relevant (and executed) only for XML playback.

	while ( ! _objects.empty() && !isExitRequested() ) {

		Core::Time t;
		DataModel::PublicObjectPtr o = _objects.front();

		// retrieve the creationTime...
		if (DataModel::Pick::Cast(o.get()))
			t = DataModel::Pick::Cast(o.get())->creationInfo().creationTime();
		else if (DataModel::Amplitude::Cast(o.get()))
			t = DataModel::Amplitude::Cast(o.get())->creationInfo().creationTime();
		else if (DataModel::Origin::Cast(o.get()))
			t = DataModel::Origin::Cast(o.get())->creationInfo().creationTime();
		else continue;

		// at the first object:
		if (objectCount == 0)
			objectsStartTime = t;

		if (_playbackSpeed > 0) {
			double dt = t - objectsStartTime;
			Core::TimeSpan dp = dt/_playbackSpeed;
			t = playbackStartTime + dp;
			if (Core::Time::GMT() < t)
				break; // until next handleTimeout() call
		} // otherwise no speed limit :)

		_objects.pop();
		addObject("", o.get());
		objectCount++;
	}

	// for an XML playback, we're done once the object queue is empty
	if ( _objects.empty() )
		quit();
}
Exemple #2
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool App::runFromEPFile(const char *fname) {
	IO::XMLArchive ar;

	if ( !ar.open(fname)) {
		SEISCOMP_ERROR("unable to open XML file: %s", fname);
		return false;
	}

	ar >> _ep;
	ar.close();

	if ( !_ep ) {
		SEISCOMP_ERROR("No event parameters found: %s", fname);
		return false;
	}

	SEISCOMP_INFO("finished reading event parameters from XML");
	SEISCOMP_INFO("  number of picks:      %ld", (long int)_ep->pickCount());
	SEISCOMP_INFO("  number of amplitudes: %ld", (long int)_ep->amplitudeCount());
	SEISCOMP_INFO("  number of origins:    %ld", (long int)_ep->originCount());

	typedef std::pair<Core::Time,DataModel::PublicObjectPtr> TimeObject;
	typedef std::vector<TimeObject> TimeObjectVector;

	// retrieval of relevant objects from event parameters
	// and subsequent DSU sort
	TimeObjectVector objs;

	for ( size_t i = 0; i < _ep->pickCount(); ++i ) {
		DataModel::PickPtr pick = _ep->pick(i);
		try {
			Core::Time t = pick->creationInfo().creationTime();
			objs.push_back(TimeObject(t, pick));
		}
		catch ( ... ) {
			SEISCOMP_WARNING("Ignore pick %s: no creation time set",
			                 pick->publicID().c_str());
		}
	}

	for ( size_t i = 0; i < _ep->amplitudeCount(); ++i ) {
		DataModel::AmplitudePtr amplitude = _ep->amplitude(i);
		try {
			Core::Time t = amplitude->creationInfo().creationTime();
			objs.push_back(TimeObject(t, amplitude));
		}
		catch ( ... ) {
			SEISCOMP_WARNING("Ignore amplitude %s: no creation time set",
			                 amplitude->publicID().c_str());
		}
	}

	for ( size_t i = 0; i < _ep->originCount(); ++i ) {
		DataModel::OriginPtr origin = _ep->origin(i);
		try {
			Core::Time t = origin->creationInfo().creationTime();
			objs.push_back(TimeObject(t, origin));
		}
		catch ( ... ) {
			SEISCOMP_WARNING("Ignore origin %s: no creation time set",
			                 origin->publicID().c_str());
		}
	}

	std::sort(objs.begin(), objs.end());
	for (TimeObjectVector::iterator
	     it = objs.begin(); it != objs.end(); ++it) {
		_objects.push(it->second);
	}

	while ( !_objects.empty() && !isExitRequested() ) {
		DataModel::PublicObjectPtr o = _objects.front();

		_objects.pop();
		addObject("", o.get());
		++objectCount;
	}

	_flush();

	ar.create("-");
	ar.setFormattedOutput(true);
	ar << _ep;
	ar.close();

	return true;
}