val i = Val[Int]
val hello = ScalaTask("i = i * 2") set (
inputs += i,
outputs += i
)
val exploration = ExplorationTask(i in (0 to 9))
val h = ToStringHook()
exploration -< (hello hook h)
The hook h is plugged to the end of the hello task. Everytime hello finishes, the hook h is
executed. Multiple hooks can also be plugged to the same task as in the present example:
val i = Val[Int]
val hello = ScalaTask("val i = 2") set (
outputs += i
)
val h1 = ToStringHook()
val h2 = ToStringHook()
val h3 = ToStringHook()
(hello hook (h1, h2, h3))
Hooks come in various declinations, with different actions on the results. The available hooks are described
hereafter.
val h = AppendToFileHook("/path/of/the/file.txt", "string ${i} to append")
Append a file to another file
Use the AppendFileFileHook as well.val file = Val[File]
val h = AppendToFileHook("${file.content}", "/path/of/the/file")
val i = Val[Int]
val h = CSVHook("/path/to/a/file/or/dir${i}.csv")
The path is expanded using the variables from the dataflow (expressions between ${} are evaluated and replaced).
The optional last parameter of AppendToCSVFileHook is the list of variables to write to the CSV file. The default behaviour when this list is not specified is to dump all the variables from the dataflow to the file. You can restrict this behaviour by listing only the variables you want to save
Some additional optional parameters can be set by calling the function set
on the newly created Hook.
csvHeader := Col1, Col2, ColZ
customises the header of the CSV file to be created with the string it receives as a parameter. Please note that this only happens if the file doesn't exist when the hook is executed.
singleRow := true
forces the flattening of the input lists such that all variables values
are written to a single row/line of the CSV file.
This workflow demonstrates the optional behaviour of AppendToCSVFileHook:
val i = Val[Int]
val j = Val[Int]
// this variable will not be written to the CSV file
val z = Val[Double]
val h = CSVHook("/path/to/a/file/or/dir${i}.csv", i, j) set (
csvHeader := "i, j",
arraysOnSingleRow := true
)
val file = Val[File]
val i = Val[Int]
val h = CopyFileHook(file, "/path/to/copy/the/file${i}.txt")
val i = Val[Int]
val j = Val[Int]
val h = ToStringHook(i, j)
If no variable is specified, ToStringHook displays the whole dataflow.
val i = Val[Int]
val h = DisplayHook("The value of i is ${i}.")