void KNMusicLyricsDownloader::onReplyFinished(QNetworkReply *reply) { //Check the reply data in the reply map. if(!m_replyMap.contains(reply)) { //Ignore the reply which is not in the map (cancelled reply). return; } //Pick out the hash data of the identifier. KNMusicRequestData &&requestData=m_replyMap.take(reply); uint identifier=requestData.identifier; //Get the request source struct. KNMusicLyricsRequestSource requestSource=m_sourceMap.value(identifier); //Check the current step data. KNMusicLyricsStep ¤tStep=requestSource.currentStep; if(!currentStep.replies.contains(reply)) { //Ignore the reply, the reply should be cancelled. return; } //Read all the data from the reply. KNMusicReplyData replyData; replyData.result=reply->readAll(); replyData.user=requestData.user; currentStep.replyCaches.append(replyData); //Remove the reply from the list. currentStep.replies.removeOne(reply); //Reduce the count. --currentStep.replyCount; //Check the reply list size, when all the reply has arrived. if(currentStep.replyCount==0) { //Stop the counter. m_timeoutCounter->stop(); //Increase the step index. ++currentStep.currentStep; //Save the reply caches. QList<KNMusicReplyData> replyResults=currentStep.replyCaches; //Clear the reply caches. currentStep.replyCaches=QList<KNMusicReplyData>(); //Update the request source. m_sourceMap.insert(identifier, requestSource); //Move to next step, however, this will be the responsibility of the //specific downloader. processStep(identifier, currentStep.currentStep, replyResults); } else { //Simply update the request source. m_sourceMap.insert(identifier, requestSource); } }
void run(Options& opts) { copyAllFiles(opts); ImageIO imageIO(opts); if (!imageIO.Good) { std::cerr << "Unable to process input folder structure. Terminating." << std::endl; exit(1); } for (auto& volumeIO: imageIO.Volumes) { std::cout << "Finding events on Volume: " << volumeIO->Name << std::endl; imageIO.SqliteHelper.beginTransaction(); for (auto& snapshotIO: volumeIO->Snapshots) { std::cout << "Parsing input files for snapshot: " << snapshotIO->Name << std::endl; processStep(*snapshotIO, opts.extra); std::cout << std::endl; } imageIO.SqliteHelper.endTransaction(); imageIO.SqliteHelper.beginTransaction(); std::cout << std::endl << "Generating unified events output..." << std::endl; volumeIO->Events << Event::getColumnHeaders(); std::vector<SnapshotIOPtr>::reverse_iterator rIt; for (rIt = volumeIO->Snapshots.rbegin(); rIt != volumeIO->Snapshots.rend(); ++rIt) { std::cout << "Processing events from snapshot: " << (*rIt)->Name << std::endl; processFinalize(**rIt); } imageIO.SqliteHelper.endTransaction(); } imageIO.SqliteHelper.close(); std::cout << std::endl; std::cout << imageIO.getSummary() << std::endl; std::cout << "Process complete." << std::endl; }
bool CCrossSectionTask::process(const bool & useInitialValues) { processStart(useInitialValues); //this instructs the process queue to call back whenever an event is //executed mpCrossSectionProblem->getModel()->getMathModel()->getProcessQueue().setEventCallBack(this, &EventCallBack); mPreviousCrossingTime = std::numeric_limits< C_FLOAT64 >::quiet_NaN(); mPeriod = std::numeric_limits< C_FLOAT64 >::quiet_NaN(); mAveragePeriod = std::numeric_limits< C_FLOAT64 >::quiet_NaN(); mLastPeriod = std::numeric_limits< C_FLOAT64 >::quiet_NaN(); mPeriodicity = -1; mLastFreq = std::numeric_limits< C_FLOAT64 >::quiet_NaN(); mFreq = std::numeric_limits< C_FLOAT64 >::quiet_NaN(); mAverageFreq = std::numeric_limits< C_FLOAT64 >::quiet_NaN(); C_FLOAT64 MaxDuration = mpCrossSectionProblem->getDuration(); //the output starts only after "outputStartTime" has passed if (mpCrossSectionProblem->getFlagLimitOutTime()) { mOutputStartTime = *mpCurrentTime + mpCrossSectionProblem->getOutputStartTime(); MaxDuration += mpCrossSectionProblem->getOutputStartTime(); } else { mOutputStartTime = *mpCurrentTime; } const C_FLOAT64 EndTime = *mpCurrentTime + MaxDuration; mStartTime = *mpCurrentTime; // It suffices to reach the end time within machine precision C_FLOAT64 CompareEndTime = mOutputStartTime - 100.0 * (fabs(EndTime) * std::numeric_limits< C_FLOAT64 >::epsilon() + std::numeric_limits< C_FLOAT64 >::min()); if (mpCrossSectionProblem->getFlagLimitCrossings()) mMaxNumCrossings = mpCrossSectionProblem->getCrossingsLimit(); else mMaxNumCrossings = 0; if (mpCrossSectionProblem->getFlagLimitOutCrossings()) mOutputStartNumCrossings = mpCrossSectionProblem->getOutCrossingsLimit(); else mOutputStartNumCrossings = 0; output(COutputInterface::BEFORE); bool flagProceed = true; mProgressFactor = 100.0 / (MaxDuration + mpCrossSectionProblem->getOutputStartTime()); mProgressValue = 0; if (mpCallBack != NULL) { mpCallBack->setName("performing simulation..."); mProgressMax = 100.0; mhProgress = mpCallBack->addItem("Completion", mProgressValue, &mProgressMax); } mState = TRANSIENT; mStatesRingCounter = 0; mNumCrossings = 0; try { do { flagProceed &= processStep(EndTime); } while ((*mpCurrentTime < CompareEndTime) && flagProceed); } catch (int) { mpCrossSectionProblem->getModel()->setState(*mpCurrentState); mpCrossSectionProblem->getModel()->updateSimulatedValues(mUpdateMoieties); finish(); CCopasiMessage(CCopasiMessage::EXCEPTION, MCTrajectoryMethod + 16); } catch (CCopasiException & Exception) { mpCrossSectionProblem->getModel()->setState(*mpCurrentState); mpCrossSectionProblem->getModel()->updateSimulatedValues(mUpdateMoieties); finish(); throw CCopasiException(Exception.getMessage()); } finish(); return true; }
bool CTSSATask::process(const bool & useInitialValues) { //***** processStart(useInitialValues); //***** C_FLOAT64 StepSize = mpTSSAProblem->getStepSize(); C_FLOAT64 NextTimeToReport; const C_FLOAT64 EndTime = *mpCurrentTime + mpTSSAProblem->getDuration(); const C_FLOAT64 StartTime = *mpCurrentTime; C_FLOAT64 StepNumber = (mpTSSAProblem->getDuration()) / StepSize; bool (*LE)(const C_FLOAT64 &, const C_FLOAT64 &); bool (*L)(const C_FLOAT64 &, const C_FLOAT64 &); if (StepSize < 0.0) { LE = &tble; L = &tbl; } else { LE = &tfle; L = &tfl; } unsigned C_INT32 StepCounter = 1; C_FLOAT64 outputStartTime = mpTSSAProblem->getOutputStartTime(); if (StepSize == 0.0 && mpTSSAProblem->getDuration() != 0.0) { CCopasiMessage(CCopasiMessage::ERROR, MCTSSAProblem + 1, StepSize); return false; } output(COutputInterface::BEFORE); bool flagProceed = true; C_FLOAT64 handlerFactor = 100.0 / mpTSSAProblem->getDuration(); C_FLOAT64 Percentage = 0; unsigned C_INT32 hProcess; if (mpCallBack) { mpCallBack->setName("performing simulation..."); C_FLOAT64 hundred = 100; hProcess = mpCallBack->addItem("Completion", CCopasiParameter::DOUBLE, &Percentage, &hundred); } if ((*LE)(outputStartTime, *mpCurrentTime)) output(COutputInterface::DURING); try { do { // This is numerically more stable then adding // mpTSSAProblem->getStepSize(). NextTimeToReport = StartTime + (EndTime - StartTime) * StepCounter++ / StepNumber; flagProceed &= processStep(NextTimeToReport); if (mpCallBack) { Percentage = (*mpCurrentTime - StartTime) * handlerFactor; flagProceed &= mpCallBack->progressItem(hProcess); } if ((*LE)(outputStartTime, *mpCurrentTime)) { output(COutputInterface::DURING); } } while ((*L)(*mpCurrentTime, EndTime) && flagProceed); } catch (int) { mpTSSAProblem->getModel()->setState(*mpCurrentState); mpTSSAProblem->getModel()->updateSimulatedValues(true); if ((*LE)(outputStartTime, *mpCurrentTime)) { output(COutputInterface::DURING); } if (mpCallBack) mpCallBack->finishItem(hProcess); output(COutputInterface::AFTER); CCopasiMessage(CCopasiMessage::EXCEPTION, MCTSSAMethod + 4); } catch (CCopasiException Exception) { mpTSSAProblem->getModel()->setState(*mpCurrentState); mpTSSAProblem->getModel()->updateSimulatedValues(true); if ((*LE)(outputStartTime, *mpCurrentTime)) { output(COutputInterface::DURING); } if (mpCallBack) mpCallBack->finishItem(hProcess); output(COutputInterface::AFTER); throw CCopasiException(Exception.getMessage()); } if (mpCallBack) mpCallBack->finishItem(hProcess); output(COutputInterface::AFTER); return true; }
bool CTrajectoryTask::process(const bool & useInitialValues) { //***** processStart(useInitialValues); //***** //size_t FailCounter = 0; C_FLOAT64 Duration = mpTrajectoryProblem->getDuration(); C_FLOAT64 StepSize = mpTrajectoryProblem->getStepSize(); C_FLOAT64 StepNumber = fabs(Duration) / StepSize; if (isnan(StepNumber) || StepNumber < 1.0) StepNumber = 1.0; //the output starts only after "outputStartTime" has passed if (useInitialValues) mOutputStartTime = mpTrajectoryProblem->getOutputStartTime(); else mOutputStartTime = *mpCurrentTime + mpTrajectoryProblem->getOutputStartTime(); C_FLOAT64 NextTimeToReport; const C_FLOAT64 EndTime = *mpCurrentTime + Duration; const C_FLOAT64 StartTime = *mpCurrentTime; C_FLOAT64 CompareEndTime; if (StepSize < 0.0) { mpLessOrEqual = &ble; mpLess = &bl; // It suffices to reach the end time within machine precision CompareEndTime = EndTime + 100.0 * (fabs(EndTime) * std::numeric_limits< C_FLOAT64 >::epsilon() + std::numeric_limits< C_FLOAT64 >::min()); } else { mpLessOrEqual = &fle; mpLess = &fl; // It suffices to reach the end time within machine precision CompareEndTime = EndTime - 100.0 * (fabs(EndTime) * std::numeric_limits< C_FLOAT64 >::epsilon() + std::numeric_limits< C_FLOAT64 >::min()); } unsigned C_INT32 StepCounter = 1; if (StepSize == 0.0 && Duration != 0.0) { CCopasiMessage(CCopasiMessage::ERROR, MCTrajectoryProblem + 1, StepSize); return false; } output(COutputInterface::BEFORE); bool flagProceed = true; C_FLOAT64 handlerFactor = 100.0 / Duration; C_FLOAT64 Percentage = 0; size_t hProcess; if (mpCallBack != NULL && StepNumber > 1.0) { mpCallBack->setName("performing simulation..."); C_FLOAT64 hundred = 100; hProcess = mpCallBack->addItem("Completion", Percentage, &hundred); } if ((*mpLessOrEqual)(mOutputStartTime, *mpCurrentTime)) output(COutputInterface::DURING); try { do { // This is numerically more stable then adding // mpTrajectoryProblem->getStepSize(). NextTimeToReport = StartTime + (EndTime - StartTime) * StepCounter++ / StepNumber; flagProceed &= processStep(NextTimeToReport); if (mpCallBack != NULL && StepNumber > 1.0) { Percentage = (*mpCurrentTime - StartTime) * handlerFactor; flagProceed &= mpCallBack->progressItem(hProcess); } if ((*mpLessOrEqual)(mOutputStartTime, *mpCurrentTime)) { output(COutputInterface::DURING); } } while ((*mpLess)(*mpCurrentTime, CompareEndTime) && flagProceed); } catch (int) { mpTrajectoryProblem->getModel()->setState(*mpCurrentState); mpTrajectoryProblem->getModel()->updateSimulatedValues(mUpdateMoieties); if ((*mpLessOrEqual)(mOutputStartTime, *mpCurrentTime)) { output(COutputInterface::DURING); } if (mpCallBack != NULL && StepNumber > 1.0) mpCallBack->finishItem(hProcess); output(COutputInterface::AFTER); CCopasiMessage(CCopasiMessage::EXCEPTION, MCTrajectoryMethod + 16); } catch (CCopasiException & Exception) { mpTrajectoryProblem->getModel()->setState(*mpCurrentState); mpTrajectoryProblem->getModel()->updateSimulatedValues(mUpdateMoieties); if ((*mpLessOrEqual)(mOutputStartTime, *mpCurrentTime)) { output(COutputInterface::DURING); } if (mpCallBack != NULL && StepNumber > 1.0) mpCallBack->finishItem(hProcess); output(COutputInterface::AFTER); throw CCopasiException(Exception.getMessage()); } if (mpCallBack != NULL && StepNumber > 1.0) mpCallBack->finishItem(hProcess); output(COutputInterface::AFTER); return true; }