You are correct, and that is certainly a bug. I added it to the dev list, and it should be fixed soon. Once the bug is fixed, the if statement will work correctly, as it did before.
Note: All following code examples will be obsolete when this bug is fixed. It may not work in future versions.
The bug is that the childexpfolder is being deleted before the On End Of Replication trigger is called. So this creates two problems. First, it leads directly to your question: how do you check if you are in the child or parent process? The best way I can think of is to check the command line parameters:
if (commandlineparam("maintenance") == "childexperiment") { // in the child
The second problem is how to pass custom data up to the parent, and do something with it. Once this bug is fixed, you can add custom data to the subnodes of the Experimenter object in the model, and then read it on the other side. But since that folder is being deleted too soon, you'll need another approach.
The best way right now is to use the repData node in the code for a Performance Measure. This code is designed to allow you to shove whatever data you want into that node. As an example, I made a performance measure with this code for its value:
/**Custom Code*/
treenode reference = param(1);
treenode extraData = param(2);
treenode repData = param(3);
if (repData) {
repData.subnodes.assert("custom data", [1, 2, 3]);
}
return 1;
Note that while you can add subnodes to the repData node, the value of that node will be overwritten with the return value.
The repData node is then transferred back to the main process, and saved in the database So in the On End Of Replication trigger, on the parent side, you can get it back out of the database by querying:
/**Custom Code*/
Object current = ownerobject(c);
int replication = param(1);
int scenario = param(2);
treenode childexpfolder = param(3);
Map task = param(4);
if (commandlineparam("maintenance") == "childexperiment") { // in the child
// the data can be shoved in a pfm, so do nothing here
} else {
// the data has been stored in the database, so get it out
Database.Connection db = function_s(ownerobject(c), "getDBConnection");
// load all the pfm nodes from the database into the tree
int taskID = task.taskID;
treenode container = Model.find("Tools").subnodes.assert("pfms");
string stmtText = "\
SELECT name, loadnode(node, ?) \
FROM pfms p JOIN pfm_values pv ON p.id = pv.pfm_id \
WHERE pv.task_id = ? \
";
var stmt = db.prepareStatement(stmtText);
if (stmt) {
stmt.bindParam(1, container, Database.DataType.Unknown);
stmt.bindParam(2, taskID, Database.DataType.Unknown);
var result = stmt.execute();
while (result.fetchNext()) {
result[2].name = result[1];
}
}
}
The point of this code is to show how to get the pfm repData nodes out of the database. The query loads the saved data as subnodes of the container node. This code is meant as a starting point; you'll probably want to customize it for what you're doing.
TestChildexpFolder.fsm