bool loadEventParam(DataModel::EventParametersPtr &ep, const string &data, bool gzip = false) { bool retn = false; bool registrationEnabled = DataModel::PublicObject::IsRegistrationEnabled(); DataModel::PublicObject::SetRegistrationEnabled(false); try { io::filtering_istreambuf buf; container_source<string> src(data); if ( gzip ) buf.push(io::gzip_decompressor()); buf.push(src); IO::XMLArchive ar; if ( !ar.open(&buf) ) SEISCOMP_ERROR("[xml] could not open stream buffer for reading"); else { ar >> ep; ar.close(); retn = true; } } catch (string &e) { SEISCOMP_ERROR("[xml] %s", e.c_str()); } catch (exception &e) { SEISCOMP_ERROR("[xml] %s", e.what()); } DataModel::PublicObject::SetRegistrationEnabled(registrationEnabled); return retn; }
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; }
bool MapCut::run() { SCScheme.map.vectorLayerAntiAlias = true; DataModel::EventParametersPtr ep; _htmlArea = commandline().hasOption("html-area"); if ( !_epFile.empty() ) { IO::XMLArchive ar; if ( !ar.open(_epFile.c_str()) ) { cerr << "Unable to open file '" << _epFile << "'" << endl; return false; } ar >> ep; if ( ep == NULL ) { cerr << "File '" << _epFile << "' does not contain event parameters" << endl; return false; } }
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> bool AmpTool::run() { if ( !_originID.empty() ) { OriginPtr org = Origin::Cast(query()->getObject(Origin::TypeInfo(), _originID)); if ( !org ) { cerr << "Origin not found!" << endl; return false; } _fetchMissingAmplitudes = false; query()->loadArrivals(org.get()); process(org.get()); return true; } if ( !_strTimeWindowStartTime.empty() || !_strTimeWindowEndTime.empty() ) { if ( database() == NULL ) { cerr << "No database currently active for time window reprocessing" << endl; return false; } Core::Time startTime, endTime; if ( !_strTimeWindowStartTime.empty() && !startTime.fromString(_strTimeWindowStartTime.c_str(), "%F %T") ) { cerr << "Invalid start time: " << _strTimeWindowStartTime << endl; return false; } if ( !_strTimeWindowEndTime.empty() && !endTime.fromString(_strTimeWindowEndTime.c_str(), "%F %T") ) { cerr << "Invalid end time: " << _strTimeWindowEndTime << endl; return false; } std::string dbQuery; dbQuery += "select PPick." + _T("publicID") + ", Pick.* from Pick,PublicObject as PPick,Amplitude " "where Pick._oid=PPick._oid and Amplitude." + _T("pickID") + "=PPick." + _T("publicID"); if ( startTime.valid() ) dbQuery += " and Pick." + _T("time_value") + ">='" + startTime.toString("%F %T") + "'"; if ( endTime.valid() ) dbQuery += " and Pick." + _T("time_value") + "<'" + endTime.toString("%F %T") + "'"; dbQuery += " group by Amplitude." + _T("pickID"); if ( !commandline().hasOption("commit") ) _testMode = true; EventParametersPtr ep; if ( _testMode ) ep = new EventParameters; typedef list<PickPtr> PickList; PickList picks; cerr << "Collecting picks ... " << flush; DatabaseIterator db_it = query()->getObjectIterator(dbQuery, Pick::TypeInfo()); ObjectPtr obj; while ( obj = db_it.get() ) { Pick *pick = static_cast<Pick*>(obj.get()); try { pick->waveformID().networkCode(); pick->waveformID().stationCode(); pick->waveformID().locationCode(); pick->waveformID().channelCode(); pick->time().value(); } catch ( ... ) { continue; } ++db_it; picks.push_back(pick); if ( ep ) ep->add(pick); } db_it.close(); cerr << picks.size() << endl; _report << std::endl; _report << "Reprocessing report" << std::endl; _report << "-------------------" << std::endl; _report << " + Picks" << std::endl; int errors = 0; int ampsRecomputed = 0; int messagesSent = 0; int idx = 1; for ( PickList::iterator it = picks.begin(); it != picks.end(); ++it, ++idx ) { PickPtr pick = *it; SingleAmplitudeMap dbAmps; if ( isExitRequested() ) break; // Clear all processors _processors.clear(); // Clear all station time windows _stationRequests.clear(); _report << " + " << pick->publicID() << std::endl; cerr << "[" << idx << "]" << " " << (*it)->publicID() << endl; db_it = query()->getAmplitudesForPick((*it)->publicID()); while ( obj = db_it.get() ) { Amplitude *amp = static_cast<Amplitude*>(obj.get()); cerr << " [" << setw(10) << left << amp->type() << "] "; AmplitudeProcessorPtr proc = AmplitudeProcessorFactory::Create(amp->type().c_str()); if ( !proc ) { if ( _amplitudeTypes.find(amp->type()) == _amplitudeTypes.end() ) cerr << "No processor"; else { cerr << "No processor but enabled"; ++errors; } } else { cerr << "Fetch data"; dbAmps[amp->type()] = amp; proc->setTrigger(pick->time().value()); proc->setReferencingPickID(pick->publicID()); proc->setPublishFunction(boost::bind(&AmpTool::storeLocalAmplitude, this, _1, _2)); _report << " + Data" << std::endl; addProcessor(proc.get(), pick.get(), None, None); } cerr << endl; ++db_it; } db_it.close(); cerr << " --------------------------------" << endl; if ( _stationRequests.empty() ) continue; for ( RequestMap::iterator it = _stationRequests.begin(); it != _stationRequests.end(); ++it ) { StationRequest &req = it->second; for ( WaveformIDSet::iterator wit = req.streams.begin(); wit != req.streams.end(); ++wit ) { const WaveformStreamID &wsid = *wit; recordStream()->addStream(wsid.networkCode(), wsid.stationCode(), wsid.locationCode(), wsid.channelCode(), req.timeWindow.startTime(), req.timeWindow.endTime()); } _report << " + TimeWindow (" << it->first << "): " << req.timeWindow.startTime().toString("%F %T") << ", " << req.timeWindow.endTime().toString("%F %T") << std::endl; } _reprocessMap.clear(); readRecords(false); list<AmplitudePtr> updates; for ( AmplitudeMap::iterator it = dbAmps.begin(); it != dbAmps.end(); ++it ) { AmplitudePtr oldAmp = it->second; AmplitudePtr newAmp = _reprocessMap[oldAmp->type()]; cerr << " [" << setw(10) << left << oldAmp->type() << "] " << oldAmp->amplitude().value() << " "; if ( newAmp ) { if ( newAmp->amplitude().value() != oldAmp->amplitude().value() ) { *oldAmp = *newAmp; if ( ep ) ep->add(oldAmp.get()); else updates.push_back(oldAmp); cerr << "-> " << newAmp->amplitude().value(); } else cerr << " no changes"; ++ampsRecomputed; } else { cerr << "-"; ++errors; } cerr << endl; } if ( !updates.empty() ) { if ( !_testMode ) { NotifierMessagePtr nmsg = new NotifierMessage; for ( list<AmplitudePtr>::iterator it = updates.begin(); it != updates.end(); ++it ) { nmsg->attach(new Notifier("EventParameters", OP_UPDATE, it->get())); } connection()->send(nmsg.get()); ++messagesSent; if ( messagesSent % 100 == 0 ) sync(); } else { cerr << " --------------------------------" << endl; cerr << " Test mode, nothing sent" << endl; } } } if ( ep ) { IO::XMLArchive ar; ar.create("-"); ar.setFormattedOutput(true); ar << ep; ar.close(); } cerr << "----------------------------------" << endl; cerr << "Recomputed " << ampsRecomputed << " amplitudes" << endl; cerr << "Sent " << messagesSent << " messages" << endl; if ( errors ) cerr << errors << " errors occurred, check the processing log" << endl; return true; } if ( !_epFile.empty() ) { _fetchMissingAmplitudes = false; // Disable database setDatabase(NULL); _cache.setDatabaseArchive(NULL); IO::XMLArchive ar; if ( !ar.open(_epFile.c_str()) ) { SEISCOMP_ERROR("Failed to open %s", _epFile.c_str()); return false; } ar >> _ep; ar.close(); if ( !_ep ) { SEISCOMP_ERROR("No event parameters found in %s", _epFile.c_str()); return false; } if ( commandline().hasOption("reprocess") ) { for ( size_t i = 0; i < _ep->amplitudeCount(); ++i ) { AmplitudePtr amp = _ep->amplitude(i); feed(amp.get()); } } for ( size_t i = 0; i < _ep->originCount(); ++i ) { OriginPtr org = _ep->origin(i); SEISCOMP_INFO("Processing origin %s", org->publicID().c_str()); process(org.get()); } ar.create("-"); ar.setFormattedOutput(true); ar << _ep; ar.close(); _ep = NULL; return true; }
bool syncInventory() { DataModel::Inventory *targetInv = Client::Inventory::Instance()->inventory(); bool createNotifier = commandline().hasOption("create-notifier"); bool testMode = commandline().hasOption("test"); if ( testMode || _output.empty() ) createNotifier = true; if ( targetInv == NULL ) { cerr << "No inventory to sync" << endl; return false; } // Disable object registration DataModel::PublicObject::SetRegistrationEnabled(false); // Disable notifier check DataModel::Notifier::SetCheckEnabled(false); vector<string> files; collectFiles(files); if ( _filebase.empty() && files.empty() ) { cerr << "Nothing to merge, no files given" << endl; return false; } DataModel::InventoryPtr mergedInventory = new DataModel::Inventory(); Merge merger(mergedInventory.get()); merger.setLogHandler(this); _continueOperation = true; _currentTask = &merger; DataModel::Notifier::SetEnabled(false); for ( size_t i = 0; i < files.size(); ++i ) { if ( _exitRequested ) break; IO::XMLArchive ar; if ( !ar.open(files[i].c_str()) ) { cerr << "Could not open file (ignored): " << files[i] << endl; continue; } DataModel::InventoryPtr inv; cerr << "Parsing " << files[i] << " ... " << flush; ar >> inv; cerr << "done" << endl; if ( !inv ) { cerr << "No inventory found (ignored): " << files[i] << endl; continue; } _inventorySources[inv.get()] = files[i]; // Pushing the inventory into the merger cleans it // completely. The ownership of all childs goes to // the merger merger.push(inv.get()); } if ( _exitRequested ) { cerr << "Exit requested: abort" << endl; return false; } cerr << "Merging inventory ... " << flush; if ( merger.merge(false) ) cerr << "done" << endl; else cerr << "failed" << endl; printLogs(); if ( !_continueOperation ) { cerr << "Unresolvable errors ... aborting" << endl; return false; } if ( _exitRequested ) { cerr << "Exit requested: abort" << endl; return false; } // Activate registration again DataModel::PublicObject::SetRegistrationEnabled(true); Sync syncTask(targetInv); _currentTask = &syncTask; if ( createNotifier ) DataModel::Notifier::SetEnabled(true); cerr << "Synchronising inventory ... " << flush; if ( syncTask.push(mergedInventory.get()) ) cerr << "done"; else cerr << "failed"; cerr << endl; if ( _exitRequested ) { cerr << "Exit requested: abort" << endl; return false; } if ( createNotifier ) DataModel::Notifier::SetEnabled(true); cerr << "Removing remaining objects ... " << flush; syncTask.cleanUp(); cerr << "done" << endl; // --- Check key files // Collect all station key files map<string,string> keyFiles; try { fs::path directory = SC_FS_PATH(_keydir); fs::directory_iterator it(directory); fs::directory_iterator dirEnd; for ( ; it != dirEnd; ++it ) { if ( fs::is_directory(SC_FS_IT_PATH(it)) ) continue; string name = SC_FS_IT_LEAF(it); if ( name.compare(0, 8, "station_") == 0 ) keyFiles[SC_FS_IT_LEAF(it)] = SC_FS_IT_STR(it); } } catch ( ... ) {} for ( size_t n = 0; n < mergedInventory->networkCount(); ++n ) { DataModel::Network *net = mergedInventory->network(n); for ( size_t s = 0; s < net->stationCount(); ++s ) { DataModel::Station *sta = net->station(s); string id = net->code() + "_" + sta->code(); string filename = "station_" + id; // Remove filename from keyFiles map<string,string>::iterator it = keyFiles.find(filename); if ( it != keyFiles.end() ) keyFiles.erase(it); } } // Warn about existing key files without a corresponding station // in inventory if ( !keyFiles.empty() ) { SEISCOMP_WARNING("Found %d key file%s without a corresponding " "station in inventory:", (int)keyFiles.size(), keyFiles.size() > 1?"s":""); for ( map<string,string>::iterator it = keyFiles.begin(); it != keyFiles.end(); ++it ) SEISCOMP_WARNING(" %s", it->second.c_str()); } DataModel::Notifier::SetEnabled(false); _currentTask = NULL; if ( _exitRequested ) { cerr << "Exit requested: abort" << endl; return false; } bool doSyncKeys = false; if ( createNotifier ) { DataModel::NotifierMessagePtr nmsg; size_t notifierCount = DataModel::Notifier::Size(); if ( notifierCount > 0 ) { cerr << notifierCount << " notifiers available" << endl; if ( !_output.empty() ) { IO::XMLArchive ar; if ( !ar.create(_output.c_str()) ) { cerr << "Failed to create output file: " << _output << endl; DataModel::Notifier::Clear(); return false; } cerr << "Generating output ... " << flush; ar.setFormattedOutput(true); nmsg = DataModel::Notifier::GetMessage(true); ar << nmsg; ar.close(); cerr << "done" << endl; } else if ( !testMode ) { // Notify about start of synchronization DataModel::InventorySyncMessagePtr ismsg = new DataModel::InventorySyncMessage(false); ismsg->setCreationInfo(DataModel::CreationInfo()); ismsg->creationInfo().setCreationTime(Core::Time::GMT()); ismsg->creationInfo().setAuthor(author()); ismsg->creationInfo().setAgencyID(agencyID()); connection()->send(Communication::Protocol::STATUS_GROUP, ismsg.get()); // Send an inital sync command to also wake-up the messaging sync(); // Send notifier DataModel::NotifierMessagePtr tmp = new DataModel::NotifierMessage(); DataModel::NotifierMessage::iterator it; int count = 0; // Fetch each single notifier message. Fetching all notifiers // in one message can take a long time if a huge amount of // notifiers is in the queue. Due to memory fragmentation // most of the time spent is in malloc. while ( (nmsg = DataModel::Notifier::GetMessage(false)) != NULL ) { if ( _exitRequested ) break; for ( it = nmsg->begin(); it != nmsg->end(); ++it ) { DataModel::Notifier* n = DataModel::Notifier::Cast(*it); if ( !n ) continue; tmp->attach(n); ++count; if ( count % 100 == 0 ) { cerr << "\rSending notifiers: " << (int)(count*100/notifierCount) << "%" << flush; if ( !send(tmp.get()) ) { SEISCOMP_ERROR("Failed to send message, abort"); return false; } tmp->clear(); sync(); } } } if ( !_exitRequested && !tmp->empty() ) { if ( !send(tmp.get()) ) { SEISCOMP_ERROR("Failed to send message, abort"); return false; } cerr << "\rSending notifiers: " << (int)(count*100/notifierCount) << "%" << flush; } cerr << endl; sync(); // Notify about end of synchronization ismsg->creationInfo().setCreationTime(Core::Time::GMT()); ismsg->isFinished = true; connection()->send(Communication::Protocol::STATUS_GROUP, ismsg.get()); doSyncKeys = true; } else { /* DataModel::NotifierMessage::iterator it; while ( (nmsg = DataModel::Notifier::GetMessage(false)) != NULL ) { for ( it = nmsg->begin(); it != nmsg->end(); ++it ) { DataModel::Notifier* n = DataModel::Notifier::Cast(*it); if ( !n ) continue; switch ( n->operation() ) { case DataModel::OP_ADD: cout << "+"; break; case DataModel::OP_REMOVE: cout << "-"; break; case DataModel::OP_UPDATE: cout << "M"; break; default: cout << "?"; break; } cout << " " << n->object()->className() << endl; } } */ DataModel::Notifier::Clear(); cout << "OK - synchronization test passed" << endl; } } else cerr << "Inventory is synchronised already, nothing to do" << endl; DataModel::Notifier::Clear(); } else { if ( _output.empty() ) _output = "-"; IO::XMLArchive ar; if ( !ar.create(_output.c_str()) ) { cerr << "Failed to create output file: " << _output << endl; return false; } cerr << "Generating output ... " << flush; ar.setFormattedOutput(true); ar << targetInv; ar.close(); cerr << "done" << endl; } if ( doSyncKeys ) { if ( !commandline().hasOption("no-rc") ) { if ( !syncRCFiles(targetInv) ) return false; } if ( !commandline().hasOption("no-keys") ) { bool syncKeys = true; try { syncKeys = configGetBool("syncKeys"); } catch (...) {} if ( syncKeys && !syncKeyFiles(targetInv) ) return false; } } return true; }
bool mergeInventory() { bool stripUnreferenced = commandline().hasOption("strip"); // Disable object registration DataModel::PublicObject::SetRegistrationEnabled(false); vector<string> files; collectFiles(files); if ( files.empty() ) { cerr << "Nothing to merge, no files given" << endl; return false; } DataModel::InventoryPtr finalInventory = new DataModel::Inventory(); Merge merger(finalInventory.get()); merger.setLogHandler(this); _continueOperation = true; _currentTask = &merger; for ( size_t i = 0; i < files.size(); ++i ) { if ( _exitRequested ) break; IO::XMLArchive ar; if ( !ar.open(files[i].c_str()) ) { cerr << "Could not open file (ignored): " << files[i] << endl; continue; } DataModel::InventoryPtr inv; cerr << "Parsing " << files[i] << " ... " << flush; ar >> inv; cerr << "done" << endl; if ( !inv ) { cerr << "No inventory found (ignored): " << files[i] << endl; continue; } _inventorySources[inv.get()] = files[i]; // Pushing the inventory into the merger cleans it // completely. The ownership of all childs went to // the merger merger.push(inv.get()); } _currentTask = NULL; if ( _exitRequested ) { cerr << "Exit requested: abort" << endl; return false; } cerr << "Merging inventory ... " << flush; merger.merge(stripUnreferenced); cerr << "done" << endl; printLogs(); if ( !_continueOperation ) { cerr << "Unresolvable errors ... aborting" << endl; return false; } if ( _output.empty() ) _output = "-"; IO::XMLArchive ar; if ( !ar.create(_output.c_str()) ) { cerr << "Failed to create output file: " << _output << endl; return false; } cerr << "Generating output ... " << flush; ar.setFormattedOutput(true); ar << finalInventory; ar.close(); cerr << "done" << endl; if ( !_rcdir.empty() ) { if ( !syncRCFiles(finalInventory.get()) ) return false; } return true; }
bool listNetworks() { // Disable object registration DataModel::PublicObject::SetRegistrationEnabled(false); vector<string> files; collectFiles(files); if ( files.empty() ) { cerr << "Nothing to merge, no files given" << endl; return false; } DataModel::InventoryPtr finalInventory = new DataModel::Inventory(); Merge merger(finalInventory.get()); _currentTask = &merger; for ( size_t i = 0; i < files.size(); ++i ) { if ( _exitRequested ) break; IO::XMLArchive ar; if ( !ar.open(files[i].c_str()) ) { cerr << "Could not open file (ignored): " << files[i] << endl; continue; } DataModel::InventoryPtr inv; cerr << "Parsing " << files[i] << " ... " << flush; ar >> inv; cerr << "done" << endl; if ( !inv ) { cerr << "No inventory found (ignored): " << files[i] << endl; continue; } _inventorySources[inv.get()] = files[i]; // Pushing the inventory into the merger cleans it // completely. The ownership of all childs went to // the merger merger.push(inv.get()); } _currentTask = NULL; if ( _exitRequested ) { cerr << "Exit requested: abort" << endl; return false; } cerr << "Merging inventory ... " << flush; merger.merge(false); cerr << "done" << endl; bool compact = commandline().hasOption("compact"); int level = 2; if ( _level == "net" ) level = 0; else if ( _level == "sta" ) level = 1; else if ( _level == "cha" ) level = 2; else if ( _level == "resp" ) level = 3; std::vector<DataModel::Network*> nets; for ( size_t n = 0; n < finalInventory->networkCount(); ++n ) nets.push_back(finalInventory->network(n)); sort(nets.begin(), nets.end(), lessID<DataModel::Network>); for ( size_t n = 0; n < nets.size(); ++n ) { DataModel::Network *net = nets[n]; if ( compact ) cout << net->code() << "\t" << epochToStr(net) << endl; else { cout << " network " << net->code(); if ( !net->description().empty() ) { cout << setfill(' ') << setw(8-net->code().size()) << ' '; cout << " " << net->description(); } cout << endl; cout << " epoch " << epochToStr(net) << endl; } std::vector<DataModel::Station*> stas; if ( level > 0 ) { for ( size_t s = 0; s < net->stationCount(); ++s ) stas.push_back(net->station(s)); } sort(stas.begin(), stas.end(), lessID<DataModel::Station>); for ( size_t s = 0; s < stas.size(); ++s ) { DataModel::Station *sta = stas[s]; if ( compact ) cout << " " << sta->code() << "\t" << epochToStr(sta) << endl; else { cout << " station " << sta->code(); if ( !sta->description().empty() ) { cout << setfill(' ') << setw(6-sta->code().size()) << ' '; cout << " " << sta->description(); } cout << endl; cout << " epoch " << epochToStr(sta) << endl; } std::vector<DataModel::SensorLocation*> locs; if ( level > 1 ) { for ( size_t l = 0; l < sta->sensorLocationCount(); ++l ) locs.push_back(sta->sensorLocation(l)); } sort(locs.begin(), locs.end(), lessID<DataModel::SensorLocation>); for ( size_t l = 0; l < locs.size(); ++l ) { DataModel::SensorLocation *loc = locs[l]; if ( compact ) { cout << " "; if ( loc->code().empty() ) cout << "__"; else cout << loc->code(); cout << "\t" << epochToStr(loc) << endl; } else { cout << " location "; if ( loc->code().empty() ) cout << "__"; else cout << loc->code(); cout << endl; cout << " epoch " << epochToStr(loc) << endl; } std::vector<DataModel::Stream*> streams; for ( size_t s = 0; s < loc->streamCount(); ++s ) streams.push_back(loc->stream(s)); sort(streams.begin(), streams.end(), lessID<DataModel::Stream>); for ( size_t s = 0; s < streams.size(); ++s ) { DataModel::Stream *str = streams[s]; if ( compact ) cout << " " << str->code() << "\t" << epochToStr(str) << endl; else { cout << " channel "; cout << str->code() << endl; cout << " epoch " << epochToStr(str) << endl; } if ( level >= 3 ) { const DataModel::Sensor *sens; const DataModel::Datalogger *dl; const DataModel::ResponsePAZ *paz; const DataModel::ResponsePolynomial *poly; const DataModel::ResponseFAP *fap; const DataModel::ResponseIIR *iir; try { int sr_num = str->sampleRateNumerator(); int sr_den = str->sampleRateDenominator(); cout << " rate " << sr_num << "/" << sr_den << " sps" << endl; } catch ( ... ) {} try { double gain = str->gain(); cout << " gain " << gain << endl; } catch ( ... ) {} try { double freq = str->gainFrequency(); cout << " freq " << freq << "Hz" << endl; } catch ( ... ) {} if ( !str->gainUnit().empty() ) cout << " unit " << str->gainUnit() << endl; sens = merger.findSensor(str->sensor()); if ( sens ) { cout << " sens " << sens->description() << endl; paz = merger.findPAZ(sens->response()); if ( paz ) { cout << " resp PAZ" << endl; cout << tabular(paz, 16) << endl; } else { poly = merger.findPoly(sens->response()); if ( poly ) { cout << " resp polynomial" << endl; cout << tabular(poly, 16) << endl; } else { fap = merger.findFAP(sens->response()); if ( fap ) { cout << " resp fap" << endl; cout << tabular(fap, 16) << endl; } else { iir = merger.findIIR(sens->response()); if ( iir ) { cout << " resp iir" << endl; cout << tabular(iir, 16) << endl; } } } } } dl = merger.findDatalogger(str->datalogger()); if ( dl ) { if ( !dl->description().empty() ) cout << " dl " << dl->description() << endl; else cout << " dl -" << endl; try { double gain = dl->gain(); cout << " gain " << gain << endl; } catch ( ... ) {} try { DataModel::Decimation *deci = dl->decimation(DataModel::DecimationIndex(str->sampleRateNumerator(), str->sampleRateDenominator())); if ( deci ) { cout << " dec " << str->sampleRateNumerator() << "/" << str->sampleRateDenominator() << " sps" << endl; cout << tabular(&merger, deci, 16) << endl; } } catch ( ... ) {} } } } } } } return true; }
bool applyNotifier() { DataModel::Inventory *targetInv = Client::Inventory::Instance()->inventory(); if ( targetInv == NULL ) { cerr << "No inventory to apply" << endl; return false; } // Disable object registration DataModel::PublicObject::SetRegistrationEnabled(false); vector<string> files; collectFiles(files); if ( files.empty() ) { cerr << "Nothing to apply, no files given" << endl; return false; } Sync syncTask(targetInv); _currentTask = &syncTask; for ( size_t i = 0; i < files.size(); ++i ) { if ( _exitRequested ) break; IO::XMLArchive ar; if ( !ar.open(files[i].c_str()) ) { cerr << "Could not open file (ignored): " << files[i] << endl; continue; } cerr << "Parsing " << files[i] << " ... " << flush; DataModel::NotifierMessagePtr msg; ar >> msg; cerr << "done" << endl; if ( !msg ) { cerr << "No notifier message found (ignored): " << files[i] << endl; continue; } size_t notifierCount = msg->size(); cerr << notifierCount << " notifiers available" << endl; if ( !_output.empty() ) { cerr << "Applying notifier ... " << flush; // Apply all notifier DataModel::NotifierMessage::iterator it; for ( it = msg->begin(); it != msg->end(); ++it ) { DataModel::Notifier* n = DataModel::Notifier::Cast(*it); if ( !n ) continue; n->apply(); } cerr << "done" << endl; } else { // Send all notifier // Send an inital sync command to also wake-up the messaging sync(); // Send notifier DataModel::NotifierMessagePtr tmp = new DataModel::NotifierMessage(); DataModel::NotifierMessage::iterator it; int count = 0; for ( it = msg->begin(); it != msg->end(); ++it ) { DataModel::Notifier* n = DataModel::Notifier::Cast(*it); if ( !n ) continue; tmp->attach(n); ++count; if ( count % 100 == 0 ) { cerr << "\rSending notifiers: " << (int)(count*100/notifierCount) << "%" << flush; if ( !send(tmp.get()) ) { SEISCOMP_ERROR("Failed to send message, abort"); return false; } tmp->clear(); sync(); } } sync(); if ( !tmp->empty() ) { if ( !send(tmp.get()) ) { SEISCOMP_ERROR("Failed to send message, abort"); return false; } cerr << "\rSending notifiers: " << (int)(count*100/notifierCount) << "%" << flush; } } } if ( _exitRequested ) { cerr << "Exit requested: abort" << endl; return false; } if ( !_output.empty() ) { IO::XMLArchive ar; if ( !ar.create(_output.c_str()) ) { cerr << "Failed to create output file: " << _output << endl; return false; } cerr << "Generating output ... " << flush; ar.setFormattedOutput(true); ar << targetInv; ar.close(); cerr << "done" << endl; } return true; }
bool syncKeys() { // Disable object registration DataModel::PublicObject::SetRegistrationEnabled(false); // Disable notifier check DataModel::Notifier::SetCheckEnabled(false); vector<string> files; collectFiles(files); if ( _filebase.empty() && files.empty() ) { cerr << "Nothing to merge, no files given" << endl; return false; } DataModel::InventoryPtr mergedInventory = new DataModel::Inventory(); Merge merger(mergedInventory.get()); merger.setLogHandler(this); _continueOperation = true; _currentTask = &merger; DataModel::Notifier::SetEnabled(false); for ( size_t i = 0; i < files.size(); ++i ) { if ( _exitRequested ) break; IO::XMLArchive ar; if ( !ar.open(files[i].c_str()) ) { cerr << "Could not open file (ignored): " << files[i] << endl; continue; } DataModel::InventoryPtr inv; cerr << "Parsing " << files[i] << " ... " << flush; ar >> inv; cerr << "done" << endl; if ( !inv ) { cerr << "No inventory found (ignored): " << files[i] << endl; continue; } _inventorySources[inv.get()] = files[i]; // Pushing the inventory into the merger cleans it // completely. The ownership of all childs goes to // the merger merger.push(inv.get()); } _currentTask = NULL; if ( _exitRequested ) { cerr << "Exit requested: abort" << endl; return false; } cerr << "Merging inventory ... " << flush; merger.merge(false); cerr << "done" << endl; printLogs(); if ( !_continueOperation ) { cerr << "Unresolvable errors ... aborting" << endl; return false; } _currentTask = NULL; if ( _exitRequested ) { cerr << "Exit requested: abort" << endl; return false; } return syncKeyFiles(mergedInventory.get()); }
bool checkInventory() { _conflicts = _errors = _warnings = _unresolved = 0; // Disable object registration DataModel::PublicObject::SetRegistrationEnabled(false); vector<string> files; collectFiles(files); if ( files.empty() ) { cerr << "Nothing to merge, no files given" << endl; return false; } DataModel::InventoryPtr finalInventory = new DataModel::Inventory(); Merge merger(finalInventory.get()); merger.setLogHandler(this); _continueOperation = true; _currentTask = &merger; for ( size_t i = 0; i < files.size(); ++i ) { if ( _exitRequested ) break; IO::XMLArchive ar; if ( !ar.open(files[i].c_str()) ) { cerr << "Could not open file (ignored): " << files[i] << endl; continue; } DataModel::InventoryPtr inv; cerr << "Parsing " << files[i] << " ... " << flush; ar >> inv; cerr << "done" << endl; if ( !inv ) { cerr << "No inventory found (ignored): " << files[i] << endl; continue; } _inventorySources[inv.get()] = files[i]; // Pushing the inventory into the merger cleans it // completely. The ownership of all childs went to // the merger merger.push(inv.get()); } _currentTask = NULL; if ( _exitRequested ) { cerr << "Exit requested: abort" << endl; return false; } cerr << "Merging inventory ... " << flush; merger.merge(false); cerr << "done" << endl; Check checker(finalInventory.get()); checker.setLogHandler(this); cerr << "Checking inventory ... " << flush; checker.check(); cerr << "done" << endl; printLogs(cout); if ( _conflicts > 0 ) cerr << _conflicts << " conflict" << (_conflicts == 1?"":"s") << endl; if ( _unresolved > 0 ) cerr << _unresolved << " unresolved reference" << (_unresolved == 1?"":"s") << endl; if ( _errors > 0 ) cerr << _errors << " error" << (_errors == 1?"":"s") << endl; if ( _warnings > 0 ) cerr << _warnings << " warning" << (_warnings == 1?"":"s") << endl; return _conflicts == 0 && _errors == 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; }