TINC
Toolkit for Interactive Computation
|
The Processor class presents an abstraction to filesystem based computation. More...
#include <Processor.hpp>
Public Types | |
typedef std::map< std::string, al::VariantValue > | Configuration |
Public Member Functions | |
Processor (std::string id_="") | |
Processor (Processor &p) | |
virtual | ~Processor () |
virtual bool | process (bool forceRecompute=false)=0 |
override this function to determine how subclasses should process More... | |
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) |
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 | |
void | callStartCallbacks () |
void | callDoneCallbacks (bool result) |
virtual bool | writeMeta () |
virtual bool | needsRecompute () |
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 |
Friends | |
class | ProcessorGraph |
The Processor class presents an abstraction to filesystem based computation.
An instance of Processor can only run a single instance of its process() function.
You can group Processor objects together in serial or parallel through ProcessorChain that is a Processor itself, allowing for sophisticated netwroks of processes.
Definition at line 61 of file Processor.hpp.
typedef std::map<std::string, al::VariantValue> tinc::Processor::Configuration |
Definition at line 272 of file Processor.hpp.
|
inline |
Definition at line 65 of file Processor.hpp.
|
inline |
Definition at line 68 of file Processor.hpp.
|
inlinevirtual |
Definition at line 77 of file Processor.hpp.
|
protected |
|
protected |
|
inline |
Return the dependencies registered with this Processor.
Definition at line 268 of file Processor.hpp.
|
inherited |
|
inherited |
get this object's id
|
inline |
Get the directory for input files.
Definition at line 119 of file Processor.hpp.
std::vector<std::string> tinc::Processor::getInputFileNames | ( | ) |
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
|
inline |
Get the directory for output files.
Definition at line 109 of file Processor.hpp.
std::vector<std::string> tinc::Processor::getOutputFileNames | ( | ) |
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
|
inline |
Get the directory for input files.
Definition at line 163 of file Processor.hpp.
bool tinc::Processor::isRunning | ( | ) |
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.
|
protected |
|
protectedvirtual |
|
inline |
Convenient syntax for registerDimension()
Definition at line 225 of file Processor.hpp.
|
pure virtual |
override this function to determine how subclasses should process
You must call prepareFunction(), callDoneCallbacks() , callStartCallbacks() and test for 'enabled' within the process() function of all child classes.
Implemented in tinc::ProcessorScript, tinc::ProcessorGraph, tinc::ProcessorCpp, and tinc::ProcessorAsyncWrapper.
Processor& tinc::Processor::registerDependency | ( | al::ParameterMeta * | param | ) |
Convenient syntax for registerParameter()
param |
Processor& tinc::Processor::registerDependency | ( | ParameterSpaceDimension & | param | ) |
Register a dependency.
param |
A dependency is a parameter that affects the result of this processor but does not trigger computation
Processor& tinc::Processor::registerDimension | ( | ParameterSpaceDimension & | dim | ) |
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
void tinc::Processor::registerDoneCallback | ( | std::function< void(bool)> | func | ) |
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.
void tinc::Processor::registerStartCallback | ( | std::function< void(void)> | func | ) |
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.
void tinc::Processor::setDataDirectory | ( | std::string | directory | ) |
Convenience function to set input and output directories in one call.
|
inherited |
|
inherited |
set this object's id
void tinc::Processor::setInputDirectory | ( | std::string | inputDirectory | ) |
Set the directory for input files.
void tinc::Processor::setInputFileNames | ( | std::vector< std::string > | inputFiles | ) |
Set the names of input files.
outputFiles | list of output file names. |
void tinc::Processor::setOutputDirectory | ( | std::string | outputDirectory | ) |
Set the directory for output files.
void tinc::Processor::setOutputFileNames | ( | std::vector< std::string > | outputFiles | ) |
Set the names of output files.
outputFiles | list of output file names. |
void tinc::Processor::setRunningDirectory | ( | std::string | directory | ) |
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 |
Definition at line 183 of file Processor.hpp.
|
inline |
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.
|
protectedvirtual |
|
friend |
Definition at line 62 of file Processor.hpp.
Configuration tinc::Processor::configuration |
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.
bool tinc::Processor::enabled {true} |
If set to false, process() has no effect and will return true;
Definition at line 194 of file Processor.hpp.
bool tinc::Processor::ignoreFail {false} |
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.
|
protected |
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.
|
protected |
Definition at line 283 of file Processor.hpp.
|
protected |
Definition at line 287 of file Processor.hpp.
|
protected |
Definition at line 294 of file Processor.hpp.
|
inherited |
Definition at line 65 of file IdObject.hpp.
|
protected |
Definition at line 284 of file Processor.hpp.
|
protected |
Definition at line 286 of file Processor.hpp.
|
protected |
Definition at line 292 of file Processor.hpp.
|
protected |
Definition at line 304 of file Processor.hpp.
|
protected |
Definition at line 285 of file Processor.hpp.
|
protected |
Definition at line 290 of file Processor.hpp.
|
protected |
Definition at line 288 of file Processor.hpp.
std::function<bool(void)> tinc::Processor::prepareFunction |
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.