Give argument to function added using TExec?

Hi, I know this is probably a really basic question answered somewhere in the documentation, but I am really new to programming so I struggle to find the answer! :slight_smile:

I want to do something like this where the argument is just a vector:

TExec* ex = new TExec("ex", "function(argument);");

and my function would look something like:

void function(std::vector<std::string> argument)
{...

This is just to draw points of different colors based on the entries of a string vector. How do I pass these arguments along? Thank you.

Hi and welcome on the forum,

If you will define function so:

void func1(const std::vector<std::string> &argument) {
}

Then you can invoke it:

TExec* ex = new TExec("ex", "func1( { \"arg1\", \"arg2\",  \"arg3\" } );");

Regards,
Sergey

Thank you for your help! I think this is barking up the right tree, but I am still having some issues that I am not sure how to resolve. Here is how I used TExec:

TExec* exLV60 = new TExec("exLV60", "DrawCol(\"LV60_statusVector\");");

LV60_statusVector has already been initialized as std::vector<std::string>.

This is how I have defined my function:

void DrawCol(std::vector<std::string> &argument) 

I am not sure why I am getting the following warnings:

Welcome to the ROOT forum

Can you provide a small macro reproducing your problem ?

Hi,

Only global variable can be used at such call.
LV60_statusVector must be declared outside of function scope.
And you should remove quotes around variable name.
Macro test.C should look like:

std::vector<std::string> LV60_statusVector = { "one", "two", "three" };

void DrawCol(const std::vector<std::string> &argument) {
}

void test() {
   ...
   TExec* exLV60 = new TExec("exLV60", "DrawCol(LV60_statusVector);");
   ...
}

Regards,
Sergey