TINC
Toolkit for Interactive Computation
|
The ProcessorScript class. More...
#include <ProcessorScript.hpp>
Public Types | |
typedef std::map< std::string, al::VariantValue > | Configuration |
Public Member Functions | |
ProcessorScript (std::string id="") | |
virtual | ~ProcessorScript () |
ProcessorScript (ProcessorScript &p) | |
void | setCommand (std::string command) |
Set the script's main command (e.g. python) More... | |
std::string | getCommand () |
Get the script's main command (e.g. python) More... | |
void | setScriptName (std::string scriptName) |
Set name of script to be run. More... | |
std::string | getScriptName () |
Get name of script to be run. More... | |
std::string | getScriptFile (bool fullPath=false) |
Query current script file name. More... | |
bool | process (bool forceRecompute=false) override |
process More... | |
void | enableJsonConfig (bool enable=true) |
if set to false disables creation and argument passing of json config More... | |
void | setArgumentTemplate (std::string argTemplate) |
bool | isRunning () |
returns true is the process() function is currently running More... | |
void | setDataDirectory (std::string directory) |
Convenience function to set input and output directories in one call. More... | |
void | setOutputDirectory (std::string outputDirectory) |
Set the directory for output files. More... | |
std::string | getOutputDirectory () |
Get the directory for output files. More... | |
void | setInputDirectory (std::string inputDirectory) |
Set the directory for input files. More... | |
std::string | getInputDirectory () |
Get the directory for input files. More... | |
void | setOutputFileNames (std::vector< std::string > outputFiles) |
Set the names of output files. More... | |
std::vector< std::string > | getOutputFileNames () |
Query the current output filenames. More... | |
void | setInputFileNames (std::vector< std::string > inputFiles) |
Set the names of input files. More... | |
std::vector< std::string > | getInputFileNames () |
Query the current input filenames. More... | |
void | setRunningDirectory (std::string directory) |
Set the current directory for process to run in. More... | |
std::string | getRunningDirectory () |
Get the directory for input files. More... | |
void | registerStartCallback (std::function< void(void)> func) |
Register a function to be called at the start of process() More... | |
void | registerDoneCallback (std::function< void(bool)> func) |
Register a function to be called at the end of process() More... | |
void | setVerbose (bool verbose=true) |
Processor & | registerDimension (ParameterSpaceDimension &dim) |
Register a dimension so that the Processor is executed on changes. More... | |
Processor & | operator<< (ParameterSpaceDimension &dim) |
Convenient syntax for registerDimension() More... | |
void | useCache (bool use=true) |
Enable simple file based caching. More... | |
Processor & | registerDependency (ParameterSpaceDimension ¶m) |
Register a dependency. More... | |
Processor & | registerDependency (al::ParameterMeta *param) |
Convenient syntax for registerParameter() More... | |
std::vector< ParameterSpaceDimension * > | getDependencies () |
Return the dependencies registered with this Processor. More... | |
std::string | getId () |
get this object's id More... | |
void | setId (std::string id) |
set this object's id More... | |
std::string | getDocumentation () const |
void | setDocumentation (const std::string &documentation) |
Static Public Member Functions | |
static std::string | sanitizeName (std::string output_name) |
Cleans a name up so it can be written to disk. More... | |
Public Attributes | |
bool | ignoreFail {false} |
bool | enabled {true} |
std::function< bool(void)> | prepareFunction |
Set a function to be called before computing to prepare data. More... | |
Configuration | configuration |
Current internal configuration key value pairs. More... | |
std::function< void(al::Socket *src)> | modified = [](al::Socket * ) {} |
Protected Member Functions | |
std::string | writeJsonConfig () |
bool | readJsonConfig (std::string filename) |
void | parametersToConfig (nlohmann::json &j) |
void | callStartCallbacks () |
void | callDoneCallbacks (bool result) |
std::string | metaFilename () |
Protected Attributes | |
std::string | mInputDirectory |
std::string | mOutputDirectory |
std::string | mRunningDirectory |
std::vector< std::string > | mOutputFileNames |
std::vector< std::string > | mInputFileNames |
bool | mVerbose |
bool | mUseCache {false} |
std::vector< ParameterSpaceDimension * > | mParameters |
std::vector< ParameterSpaceDimension * > | mDependencies |
std::vector< std::unique_ptr< ParameterSpaceDimension > > | mInternalDimensions |
std::mutex | mProcessLock |
std::string | mId |
std::string | mDocumentation |
The ProcessorScript class.
The script will be passed options through a json file, and can also recieve feedback from the script through the same file. The filename is passed to the script as its first argument.
Definition at line 78 of file ProcessorScript.hpp.
|
inherited |
Definition at line 272 of file Processor.hpp.
|
inline |
Definition at line 80 of file ProcessorScript.hpp.
|
inlinevirtual |
Definition at line 82 of file ProcessorScript.hpp.
|
inline |
Definition at line 85 of file ProcessorScript.hpp.
|
protectedinherited |
|
protectedinherited |
void tinc::ProcessorScript::enableJsonConfig | ( | bool | enable = true | ) |
if set to false disables creation and argument passing of json config
enable |
|
inline |
Get the script's main command (e.g. python)
Definition at line 97 of file ProcessorScript.hpp.
|
inlineinherited |
Return the dependencies registered with this Processor.
Definition at line 268 of file Processor.hpp.
|
inherited |
|
inherited |
get this object's id
|
inlineinherited |
Get the directory for input files.
Definition at line 119 of file Processor.hpp.
|
inherited |
Query the current input filenames.
This function contains the filenames set in C++ using setInputFileNames or the filenames set by the Processor after running, see for example ProcessorScript
|
inlineinherited |
Get the directory for output files.
Definition at line 109 of file Processor.hpp.
|
inherited |
Query the current output filenames.
This function contains the filenames set in C++ using setOutputFileNames or the filenames set by the Processor after running, see for example ProcessorScript
|
inlineinherited |
Get the directory for input files.
Definition at line 163 of file Processor.hpp.
std::string tinc::ProcessorScript::getScriptFile | ( | bool | fullPath = false | ) |
Query current script file name.
|
inline |
Get name of script to be run.
Definition at line 112 of file ProcessorScript.hpp.
|
inherited |
returns true is the process() function is currently running
This is useful for soft queries, for example for user feedback. The processor might have started running before this function exits even if it reports it is idle and viceversa.
|
protectedinherited |
|
inlineinherited |
Convenient syntax for registerDimension()
Definition at line 225 of file Processor.hpp.
|
protected |
|
overridevirtual |
process
Implements tinc::Processor.
|
protected |
|
inherited |
Convenient syntax for registerParameter()
param |
|
inherited |
Register a dependency.
param |
A dependency is a parameter that affects the result of this processor but does not trigger computation
|
inherited |
Register a dimension so that the Processor is executed on changes.
You should only register dimensions in this way if you are not using the processor through ParameterSpace::process() or ParameterSpace::sweep(). The tow modes are provided for flexibility but should not be used concurrently.
Processor is executed on changes of this parameter
|
inherited |
Register a function to be called at the end of process()
This function is passed true if the process() function has been sucessful.
These callbacks should only be used for data related actions, as they will be skipped when reusing cache in ParameterSpace.
|
inherited |
Register a function to be called at the start of process()
These callbacks should only be used for data related actions, as they will be skipped when reusing cache in ParameterSpace.
|
static |
Cleans a name up so it can be written to disk.
output_name | the source name |
This function will remove any characters not allowed by the operating system like :,/,\ etc. And will remove any characters like '.' that can confuse the parsing of the name on read.
|
inline |
commandLineTemplate | If a template is set, it will be populated by parameters and file names and passed to the command as the command line flags after the command and script name. If the template is used, the json config file is still created, unless enableJsonConfig(false) is called |
Definition at line 152 of file ProcessorScript.hpp.
|
inline |
Set the script's main command (e.g. python)
Definition at line 92 of file ProcessorScript.hpp.
|
inherited |
Convenience function to set input and output directories in one call.
|
inherited |
|
inherited |
set this object's id
|
inherited |
Set the directory for input files.
|
inherited |
Set the names of input files.
outputFiles | list of output file names. |
|
inherited |
Set the directory for output files.
|
inherited |
Set the names of output files.
outputFiles | list of output file names. |
|
inherited |
Set the current directory for process to run in.
You must ensure you don;t change the running directory while the processor is running, otherwise different parts of the processing (the callbacks and the processing function) might execute in a different directory
|
inline |
Set name of script to be run.
scriptName |
Definition at line 104 of file ProcessorScript.hpp.
|
inlineinherited |
Definition at line 183 of file Processor.hpp.
|
inlineinherited |
Enable simple file based caching.
use | This caching is a simple but brittle caching mechanism. Whenever possible use the caching provided by ParameterSpace, as it is more robust. |
For this caching to work, you will need to ensure that every independent run produces unique and reproducible filenames. i.e. you will need to set the output file names on every run to include in their name all parameter values and dependencies, or have some other way of connecting the parameters/ parameter space to the file.
This will cache the output as written in the output files. You can set and query the files using getOutputFiles() setOutputFiles().
Definition at line 245 of file Processor.hpp.
|
protected |
|
inherited |
Current internal configuration key value pairs.
Reflects the most recently used configuration (whether successful or failed) or the configuration for the currently running process.
Definition at line 280 of file Processor.hpp.
|
inherited |
If set to false, process() has no effect and will return true;
Definition at line 194 of file Processor.hpp.
|
inherited |
If set to true, ProcessorChains will continue even if this processor fails. Has no effect if running chain asychronously
Definition at line 189 of file Processor.hpp.
|
protectedinherited |
Definition at line 293 of file Processor.hpp.
|
protectedinherited |
Definition at line 69 of file IdObject.hpp.
|
protectedinherited |
Definition at line 68 of file IdObject.hpp.
|
protectedinherited |
Definition at line 283 of file Processor.hpp.
|
protectedinherited |
Definition at line 287 of file Processor.hpp.
|
protectedinherited |
Definition at line 294 of file Processor.hpp.
|
inherited |
Definition at line 65 of file IdObject.hpp.
|
protectedinherited |
Definition at line 284 of file Processor.hpp.
|
protectedinherited |
Definition at line 286 of file Processor.hpp.
|
protectedinherited |
Definition at line 292 of file Processor.hpp.
|
protectedinherited |
Definition at line 304 of file Processor.hpp.
|
protectedinherited |
Definition at line 285 of file Processor.hpp.
|
protectedinherited |
Definition at line 290 of file Processor.hpp.
|
protectedinherited |
Definition at line 288 of file Processor.hpp.
|
inherited |
Set a function to be called before computing to prepare data.
When writing the prepare function you should access values and ids through Processor::configuration. If you access values directly from dimensions, you will likely break ParameterSpace::sweep used with this Processor as sweep() does not change the internal values of the parameter space and its dimensions.
If this function returns false, computation is not performed and process() will return false. You can use this function to avoid computation when conditions are not right.
Definition at line 209 of file Processor.hpp.