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.";
212 for (
int i = p_pausePosition; i <
Size(); i++) {
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;
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)) {
514 p_outputListNeedsModifiers =
true;
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 =
"";
603 QString pauseAppId =
"";
622 p_apps.push_back(cubeAtt);
641 for (
unsigned int appIdentifier = 0; appIdentifier <
p_appIdentifiers.size(); appIdentifier++) {
643 QString message =
"The application identifier [" + appname +
"] is not unique. Please use " +
644 "the other AddToPipeline method providing a unique identifier";
651 QString cubeAttId =
"";
677 p_apps.push_back(cubeAtt);
696 while (!found && index <
Size()) {
706 QString msg =
"Application identified by [" + identifier +
"] has not been added to the pipeline";
723 if (index >
Size()) {
724 QString msg =
"Index [" + QString(index) +
"] out of bounds";
746 for (appIndex = 0; appIndex < (int)
p_apps.size() &&
747 p_apps[appIndex]->
Name() != appname; appIndex++) {
748 if (
p_apps[appIndex] == NULL)
continue;
749 p_apps[appIndex]->Disable();
755 if (appIndex >= (
int)
p_apps.size()) {
756 QString msg =
"Pipeline could not find application [" + appname +
"]";
775 int appIndex =
p_apps.size() - 1;
776 for (appIndex =
p_apps.size() - 1; appIndex >= 0 &&
p_apps[appIndex]->Name() != appname; appIndex --) {
777 if (
p_apps[appIndex] == NULL)
continue;
778 p_apps[appIndex]->Disable();
782 QString msg =
"Pipeline could not find application [" + appname +
"]";
804 if (
p_apps.size() == 0)
return output;
808 QString msg =
"Output not set for branch [" + QString(branch) +
"]";
812 if (!p_outputListNeedsModifiers) {
853 else if (addModifiers) {
879 Pvl &pref = Preference::Preferences();
880 return pref.
findGroup(
"DataDirectory")[
"Temporary"];
893 for (
int i = 0; i <
Size(); i++) {
918 if (!pipeline.
Name().isEmpty()) {
919 os <<
"PIPELINE -------> " << pipeline.
Name() <<
" <------- PIPELINE" << endl;
922 for (
int i = 0; i < pipeline.
Size(); i++) {
925 for (
int j = 0; j < (int)params.size(); j++) {
926 QString special(params[j].mid(0, 7));
927 if (special ==
">>LIST ") {
928 QString cmd = params[j].mid(7);
931 QString file = listFileData.takeFirst();
932 os <<
"echo -e \"" << listFileData.join(
"\\n") <<
"\" > " << file << endl;
942 for (
int i = 0; i < pipeline.
Size(); i++) {
945 for (
int file = 0; file < (int)tmpFiles.size(); file++) {
946 if (!tmpFiles[file].contains(
"blank")) {
947 os <<
"rm " << tmpFiles[file] << endl;
954 if (!pipeline.
Name().isEmpty()) {
955 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.
QString original() const
Returns the full file name including the file path.
@ Programmer
This error is for when a programmer made an API call that was illegal.
void print() const
Prints a string representation of this exception to stderr.
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.
QString OutputExtension()
This returns this application's output file name's extension.
const bool & Enabled() const
Returns true if this program will be run.
QString OutputNameModifier()
This returns this application's output name modifier.
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 SetPrevious(PipelineApplication *prev)
Link to the previous 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...
const std::vector< QString > & OutputBranches() const
Get the branches this program has as output.
This class helps to call other Isis Applications in a Pipeline.
void Run()
This method executes the pipeline.
void KeepTemporaryFiles(bool keep)
Set whether or not to keep temporary files (files generated in the middle of the pipeline that are ne...
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 SetMaximumSteps(const int steps)
This sets the maximum number of steps in the process.
void SetText(const QString &text)
Changes the value of the text string reported just before 0% processed.
void CheckStatus()
Checks and updates the status.
Container for cube-like labels.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Command Line and Xml loader, validation, and access.
Isis::CubeAttributeInput & GetInputAttribute(const QString ¶mName)
Gets the attributes for an input cube.
QString GetFileName(const QString ¶mName, QString extension="") const
Allows the retrieval of a value for a parameter of type "filename".
bool WasEntered(const QString ¶mName) const
Returns a true if the parameter has a value, and false if it does not.
QString GetCubeName(const QString ¶mName, QString extension="") const
Retrieves of a value for a parameter of type "cubename".
QString GetAsString(const QString ¶mName) const
Allows the retrieval of a value for a parameter of any type.
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.