This is just an idea, inspired by the new scripting power available with ROOT6/Cling:
One often needs some glue scripts to integrate ROOT (and custom) classes with shell code, batch systems, and so on. If ROOT scripts could be made executable, they would be well suited to take this role.
While it is, of course, always possible to call scripts explicitly via “root myscript.C”, one has to provide the path to the script (absolute or relative, depending on where you are). Executable scripts have the advantage that they just need to be the PATH, and that the user doesn’t have to care in which language they are implemented.
In ROOT-5, this was possible, after a fashion, as CINT was lax enough to tolerate a line starting with “#” at the beginning of a script. Given a executable shell script “root-batch” (on PATH) like this
#!/bin/bash
exec root -l -b -q "$@"
one could make an executable CINT script (mode 755) hello.C like this
#!/usr/bin/env root-batch
{
cout << "Hello, World!" << endl;
}
and directly run it on the shell:
$ hello.C
The script “root-batch” is necessary because env only allows one parameter, and we’d like to call ROOT with the options “-l -b -q”.
Fortunately in general, but unfortunately in this case, Cling is a lot more precise when it comes to input validity, and doesn’t accept a “#!..” line at the top of a script. However, maybe this could be changed, as a special case during parsing?
Currently, many experiments use python scripts for such glue code. However, with ROOT6/Cling we now have powerful and fast true C++(98/11) scripting available that in some cases may be preferable:
- Only one language to deal with
- Template support
- Superior speed, allowing for time-critical operations in scripts
One other thing that is missing to make this work for non-trivial use cases is the ability to pass command line arguments to the script. A possible solution would be for ROOT6/Cling to support a “–” command line option (like some other programs) and pass all arguments after the “–” through to the script. The arguments could be made available in global argc/argv variables. Even more C+±like, Cling could supports scripts with a “main(argc, argv)” function.