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;
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();
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) {
843 if (addModifiers && p_finalOutput.size() > 1)
851 if (p_finalOutput.size() <= 1) {
855 if (addModifiers && p_finalOutput.size() > 1)
861 else if (addModifiers) {
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++) {
933 for (
int j = 0; j < (int)params.size(); j++) {
934 QString special(params[j].mid(0, 7));
935 if (special ==
">>LIST ") {
936 QString cmd = params[j].mid(7);
939 QString file = listFileData.takeFirst();
940 os <<
"echo -e \"" << listFileData.join(
"\\n") <<
"\" > " << file << endl;
950 for (
int i = 0; i < pipeline.
Size(); i++) {
953 for (
int file = 0; file < (int)tmpFiles.size(); file++) {
954 if (!tmpFiles[file].contains(
"blank")) {
955 os <<
"rm " << tmpFiles[file] << endl;
962 if (!pipeline.
Name().isEmpty()) {
963 os <<
"PIPELINE -------> " << pipeline.
Name() <<
" <------- PIPELINE" << endl;
void SetInputFile(const char *inputParam)
This method is used to set the original input file.
void SetInputListFile(const char *inputParam)
This method is used to set the original input files.
QString path() const
Returns the path of the file name.
static void RunIsisProgram(QString isisProgramName, QString arguments)
Executes the Isis program with the given arguments.
QString TemporaryFolder()
This method returns the user's temporary folder for temporary files.
void SetPrevious(PipelineApplication *prev)
Link to the previous application in the pipeline.
void SetLastApplication(const QString &appname)
This method disables all applications after to this one.
void Run()
This method executes the pipeline.
void SetMaximumSteps(const int steps)
This sets the maximum number of steps in the process.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
QString GetFileName(const QString ¶mName, QString extension="") const
Allows the retrieval of a value for a parameter of type "filename".
static UserInterface & GetUserInterface()
Returns the UserInterface object.
File name manipulation and expansion.
const QString & Name() const
Get the name of this pipeline application.
~Pipeline()
This destroys the pipeline.
QString OutputNameModifier()
This returns this application's output name modifier.
Namespace for the standard library.
QString GetAsString(const QString ¶mName) const
Allows the retrieval of a value for a parameter of any type.
Pipeline(const QString &procAppName="")
This is the one and only Pipeline constructor.
This class helps to call other Isis Applications in a Pipeline.
void Close()
Closes file. Called automatically by TextFile destructor.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
bool KeepTemporaryFiles()
Returns true if temporary files will not be deleted, false if they will.
This error is for when a programmer made an API call that was illegal.
const std::vector< QString > & ParamString() const
Get the parameters for running this program; one element in the vector per run.
const bool & Enabled() const
Returns true if this program will be run.
void CheckStatus()
Checks and updates the status.
void SetFirstApplication(const QString &appname)
This method disables all applications up to this one.
Program progress reporter.
void SetOutputFile(const char *outputParam)
This method is used to set the final output file.
void SetOutputListFile(const char *outputFileNameParam)
This method is used to set an output list file.
void SetText(const QString &text)
Changes the value of the text string reported just before 0% processed.
PipelineApplication * Previous() const
This returns the last enabled pipeline application or null.
This class represents one application in the pipeline.
#define _FILEINFO_
Macro for the filename and line number.
void AddToPipeline(const QString &appname)
Add a new program to the pipeline.
void Prepare()
This method is the core of the pipeline class.
QString Name() const
Returns the name of the pipeline.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
QString original() const
Returns the full file name including the file path.
void SetNext(PipelineApplication *next)
Link to the next application in the pipeline.
Isis::CubeAttributeInput & GetInputAttribute(const QString ¶mName)
Gets the attributes for an input cube.
Container for cube-like labels.
int Size() const
Returns the number of applications in the pipeline.
QString FinalOutput(int branch=0, bool addModifiers=true)
This gets the final output for the specified branch; this is necessary for the PipelineApplications t...
Provides access to sequential ASCII stream I/O.
void print() const
Prints a string representation of this exception to stderr.
QString baseName() const
Returns the name of the file without the path and without extensions.
const std::vector< QString > & OutputBranches() const
Get the branches this program has as output.
void PutLine(const QString &line)
Writes string to file and appends a 'newline' string.
Namespace for ISIS/Bullet specific routines.
Command Line and Xml loader, validation, and access.
void KeepTemporaryFiles(bool keep)
Set whether or not to keep temporary files (files generated in the middle of the pipeline that are ne...
QDebug operator<<(QDebug debug, const Hillshade &hillshade)
Print this class out to a QDebug object.
QString OutputExtension()
This returns this application's output file name's extension.
void AddPause()
Add a pause to the pipeline.
bool WasEntered(const QString ¶mName) const
Returns a true if the parameter has a value, and false if it does not.
PipelineApplication & Application(const QString &identifier)
This is an accessor to get a specific PipelineApplication.
std::vector< QString > TemporaryFiles()
This method returns a list of the temporary files generated by this program.
void EnableAllApplications()
This method re-enables all applications.