9 #include "PipelineApplication.h"
11 #include "IException.h"
12 #include "Application.h"
33 if(p_pipeline->OriginalBranches().size() == 1) {
34 p_inBranches.push_back(
"");
35 p_outBranches.push_back(
"");
36 p_enableBranch.push_back(
true);
40 p_outBranches = p_pipeline->OriginalBranches();
41 for(
int i=0; i<(int)p_outBranches.size(); i++) {
42 p_enableBranch.push_back(
true);
58 p_previous = previous;
62 p_inBranches = p_previous->OutputBranches();
63 p_outBranches = p_previous->OutputBranches();
64 for(
int i=0; i<(int)p_outBranches.size(); i++) {
65 p_enableBranch.push_back(
true);
67 p_previous->SetNext(
this);
82 p_supportsVirtualBands = supportsVirtualBands;
97 if(value == LastAppOutputList) {
99 p_outBranches.clear();
100 p_outBranches.push_back(
"");
102 else if(value == LastAppOutputListNoMerge) {
104 value = LastAppOutputList;
108 p_supportsVirtualBands = supportsVirtualBands;
123 const QString &outNameModifier,
const QString &outFileExtension) {
124 p_output.push_back(
PipelineParameter(FindBranch(branch,
false), outputParamName));
125 p_outputMod = outNameModifier;
126 p_outputExtension = outFileExtension;
140 p_outputMod = outNameModifier;
141 p_outputExtension = outFileExtension;
164 if(modString ==
"") {
165 string msg =
"Can not add empty branch to pipeline";
174 if(p_outBranches[0] ==
"") {
175 p_outBranches.clear();
176 p_enableBranch.clear();
179 if(p_inBranches.size() == 1) {
180 p_outBranches.push_back(modString);
181 p_enableBranch.push_back(
true);
183 else if(p_inBranches.size() == p_outBranches.size()) {
184 for(
int outBranch = p_outBranches.size() - 1; outBranch >= 0; outBranch --) {
185 if(p_inBranches[outBranch] == p_outBranches[outBranch]) {
186 p_outBranches[outBranch] = p_inBranches[outBranch] +
"." + modString;
189 p_outBranches.push_back(p_inBranches[outBranch] +
"." + modString);
190 p_enableBranch.push_back(
true);
195 for(
unsigned int inBranch = 0; inBranch < p_inBranches.size(); inBranch ++) {
196 p_outBranches.push_back(p_inBranches[inBranch] +
"." + modString);
197 p_enableBranch.push_back(
true);
247 for(
unsigned int i = 0; !added && i < p_params.size(); i++) {
248 if(p_params[i].Name() == appParamName) {
271 p_params.push_back(
PipelineParameter(FindBranch(branch,
false), appParamName, appParamValue));
296 p_params.push_back(
PipelineParameter(FindBranch(branch,
false), appParamName, value));
309 p_paramString.clear();
313 if(!Enabled())
return;
317 bool needList =
false;
320 bool runOnce = Merges() && !Branches();
333 if(!runOnce && p_input.size() == 1) {
338 for(
int param = 0; param < (int)p_params.size() && runOnce; param++) {
339 runOnce = (p_params[param].IsSpecial() && p_params[param].Special() == LastAppOutputList) ||
340 (!p_params[param].
IsSpecial() && p_params[param].AffectsAllBranches());
346 for(
int branch = 0; branch < (int)p_inBranches.size(); branch ++) {
347 if(runOnce && branch > 0) {
351 if(!BranchEnabled(branch)) {
352 QString tmpBranch(branch);
353 p_outputs.push_back(p_name +
"." +tmpBranch +
".blank");
359 QString inputFile = CalculateInputFile(branch);
361 QString outputFile = CalculateOutputFile(branch);
370 needList = (inputParam.
IsSpecial() && inputParam.
Special() == LastAppOutputList);
372 for(
int param = 0; param < (int)p_params.size() && !needList; param++) {
373 needList = (p_params[param].IsSpecial() && p_params[param].Special() == LastAppOutputList);
379 QString listName = outputFile;
381 if(listName.isEmpty()) {
388 QString input = p_pipeline->TemporaryFolder() +
"/" +
FileName(listName).
baseName() +
".lis";
389 params =
">>LIST " + input +
" ";
393 while(prev != NULL && infile < (
int)p_inBranches.size()) {
403 p_tempFiles.push_back(input);
404 p_paramString.push_back(params);
412 params = GetInputParameter(branch).
Name() +
"=\"" + listFile +
"\"";
417 params = GetInputParameter(branch).Name() +
"=\"" + inputFile;
418 if(p_virtualBands.size() == 1) {
419 params +=
"+" + p_virtualBands[0];
421 else if(p_virtualBands.size() == p_inBranches.size() && !p_virtualBands[branch].isEmpty()) {
422 params +=
"+" + p_virtualBands[branch];
429 if(p_output.size() != 0) {
430 if(Branches() && p_output.size() != 1) {
432 for(
unsigned int outBranch = 0; outBranch < p_outBranches.size(); outBranch ++) {
434 bool outputSet =
false;
437 if(p_inBranches.size() > 1) {
438 if(!StringStartsWith(p_outBranches[outBranch], p_inBranches[branch])) {
444 for(
unsigned int outParam = 0; outParam < p_output.size(); outParam++) {
445 if(p_output[outParam].AppliesToBranch(outBranch)) {
446 params +=
" " + p_output[outParam].Name() +
"=\"" + p_outputs[outBranch] +
"\"";
449 QString message =
"Application [" + Name() +
"] in the pipeline branches with an ";
450 message +=
"output parameter for each branch, but branch [" + p_outBranches[outBranch];
451 message +=
"] has multiple output files specified.";
460 QString message =
"Application [" + Name() +
"] in the pipeline branches with an ";
461 message +=
"output parameter for each branch, but branch [" + p_outBranches[outBranch];
462 message +=
"] has no output files specified.";
468 bool foundBranch =
false;
471 for(
unsigned int outputParam = 0; outputParam < p_output.size(); outputParam++) {
472 if(p_output[outputParam].AppliesToBranch(branch)) {
473 params +=
" " + p_output[0].Name() +
"=\"" + outputFile +
"\"";
478 if(!foundBranch)
continue;
483 for(
int i = 0; i < (int)p_params.size() && i < (int)p_params.size(); i++) {
484 if(p_params[i].AppliesToBranch(branch)) {
486 params +=
" " + p_params[i].Name() +
"=\"" + p_params[i].Value() +
"\"";
488 else if(p_params[i].Special() == LastOutput) {
489 params +=
" " + p_params[i].Name() +
"=\"" + GetRealLastOutput(
true) +
"\"";
491 else if(p_params[i].Special() == LastAppOutputList) {
492 params +=
" " + p_params[i].Name() +
"=\"" + listFile +
"\"";
497 if(inputFile.isEmpty()) {
498 QString message =
"There was a problem with calculating the inputs for program [" + Name();
499 message +=
"]. Please verify your program is not setting outputs for branches that ";
500 message +=
"don't have input.";
505 p_paramString.push_back(params);
530 while (prev != NULL && file==
"") {
533 string msg =
"Application branches but branch is disabled";
563 file = p_pipeline->OriginalInput(branch);
564 if (file.isEmpty()) {
565 int index = branch / (p_pipeline->OriginalBranchesSize() / p_pipeline->OriginalInputSize());
566 file = p_pipeline->OriginalInput(index);
571 for(
int i = 0; i < (int)p_input.size(); i++) {
572 if(p_input[i].AppliesToBranch(branch) && p_input[i].IsSpecial()) {
573 if(p_input[i].Special() == LastOutput) {
574 file = GetRealLastOutput();
592 QString outFolder = p_pipeline->TemporaryFolder();
596 bool usedBranch =
false;
597 unsigned int usedBranchIndex = 0;
598 unsigned int numUsedBranches = 0;
600 for(
unsigned int outputBranch = 0; outputBranch < p_outBranches.size(); outputBranch++) {
601 bool outBranchUsed =
false;
603 for(
unsigned int outputParam = 0; outputParam < p_output.size(); outputParam ++) {
604 if(p_output[outputParam].AppliesToBranch(outputBranch)) {
605 outBranchUsed =
true;
610 if(outputBranch < (
unsigned int)branch) {
614 if((
unsigned int)branch == outputBranch) {
622 if(!usedBranch)
return "";
624 if(!LastApplicationWithOutput()) {
625 QString lastOutput = p_pipeline->FinalOutput(branch,
false);
626 outputFile = outFolder +
"/" +
627 FileName(lastOutput).
baseName() +
"." + p_outputMod +
"." + p_outputExtension;
629 if(p_outputMod.isEmpty()) {
630 outputFile = outFolder +
"/" +
635 outputFile = p_pipeline->FinalOutput(branch, numUsedBranches > 1);
639 if(!LastApplicationWithOutput() && numUsedBranches != 1 && !p_outputMod.isEmpty()) {
642 QString realOut(outFolder +
"/" + outfile.
baseName() +
"." + p_outBranches[branch] +
"." + p_outputExtension);
647 if(p_outputs.size() == usedBranchIndex) {
648 p_outputs.push_back(realOut);
654 if(branch == 0 && Branches()) {
655 for(
unsigned int i = 1; i < OutputBranches().size(); i++) {
656 CalculateOutputFile(i);
665 outputFile = realOut;
669 else if(!p_outputMod.isEmpty()) {
670 if(p_outputs.size() == usedBranchIndex) {
671 p_outputs.push_back(outputFile);
677 if(branch == 0 && Branches()) {
678 for(
unsigned int i = 1; i < OutputBranches().size(); i++) {
679 CalculateOutputFile(i);
695 if(!Next() && !p_output.empty()) {
698 if(!Next() && p_output.empty()) {
703 return !Next()->FutureOutputFileCreated();
714 if(!p_output.empty()) {
718 if(!Next() && p_output.empty()) {
722 return Next()->FutureOutputFileCreated();
734 for(
int i = 0; i < (int)p_input.size(); i++) {
735 if(p_input[i].AppliesToBranch(branch)) {
740 if(p_inBranches[0] !=
"") {
741 QString msg =
"Application [" + Name() +
"] in the pipeline does not have an input for branch [" + p_inBranches[branch] +
"]";
745 QString msg =
"Application [" + Name() +
"] in the pipeline does not have an input";
764 while(!found && branchIndex < (
int)p_inBranches.size()) {
765 if(p_inBranches[branchIndex] == name) {
774 while(!found && branchIndex < (
int)p_outBranches.size()) {
775 if(p_outBranches[branchIndex] == name) {
785 QString msg =
"Branch [" + name +
"] does not exist in the pipeline application [" + Name() +
"]";
802 if(!LastApplicationWithOutput()) {
803 for(
int i = 0; i < (int)p_outputs.size(); i++) {
804 tmp.push_back(p_outputs[i]);
808 for(
int i = 0; i < (int)p_tempFiles.size(); i++) {
809 tmp.push_back(p_tempFiles[i]);
827 return GetOutputs()[GetOutputs().size()-1];
830 if(p_outputs.size() > 1) {
831 return GetOutputs()[GetOutputs().size()-2];
834 return Previous()->GetOutputs()[Previous()->GetOutputs().size()-1];
845 if(!Enabled())
return false;
846 return p_supportsVirtualBands;
857 p_virtualBands = bands;
862 if(Enabled() && p_outputs.size() != 0) {
865 else if(Previous()) {
866 return Previous()->GetOutputs();