Ejemplo n.º 1
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool Check::check() {
	if ( _inv == NULL ) return false;

	EpochMap networkEpochs;

	for ( size_t n = 0; n < _inv->networkCount(); ++n ) {
		Network *net = _inv->network(n);
		checkEpoch(net);
		checkOverlap(networkEpochs[net->code()], net);

		EpochMap stationEpochs;

		for ( size_t s = 0; s < net->stationCount(); ++s ) {
			Station *sta = net->station(s);
			checkEpoch(sta);
			checkOverlap(stationEpochs[sta->code()], sta);
			checkOutside(net, sta);

			EpochMap locationEpochs;
			double lat = sta->latitude();
			double lon = sta->longitude();

			if ( lat == 0.0 && lon == 0.0 ) {
				log(LogHandler::Warning,
				    (string(sta->className()) + " " + id(sta) + "\n  "
				     "coordinates are 0.0/0.0").c_str(),
				     NULL, NULL);
			}

			for ( size_t l = 0; l < sta->sensorLocationCount(); ++l ) {
				SensorLocation *loc = sta->sensorLocation(l);
				checkEpoch(loc);
				checkOverlap(locationEpochs[loc->code()], loc);
				checkOutside(sta, loc);

				double llat = loc->latitude();
				double llon = loc->longitude();

				if ( llat == 0.0 && llon == 0.0 ) {
					log(LogHandler::Warning,
					    (string(loc->className()) + " " + id(loc) + "\n  "
					     "coordinates are 0.0/0.0").c_str(),
					     NULL, NULL);
				}

				double dist,a1,a2;

				Math::Geo::delazi(lat,lon,llat,llon, &dist, &a1, &a2);
				dist = Math::Geo::deg2km(dist);

				if ( dist > 10 ) {
					log(LogHandler::Warning,
					    (string(loc->className()) + " " + id(loc) + "\n  "
					     "location is " + Core::toString(dist) + "km away from parent Station").c_str(),
					     NULL, NULL);
				}

				EpochMap channelEpochs;

				for ( size_t c = 0; c < loc->streamCount(); ++c ) {
					Stream *cha = loc->stream(c);
					checkEpoch(cha);
					checkOverlap(channelEpochs[cha->code()], cha);
					checkOutside(loc, cha);
					try {
						if ( cha->gain() == 0.0 ) {
							log(LogHandler::Warning,
							    (string(cha->className()) + " " + id(cha) + "\n  "
							     "invalid gain of 0").c_str(), NULL, NULL);
						}
					}
					catch ( ... ) {
						log(LogHandler::Warning,
						    (string(cha->className()) + " " + id(cha) + "\n  "
						     "no gain set").c_str(), NULL, NULL);
					}

					if ( cha->gainUnit().empty() ) {
						log(LogHandler::Warning,
						    (string(cha->className()) + " " + id(cha) + "\n  "
						     "no gain unit set").c_str(), NULL, NULL);
					}

					if ( !cha->sensor().empty() ) {
						// Done already in merge
						/*
						Sensor *sensor = findSensor(cha->sensor());
						if ( sensor == NULL ) {
							log(LogHandler::Unresolved,
							    (string(cha->className()) + " " + id(cha) + "\n  "
							     "referenced sensor is not available").c_str(), NULL, NULL);
						}
						*/
					}
					else
						log(LogHandler::Information,
						    (string(cha->className()) + " " + id(cha) + "\n  "
						     "no sensor and thus no response information available").c_str(), NULL, NULL);
				}
			}
		}
	}

	for ( size_t i = 0; i < _inv->sensorCount(); ++i ) {
		Sensor *sensor = _inv->sensor(i);
		Object *o = findPAZ(sensor->response());
		if ( o == NULL ) o = findPoly(sensor->response());
		if ( o == NULL ) {
			// Done in merge
			/*
			log(LogHandler::Unresolved,
			    (string(sensor->className()) + " " + id(sensor) + "\n  "
			     "referenced response is not available").c_str(), NULL, NULL);
			*/
		}
	}

	return true;
}
Ejemplo n.º 2
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool Envelope::init() {
	if ( !Application::init() ) return false;

	// Construct stream firewall
	for ( size_t i = 0; i < _config.streamsWhiteList.size(); ++i ) {
		Core::trim(_config.streamsWhiteList[i]);
		if ( !_config.streamsWhiteList[i].empty() ) {
			SEISCOMP_DEBUG("Adding pattern to stream whitelist: %s",
			               _config.streamsWhiteList[i].c_str());
			_streamFirewall.allow.insert(_config.streamsWhiteList[i]);
		}
	}

	for ( size_t i = 0; i < _config.streamsBlackList.size(); ++i ) {
		Core::trim(_config.streamsBlackList[i]);
		if ( !_config.streamsBlackList[i].empty() ) {
			SEISCOMP_DEBUG("Adding pattern to stream blacklist: %s",
			               _config.streamsBlackList[i].c_str());
			_streamFirewall.deny.insert(_config.streamsBlackList[i]);
		}
	}

	Inventory *inv = Client::Inventory::Instance()->inventory();
	if ( inv == NULL ) {
		SEISCOMP_ERROR("Inventory not available");
		return false;
	}

	Core::Time now = Core::Time::GMT();

	for ( size_t n = 0; n < inv->networkCount(); ++n ) {
		Network *net = inv->network(n);
		try { if ( net->end() < now ) continue; }
		catch ( ... ) {}

		for ( size_t s = 0; s < net->stationCount(); ++s ) {
			Station *sta = net->station(s);
			try { if ( sta->end() < now ) continue; }
			catch ( ... ) {}

			// Find velocity and strong-motion streams
			DataModel::WaveformStreamID tmp(net->code(), sta->code(), "", "", "");

			Stream *maxVel, *maxAcc;
			maxVel = Private::findStreamMaxSR(sta, now,
			                                  Processing::WaveformProcessor::MeterPerSecond,
			                                  &_streamFirewall);
			maxAcc = Private::findStreamMaxSR(sta, now,
			                                  Processing::WaveformProcessor::MeterPerSecondSquared,
			                                  &_streamFirewall);

			if ( !maxAcc && !maxVel ) {
				SEISCOMP_WARNING("%s.%s: no usable velocity and acceleration channel found",
				                 net->code().c_str(), sta->code().c_str());
				continue;
			}

			// Add velocity data if available
			if ( maxVel ) {
				tmp.setLocationCode(maxVel->sensorLocation()->code());
				tmp.setChannelCode(maxVel->code().substr(0,2));
				addProcessor(maxVel->sensorLocation(), tmp, now, "velocity", "vel");
			}

			// Add velocity data if available
			if ( maxAcc ) {
				tmp.setLocationCode(maxAcc->sensorLocation()->code());
				tmp.setChannelCode(maxAcc->code().substr(0,2));
				addProcessor(maxAcc->sensorLocation(), tmp, now, "accelerometric", "acc");
			}
		}
	}

	if ( _config.ts.valid() ) recordStream()->setStartTime(_config.ts);
	if ( _config.te.valid() ) recordStream()->setEndTime(_config.te);

	_creationInfo.setAgencyID(agencyID());
	_creationInfo.setAuthor(author());

	// We do not need lookup objects by publicID
	PublicObject::SetRegistrationEnabled(false);

	_sentMessages = 0;
	_sentMessagesTotal = 0;

#ifndef SC3_SYNC_VERSION
	_mpsReset.setCallback(boost::bind(&Envelope::resetMPSCount, this));
	_mpsReset.setTimeout(1);
	_mpsReset.start();
#endif

	return true;
}