12#include "PipelineApplication.h"
13#include "ProgramLauncher.h"
14#include "IException.h"
15#include "Application.h"
16#include "Preference.h"
40 p_outputListNeedsModifiers =
false;
50 for (
int i = 0; i < (int)
p_apps.size(); i++) {
71 if (
p_apps.size() == 0)
return;
74 bool successfulPrepare =
false;
76 while (!successfulPrepare) {
78 successfulPrepare =
true;
79 bool foundFirst =
false;
82 bool mustElimBands =
false;
90 vector<QString> tmpFiles;
95 for (
int i = 0; i < (int)
p_apps.size() && successfulPrepare; i++) {
96 if (
p_apps[i] == NULL)
continue;
97 if (mustElimBands &&
p_apps[i]->SupportsVirtualBands()) {
99 QString message =
"If multiple original inputs were set in the pipeline, the first application must support virtual bands.";
104 mustElimBands =
false;
115 successfulPrepare =
false;
122 vector<QString> empty;
123 p_apps[i]->SetVirtualBands(empty);
128 p_apps[i]->BuildParamString();
131 vector<QString> theseTempFiles =
p_apps[i]->TemporaryFiles();
132 for (
int tmpFile = 0; tmpFile < (int)theseTempFiles.size(); tmpFile++) {
134 if (theseTempFiles[tmpFile].contains(
"blank")) {
135 tmpFiles.push_back(theseTempFiles[tmpFile]);
139 if (!foundFirst &&
p_apps[i]->Enabled()) {
143 QString msg =
"The program [" +
p_apps[i]->Name() +
"] can not be the first in the pipeline";
144 msg +=
" because it must be run multiple times with unspecified varying inputs";
152 string msg =
"No applications are enabled in the pipeline";
157 for (
int i = 0; successfulPrepare && i < (int)tmpFiles.size(); i++) {
158 for (
int j = i + 1; j < (int)tmpFiles.size(); j++) {
159 if (tmpFiles[i] == tmpFiles[j]) {
160 QString msg =
"There is a conflict with the temporary file naming. The temporary file [";
161 msg += tmpFiles[i] +
"] is created twice.";
168 if (successfulPrepare && mustElimBands) {
173 successfulPrepare =
false;
176 int lastApp =
p_apps.size()-1;
178 lastApp =
p_apps.size() - 2;
180 if (
p_apps[lastApp]->GetOutputs().size() == 0) {
181 string msg =
"There are no outputted files in the pipeline. At least one program must generate an output file.";
208 pipelineProg.SetMaximumSteps(1);
209 pipelineProg.CheckStatus();
212 for (
int i = p_pausePosition; i <
Size(); i++) {
223 appName.SetMaximumSteps(1);
224 appName.CheckStatus();
228 for (
int j = 0; j < (int)params.size(); j++) {
231 QString special(params[j].mid(0, 7));
234 if (special ==
">>LIST ") {
235 QString cmd = params[j].mid(7);
238 QString listFileName = listData.takeFirst();
241 while (!listData.isEmpty()) {
242 listFile.push_back(listData.takeFirst());
245 listFile.
write(listFileName);
258 cerr <<
"Continuing ......" << endl;
268 for (
int i = 0; i <
Size(); i++) {
269 if (
p_apps[i] == NULL)
continue;
272 for (
int file = 0; file < (int)tmpFiles.size(); file++) {
273 QFile::remove(tmpFiles[file]);
280 p_pausePosition = -1;
311 p_virtualBands.push_back(ui.GetInputAttribute(inputParam).toString());
371 FileList filelist(inputFileName.expanded());
375 while (!filelist.isEmpty()) {
376 filename = filelist.takeFirst();
385 p_outputListNeedsModifiers =
true;
401 SetInputFile(QString(inputParam), QString(virtualBandsParam));
423 if (!virtualBandsParam.isEmpty() && ui.WasEntered(virtualBandsParam)) {
459 if (ui.WasEntered(outputParam)) {
503 if (ui.WasEntered(outputFileNameParam)) {
514 p_outputListNeedsModifiers =
true;
528 FileList filelist(outputFileNameList.expanded());
531 while (!filelist.isEmpty()) {
532 filename = filelist.takeFirst().expanded();
536 p_outputListNeedsModifiers =
false;
560 QString pauseAppId =
"";
563 p_apps.push_back(pauseApp);
583 for (
unsigned int appIdentifier = 0; appIdentifier <
p_appIdentifiers.size(); appIdentifier++) {
585 QString message =
"The application identifier [" + identifier +
"] is not unique. " +
586 "Please providing a unique identifier";
593 QString cubeAttId =
"";
604 QString pauseAppId =
"";
606 for (
int iapp = 0; iapp < (int)
p_apps.size(); iapp++)
607 if (
p_apps[iapp] != NULL) appsSize++;
626 p_apps.push_back(cubeAtt);
645 for (
unsigned int appIdentifier = 0; appIdentifier <
p_appIdentifiers.size(); appIdentifier++) {
647 QString message =
"The application identifier [" + appname +
"] is not unique. Please use " +
648 "the other AddToPipeline method providing a unique identifier";
655 QString cubeAttId =
"";
681 p_apps.push_back(cubeAtt);
700 while (!found && index <
Size()) {
710 QString msg =
"Application identified by [" + identifier +
"] has not been added to the pipeline";
727 if (index >
Size()) {
728 QString msg =
"Index [" + QString(index) +
"] out of bounds";
750 for (appIndex = 0; appIndex < (int)
p_apps.size() &&
751 p_apps[appIndex]->Name() != appname; appIndex++) {
752 if (
p_apps[appIndex] == NULL)
continue;
753 p_apps[appIndex]->Disable();
759 if (appIndex >= (
int)
p_apps.size()) {
760 QString msg =
"Pipeline could not find application [" + appname +
"]";
779 int appIndex =
p_apps.size() - 1;
780 for (appIndex =
p_apps.size() - 1; appIndex >= 0 &&
p_apps[appIndex]->Name() != appname; appIndex --) {
781 if (
p_apps[appIndex] == NULL)
continue;
782 p_apps[appIndex]->Disable();
786 QString msg =
"Pipeline could not find application [" + appname +
"]";
808 if (
p_apps.size() == 0)
return output;
812 QString msg =
"Output not set for branch [" + QString(branch) +
"]";
816 if (!p_outputListNeedsModifiers) {
827 if (!last->Enabled()) last = last->
Previous();
838 if (!addModifiers || last->OutputBranches().size() == 1) {
840 output +=
"." + last->OutputNameModifier();
842 output +=
"." + last->OutputExtension();
848 output +=
"." + last->OutputBranches()[branch];
852 output +=
"." + last->OutputNameModifier();
854 output +=
"." + last->OutputExtension();
857 else if (addModifiers) {
859 if (!last->Enabled()) last = last->
Previous();
863 last->OutputBranches()[branch] +
".";
866 output += last->OutputNameModifier() +
".";
869 output += last->OutputExtension();
883 Pvl &pref = Preference::Preferences();
884 return pref.findGroup(
"DataDirectory")[
"Temporary"];
897 for (
int i = 0; i <
Size(); i++) {
922 if (!pipeline.Name().isEmpty()) {
923 os <<
"PIPELINE -------> " << pipeline.Name() <<
" <------- PIPELINE" << endl;
926 for (
int i = 0; i < pipeline.Size(); i++) {
927 if (pipeline.Application(i).Enabled()) {
928 const vector<QString> ¶ms = pipeline.Application(i).ParamString();
929 for (
int j = 0; j < (int)params.size(); j++) {
930 QString special(params[j].mid(0, 7));
931 if (special ==
">>LIST ") {
932 QString cmd = params[j].mid(7);
935 QString file = listFileData.takeFirst();
936 os <<
"echo -e \"" << listFileData.join(
"\\n") <<
"\" > " << file << endl;
939 os << pipeline.Application(i).Name() <<
" " << params[j] << endl;
945 if (!pipeline.KeepTemporaryFiles()) {
946 for (
int i = 0; i < pipeline.Size(); i++) {
947 if (pipeline.Application(i).Enabled()) {
948 vector<QString> tmpFiles = pipeline.Application(i).TemporaryFiles();
949 for (
int file = 0; file < (int)tmpFiles.size(); file++) {
950 if (!tmpFiles[file].contains(
"blank")) {
951 os <<
"rm " << tmpFiles[file] << endl;
958 if (!pipeline.Name().isEmpty()) {
959 os <<
"PIPELINE -------> " << pipeline.Name() <<
" <------- PIPELINE" << endl;
static UserInterface & GetUserInterface()
Returns the UserInterface object.
Internalizes a list of files.
void write(FileName outputFileList)
writes to a FileName obj
File name manipulation and expansion.
QString path() const
Returns the path of the file name.
QString baseName() const
Returns the name of the file without the path and without extensions.
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
@ Programmer
This error is for when a programmer made an API call that was illegal.
This class represents one application in the pipeline.
const QString & Name() const
Get the name of this pipeline application.
PipelineApplication * Previous() const
This returns the last enabled pipeline application or null.
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 SetOutputParameter(const QString &outputParamName, const QString &outNameModifier, const QString &outFileExtension="cub")
Set the output parameter for this application and it's naming convention.
std::vector< QString > TemporaryFiles()
This method returns a list of the temporary files generated by this program.
void SetNext(PipelineApplication *next)
Link to the next application in the pipeline.
void SetInputParameter(const QString &inputParamName, bool supportsVirtualBands)
Set the input parameter for this application and whether or not this application supports the virtual...
This class helps to call other Isis Applications in a Pipeline.
void Run()
This method executes the pipeline.
void SetInputFile(const char *inputParam)
This method is used to set the original input file.
bool p_keepTemporary
True if keeping temporary files.
std::vector< PipelineApplication * > p_apps
The pipeline applications.
void SetInputListFile(const char *inputParam)
This method is used to set the original input files.
void AddPause()
Add a pause to the pipeline.
bool KeepTemporaryFiles()
Returns true if temporary files will not be deleted, false if they will.
std::vector< QString > p_appIdentifiers
The strings to identify the pipeline applications.
bool p_addedCubeatt
True if the "cubeatt" program was added.
PipelineApplication & Application(const QString &identifier)
This is an accessor to get a specific PipelineApplication.
QString p_procAppName
The name of 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...
QString TemporaryFolder()
This method returns the user's temporary folder for temporary files.
void Prepare()
This method is the core of the pipeline class.
Pipeline(const QString &procAppName="")
This is the one and only Pipeline constructor.
std::vector< QString > p_inputBranches
Branches for input list.
std::vector< QString > p_finalOutput
The final output file (empty if needs calculated)
void AddToPipeline(const QString &appname)
Add a new program to the pipeline.
std::vector< QString > p_virtualBands
The virtual bands string.
int Size() const
Returns the number of applications in the pipeline.
~Pipeline()
This destroys the pipeline.
void SetLastApplication(const QString &appname)
This method disables all applications after to this one.
void SetFirstApplication(const QString &appname)
This method disables all applications up to this one.
void EnableAllApplications()
This method re-enables all applications.
void SetOutputFile(const char *outputParam)
This method is used to set the final output file.
std::vector< QString > p_originalInput
The original input file.
QString Name() const
Returns the name of the pipeline.
std::vector< QString > OriginalBranches()
Returns the names of the original branches of the pipeline (input files * branches if any)
void SetOutputListFile(const char *outputFileNameParam)
This method is used to set an output list file.
bool p_continue
continue the execution even if exception is encountered.
static void RunIsisProgram(QString isisProgramName, QString arguments)
Executes the Isis program with the given arguments.
Program progress reporter.
void SetText(const QString &text)
Changes the value of the text string reported just before 0% processed.
Container for cube-like labels.
Command Line and Xml loader, validation, and access.
This is free and unencumbered software released into the public domain.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
QDebug operator<<(QDebug debug, const Hillshade &hillshade)
Print this class out to a QDebug object.
Namespace for the standard library.