std::vector<std::string> parseInputFile(std::istream & ifs) { std::vector<std::string> result; std::string record; //keep grabbing records from file until EOF while (std::getline(ifs, record)) { std::stringstream recordStream(record); std::string field; //parse record by extracting individual field from it and dump the delimiter while (std::getline(recordStream, field, DELIMITER)) { result.push_back(field); } } return result; }
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> void Envelope::addProcessor(SensorLocation *loc, const WaveformStreamID &id, const Core::Time ×tamp, const char *type, const char *short_type) { DataModel::ThreeComponents tc; DataModel::WaveformStreamID tmp(id); try { DataModel::getThreeComponents( tc, loc, id.channelCode().c_str(), timestamp ); } catch ( exception &e ) { SEISCOMP_ERROR("%s: cannot query three components: %s: " "%s channels not used", Private::toStreamID(tmp).c_str(), e.what(), type); } for ( int i = 0; i < 3; ++i ) { if ( tc.comps[i] == NULL ) continue; tmp.setChannelCode(tc.comps[i]->code()); if ( !_streamFirewall.isAllowed(Private::toStreamID(tmp)) ) continue; SEISCOMP_INFO("%s: +%s", Private::toStreamID(tmp).c_str(), short_type); recordStream()->addStream(tmp.networkCode(), tmp.stationCode(), tmp.locationCode(), tmp.channelCode()); ProcessorPtr proc = new Processor(_config.baselineCorrectionBufferLength); switch ( i ) { case ThreeComponents::Vertical: proc->setUsedComponent(Processing::WaveformProcessor::Vertical); proc->setName("Z"); break; case ThreeComponents::FirstHorizontal: proc->setUsedComponent(Processing::WaveformProcessor::FirstHorizontal); proc->setName("H1"); break; case ThreeComponents::SecondHorizontal: proc->setUsedComponent(Processing::WaveformProcessor::SecondHorizontal); proc->setName("H2"); break; } Processing::StreamPtr stream = new Processing::Stream; stream->init(tmp.networkCode(), tmp.stationCode(), tmp.locationCode(), tmp.channelCode(), timestamp); proc->streamConfig((Processing::WaveformProcessor::Component)proc->usedComponent()) = *stream; proc->setWaveformID(tmp); proc->setSaturationThreshold(_config.saturationThreshold); proc->useVSFilterImplementation(!_config.useSC3Filter); if ( proc->streamConfig((Processing::WaveformProcessor::Component)proc->usedComponent()).gain == 0.0 ) { SEISCOMP_WARNING("%s: -%s: gain not defined (= 0.0)", short_type, Private::toStreamID(tmp).c_str()); continue; } proc->setPublishFunction(boost::bind(&Envelope::emitResult, this, _1, _2, _3, _4, _5, _6)); _processors[Private::toStreamID(tmp)] = proc; } }
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 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; }