I have a class derived from TSelector, and I am trying to instantiate it with GetSelector(), and then call some initalization methods before calling TChain->Process(). I am attempting to compile everything within root (i.e. root -b -q run.C+).
However, when I use this method to change myAnalysis->testvar = 10, it “works” (in run.C I can show that it changed), but when TTree->Process(mySelector) is called, my debug output shows that testvar is now at its default value of 3.
// chose compilation options
if ( !compileAll(“Ok”) ) {
std::cout << “ERROR: Problem compiling and/or loading code. Not running analysis.” << std::endl;
return;
}
// Instantiate TSelector object and try to set some methods
MyAnalysis * myAnalysis = (MyAnalysis*) TSelector::GetSelector(“MyAnalysis.C+O”);
myAnalysis->testvar = 10;
Here is an example, it should work on any tree you have lying around, because it doesn’t access any branches at all. (if you change the filename, of course). You have to run with the + option.
It is interesting that the address changes between the constructor and the pointer accessed in run_dummy.C. Here is the output:
root [0]
Processing run_dummy.C+…
Info in TUnixSystem::ACLiC: creating shared library /Users/ameade/workarea/newAnalysis/dummy/./run_dummy_C.so
In constructor
This = 0x27cd210
Testvar in constructor: -999
In Macro after GetSelector
This = 0x27cd280
Testvar before Process: 10
Due to an over-sight, when you useTSelector::GetSelector("MyAnalysis.C+O"); where you use the prefix +O, TSelector::GetSelector returns a TSelectorCint instead of directly returning your Selector. Until this oversight is fixed, you can use the following work around TSelector *sel = TSelector::GetSelector("dummy.C+O");
delete sel;
dummy * mydummy = (dummy*)TSelector::GetSelector("dummy.C+");
Here the problem is that you must insure that the static variable is not re-initialize which happens if (and whenever) the library is reloaded.
In the example I showed there is one reload. So instead you will need to use the underlying interface of ACLiC. So rather than “TSelector::GetSelector(“dummy.C+O”);” try:gSystem->CompileMacro("dummy.C","kOc"); // k: keep, O: optimize, c: compile only (do not load)
This didn’t seem to change the problem… I compiled as you suggested, changed MySelector::myVar, and the called Process(“MySelector.C+O”), and the value was not updated.
So the problem goes away if you compile the selector and just create it with new, in an interpreted “run” macro…
I’m very sorry I’m having trouble reproducing the problem in a simple context. I appreciate all your help. I’ll have to come back to this later though.