TEST_F(AnalysisDriverFixture,SimpleProject_EditProblemWithTwoWorkflows) { // Written to reproduce Bug 1189 { // Create PAT project with an IDF measure SimpleProject project = getCleanPATProject("SimpleProject_EditProblemWithTwoWorkflows"); Problem problem = project.analysis().problem(); OptionalInt index = problem.getWorkflowStepIndexByJobType(JobType::EnergyPlusPreProcess); ASSERT_TRUE(index); MeasureGroup dv("Idf Measure",MeasureVector(1u,NullMeasure())); problem.insert(*index,dv); BOOST_FOREACH(const BCLMeasure& measure,BCLMeasure::patApplicationMeasures()) { if (measure.inputFileType() == FileReferenceType::IDF) { RubyMeasure measure(measure); dv.push(measure); break; } } project.save(); ProjectDatabase database = project.projectDatabase(); RunManager runManager = project.runManager(); WorkflowRecordVector workflowRecords = WorkflowRecord::getWorkflowRecords(database); EXPECT_EQ(2u,workflowRecords.size()); BOOST_FOREACH(const WorkflowRecord& wr,workflowRecords) { EXPECT_NO_THROW(runManager.loadWorkflow(wr.runManagerWorkflowKey())); } }
std::vector<WorkflowRecord> ProblemRecord_Impl::workflowRecords() const { WorkflowRecordVector result; ProjectDatabase database = projectDatabase(); QSqlQuery query(*(database.qSqlDatabase())); query.prepare(toQString("SELECT * FROM " + WorkflowRecord::databaseTableName() + " WHERE problemRecordId=:problemRecordId ORDER BY workflowIndex")); query.bindValue(":problemRecordId",id()); assertExec(query); OptionalInt previousIndex; bool resort(false); while (query.next()) { result.push_back(WorkflowRecord::factoryFromQuery(query, database).get()); int index = result.back().workflowIndex(); if (previousIndex) { if (index < previousIndex.get()) { resort = true; } } previousIndex = index; } if (resort) { WorkflowRecordWorkflowIndexLess comparator; std::sort(result.begin(),result.end(),comparator); } return result; }
analysis::Problem ProblemRecord_Impl::problem() const { InputVariableRecordVector inputVariableRecords = this->inputVariableRecords(); WorkflowRecordVector workflowRecords = this->workflowRecords(); analysis::WorkflowStepVector workflow; // mesh InputVariables and WorkItems together to form overall workflow int ivrIndex(0); // index into input variable records int wrIndex(0); // index into workflow records int wIndex(0); // index into workflow int ivrN = inputVariableRecords.size(); int wrN = workflowRecords.size(); OptionalInt ivrWIndex; // saved index into workflow for next input variable OptionalInt wrWIndex; // saved index into workflow for next workflow record if (!inputVariableRecords.empty()) { ivrWIndex = inputVariableRecords[ivrIndex].variableVectorIndex(); } if (!workflowRecords.empty()) { wrWIndex = workflowRecords[wrIndex].workflowIndex(); } for (int i = 0, n = ivrN + wrN; i < n; ++i) { if (!wrWIndex || (ivrWIndex && (*ivrWIndex < *wrWIndex))) { // InputVariable is next BOOST_ASSERT(*ivrWIndex == wIndex); // saved and expected index into workflow match BOOST_ASSERT(ivrIndex < ivrN); // there is an input variable record to deserialize workflow.push_back(WorkflowStep(inputVariableRecords[ivrIndex].inputVariable())); ++ivrIndex; // go to next input variable record ++wIndex; // and next index into workflow BOOST_ASSERT(wIndex == int(workflow.size())); // next index into workflow should match current size if (ivrIndex < ivrN) { ivrWIndex = inputVariableRecords[ivrIndex].variableVectorIndex(); } else { ivrWIndex.reset(); // no more input variables to deserialize } } else { // Workflow is next BOOST_ASSERT(wrWIndex); int temp = *wrWIndex; // for debugging BOOST_ASSERT(temp == wIndex); // saved index into workflow should match expected value BOOST_ASSERT(wrIndex < wrN); // there is a workflow record to deserialize std::vector<runmanager::WorkItem> workItems = workflowRecords[wrIndex].workflow().toWorkItems(); workflow.insert(workflow.end(),workItems.begin(),workItems.end()); ++wrIndex; // go to next workflow record wIndex += workItems.size(); // update next expected workflow index BOOST_ASSERT(wIndex == int(workflow.size())); // next index into workflow should match current size if (wrIndex < wrN) { wrWIndex = workflowRecords[wrIndex].workflowIndex(); } else { wrWIndex.reset(); // no more workflow records to deserialize } } } analysis::FunctionVector responses; FunctionRecordVector responseRecords = this->responseRecords(); BOOST_FOREACH(const FunctionRecord responseRecord,responseRecords) { responses.push_back(responseRecord.function()); }