32 p_procAppName = procAppName;
33 p_addedCubeatt =
false;
34 p_outputListNeedsModifiers =
false;
44 for (
int i = 0; i < (int)p_apps.size(); i++) {
65 if (p_apps.size() == 0)
return;
68 bool successfulPrepare =
false;
70 while (!successfulPrepare) {
72 successfulPrepare =
true;
73 bool foundFirst =
false;
76 bool mustElimBands =
false;
79 for (
unsigned int i = 0; i < p_virtualBands.size(); i++) {
80 mustElimBands |= !p_virtualBands[i].isEmpty();
84 vector<QString> tmpFiles;
89 for (
int i = 0; i < (int)p_apps.size() && successfulPrepare; i++) {
90 if (p_apps[i] == NULL)
continue;
91 if (mustElimBands && p_apps[i]->SupportsVirtualBands()) {
92 if (i != 0 && p_virtualBands.size() != 1) {
93 QString message =
"If multiple original inputs were set in the pipeline, the first application must support virtual bands.";
97 p_apps[i]->SetVirtualBands(p_virtualBands);
98 mustElimBands =
false;
103 if (p_addedCubeatt && i != (
int)p_apps.size() - 1) {
104 delete p_apps[p_apps.size() - 1];
105 p_apps.resize(p_apps.size() - 1);
106 p_appIdentifiers.resize(p_appIdentifiers.size() - 1);
107 p_apps[p_apps.size() - 1]->SetNext(NULL);
108 p_addedCubeatt =
false;
109 successfulPrepare =
false;
116 vector<QString> empty;
117 p_apps[i]->SetVirtualBands(empty);
122 p_apps[i]->BuildParamString();
125 vector<QString> theseTempFiles = p_apps[i]->TemporaryFiles();
126 for (
int tmpFile = 0; tmpFile < (int)theseTempFiles.size(); tmpFile++) {
128 if (theseTempFiles[tmpFile].contains(
"blank")) {
129 tmpFiles.push_back(theseTempFiles[tmpFile]);
133 if (!foundFirst && p_apps[i]->Enabled()) {
136 if (p_apps[i]->InputBranches().size() != OriginalBranches().size()) {
137 QString msg =
"The program [" + p_apps[i]->Name() +
"] can not be the first in the pipeline";
138 msg +=
" because it must be run multiple times with unspecified varying inputs";
146 string msg =
"No applications are enabled in the pipeline";
151 for (
int i = 0; successfulPrepare && i < (int)tmpFiles.size(); i++) {
152 for (
int j = i + 1; j < (int)tmpFiles.size(); j++) {
153 if (tmpFiles[i] == tmpFiles[j]) {
154 QString msg =
"There is a conflict with the temporary file naming. The temporary file [";
155 msg += tmpFiles[i] +
"] is created twice.";
162 if (successfulPrepare && mustElimBands) {
163 AddToPipeline(
"cubeatt",
"~PIPELINE_RESERVED_FOR_BANDS~");
164 Application(
"~PIPELINE_RESERVED_FOR_BANDS~").SetInputParameter(
"FROM",
true);
165 Application(
"~PIPELINE_RESERVED_FOR_BANDS~").SetOutputParameter(
"TO",
"final");
166 p_addedCubeatt =
true;
167 successfulPrepare =
false;
170 int lastApp = p_apps.size()-1;
171 if (p_apps[p_apps.size()-1] == NULL)
172 lastApp = p_apps.size() - 2;
174 if (p_apps[lastApp]->GetOutputs().size() == 0) {
175 string msg =
"There are no outputted files in the pipeline. At least one program must generate an output file.";
201 pipelineProg.
SetText(p_procAppName);
206 for (
int i = p_pausePosition; i < Size(); i++) {
209 if (p_apps[i] == NULL) {
221 const vector<QString> ¶ms =
Application(i).ParamString();
222 for (
int j = 0; j < (int)params.size(); j++) {
225 QString special(params[j].mid(0, 7));
228 if (special ==
">>LIST ") {
229 QString cmd = params[j].mid(7);
232 QString listFileName = listData.takeFirst();
233 TextFile listFile(listFileName,
"overwrite");
235 while (!listData.isEmpty()) {
236 listFile.
PutLine(listData.takeFirst());
252 cerr <<
"Continuing ......" << endl;
261 if (!KeepTemporaryFiles()) {
262 for (
int i = 0; i < Size(); i++) {
263 if (p_apps[i] == NULL)
continue;
265 vector<QString> tmpFiles =
Application(i).TemporaryFiles();
266 for (
int file = 0; file < (int)tmpFiles.size(); file++) {
267 QFile::remove(tmpFiles[file]);
274 p_pausePosition = -1;
287 SetInputFile(QString(inputParam));
303 p_originalInput.push_back(ui.
GetFileName(inputParam));
304 p_inputBranches.push_back(inputParam);
319 p_originalInput.push_back(inputFile.original());
320 p_inputBranches.push_back(inputFile.original());
321 p_virtualBands.push_back(
"");
334 SetInputListFile(QString(inputParam));
355 while (filelist.GetLineNoFilter(filename)) {
356 p_originalInput.push_back(filename);
357 p_inputBranches.push_back(inputParam +
toString(branch));
358 p_virtualBands.push_back(
"");
359 p_finalOutput.push_back(
FileName(filename).name());
364 p_outputListNeedsModifiers =
true;
377 TextFile filelist(inputFileName.expanded());
381 while (filelist.GetLineNoFilter(filename)) {
382 p_originalInput.push_back(filename);
383 p_inputBranches.push_back(
FileName(inputFileName).expanded() +
" " + QString(branch));
384 p_finalOutput.push_back(
FileName(filename).name());
385 p_virtualBands.push_back(
"");
390 p_outputListNeedsModifiers =
true;
406 SetInputFile(QString(inputParam), QString(virtualBandsParam));
425 p_originalInput.push_back(ui.
GetAsString(inputParam));
426 p_inputBranches.push_back(inputParam);
428 if (!virtualBandsParam.isEmpty() && ui.
WasEntered(virtualBandsParam)) {
429 p_virtualBands.push_back(ui.
GetAsString(virtualBandsParam));
432 p_virtualBands.push_back(
"");
447 SetOutputFile(QString(outputParam));
462 p_finalOutput.clear();
465 p_finalOutput.push_back(ui.
GetAsString(outputParam));
479 p_finalOutput.clear();
480 p_finalOutput.push_back(outputFile.expanded());
493 SetOutputListFile(QString(outputFileNameParam));
512 p_finalOutput.clear();
515 for (
unsigned int i = 0; i < p_originalInput.size(); i++) {
516 p_finalOutput.push_back(
FileName(p_originalInput[i]).name());
519 p_outputListNeedsModifiers =
true;
531 p_finalOutput.clear();
533 TextFile filelist(outputFileNameList.expanded());
536 while (filelist.GetLineNoFilter(filename)) {
537 p_finalOutput.push_back(filename);
540 p_outputListNeedsModifiers =
false;
551 p_keepTemporary = keep;
564 QString pauseAppId =
"";
567 p_apps.push_back(pauseApp);
568 p_appIdentifiers.push_back(pauseAppId);
587 for (
unsigned int appIdentifier = 0; appIdentifier < p_appIdentifiers.size(); appIdentifier++) {
588 if (p_appIdentifiers[appIdentifier] == identifier) {
589 QString message =
"The application identifier [" + identifier +
"] is not unique. " +
590 "Please providing a unique identifier";
597 QString cubeAttId =
"";
598 if (p_addedCubeatt) {
599 cubeAtt = p_apps[p_apps.size()-1];
600 cubeAttId = p_appIdentifiers[p_appIdentifiers.size()-1];
601 p_apps.resize(p_apps.size() - 1);
602 p_appIdentifiers.resize(p_appIdentifiers.size() - 1);
603 p_apps[p_apps.size()-1]->
SetNext(NULL);
608 QString pauseAppId =
"";
610 for (
int iapp = 0; iapp < (int) p_apps.size(); iapp++)
611 if (p_apps[iapp] != NULL) appsSize++;
614 if (p_apps.size() == 0) {
618 if (p_apps[p_apps.size()-1] != NULL)
624 p_appIdentifiers.push_back(identifier);
628 p_apps[p_apps.size()-1]->SetNext(cubeAtt);
630 p_apps.push_back(cubeAtt);
631 p_appIdentifiers.push_back(cubeAttId);
649 for (
unsigned int appIdentifier = 0; appIdentifier < p_appIdentifiers.size(); appIdentifier++) {
650 if (p_appIdentifiers[appIdentifier] == appname) {
651 QString message =
"The application identifier [" + appname +
"] is not unique. Please use " +
652 "the other AddToPipeline method providing a unique identifier";
659 QString cubeAttId =
"";
660 if (p_addedCubeatt) {
661 cubeAtt = p_apps[p_apps.size()-1];
662 cubeAttId = p_appIdentifiers[p_appIdentifiers.size()-1];
663 p_apps.resize(p_apps.size() - 1);
664 p_appIdentifiers.resize(p_appIdentifiers.size() - 1);
665 p_apps[p_apps.size()-1]->
SetNext(NULL);
669 if (p_apps.size() == 0) {
673 if (p_apps[p_apps.size()-1] != NULL)
679 p_appIdentifiers.push_back(appname);
683 p_apps[p_apps.size()-1]->SetNext(cubeAtt);
685 p_apps.push_back(cubeAtt);
686 p_appIdentifiers.push_back(cubeAttId);
704 while (!found && index < Size()) {
705 if (p_appIdentifiers[index] == identifier) {
714 QString msg =
"Application identified by [" + identifier +
"] has not been added to the pipeline";
718 return *p_apps[index];
731 if (index > Size()) {
732 QString msg =
"Index [" + QString(index) +
"] out of bounds";
736 return *p_apps[index];
754 for (appIndex = 0; appIndex < (int)p_apps.size() &&
755 p_apps[appIndex]->Name() != appname; appIndex++) {
756 if (p_apps[appIndex] == NULL)
continue;
757 p_apps[appIndex]->Disable();
763 if (appIndex >= (
int)p_apps.size()) {
764 QString msg =
"Pipeline could not find application [" + appname +
"]";
783 int appIndex = p_apps.size() - 1;
784 for (appIndex = p_apps.size() - 1; appIndex >= 0 && p_apps[appIndex]->Name() != appname; appIndex --) {
785 if (p_apps[appIndex] == NULL)
continue;
786 p_apps[appIndex]->Disable();
790 QString msg =
"Pipeline could not find application [" + appname +
"]";
810 QString output = ((p_finalOutput.size() != 0) ? p_finalOutput[0] :
"");
812 if (p_apps.size() == 0)
return output;
814 if (p_finalOutput.size() > 1) {
815 if ((
unsigned int)branch >= p_finalOutput.size()) {
816 QString msg =
"Output not set for branch [" + QString(branch) +
"]";
820 if (!p_outputListNeedsModifiers) {
821 return p_finalOutput[branch];
824 output = p_finalOutput[branch];
830 if (last == NULL) last = p_apps[p_apps.size()-2];
833 if (output ==
"" || p_finalOutput.size() > 1) {
835 output =
"./" +
FileName(p_originalInput[0]).baseName();
838 output =
"./" +
FileName(p_originalInput[branch]).baseName();
843 if (addModifiers && p_finalOutput.size() > 1)
851 if (p_finalOutput.size() <= 1) {
855 if (addModifiers && p_finalOutput.size() > 1)
861 else if (addModifiers) {
866 FileName(p_finalOutput[0]).baseName() +
"." +
869 if (p_finalOutput.size() > 1) {
887 Pvl &pref = Preference::Preferences();
888 return pref.
findGroup(
"DataDirectory")[
"Temporary"];
901 for (
int i = 0; i < Size(); i++) {
902 if (p_apps[i] != NULL) p_apps[i]->Enable();
926 if (!pipeline.
Name().isEmpty()) {
927 os <<
"PIPELINE -------> " << pipeline.
Name() <<
" <------- PIPELINE" << endl;
930 for (
int i = 0; i < pipeline.
Size(); i++) {
934 for (
int j = 0; j < (int)params.size(); j++) {
935 QString special(params[j].mid(0, 7));
936 if (special ==
">>LIST ") {
937 QString cmd = params[j].mid(7);
940 QString file = listFileData.takeFirst();
941 os <<
"echo -e \"" << listFileData.join(
"\\n") <<
"\" > " << file << endl;
951 for (
int i = 0; i < pipeline.
Size(); i++) {
955 for (
int file = 0; file < (int)tmpFiles.size(); file++) {
956 if (!tmpFiles[file].contains(
"blank")) {
957 os <<
"rm " << tmpFiles[file] << endl;
964 if (!pipeline.
Name().isEmpty()) {
965 os <<
"PIPELINE -------> " << pipeline.
Name() <<
" <------- PIPELINE" << endl;